126 lines
9.3 KiB
Kotlin
126 lines
9.3 KiB
Kotlin
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)
|
|
val rejectFields=mutableListOf<String>()
|
|
val badCursor=meta+("edges" to listOf(graph[0]+("toPtsUs" to 1L))+graph.drop(1))
|
|
check(EmotionActionManifest.read(badCursor,pin,pin,onReject=rejectFields::add) { path,hash ->
|
|
packs[path.substringBefore('/')]?.takeIf { it.manifestSha==hash }
|
|
}==null)
|
|
check(rejectFields==listOf("edges[0].toPtsUs"))
|
|
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++
|
|
|
|
// Optional bridge-own runtime admission: own body SHA and every timing field.
|
|
val bridgeOwn=dynamicPack(12,24,pin)
|
|
val reference=mapOf("path" to "bridge/manifest.json","sha256" to bridgeOwn.manifestSha)
|
|
val talkGraph=graph.map { it+mapOf("mouthRuntimeManifest" to reference,"mouthAllowed" to true) }
|
|
fun bridgeRead(edges: List<Map<String,Any?>>,own: ContinuousAvatarPack=bridgeOwn)=
|
|
EmotionActionManifest.read(meta+("edges" to edges),pin,pin) { path,hash ->
|
|
(if(path=="bridge/manifest.json") own else packs[path.substringBefore('/')])?.takeIf { it.manifestSha==hash }
|
|
}
|
|
check(bridgeRead(talkGraph)?.edges?.all { it.mouthRuntime?.body?.frameCount==12 }==true)
|
|
var bridgeRejected=0
|
|
for(own in listOf(bridgeOwn.copy(body=bridgeOwn.body.copy(sha256="a".repeat(64))),
|
|
bridgeOwn.copy(body=bridgeOwn.body.copy(ptsUs=bridgeOwn.body.ptsUs.mapIndexed { i,t->t+if(i==1) 1 else 0 })),
|
|
bridgeOwn.copy(body=bridgeOwn.body.copy(durationUs=500001)),
|
|
bridgeOwn.copy(body=bridgeOwn.body.copy(fpsNumerator=30)),
|
|
bridgeOwn.copy(body=bridgeOwn.body.copy(frameCount=11)),
|
|
bridgeOwn.copy(body=bridgeOwn.body.copy(width=481)),
|
|
bridgeOwn.copy(apertureMode=false),bridgeOwn.copy(patches=bridgeOwn.patches.dropLast(1)))) {
|
|
check(bridgeRead(talkGraph,own)==null);bridgeRejected++
|
|
}
|
|
for(change in listOf(mapOf("mouthAllowed" to false),mapOf("nativeLoop" to true),
|
|
mapOf("mouthRuntimeManifest" to reference+("path" to "../bridge/manifest.json")),
|
|
mapOf("mouthRuntimeManifest" to reference+("sha256" to "a".repeat(64))))) {
|
|
check(bridgeRead(listOf(talkGraph[0]+change)+talkGraph.drop(1))==null);bridgeRejected++
|
|
}
|
|
check(read(meta+("edges" to graph.map { it+("mouthAllowed" to true) }))==null);bridgeRejected++
|
|
val inflated=bridgeOwn.copy(patches=bridgeOwn.patches.map { it.copy(width=128,height=128) })
|
|
// Each runtime remains below8MB; bridge resources together exceed32MB.
|
|
val overGraph=List(40) { i->talkGraph[0]+("id" to "extra-$i") }+talkGraph
|
|
check(inflated.rgbaBytes<BodyTimeline.MAX_RGBA_BYTES && bridgeRead(overGraph,inflated)==null);bridgeRejected++
|
|
println("PASS: bridge-own optional runtime binding and $bridgeRejected SHA/PTS/N/fps/duration/shape/path/flag/cache rejection cases; old silent graph compatible, no self approval")
|
|
|
|
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")
|
|
}
|