feat: validate per-body mouth timelines and reviewed conversation routes
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only Gate1 plus production Kotlin admission; never imports or approves assets."""
|
||||
import argparse
|
||||
from decimal import Decimal
|
||||
from fractions import Fraction
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from PIL import Image
|
||||
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
parser=argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--manifest',type=Path,required=True)
|
||||
parser.add_argument('--sha256',required=True,help='Exact candidate hash; this is not a publication approval')
|
||||
parser.add_argument('--output',type=Path,required=True,help='New evidence file outside owner asset directory')
|
||||
args=parser.parse_args()
|
||||
|
||||
def require(value,reason):
|
||||
if not value: raise ValueError(reason)
|
||||
|
||||
def main():
|
||||
source=args.manifest.resolve(strict=True);directory=source.parent
|
||||
output=args.output.resolve()
|
||||
require(not output.exists() and not output.is_relative_to(directory),'evidence must be new and outside owner directory')
|
||||
require(source.stat().st_size<=2_000_000,'manifest byte bound')
|
||||
raw=source.read_bytes();digest=hashlib.sha256(raw).hexdigest()
|
||||
require(re.fullmatch('[0-9a-f]{64}',args.sha256) and digest==args.sha256,'candidate manifest drift')
|
||||
def unique(pairs):
|
||||
result={}
|
||||
for key,value in pairs:
|
||||
require(key not in result,'duplicate manifest key');result[key]=value
|
||||
return result
|
||||
manifest=json.loads(raw,object_pairs_hook=unique)
|
||||
body=manifest['body'];count=body['frameCount']
|
||||
require(type(count) is int and 2<=count<=720,'body frame bound')
|
||||
dynamic=manifest['schemaVersion']==2
|
||||
require(dynamic or manifest['packId'] in ('a01-neutral-graph-v1-runtime-03','a01-neutral-graph-v1-runtime-04'),'new bodies require schema2')
|
||||
if dynamic:
|
||||
require(manifest['patchFormat']['bodySha256']==body['sha256'],'own-mouth body binding')
|
||||
verified={}
|
||||
def file(row,pattern,bound):
|
||||
name=row['path'];require(re.fullmatch(pattern,name),'asset path shape')
|
||||
path=(directory/name).resolve(strict=True)
|
||||
require(path.is_relative_to(directory),'asset path escape')
|
||||
require(path.stat().st_size<=bound,'asset file byte bound')
|
||||
sha=hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
require(sha==row['sha256'],'asset file hash mismatch')
|
||||
verified[name]=sha
|
||||
return path
|
||||
video=file(body,r'body/[A-Za-z0-9_.-]+\.mp4',64_000_000)
|
||||
probe=subprocess.run(['/home/ubuntu/miniconda3/envs/gori-speech/bin/ffprobe','-v','error','-show_streams','-show_frames','-of','json',str(video)],capture_output=True,check=True,timeout=60)
|
||||
decoded=json.loads(probe.stdout);streams=decoded['streams'];frames=decoded['frames']
|
||||
require(len(streams)==1 and streams[0]['codec_type']=='video' and body['hasAudio'] is False,'conversation must be silent video')
|
||||
stream=streams[0]
|
||||
require(stream['codec_name']=='h264' and (stream['width'],stream['height'])==(body['width'],body['height'])==(480,848),'codec/shape mismatch')
|
||||
require(Fraction(stream['r_frame_rate'])==Fraction(body['fpsNumerator'],body['fpsDenominator']),'measured nominal fps mismatch')
|
||||
require(len(frames)==count,'decoded actual N mismatch')
|
||||
pts=[int((Decimal(frame['best_effort_timestamp_time'])*1_000_000).to_integral_value()) for frame in frames]
|
||||
expected=body['ptsUs'] if dynamic else [i*1_000_000//24 for i in range(count)]
|
||||
require(len(expected)==count and all(abs(a-b)<=2 for a,b in zip(pts,expected)),'decoded actual PTS mismatch')
|
||||
duration=int((Decimal(stream['duration'])*1_000_000).to_integral_value())
|
||||
require(abs(duration-body['durationUs'])<=2,'decoded duration mismatch')
|
||||
subprocess.run(['/home/ubuntu/gori-bin/ffmpeg','-v','error','-xerror','-i',str(video),'-map','0:v:0','-f','null','-'],capture_output=True,check=True,timeout=60)
|
||||
patches=manifest['patches'];require(len(patches)==count,'N patches required')
|
||||
rgba=0;paths=[];aperture=manifest['packId'].endswith('runtime-04')
|
||||
for i,patch in enumerate(patches):
|
||||
require(patch['frameIndex']==i and abs(patch['ptsUs']-pts[i])<=2,'own-frame patch binding')
|
||||
if dynamic: require(patch['ptsUs']==expected[i],'schema2 exact patch PTS binding')
|
||||
width,height=patch['width'],patch['height']
|
||||
require(type(width) is int and type(height) is int and 1<=width<=128 and 1<=height<=128,'patch shape bound')
|
||||
levels=patch['levels'] if aperture else [patch]
|
||||
require(len(levels)==(5 if aperture else 1),'five own levels required')
|
||||
for level in levels:
|
||||
image=file(level,r'patches/[A-Za-z0-9_.-]+\.png',256_000);paths.append(level['path'])
|
||||
with Image.open(image) as bitmap:
|
||||
require(bitmap.format=='PNG' and bitmap.mode=='RGBA' and bitmap.size==(width,height),'decoded PNG RGBA/shape mismatch')
|
||||
bitmap.load()
|
||||
rgba+=width*height*4
|
||||
require(len(set(paths))==len(paths) and rgba<=8_000_000,'unique N levels/cache bound')
|
||||
result=subprocess.run([sys.executable,str(ROOT/'scripts/check-reply-regressions.py'),'--suite','avatar','--runtime-manifest',str(source)],capture_output=True,text=True,timeout=120)
|
||||
require(result.returncode==0,'production Kotlin admission failed (candidate format or metadata)')
|
||||
require('PASS: actual exported runtime manifest parsed' in result.stdout,'actual parser evidence absent')
|
||||
require(source.read_bytes()==raw,'manifest changed during gate')
|
||||
for name,sha in verified.items():
|
||||
require(hashlib.sha256((directory/name).read_bytes()).hexdigest()==sha,'asset changed during gate')
|
||||
evidence={'status':'passed','scope':'read_only_machine_gate_no_approval_no_activation','manifest_sha256':digest,
|
||||
'body_sha256':body['sha256'],'schema_version':manifest['schemaVersion'],'actual_frame_count':count,
|
||||
'actual_pts_count':len(pts),'actual_duration_us':duration,'patch_images':len(paths),'rgba_cache_bytes':rgba,
|
||||
'verified_files':len(verified),'full_decode':'passed','production_kotlin_parser':'passed','naturalness':'pending','real_device':'not_run'}
|
||||
output.parent.mkdir(parents=True,exist_ok=True)
|
||||
with output.open('x') as target: json.dump(evidence,target,indent=2);target.write('\n')
|
||||
print(json.dumps(evidence))
|
||||
|
||||
try: main()
|
||||
except (ValueError,KeyError,TypeError,OSError,subprocess.SubprocessError) as error:
|
||||
print('FAIL: runtime gate: '+str(error),file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
@@ -27,7 +27,7 @@ source = ROOT/'app/src/main/java/com/gorios/lanvoice'
|
||||
suites = [
|
||||
('session','ConnectionCheckKt', [source/'audio/PlaybackActivity.kt', source/'audio/VoiceSession.kt', source/'avatar/ActionController.kt', source/'dialogue/ReplyEmotion.kt', source/'net/DialogueClient.kt', source/'expression/FaceCueRules.kt', source/'expression/ExpressionRules.kt', source/'expression/FaceDiagnostics.kt']),
|
||||
('playback','PlaybackCheckKt', [source/'audio/AudioPlayback.kt', source/'audio/PlaybackActivity.kt']),
|
||||
('avatar','AvatarCheckKt', [source/'avatar/EmotionActionManifest.kt', source/'avatar/ActionController.kt', source/'avatar/RoleVisualSelection.kt', source/'avatar/ContinuousAvatarManifest.kt', source/'avatar/ContinuousMouth.kt', source/'avatar/ContinuousFramePresenter.kt', source/'avatar/ContinuousBodyRenderer.kt', source/'avatar/EngineeringGraphAdmission.kt', source/'avatar/OfflineAvatarTrace.kt', source/'avatar/NeutralGraphContract.kt', source/'avatar/SafeVideoDriver.kt', source/'avatar/CodecAnchorVideoPort.kt', source/'avatar/AutoConversation.kt', source/'avatar/SafeAvatarGraph.kt', source/'avatar/SafeTransitionPlanner.kt', source/'avatar/SafeAvatarManifest.kt', source/'avatar/TransitionDiagnostics.kt', source/'avatar/AvatarController.kt', source/'avatar/CallIntent.kt', source/'avatar/AvatarVideoView.kt', source/'audio/PlaybackActivity.kt', source/'dialogue/ReplyEmotion.kt']),
|
||||
('avatar','AvatarCheckKt', [source/'avatar/ConversationPackagePlanner.kt', source/'avatar/EmotionActionManifest.kt', source/'avatar/ActionController.kt', source/'avatar/RoleVisualSelection.kt', source/'avatar/ContinuousAvatarManifest.kt', source/'avatar/ContinuousMouth.kt', source/'avatar/ContinuousFramePresenter.kt', source/'avatar/ContinuousBodyRenderer.kt', source/'avatar/EngineeringGraphAdmission.kt', source/'avatar/OfflineAvatarTrace.kt', source/'avatar/NeutralGraphContract.kt', source/'avatar/SafeVideoDriver.kt', source/'avatar/CodecAnchorVideoPort.kt', source/'avatar/AutoConversation.kt', source/'avatar/SafeAvatarGraph.kt', source/'avatar/SafeTransitionPlanner.kt', source/'avatar/SafeAvatarManifest.kt', source/'avatar/TransitionDiagnostics.kt', source/'avatar/AvatarController.kt', source/'avatar/CallIntent.kt', source/'avatar/AvatarVideoView.kt', source/'audio/PlaybackActivity.kt', source/'dialogue/ReplyEmotion.kt']),
|
||||
('capture','CaptureCheckKt', [source/'audio/AudioCapture.kt']),
|
||||
('protocol','ProtocolCheckKt', [source/'avatar/ActionController.kt', source/'net/DialogueProtocol.kt', source/'dialogue/ReplyEmotion.kt', source/'expression/FaceCueRules.kt', source/'expression/ExpressionRules.kt']),
|
||||
]
|
||||
@@ -50,7 +50,7 @@ for name, main, real in suites:
|
||||
if isinstance(value,(list,dict)):
|
||||
result=('listOf<Any?>('+','.join(map(kotlin,value))+')' if isinstance(value,list) else
|
||||
'mapOf<String,Any?>('+','.join(kotlin(k)+' to '+kotlin(v) for k,v in value.items())+')')
|
||||
# Actual97x5 metadata exceeds a single JVM method. Preserve every
|
||||
# Actual N×5 metadata can exceed a single JVM method. Preserve every
|
||||
# field while splitting literal construction into bounded helpers.
|
||||
method='metadata'+str(len(definitions))
|
||||
kind='List<Any?>' if isinstance(value,list) else 'Map<String,Any?>'
|
||||
@@ -63,9 +63,9 @@ for name, main, real in suites:
|
||||
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==97 && pack.body.frameCount==97 && pack.curves.size==5)\n'+
|
||||
('check(pack.apertureMode && pack.textureImages.size==485 && pack.patches.all { it.levels.size==5 })\n' if json.loads(raw)['packId'].endswith('runtime-04') else 'check(!pack.apertureMode && pack.textureImages.size==97)\n')+
|
||||
'println("PASS: actual exported runtime manifest parsed by production Kotlin, exact hash '+digest+'; 97 body/patch frames and five authored curves/routing")\n}\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')
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user