Support bridge-owned TALK layers and recover free P4a candidate

This commit is contained in:
zenord
2026-10-13 04:35:33 +08:00
parent fcc55b8370
commit a53600db92
22 changed files with 18696 additions and 43 deletions
+58 -6
View File
@@ -87,14 +87,16 @@ def check_bundle(manifest,expected,output):
files[name]=row
require(sum(f['bytes'] for f in files.values())<=512_000_000,'bundle byte bound')
return p
for row in rows:
ref=row['runtimeManifest'];path=add(ref['path'],ref['sha256'],2_000_000)
references=[(row['id'],row['runtimeManifest']) for row in rows]
references += [('bridge:'+edge['id'],edge['mouthRuntimeManifest']) for edge in index['edges'] if 'mouthRuntimeManifest' in edge]
for runtime_id,ref in references:
path=add(ref['path'],ref['sha256'],2_000_000)
evidence,verified=runtime_gate.check_runtime(path,ref['sha256'],kotlin=False)
m=read_json(path);prefix=PurePosixPath(ref['path']).parent
for name,digest in verified.items(): add(str(prefix/name),digest,64_000_000 if name.endswith('.mp4') else 256_000)
body=m['body'];measurements[str(prefix/body['path'])]={'ptsUs':body['ptsUs'] if m['schemaVersion']==2 else [i*1_000_000//24 for i in range(body['frameCount'])],
'durationUs':body['durationUs'],'fps':Fraction(body['fpsNumerator'],body['fpsDenominator'])}
runtimes.append({'package_id':row['id'],**evidence})
runtimes.append({'package_id':runtime_id,**evidence})
rgba=sum(r['rgba_cache_bytes'] for r in runtimes);require(rgba<=32_000_000,'combined runtime cache bound')
require(len(index['edges'])<=100,'edge count bound')
for edge in index['edges']:
@@ -149,6 +151,45 @@ def import_files(root,files,target):
finally: os.unlink(tmp)
def replace_known_import(root,files,target,previous_report,previous_pin,backup):
"""Replace only a completely verified code-owned previous import; retain rollback."""
require(re.fullmatch('[0-9a-f]{64}',previous_pin or ''),'previous exact pin required')
require(not target.is_symlink() and target.is_dir(),'previous target directory')
old=read_json(previous_report)
require(old['status']=='passed' and old['manifest_sha256']==previous_pin,'previous report pin mismatch')
previous_manifest=target/'manifest.json'
require(file_sha(previous_manifest)==previous_pin,'previous import index drift')
inventory=read_json(previous_manifest)['files']
if isinstance(inventory,dict): inventory=[dict(row,path=name) for name,row in inventory.items()]
known={relative(row['path']):{'sha256':row['sha256'],'bytes':row['bytes']} for row in inventory}
known['manifest.json']={'sha256':previous_pin,'bytes':previous_manifest.stat().st_size}
previous=old['files']
require(all(known.get(relative(name))==row for name,row in previous.items()),'previous report not bound to pinned inventory')
require(not any(p.is_symlink() for p in target.rglob('*')),'previous import symlink preserved')
actual={str(p.relative_to(target)) for p in target.rglob('*') if p.is_file()}
require(actual==set(previous),'unknown import files preserved')
def verify_previous():
for name,row in previous.items():
p=locate(target,name)
require(p.stat().st_size==row['bytes'] and file_sha(p)==row['sha256'],'previous import bytes drift: '+name)
verify_previous()
require(not backup.exists() and not backup.is_symlink() and not backup.resolve().is_relative_to(target.resolve()),'new external backup required')
require(not backup.resolve().is_relative_to(root.resolve()),'backup must not modify asset owner directory')
target.parent.mkdir(parents=True,exist_ok=True)
staging=Path(tempfile.mkdtemp(prefix='.emotion-stage-',dir=target.parent))
try:
import_files(root,files,staging)
verify_previous()
backup.parent.mkdir(parents=True,exist_ok=True)
os.rename(target,backup)
try: os.rename(staging,target)
except BaseException:
os.rename(backup,target);raise
finally:
if staging.exists(): shutil.rmtree(staging)
def badging(path):
return subprocess.check_output([str(TOOLS/'aapt'),'dump','badging',str(path)],text=True,stderr=subprocess.STDOUT)
@@ -162,7 +203,7 @@ def tested_source():
client=json.loads((ROOT/'logs/avatar-safe-061/client-tests.json').read_text())
require(client['status']=='passed' and client['jvm_entry_points']==9,'client regression evidence')
for name,digest in client['hashes'].items(): require(file_sha(ROOT/name)==digest,'untested source: '+name)
evidence=json.loads((ROOT/'logs/action-emotion/media-wiring/delivery.json').read_text())
evidence=json.loads((ROOT/'logs/action-emotion/bridge-talk/delivery.json').read_text())
require(evidence['gateway_passed']==97 and evidence['gateway_skipped']==1 and evidence['offline_gles_goldens']==40,'gateway/GLES evidence')
for name,digest in evidence['source_hashes'].items():
if name.startswith('app/'): require(file_sha(ROOT/name)==digest,'media evidence drift: '+name)
@@ -175,6 +216,8 @@ def packaging_tests_current():
def publish(report,output,requested):
require(all(edge.get('nativeLoop') is True or 'mouthRuntimeManifest' in edge for edge in read_json(ROOT/'app/src/main/assets'/ASSET_ROOT/'manifest.json')['edges']),
'live emotion release needs bridge-own TALK runtimes')
tested_source();packaging_tests_current();require(file_sha(ROLLBACK)==ROLLBACK_SHA,'rollback drift')
version=next_version((ROOT/'artifacts').glob('*.apk'))
if requested is not None:
@@ -183,7 +226,7 @@ def publish(report,output,requested):
'-PavatarNatural=true','-PavatarMouthCandidate=true','-PnaturalManifestSha='+LEGACY_PIN,
'-PemotionManifestSha='+report['manifest_sha256'],'-PactionVersionCode='+str(version)],check=True,cwd=ROOT)
built=ROOT/'app/build/outputs/apk/debug/app-debug.apk';badge=badging(built)
for text in ("name='com.gorios.lanvoice'",f"versionCode='{version}'","versionName='0.7.0-stage-dev'","sdkVersion:'26'","targetSdkVersion:'34'"):
for text in ("name='com.gorios.lanvoice'",f"versionCode='{version}'","versionName='0.7.0-emotion-stage-dev'","sdkVersion:'26'","targetSdkVersion:'34'"):
require(text in badge,'APK metadata: '+text)
require(re.search(r'^native-code: (.+)$',badge,re.M)[1].strip()=="'arm64-v8a'",'APK ABI')
cert=subprocess.check_output([str(TOOLS/'apksigner'),'verify','--verbose','--print-certs',str(built)],text=True)
@@ -221,6 +264,9 @@ def main():
parser.add_argument('--output',type=Path,required=True,help='New evidence directory outside owner storage')
parser.add_argument('--pi-pin',help='External exact Pi pin, required for import/publish')
mode=parser.add_mutually_exclusive_group();mode.add_argument('--import-only',action='store_true');mode.add_argument('--publish',action='store_true')
parser.add_argument('--previous-import-report',type=Path,help='Verified previous bundle-gate.json; requires --previous-pin and fresh backup')
parser.add_argument('--previous-pin')
parser.add_argument('--backup',type=Path)
parser.add_argument('--version-code',type=int,help='Default max existing APK code+1, minimum17')
args=parser.parse_args();manifest=args.manifest.resolve(strict=True);output=args.output.resolve()
require(not output.exists() and not output.is_relative_to(manifest.parent),'new evidence outside owner root required')
@@ -228,7 +274,13 @@ def main():
output.mkdir(parents=True)
report=check_bundle(manifest,args.sha256,output)
if args.import_only or args.publish:
import_files(manifest.parent,report['files'],ROOT/'app/src/main/assets'/ASSET_ROOT)
target=ROOT/'app/src/main/assets'/ASSET_ROOT
if args.previous_import_report:
require(args.previous_pin and args.backup,'previous replacement requires exact pin and backup')
replace_known_import(manifest.parent,report['files'],target,args.previous_import_report,args.previous_pin,args.backup)
else:
require(not args.previous_pin and not args.backup,'previous import report required')
import_files(manifest.parent,report['files'],target)
(output/'import.json').write_text(json.dumps({'externally_pinned_sha256':args.pi_pin,'files':len(report['files']),'naturalness':'not_certified'})+'\n')
result=publish(report,output,args.version_code) if args.publish else {k:v for k,v in report.items() if k!='files'}
print(json.dumps(result,indent=2))