Prepare pinned partial emotion bundle gate and safe candidate packaging

This commit is contained in:
zenord
2026-10-13 03:22:55 +08:00
parent 515d106da7
commit fcc55b8370
6 changed files with 504 additions and 30 deletions
+36 -10
View File
@@ -34,17 +34,19 @@ suites = [
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--suite', choices=[name for name, _, _ in suites])
parser.add_argument('--runtime-manifest',type=Path,help='Additionally exercise real continuous parser with actual offline manifest metadata')
parser.add_argument('--index-manifest',type=Path,help='Additionally admit an exact offline v2 index and each referenced runtime through production parsers; no activation')
args = parser.parse_args()
if args.index_manifest and args.runtime_manifest: parser.error('Choose runtime or index manifest, not both')
for name, main, real in suites:
if args.suite and name != args.suite: continue
with tempfile.TemporaryDirectory(prefix=f'lan-voice-{name}-') as out:
files = list((ROOT/'tests'/name).glob('*.kt')) + real
if name == 'avatar' and args.runtime_manifest:
if name == 'avatar' and (args.runtime_manifest or args.index_manifest):
definitions=[]
def kotlin(value):
if value is None: return 'null'
if isinstance(value,bool): return str(value).lower()
if isinstance(value,str): return json.dumps(value,ensure_ascii=False).replace('$','\\$')
if isinstance(value,str): return json.dumps(value,ensure_ascii=False).replace('$',chr(92)+'$')
if isinstance(value,int): return str(value)+'L'
if isinstance(value,float): return repr(value)
if isinstance(value,(list,dict)):
@@ -58,17 +60,41 @@ for name, main, real in suites:
return method+'()'
raise TypeError(type(value))
import hashlib
raw=args.runtime_manifest.read_bytes();digest=hashlib.sha256(raw).hexdigest()
extra=Path(out)/'ActualRuntimeCheck.kt'
literal=kotlin(json.loads(raw))
extra.write_text('import com.gorios.lanvoice.avatar.*\n'+''.join(definitions)+'fun main() {\nval root='+literal+'\n'+
'val pack=checkNotNull(ContinuousAvatarManifest.read(root,"'+digest+'","'+digest+'",true,"runtime/"))\n'+
'check(pack.patches.size==pack.body.frameCount && pack.curves.size==5)\n'+
('check(pack.apertureMode && pack.textureImages.size==pack.body.frameCount*5 && pack.patches.all { it.levels.size==5 })\n' if json.loads(raw)['packId'].endswith('runtime-04') else 'check(!pack.apertureMode && pack.textureImages.size==pack.body.frameCount)\n')+
'println("PASS: actual exported runtime manifest parsed by production Kotlin, exact hash '+digest+'; per-body actual frame count/PTS and five authored curves/routing")\n}\n')
if args.runtime_manifest:
raw=args.runtime_manifest.read_bytes();digest=hashlib.sha256(raw).hexdigest()
extra=Path(out)/'ActualRuntimeCheck.kt'
literal=kotlin(json.loads(raw))
extra.write_text('import com.gorios.lanvoice.avatar.*\n'+''.join(definitions)+'fun main() {\nval root='+literal+'\n'+
'val pack=checkNotNull(ContinuousAvatarManifest.read(root,"'+digest+'","'+digest+'",true,"runtime/"))\n'+
'check(pack.patches.size==pack.body.frameCount && pack.curves.size==5)\n'+
('check(pack.apertureMode && pack.textureImages.size==pack.body.frameCount*5 && pack.patches.all { it.levels.size==5 })\n' if json.loads(raw)['packId'].endswith('runtime-04') else 'check(!pack.apertureMode && pack.textureImages.size==pack.body.frameCount)\n')+
'println("PASS: actual exported runtime manifest parsed by production Kotlin, exact hash '+digest+'; per-body actual frame count/PTS and five authored curves/routing")\n}\n')
else:
index_path=args.index_manifest.resolve(strict=True)
raw=index_path.read_bytes();digest=hashlib.sha256(raw).hexdigest()
data=json.loads(raw);runtimes={};hashes={}
for row in data['conversationPackages']:
reference=row['runtimeManifest'];path=reference['path']
runtime_path=(index_path.parent/path).resolve(strict=True)
if not runtime_path.is_relative_to(index_path.parent): raise ValueError('Runtime path escape')
runtime_raw=runtime_path.read_bytes();runtime_hash=hashlib.sha256(runtime_raw).hexdigest()
if runtime_hash!=reference['sha256']: raise ValueError('Runtime hash drift')
runtimes[path]=json.loads(runtime_raw);hashes[path]=runtime_hash
index_literal=kotlin(data);runtime_literal=kotlin(runtimes);hash_literal=kotlin(hashes)
extra=Path(out)/'ActualIndexCheck.kt'
extra.write_text('import com.gorios.lanvoice.avatar.*\n'+''.join(definitions)+
'fun main() {\nval root='+index_literal+'\nval runtimes='+runtime_literal+'\nval hashes='+hash_literal+'\n'+
'val index=checkNotNull(EmotionActionManifest.read(root,"'+digest+'","'+digest+'","fixture/") { path,hash ->\n'+
'check(hashes[path]==hash)\n@Suppress("UNCHECKED_CAST")\n'+
'ContinuousAvatarManifest.read(runtimes[path] as Map<String,Any?>,hash,hash,true,"fixture/"+path.substringBeforeLast(47.toChar())+"/")\n})\n'+
'check(index.packages.values.all { it.textureImages.size==it.body.frameCount*5 })\n'+
('check(index.actionPack==null)\n' if not data['actions'] else 'check(index.actionPack?.assets?.size==2)\n')+
'println("PASS: actual exported v2 index parsed by production Kotlin, exact hash '+digest+'; packages="+index.packages.size+" rgbaBytes="+index.packages.values.sumOf { it.rgbaBytes }+" danceAvailable="+(index.actionPack!=null))\n}\n')
files.append(extra)
subprocess.run([JAVA,'-cp',compiler,'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler','-no-stdlib',
'-no-reflect','-jvm-target','17','-nowarn','-classpath',cp,'-d',out, *map(str,files)],check=True,cwd=ROOT)
subprocess.run([JAVA,'-cp',out+':'+cp,main],check=True,cwd=ROOT,timeout=30)
if name == 'avatar' and args.runtime_manifest:
subprocess.run([JAVA,'-cp',out+':'+cp,'ActualRuntimeCheckKt'],check=True,cwd=ROOT,timeout=30)
if name == 'avatar' and args.index_manifest:
subprocess.run([JAVA,'-cp',out+':'+cp,'ActualIndexCheckKt'],check=True,cwd=ROOT,timeout=30)