Files
baji-vc/tests/avatar/SafePlannerCheck.kt
T
zenord 9ea5eb31c1 feat: deliver clean avatar home in 0.6.2 UI debug candidate
Keep the avatar mounted while all connection, permission, privacy and diagnostic controls live in a settings sheet. Save the tested continuous-body renderer, safe transition driver and foreground HELLO/permission workflow from this session. Pin runtime03 for the code14 UI-only candidate; mouth deformation remains unresolved. Add source UI contracts, an optional sensor-free device probe, exact asset import and candidate packaging checks. Portrait binaries and diagnostics remain private and untracked.
2026-10-12 22:19:56 +08:00

118 lines
9.0 KiB
Kotlin

import com.gorios.lanvoice.avatar.*
private val approved = AnchorReview.APPROVED
// Entirely synthetic, 20fps/1s fixture. No real avatar annotations or approval claims.
fun syntheticGraph(): SafeAvatarGraph {
val anchors = listOf(VisualAnchor("closed",true,approved),VisualAnchor("open",false,approved)).associateBy { it.id }
fun interval(id: String,anchor: String,start: Long,end: Long) = AnchorInterval(id,anchor,start,end,(start/50).toInt(),(end/50).toInt(),approved)
fun clip(id: String,role: SafeClipRole,entry: String,exit: String) = SafeAvatarClip(id,"videos/$id.mp4",role,1000,20,20,1,
listOf(interval("entry",entry,0,100)),listOf(interval("exit",exit,800,900)),approved,
loop=role in setOf(SafeClipRole.IDLE,SafeClipRole.TALK),loopSeamReview=approved,seekReview=approved,
mouthStateWindows=listOf(MouthStateWindow(if (entry == "closed") ReviewedMouthState.CLOSED_STABLE else ReviewedMouthState.ACTIVE,
0,100,0,2,approved)))
val clips = listOf(clip("idle",SafeClipRole.IDLE,"closed","closed"),clip("opening",SafeClipRole.OPENING,"closed","open"),
clip("talk",SafeClipRole.TALK,"open","open"),clip("closing",SafeClipRole.CLOSING,"open","closed"),
clip("waiting",SafeClipRole.WAITING,"closed","closed")).associateBy { it.id }
fun edge(from: String,to: String) = SafeAvatarEdge("${from}_$to",from,"exit",to,"entry",approved,latestWaitMs=100)
return SafeAvatarGraph(clips,anchors,listOf(edge("idle","opening"),edge("opening","talk"),edge("talk","closing"),
edge("closing","idle"),edge("idle","waiting")),"idle","entry",approved)
}
private class Driver(val graph: SafeAvatarGraph = syntheticGraph(), initial: String = "idle") {
val planner = SafeTransitionPlanner(graph,initial)
private var serial=0L
fun observation(position: Long,now: Long=position,loop: Long=0) =
ClipObservation(planner.snapshot(now).actualClip,position,(position/50).toInt(),loop,++serial,now)
fun tick(position: Long,now: Long=position,loop: Long=0) = planner.tick(observation(position,now,loop),now)
fun stage(position: Long=100,now: Long=100): TransitionAction.Stage = tick(position,now).single() as TransitionAction.Stage
fun ready(stage: TransitionAction.Stage, position: Long=0) = StagedFrame(stage.ticket,position,(position/50).toInt(),true,true,true)
fun cut(stage: TransitionAction.Stage,now: Long): TransitionAction.Reveal {
check(planner.targetReady(ready(stage)))
val offer = tick(820,now).single() as TransitionAction.OfferCut
return planner.commit(offer.ticket,observation(830,now+10),ready(stage),now+10).single() as TransitionAction.Reveal
}
}
fun checkSafePlanner() {
val d=Driver(); val p=d.planner
check(p.request(MouthIntent(1,1,42,SafeClipRole.TALK),0).isEmpty())
check(p.snapshot(10).actualRole == SafeClipRole.IDLE)
val stage=d.stage()
for (bad in listOf(d.ready(stage).copy(paused=false),d.ready(stage).copy(seekComplete=false),
d.ready(stage).copy(textureReady=false),d.ready(stage,150))) check(!p.targetReady(bad))
check(d.tick(820).single() == TransitionAction.Hold(TransitionReason.TARGET_NOT_READY))
check(p.targetReady(d.ready(stage)))
val late=d.tick(830).single() as TransitionAction.OfferCut
check(p.commit(late.ticket,d.observation(910,910),d.ready(stage),910).single() is TransitionAction.Hold)
check(p.snapshot(910).actualClip == "idle")
check(d.tick(920).single() == TransitionAction.Hold(TransitionReason.WAIT_BUDGET_EXCEEDED))
// Expired offer cannot reveal; next approved wrap permits a fresh offer.
val wrap=d.tick(820,1820,1).single() as TransitionAction.OfferCut
check(p.commit(wrap.ticket,d.observation(830,1830,1),d.ready(stage),1830).single() is TransitionAction.Reveal)
check(p.snapshot(1830).actualClip == "opening")
// Visible bridge finishes on approved graph edges using the latest desired idle.
p.request(MouthIntent(2,1,null,SafeClipRole.IDLE,VisualIntentReason.ABORT),1840)
val bridge=d.stage(100,1900); check(bridge.ticket.target == "talk")
d.cut(bridge,2000)
check(p.snapshot(2010).desired == SafeClipRole.IDLE) // callback never restores old talk intent
val closing=d.stage(100,2100); check(closing.ticket.target == "closing"); d.cut(closing,2200)
val idle=d.stage(100,2300); d.cut(idle,2400)
check(p.snapshot(2410).actualRole == SafeClipRole.IDLE && p.snapshot(2410).closedMouthLagMs == 570L)
val staleIntent=p.request(MouthIntent(1,9,42,SafeClipRole.TALK),2500)
check(staleIntent.single() == TransitionAction.Hold(TransitionReason.OLD_INTENT))
p.request(MouthIntent(2,2,null,SafeClipRole.WAITING,VisualIntentReason.HANGUP),2500)
check(p.snapshot(2600).exitPending)
val waiting=d.stage(100,2600); d.cut(waiting,2700)
check(!p.snapshot(2710).exitPending)
check(p.background().last() == TransitionAction.Release)
check(!p.targetReady(d.ready(waiting)))
val startup=checkNotNull(p.stageForeground(3))
val startupFrame=d.ready(startup)
check(!p.foreground(3,"idle",startup.entry.copy(endMs=999),startupFrame,3000))
check(!p.foreground(3,"idle",startup.entry,startupFrame.copy(textureReady=false),3000))
check(p.foreground(3,"idle",startup.entry,startupFrame,3000))
check(!p.foreground(3,"idle",startup.entry,startupFrame,3001))
val reversal=Driver(); reversal.planner.request(MouthIntent(1,1,5,SafeClipRole.TALK),0)
val retired=reversal.stage(); reversal.planner.targetReady(reversal.ready(retired))
val offered=reversal.tick(820).single() as TransitionAction.OfferCut
check(reversal.planner.request(MouthIntent(1,2,5,SafeClipRole.IDLE),825).single() is TransitionAction.Cancel)
check(!reversal.planner.targetReady(reversal.ready(retired)))
check(reversal.planner.commit(offered.ticket,reversal.observation(830),reversal.ready(retired),830).single() is TransitionAction.Hold)
check(reversal.planner.request(MouthIntent(1,3,6,SafeClipRole.TALK),840).single() == TransitionAction.Hold(TransitionReason.OLD_INTENT))
check(reversal.planner.request(MouthIntent(1,4,4,SafeClipRole.IDLE,VisualIntentReason.ABORT),841).single() == TransitionAction.Hold(TransitionReason.OLD_INTENT))
check(reversal.planner.snapshot(840).actualRole == SafeClipRole.IDLE)
val g=syntheticGraph()
val noEdge=Driver(g.copy(edges=emptyList()),"talk")
noEdge.planner.request(MouthIntent(1,1,null,SafeClipRole.IDLE,VisualIntentReason.DISCONNECT),0)
check(noEdge.tick(100).single() == TransitionAction.Hold(TransitionReason.NO_REVIEWED_EDGE))
check(noEdge.planner.snapshot(5000).visualWaitMs == 5000L)
val unreviewed=Driver(g.copy(clips=g.clips + ("idle" to g.clips.getValue("idle").copy(loopSeamReview=AnchorReview.PENDING))))
unreviewed.planner.request(MouthIntent(1,1,5,SafeClipRole.TALK),0)
check(unreviewed.tick(100,1100,1).single() == TransitionAction.Hold(TransitionReason.LOOP_UNREVIEWED))
val held=Driver(g.copy(edges=g.edges.map { it.copy(missedWindowPolicy=MissedWindowPolicy.HOLD) }))
held.planner.request(MouthIntent(1,1,5,SafeClipRole.TALK),0)
val hs=held.stage(); held.planner.targetReady(held.ready(hs))
check(held.tick(950).single() is TransitionAction.Hold)
check(held.tick(820,1820,1).single() == TransitionAction.Hold(TransitionReason.WINDOW_MISSED))
val stale=Driver(); stale.planner.request(MouthIntent(1,1,5,SafeClipRole.TALK),0)
check(stale.planner.tick(stale.observation(100,100).copy(continuous=false),100).single() == TransitionAction.Hold(TransitionReason.STALE_POSITION))
check(stale.planner.tick(stale.observation(100,100),141).single() == TransitionAction.Hold(TransitionReason.STALE_POSITION))
val eos=Driver(); eos.planner.request(MouthIntent(1,1,5,SafeClipRole.TALK),0)
val es=eos.stage(); eos.planner.targetReady(eos.ready(es))
val eo=eos.tick(820).single() as TransitionAction.OfferCut
check(eos.planner.commit(eo.ticket,eos.observation(830).copy(ended=true),eos.ready(es),830).single() == TransitionAction.Hold(TransitionReason.LATE_CUT))
check(eos.planner.tick(eos.observation(850).copy(ended=true),850).single() == TransitionAction.Hold(TransitionReason.WINDOW_MISSED))
val cursor=ActualClipCursor(); val clip=g.clips.getValue("idle")
check(cursor.observe(clip,950,19,100).continuous)
check(cursor.observe(clip,0,0,150).loop == 1L)
check(!cursor.observe(clip,500,10,1200).continuous) // may have missed a whole loop
cursor.reset(); cursor.observe(clip,500,10,0)
check(!cursor.observe(clip,450,9,20).continuous) // seek/jitter is not a seam
val diag=TransitionDiagnostics()
check(diag.summary(p.snapshot(4000),AssetEmotion(),4000)?.contains("wait_ms=") == true)
check(diag.summary(p.snapshot(4999),AssetEmotion(),4999) == null)
check(diag.summary(p.snapshot(5000),AssetEmotion(),5000) != null)
println("PASS: safe planner reviewed graph/bridge, paused seek+texture gate, fresh second sample, missed/late/noedge/unreviewed loop, latest intent/old turn, abort closing/hangup exit, background/new foreground, cursor continuity, bounded diagnostics; synthetic anchors only")
}