Files
baji-vc/tests/avatar/SafetyManifestCheck.kt
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

61 lines
5.6 KiB
Kotlin

import com.gorios.lanvoice.avatar.*
private val fakeSha = "a".repeat(64)
fun syntheticManifest(): Map<String,Any?> {
val g=syntheticGraph()
fun interval(i: AnchorInterval): Map<String,Any?> = mapOf("id" to i.id,"anchorId" to i.anchorId,
"startMs" to i.startMs,"endMs" to i.endMs,"startFrame" to i.startFrame,"endFrame" to i.endFrame,"reviewStatus" to "approved")
return mapOf("schemaVersion" to 1,"assets" to g.clips.values.map { mapOf("id" to it.id,"path" to it.path) },
"safeTransitions" to mapOf("version" to 1,"reviewStatus" to "approved","initialAssetId" to g.initialClip,"initialEntryId" to g.initialEntry,
"anchors" to g.anchors.values.map { mapOf("id" to it.id,"closedMouth" to it.closedMouth,"reviewStatus" to "approved") },
"clips" to g.clips.values.map { mapOf("assetId" to it.id,"role" to it.role.name.lowercase(),
"durationMs" to it.durationMs,"frameCount" to it.frameCount,"fpsNumerator" to it.fpsNumerator,"fpsDenominator" to it.fpsDenominator,
"entryAnchors" to it.entryAnchors.map(::interval),"safeExitWindows" to it.safeExitWindows.map(::interval),
"mouthStateWindows" to it.mouthStateWindows.map { w -> mapOf("state" to w.state.name.lowercase(),
"startMs" to w.startMs,"endMs" to w.endMs,"startFrame" to w.startFrame,"endFrame" to w.endFrame,"reviewStatus" to "approved") },
"loop" to it.loop,"reviewStatus" to "approved","loopSeamReviewStatus" to "approved","seekReviewStatus" to "approved") },
"transitions" to g.edges.map { mapOf("id" to it.id,"sourceAssetId" to it.source,"sourceWindowId" to it.sourceWindow,
"targetAssetId" to it.target,"targetEntryId" to it.targetEntry,"reviewStatus" to "approved",
"earliestPolicy" to "next_safe_window","latestPolicy" to "next_reviewed_loop","earliestWaitMs" to 0L,"latestWaitMs" to 100L) }))
}
@Suppress("UNCHECKED_CAST")
fun checkSafetyManifest() {
val root=syntheticManifest()
val extension=root["safeTransitions"] as Map<String,Any?>
fun modifiedExtension(change: Map<String,Any?>) = root + ("safeTransitions" to (extension + change))
fun status(value: Map<String,Any?>) = SafeAvatarManifest.read(value,fakeSha,setOf(fakeSha)).status
check(status(root - "safeTransitions") == SafetyManifestStatus.LEGACY_UNANNOTATED)
// a01-v2's draft annotations are not this reviewed schema and grant no safety.
check(status((root - "safeTransitions") + mapOf("approvedEdges" to emptyList<Any>(),"safeExits" to emptyList<Any>())) == SafetyManifestStatus.LEGACY_UNANNOTATED)
check(status(modifiedExtension(mapOf("reviewStatus" to "pending","anchors" to emptyList<Any>(),"clips" to emptyList<Any>()))) == SafetyManifestStatus.REVIEW_PENDING)
check(SafeAvatarManifest.read(root,fakeSha).status == SafetyManifestStatus.HASH_NOT_APPROVED)
check(SafeAvatarManifest.read(root,"not-a-sha",setOf("not-a-sha")).status == SafetyManifestStatus.HASH_NOT_APPROVED)
val approved=SafeAvatarManifest.read(root,fakeSha,setOf(fakeSha))
check(approved.status == SafetyManifestStatus.APPROVED && approved.graph?.nextEdge("idle",SafeClipRole.TALK) != null)
check(approved.graph?.clips?.getValue("idle")?.mouthStateWindows?.single()?.state == ReviewedMouthState.CLOSED_STABLE)
check(status(root + ("schemaVersion" to 1.0)) == SafetyManifestStatus.INVALID)
check(status(modifiedExtension(mapOf("version" to 2))) == SafetyManifestStatus.INVALID)
check(status(modifiedExtension(mapOf("reviewStatus" to "almost_approved"))) == SafetyManifestStatus.INVALID)
val clips=extension["clips"] as List<Map<String,Any?>>
val closingAlias=clips.map { if (it["role"] == "closing") it + ("role" to "end-talk") else it }
check(status(modifiedExtension(mapOf("clips" to closingAlias))) == SafetyManifestStatus.APPROVED)
val badMouth=clips.first() + ("mouthStateWindows" to listOf(mapOf("state" to "active","startMs" to 0L,
"endMs" to 9999L,"startFrame" to 0,"endFrame" to 1,"reviewStatus" to "approved")))
check(status(modifiedExtension(mapOf("clips" to listOf(badMouth)+clips.drop(1)))) == SafetyManifestStatus.INVALID)
for (change in listOf(mapOf("durationMs" to 4000.5),mapOf("durationMs" to -1L),mapOf("frameCount" to 1),mapOf("frameCount" to 3600),
mapOf("assetId" to "missing"),mapOf("entryAnchors" to emptyList<Any>()),mapOf("fpsDenominator" to 0))) {
check(status(modifiedExtension(mapOf("clips" to listOf(clips.first()+change)+clips.drop(1)))) == SafetyManifestStatus.INVALID)
}
val edges=extension["transitions"] as List<Map<String,Any?>>
for (change in listOf(mapOf("targetEntryId" to "missing"),mapOf("sourceWindowId" to "missing"),
mapOf("bridgeAssetId" to "closing"),mapOf("latestPolicy" to "force_cut"),mapOf("latestWaitMs" to -1))) {
check(status(modifiedExtension(mapOf("transitions" to listOf(edges.first()+change)+edges.drop(1)))) == SafetyManifestStatus.INVALID)
}
val unreviewed=SafeAvatarManifest.read(modifiedExtension(mapOf("transitions" to edges.map { it + ("reviewStatus" to "pending") })),fakeSha,setOf(fakeSha))
check(unreviewed.graph?.nextEdge("idle",SafeClipRole.TALK) == null)
check(status(root + ("assets" to List(33) { mapOf("id" to "a$it","path" to "videos/a.mp4") })) == SafetyManifestStatus.INVALID)
check(status(root + ("assets" to listOf(mapOf("id" to "idle","path" to "../private.mp4")) +
(root["assets"] as List<Map<String,Any?>>).drop(1))) == SafetyManifestStatus.INVALID)
println("PASS: manifest legacy/draft unsafe, pending unknown allowed without invented windows, hash allowlist, strict bounded metadata/frame/pose/reference/policy validation; fixture approval only")
}