Wire legal idle variants and validate dance media offline
This commit is contained in:
@@ -12,6 +12,7 @@ fun main() {
|
||||
conversationPackageCheck()
|
||||
actualMediaViewCheck()
|
||||
mediaBoundaryCheck()
|
||||
idleVariantCheck()
|
||||
checkContinuous()
|
||||
checkEngineering()
|
||||
checkSafeDriver()
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import com.gorios.lanvoice.avatar.*
|
||||
import com.gorios.lanvoice.dialogue.RoleEmotion
|
||||
|
||||
/** Actual driver callbacks, synthetic bodies; no naturalness or device claim. */
|
||||
fun idleVariantCheck() {
|
||||
var checks=0
|
||||
class Port: CompositeMediaPort {
|
||||
lateinit var pack: ContinuousAvatarPack
|
||||
lateinit var frame: (BodyFrameKey,Boolean)->Unit
|
||||
lateinit var ended: ()->Unit
|
||||
var talking=false;var closed=false;var loop=false
|
||||
override fun prepare(pack: ContinuousAvatarPack,entryFrame: Int,mouth: Boolean,loop: Boolean,
|
||||
frame: (BodyFrameKey,Boolean)->Unit,ended: ()->Unit,failed: ()->Unit) {
|
||||
this.pack=pack;this.frame=frame;this.ended=ended;this.loop=loop
|
||||
}
|
||||
override fun advance() {}
|
||||
override fun mouth(talk: Boolean,generation: Long,revision: Long) { talking=talk }
|
||||
override fun close(released: ()->Unit) { closed=true;released() }
|
||||
fun emit(i: Int,ordinal: Long=0) { frame(BodyFrameKey(i,ordinal,pack.body.ptsUs[i]),!talking) }
|
||||
}
|
||||
val base=mediaFixtureIndex()
|
||||
val index=base.copy(actionPack=null,visuals=base.visuals.map {
|
||||
if(it.id=="neutral") it else it.copy(emotion=RoleEmotion.NEUTRAL)
|
||||
})
|
||||
val music=object: MusicMediaPort {
|
||||
override fun prepare(media: ActionMedia,ready: ()->Unit,firstFrame: ()->Unit,ended: ()->Unit,failed: ()->Unit) { error("No music") }
|
||||
override fun start() { error("No music") }
|
||||
override fun close(released: ()->Unit) { released() }
|
||||
}
|
||||
val ports=mutableListOf<Port>();val trace=mutableListOf<String>()
|
||||
val driver=ConversationMediaDriver(index,{ Port().also(ports::add) },music,{}, { phase,_->trace.add(phase) },chooseIdle={0})
|
||||
driver.beginTurn(7);driver.start();val fallback=ports.single()
|
||||
(0..95).forEach { fallback.emit(it) }
|
||||
check(ports.size==1);checks++ // No arbitrary phase departure.
|
||||
fallback.emit(96);check(ports.size==3 && trace.contains("idle_variant_queued"));checks++
|
||||
fun bridgeTo(target: Port,bridge: Port) {
|
||||
target.emit(0);bridge.emit(0)
|
||||
check(trace.last()=="bridge" && !bridge.loop);checks++
|
||||
(1 until bridge.pack.body.frameCount).forEach { bridge.emit(it) };bridge.ended()
|
||||
check(bridge.closed && driver.currentPackageId!=null);checks++
|
||||
}
|
||||
val idle1=ports[1];bridgeTo(idle1,ports[2])
|
||||
check(driver.currentPackageId=="happy" && driver.visualStatus=="neutral_idle_variant");checks++
|
||||
(1 until idle1.pack.body.frameCount).forEach { idle1.emit(it) }
|
||||
check(trace.contains("idle_variant_return_queued") && ports.size==5);checks++
|
||||
val returned=ports[3];bridgeTo(returned,ports[4])
|
||||
(1..96).forEach { returned.emit(it) }
|
||||
val idle2=ports[5];bridgeTo(idle2,ports[6])
|
||||
check(driver.currentPackageId=="sad");checks++ // Pick0 still excludes previous idle1.
|
||||
driver.intent(mediaReply(RoleEmotion.NEUTRAL),true)
|
||||
check(idle2.talking && ports.size==9);checks++ // Audio continues on current own body while returning.
|
||||
(1 until idle2.pack.body.frameCount).forEach { idle2.emit(it) }
|
||||
val speakingFallback=ports[7];bridgeTo(speakingFallback,ports[8])
|
||||
check(speakingFallback.talking);checks++
|
||||
(1..96).forEach { speakingFallback.emit(it) }
|
||||
check(ports.size==9);checks++ // No variation during active TALK.
|
||||
driver.stop {};val count=trace.size
|
||||
idle2.emit(0);ports[8].ended();check(trace.size==count && ports.all { it.closed });checks++
|
||||
|
||||
// Missing bridge mouth prevents idle activation even with valid own body layers.
|
||||
val noMouth=index.copy(edges=index.edges.map { if(it.nativeLoop) it else it.copy(mouthRuntime=null) })
|
||||
val guarded=mutableListOf<Port>()
|
||||
val other=ConversationMediaDriver(noMouth,{ Port().also(guarded::add) },music,{},chooseIdle={0})
|
||||
other.beginTurn(7);other.start();(0..96).forEach { guarded[0].emit(it) }
|
||||
check(guarded.size==1);checks++;other.stop {}
|
||||
// A retained happy/sad expression must not turn neutral when speech ends.
|
||||
val expressive=mutableListOf<Port>()
|
||||
val retained=ConversationMediaDriver(base,{ Port().also(expressive::add) },music,{},chooseIdle={0})
|
||||
retained.beginTurn(7);retained.start();retained.intent(mediaReply(RoleEmotion.HAPPY),false)
|
||||
(0..96).forEach { expressive[0].emit(it) };expressive[1].emit(0);expressive[2].emit(0)
|
||||
expressive[2].emit(1);expressive[2].emit(2);expressive[2].ended()
|
||||
(1..48).forEach { expressive[1].emit(it) }
|
||||
check(retained.currentPackageId=="happy" && expressive.size==3);checks++;retained.stop {}
|
||||
println("PASS: $checks idle variant driver assertions: complete cycle/legal own-mouth bridges, different N/fps, no consecutive repeat, TALK priority, release/late callbacks, expression retention; fixtures only")
|
||||
}
|
||||
@@ -138,6 +138,25 @@ fun actualMediaViewCheck() {
|
||||
check(statuses.size==before);cases++
|
||||
actionView.dispose();TestScheduler.advanceBy(100)
|
||||
}
|
||||
// New idle rows use the actual view/renderer/codec path and reviewed graph.
|
||||
reset()
|
||||
val idleIndex=mediaFixtureIndex().let { it.copy(actionPack=null,visuals=it.visuals.map { p->p.copy(emotion=RoleEmotion.NEUTRAL) }) }
|
||||
val (idleView,idleBinding,idleTrace)=rig(idleIndex)
|
||||
TestScheduler.advanceBy(3000)
|
||||
check(idleTrace.all { it.actual=="body_neutral" });cases++
|
||||
TestScheduler.until { idleBinding.currentPackageId in setOf("happy","sad") }
|
||||
val firstIdle=idleBinding.currentPackageId
|
||||
check(idleTrace.any { it.actual=="bridge" } && idleBinding.visualStatus=="neutral_idle_variant");cases++
|
||||
TestScheduler.until { idleBinding.currentPackageId=="neutral" }
|
||||
TestScheduler.until { idleBinding.currentPackageId in setOf("happy","sad") }
|
||||
check(idleBinding.currentPackageId!=firstIdle && idleTrace.none { it.actual=="media_failed" });cases++
|
||||
idleBinding.intent(mediaReply(RoleEmotion.NEUTRAL),true)
|
||||
TestScheduler.until { idleBinding.currentPackageId=="neutral" }
|
||||
val speechStart=idleTrace.size;TestScheduler.advanceBy(9000)
|
||||
check(idleTrace.drop(speechStart).all { it.actual=="body_neutral" });cases++
|
||||
val beforeDispose=idleTrace.size;idleView.dispose();TestScheduler.advanceBy(1000)
|
||||
check(idleTrace.size==beforeDispose && driverField.get(idleView)==null && CodecFixture.releases>=7);cases++
|
||||
|
||||
// Real renderer path over a25-frame own-mouth bridge, no loop or endpoint patches.
|
||||
reset()
|
||||
val ownBridge=dynamicPack(25,24,"f".repeat(64)).copy(root="bridge25/")
|
||||
|
||||
@@ -40,6 +40,10 @@ class PackageTests(unittest.TestCase):
|
||||
'bytes':(cls.source/'neutral'/name).stat().st_size} for name in names],
|
||||
'fixtureNotice':'Synthetic index declaration, ${noInterpolation}, not Pi review'}
|
||||
cls.manifest=cls.source/'manifest.json'
|
||||
cls.music=cls.source/'synthetic-music.mp4'
|
||||
subprocess.run(['/home/ubuntu/gori-bin/ffmpeg','-v','error','-f','lavfi','-i',
|
||||
'color=c=gray:s=480x848:r=24:d=1','-f','lavfi','-i','sine=frequency=440:sample_rate=48000:duration=1',
|
||||
'-c:v','libx264','-threads','1','-pix_fmt','yuv420p','-c:a','aac','-ac','2','-t','1',str(cls.music)],check=True)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls): cls.temp.cleanup()
|
||||
@@ -69,9 +73,52 @@ class PackageTests(unittest.TestCase):
|
||||
bad=copy.deepcopy(self.index);bad['files']=bad['files'][1:]
|
||||
with self.assertRaisesRegex(ValueError,'inventory missing'): self.gate(bad,'inventory-gate')
|
||||
|
||||
def test_no_dance_in_partial_packer(self):
|
||||
def test_incomplete_dance_set_rejected(self):
|
||||
bad=copy.deepcopy(self.index);bad['actions']=[{'id':'asset_01'}]
|
||||
with self.assertRaisesRegex(ValueError,'requires actions'): self.gate(bad,'action-gate')
|
||||
with self.assertRaisesRegex(ValueError,'actions require exactly'): self.gate(bad,'action-gate')
|
||||
|
||||
def dance_index(self):
|
||||
index=copy.deepcopy(self.index);measured=pack.probe_music_clip(self.music)
|
||||
clip={'path':self.music.name,'sha256':pack.file_sha(self.music),'width':480,'height':848,
|
||||
'hasAudio':True,'frameCount':len(measured['ptsUs']),'ptsUs':measured['ptsUs'],
|
||||
'durationUs':measured['durationUs'],'fpsNumerator':measured['fps'].numerator,'fpsDenominator':measured['fps'].denominator}
|
||||
index['actions']=[{'id':name,'kind':'dance','mouthAllowed':False,'disallowTALK':True,
|
||||
'entryAnchor':'A','returnAnchor':'A','sourcePackageId':'neutral','returnPackageId':'neutral',
|
||||
'sourceFrame':96,'sourcePtsUs':4_000_000,'returnFrame':0,'returnPtsUs':0,
|
||||
'audioEndUs':measured['audioEndUs'],'clip':clip,'reviewEvidence':'synthetic color+sine; no dance/naturalness claim'}
|
||||
for name in ('asset_01','asset_02')]
|
||||
index['files'].append({'path':self.music.name,'sha256':clip['sha256'],'bytes':self.music.stat().st_size})
|
||||
return index
|
||||
|
||||
def test_music_pcm_and_full_index_readonly(self):
|
||||
result=self.gate(self.dance_index(),'music-full-gate')
|
||||
self.assertEqual(result['action_count'],2);self.assertTrue(result['candidate_dance_validated'])
|
||||
self.assertFalse(result['dance_available'])
|
||||
for measured in result['action_measurements']:
|
||||
self.assertEqual(len(measured['ptsUs']),24)
|
||||
self.assertEqual(measured['audioEndUs'],1_000_000)
|
||||
self.assertGreater(measured['pcmFrames'],47000);self.assertGreater(measured['audioRms'],0)
|
||||
self.assertLess(measured['audioPeak'],1);self.assertEqual(measured['humanListening'],'not_run')
|
||||
|
||||
def test_music_actual_audio_end_mismatch(self):
|
||||
bad=self.dance_index();bad['actions'][0]['audioEndUs']-=1000
|
||||
with self.assertRaisesRegex(ValueError,'audioEndUs mismatch'): self.gate(bad,'music-end-gate')
|
||||
|
||||
def test_music_actual_video_pts_mismatch(self):
|
||||
bad=self.dance_index();bad['actions'][0]['clip']['ptsUs'][1]+=4
|
||||
with self.assertRaisesRegex(ValueError,'dance decoded PTS mismatch'): self.gate(bad,'music-pts-gate')
|
||||
|
||||
def test_music_silent_video_rejected(self):
|
||||
with self.assertRaisesRegex(ValueError,'exactly video.audio'):
|
||||
pack.probe_music_clip(self.source/'neutral'/self.runtime['body']['path'])
|
||||
|
||||
def test_dance_not_imported_by_readonly_gate(self):
|
||||
self.manifest.write_text(json.dumps(self.dance_index()));out=self.base/'dance-no-import'
|
||||
digest=pack.file_sha(self.manifest)
|
||||
result=subprocess.run([sys.executable,str(ROOT/'scripts/package-avatar-emotion.py'),
|
||||
'--manifest',str(self.manifest),'--sha256',digest,'--pi-pin',digest,'--output',str(out),'--import-only'],capture_output=True,text=True)
|
||||
self.assertNotEqual(result.returncode,0);self.assertIn('read-only gate supported',result.stderr)
|
||||
self.assertFalse(out.exists())
|
||||
|
||||
def test_paths(self):
|
||||
for name in ('../x','x/../y','x//y','/x','x/./y','https://host/x','x\\y'):
|
||||
|
||||
Reference in New Issue
Block a user