feat: validate per-body mouth timelines and reviewed conversation routes

This commit is contained in:
zenord
2026-10-13 01:23:43 +08:00
parent 4358fc9cae
commit 4ead34a944
17 changed files with 646 additions and 61 deletions
+2
View File
@@ -6,8 +6,10 @@ import android.media.MediaPlayer
import android.view.TextureView
fun main() {
dynamicBodyCheck()
actionCheck()
emotionActionCheck()
conversationPackageCheck()
checkContinuous()
checkEngineering()
checkSafeDriver()
+88
View File
@@ -0,0 +1,88 @@
import com.gorios.lanvoice.avatar.*
import com.gorios.lanvoice.dialogue.RoleEmotion
/** Synthetic metadata invokes production admission/routing, never asset approval. */
@Suppress("UNCHECKED_CAST")
fun conversationPackageCheck() {
val pin="b".repeat(64)
val packs=linkedMapOf("neutral" to dynamicPack(97,24,"c".repeat(64)),
"happy" to dynamicPack(121,30,"d".repeat(64)),"sad" to dynamicPack(49,24,"e".repeat(64)))
fun row(id: String,pack: ContinuousAvatarPack)=mapOf<String,Any?>("id" to id,
"emotion" to if(id=="neutral") "neutral" else if(id=="sad") "sad" else "happy",
"visualIntensity" to if(id=="neutral") 0 else 1,"mouthBodySha256" to pack.body.sha256,
"runtimeManifest" to mapOf("path" to "$id/manifest.json","sha256" to pack.manifestSha),
"entryAnchor" to "A","exitAnchor" to "A","legalExitFrames" to listOf(pack.body.frameCount-1),"loopEdge" to "$id-loop")
val clip=mapOf<String,Any?>("path" to "clips/bridge.mp4","sha256" to pin,"hasAudio" to false,
"width" to 480,"height" to 848,"fpsNumerator" to 24,"fpsDenominator" to 1,
"frameCount" to 12,"ptsUs" to List(12) { it*1_000_000L/24 },"durationUs" to 500_000L)
fun edges(data: Map<String,ContinuousAvatarPack>): List<Map<String,Any?>> {
fun edge(id: String,from: String,to: String)=mapOf<String,Any?>("id" to id,"from" to from,"to" to to,
"fromAnchor" to "A","toAnchor" to "A","fromFrame" to data.getValue(from).body.frameCount-1,"toFrame" to 0,
"fromPtsUs" to data.getValue(from).body.ptsUs.last(),"toPtsUs" to 0L,"clip" to clip)
return data.keys.map { edge("$it-loop",it,it) }+data.keys.filter { it!="neutral" }.flatMap {
listOf(edge("neutral-$it","neutral",it),edge("$it-neutral",it,"neutral"))
}
}
fun root(data: Map<String,ContinuousAvatarPack>)=mapOf<String,Any?>("schemaVersion" to 2,"identityId" to "a01",
"packId" to "a01-expression-action-v1","fallbackPackageId" to "neutral",
"conversationPackages" to data.map { row(it.key,it.value) },"edges" to edges(data),"actions" to emptyList<Any>())
fun read(meta: Map<String,Any?>,data: Map<String,ContinuousAvatarPack> = packs)=EmotionActionManifest.read(meta,pin,pin) { path,hash ->
data[path.substringBefore('/')]?.takeIf { it.manifestSha==hash }
}
val meta=root(packs);val index=checkNotNull(read(meta))
check(index.packages.values.map { it.body.frameCount }==listOf(97,121,49) && index.actionPack==null)
check(index.edges.size==7 && index.edges.all { it.clip.ptsUs.size==12 && it.clip.sha256==pin })
val graph=edges(packs)
var rejected=0
fun invalid(change: Map<String,Any?>) { check(read(meta+change)==null);rejected++ }
invalid(mapOf("edges" to graph.filterNot { it["id"]=="sad-neutral" }))
for(change in listOf(mapOf("fromFrame" to 1),mapOf("fromPtsUs" to 99L),mapOf("toPtsUs" to 1L),
mapOf("toFrame" to 49),mapOf("clip" to clip+("hasAudio" to true)),
mapOf("clip" to clip+("frameCount" to 4_294_967_308L)),mapOf("clip" to clip+("fpsNumerator" to 4_294_967_320L)),
mapOf("clip" to clip+("path" to "../bridge.mp4")),mapOf("clip" to clip+("ptsUs" to listOf(0L))))) {
invalid(mapOf("edges" to listOf(graph[0]+change)+graph.drop(1)))
}
val rows=packs.map { row(it.key,it.value) }
for(change in listOf(mapOf("mouthBodySha256" to pin),mapOf("emotion" to "angry"),mapOf("emotion" to "curious"),
mapOf("visualIntensity" to 2))) invalid(mapOf("conversationPackages" to listOf(rows[0],rows[1]+change,rows[2])))
val largeRoot=dynamicRuntimeFixture(100,24,1,"f".repeat(64))
val largePatches=(largeRoot["patches"] as List<Map<String,Any?>>).map { it+mapOf("width" to 80,"height" to 44) }
val large=checkNotNull(ContinuousAvatarManifest.read(largeRoot+("patches" to largePatches),"f".repeat(64),"f".repeat(64),true,"large/"))
check(large.rgbaBytes<BodyTimeline.MAX_RGBA_BYTES)
val oversized=listOf("neutral","happy","sad","idle1","idle2").associateWith { large }
check(read(root(oversized),oversized)==null);rejected++
val planner=ConversationPackagePlanner(index)
planner.newTurn(10)
fun expression(emotion: RoleEmotion,seq: Long=1,intensity: Int=1)=PreparedExpression(10,seq,emotion,intensity)
check(planner.prepare(expression(RoleEmotion.HAPPY)) && planner.selected==null && planner.visiblePackage=="neutral")
check(!planner.prepare(expression(RoleEmotion.SAD)) && !planner.prepare(PreparedExpression(9,2,RoleEmotion.SAD,1)))
planner.cancelPrepare(9);check(planner.prepared!=null)
check(planner.commit(expression(RoleEmotion.SAD,2,2)) && planner.prepared==null)
check(planner.selected?.selectedEmotion==RoleEmotion.SAD && planner.selected?.selectedIntensity==2 &&
planner.selected?.visualIntensity==1 && planner.selected?.reason=="slight_only")
check(planner.nextEdge(1)==null)
val toSad=checkNotNull(planner.nextEdge(96));check(toSad.edge.to=="sad")
check(planner.nextEdge(96)==null && !planner.presented(toSad,1))
check(planner.presented(toSad,0) && !planner.presented(toSad,0) && planner.visiblePackage=="sad")
check(!planner.commit(expression(RoleEmotion.HAPPY,2)))
check(planner.commit(expression(RoleEmotion.HAPPY,3)))
check(planner.nextEdge(47)==null)
val returnA=checkNotNull(planner.nextEdge(48));check(returnA.edge.to=="neutral")
check(planner.presented(returnA,0) && planner.visiblePackage=="neutral")
val toHappy=checkNotNull(planner.nextEdge(96));check(toHappy.edge.to=="happy")
check(planner.presented(toHappy,0))
check(planner.commit(expression(RoleEmotion.SAD,4)))
val newerReturn=checkNotNull(planner.nextEdge(120))
check(!planner.presented(returnA,0) && planner.presented(newerReturn,0))
val newerSad=checkNotNull(planner.nextEdge(96))
check(!planner.presented(toSad,0) && planner.presented(newerSad,0))
check(planner.commit(expression(RoleEmotion.ANGRY,5,2)))
check(planner.selected?.selectedEmotion==RoleEmotion.ANGRY && planner.selected?.packageId=="neutral")
val oldTurn=checkNotNull(planner.nextEdge(48));planner.newTurn(11)
check(!planner.presented(oldTurn,0) && !planner.commit(expression(RoleEmotion.HAPPY,6)))
val noOwn=index.visuals.map { if(it.id=="happy") it.copy(mouthBodySha=null) else it }
val fallback=RoleVisualSelector.select(RoleEmotion.HAPPY,2,noOwn,"neutral")
check(fallback.selectedIntensity==2 && fallback.selectedEmotion==RoleEmotion.HAPPY && fallback.packageId=="neutral")
println("PASS: production multi-package97/121/49 admission, $rejected invalid graph/cache cases; preload-only/final-authority, slight/fallback, legal sad-neutral-happy bridges, duplicate serial and old-turn fences; no approved assets activated")
}
+101
View File
@@ -0,0 +1,101 @@
import com.gorios.lanvoice.avatar.*
import com.gorios.lanvoice.dialogue.RoleEmotion
import android.media.CodecFixture
import android.graphics.BitmapFactory
import android.graphics.SurfaceTexture
import android.view.Surface
import android.os.TestScheduler
import android.opengl.GLFixture
@Suppress("UNCHECKED_CAST")
fun dynamicRuntimeFixture(count: Int=121,fpsN: Int=30,fpsD: Int=1,sha: String="c".repeat(64)): Map<String,Any?> {
val old=continuousFixture()
val pts=List(count) { it*1_000_000L*fpsD/fpsN }
val base=(old["patches"] as List<Map<String,Any?>>).first()
val patches=pts.mapIndexed { i,t ->
val levels=List(5) { l -> mapOf<String,Any?>("levelIndex" to l,"aperture" to l/4f,"path" to "patches/f$i-l$l.png","sha256" to sha) }
base+mapOf("frameIndex" to i,"ptsUs" to t,"levels" to levels,"path" to levels[4]["path"],"sha256" to sha)
}
val states=(old["mouthStates"] as List<Map<String,Any?>>).map { state ->
val n=(state["globalAlphaByFrame"] as List<*>).size
state+("ptsUs" to List(n) { it*1_000_000L/24 })
}
return old+mapOf("schemaVersion" to 2,"packId" to "a01-expression-action-v1-test-runtime-04",
"body" to (old["body"] as Map<String,Any?>)+mapOf("sha256" to sha,"frameCount" to count,
"fpsNumerator" to fpsN,"fpsDenominator" to fpsD,"ptsUs" to pts,"durationUs" to (count*1_000_000L*fpsD+fpsN/2)/fpsN),
"patches" to patches,"mouthStates" to states,"patchFormat" to mapOf("bodySha256" to sha,
"format" to "PNG RGBA 8bit","alphaEncoding" to "straight_unassociated","apertureLevels" to listOf(0f,.25f,.5f,.75f,1f),"requiresRendererExtension" to true))
}
fun dynamicPack(count: Int,fps: Int,sha: String): ContinuousAvatarPack = checkNotNull(
ContinuousAvatarManifest.read(dynamicRuntimeFixture(count,fps,1,sha),sha,sha,true,"dynamic/"))
@Suppress("UNCHECKED_CAST")
fun dynamicBodyCheck() {
var boundaries=0
for((count,fpsN,fpsD) in listOf(Triple(121,30,1),Triple(49,24,1),Triple(61,30000,1001))) {
val sha="c".repeat(64);val root=dynamicRuntimeFixture(count,fpsN,fpsD,sha)
fun read(data: Map<String,Any?>)=ContinuousAvatarManifest.read(data,sha,sha,true,"fixture/")
val pack=checkNotNull(read(root));check(pack.body.frameCount==count && pack.textureImages.size==count*5)
val presenter=ContinuousFramePresenter(pack) { 0 }
repeat(2) { loop ->
for(i in 0 until count) {
val pts=pack.body.ptsUs[i];presenter.decoded(pts)
val frame=checkNotNull(presenter.present(pts*1000,loop*10000L+pts/1000) {})
check(frame.key.index==i && frame.patch.ptsUs==pts && frame.key.loopOrdinal==loop.toLong())
for(level in 0..4) {
val s=selectMouthPatch(pack,i,level/4f)
check(s.textureSlot==i*5+level && s.opacity==if(level==0) 0f else 1f)
boundaries++
}
}
presenter.wrap()
}
val body=root["body"] as Map<String,Any?>;val patches=root["patches"] as List<Map<String,Any?>>
fun invalid(data: Map<String,Any?>) { check(read(data)==null);boundaries++ }
invalid(root+("body" to body+("frameCount" to 97)))
invalid(root+("body" to body+("durationUs" to 100_000_000L)))
invalid(root+("body" to body+("fpsDenominator" to 0)))
invalid(root+("body" to body+("ptsUs" to pack.body.ptsUs.dropLast(1))))
invalid(root+("body" to body+("ptsUs" to listOf(1L)+pack.body.ptsUs.drop(1))))
invalid(root+("patches" to listOf(patches[0]+("ptsUs" to 1L))+patches.drop(1)))
invalid(root+("patches" to patches.dropLast(1)))
invalid(root+("patches" to patches.map { it+mapOf("width" to 128,"height" to 128) }))
invalid(root+("patchFormat" to (root["patchFormat"] as Map<String,Any?>)+("bodySha256" to "b".repeat(64))))
invalid(root+("schemaVersion" to 1))
invalid(root+("body" to body+("frameCount" to 721)))
invalid(root+("body" to body+("frameCount" to 4_294_967_417L)))
invalid(root+("body" to body+("fpsNumerator" to 61)))
invalid(root+("body" to body+("ptsUs" to listOf(0L,0L)+pack.body.ptsUs.drop(2))))
val levels=patches[0]["levels"] as List<Map<String,Any?>>
invalid(root+("patches" to listOf(patches[0]+("levels" to levels.dropLast(1)))+patches.drop(1)))
invalid(root+("patches" to listOf(patches[0]+("levels" to listOf(levels[0],levels[1]+("path" to levels[0]["path"]))+levels.drop(2)))+patches.drop(1)))
val states=root["mouthStates"] as List<Map<String,Any?>>
invalid(root+("mouthStates" to listOf(states[0]+("ptsUs" to listOf(0L)))+states.drop(1)))
check(runCatching { ContinuousFramePresenter(pack).decoded(pack.body.ptsUs[1]) }.isFailure)
check(runCatching { selectMouthPatch(pack,count,.5f) }.isFailure)
if(fpsD==1) {
TestScheduler.reset();CodecFixture.reset();GLFixture.reset();BitmapFactory.wrongSize=false
CodecFixture.frames=count;CodecFixture.fps=fpsN
CodecFixture.onRender={ pts -> SurfaceTexture.lastCreated?.emit(pts*1000) }
val frames=mutableListOf<ComposedBodyFrame>();val errors=mutableListOf<String>()
val renderer=ContinuousBodyRenderer(android.content.Context(),pack,Surface(SurfaceTexture(0)),480,848,
{ frame,_ -> frames.add(frame) },errors::add)
renderer.intent(true,1,1);TestScheduler.advanceBy((pack.body.durationUs/1000)*2+100)
check(errors.isEmpty() && frames.size>count && frames[count].key.index==0 && frames[count].key.loopOrdinal==1L) {
"dynamic renderer count=$count fps=$fpsN errors=$errors frames=${frames.size} wrap=${frames.getOrNull(count)?.key}"
}
check(frames.all { it.patch.ptsUs==pack.body.ptsUs[it.key.index] && it.selection.textureSlot in pack.textureImages.indices })
renderer.close();TestScheduler.advanceBy(100)
}
}
val sha="c".repeat(64);val root=dynamicRuntimeFixture();val body=root["body"] as Map<String,Any?>
val pts=(body["ptsUs"] as List<Long>).mapIndexed { i,t -> t+if(i%2==1) 1000 else 0 }
val patches=(root["patches"] as List<Map<String,Any?>>).mapIndexed { i,p -> p+("ptsUs" to pts[i]) }
val variable=root+mapOf("body" to body+("ptsUs" to pts),"patches" to patches)
check(ContinuousAvatarManifest.read(variable,sha,sha,true,"variable/")!=null)
val curve=MouthCurve("opening",400,listOf(0f,.25f,1f),listOf(0L,100_000L,300_000L))
val mouth=ContinuousMouth(continuousPack().curves+("opening" to curve))
mouth.request(true,1,1);mouth.sample(0)
check(kotlin.math.abs(mouth.sample(200).alpha-.625f)<.0001f)
println("PASS: dynamic121/49/61 bodies + rational/nonuniform actual PTS, $boundaries frame/level/rejection checks; production decoder/render wrap on121@30/49@24, per-curve timing, SHA/cache/schema fences; fixtures only")
}
+2 -2
View File
@@ -6,9 +6,9 @@ fun emotionActionCheck() {
patch.copy(levels=List(5) { MouthPatchLevel(it,it/4f,"patches/${patch.frameIndex}-$it.png",sha) })
}) }
fun clip(audio: Boolean)=mapOf<String,Any?>("path" to "clips/bridge.mp4","sha256" to sha,"hasAudio" to audio,
"frameCount" to 48,"ptsUs" to List(48) { it*1_000_000L/24 },"durationUs" to 2_000_000L)
"width" to 480,"height" to 848,"fpsNumerator" to 24,"fpsDenominator" to 1,"frameCount" to 48,"ptsUs" to List(48) { it*1_000_000L/24 },"durationUs" to 2_000_000L)
fun edge(id: String,from: String,to: String)=mapOf<String,Any?>("id" to id,"from" to from,"to" to to,
"fromAnchor" to "A","toAnchor" to "A","fromFrame" to 96,"toFrame" to 0,"clip" to clip(false))
"fromPtsUs" to 4_000_000L,"toPtsUs" to 0L,"fromAnchor" to "A","toAnchor" to "A","fromFrame" to 96,"toFrame" to 0,"clip" to clip(false))
fun conversation(id: String)=mapOf<String,Any?>("id" to id,"emotion" to if(id=="neutral") "neutral" else "happy",
"visualIntensity" to if(id=="neutral") 0 else 1,"mouthBodySha256" to sha,
"runtimeManifest" to mapOf("path" to "$id/manifest.json","sha256" to sha),"entryAnchor" to "A","exitAnchor" to "A",