fix(android): retain action layer and idle rotation across turns
This commit is contained in:
@@ -6,6 +6,7 @@ import android.media.MediaPlayer
|
||||
import android.view.TextureView
|
||||
|
||||
fun main() {
|
||||
boundedRuntimeDiagnosticCheck()
|
||||
dynamicBodyCheck()
|
||||
actionCheck()
|
||||
emotionActionCheck()
|
||||
|
||||
@@ -1,2 +1,12 @@
|
||||
package com.gorios.lanvoice.diag
|
||||
object DiagnosticLog { fun record(tag: String,msg: String) {} }
|
||||
import com.gorios.lanvoice.diag.DiagnosticLog
|
||||
fun boundedRuntimeDiagnosticCheck() {
|
||||
val before=DiagnosticLog.snapshot().size
|
||||
repeat(501) { DiagnosticLog.state("bounded_test","action","owner=action frame=$it",it.toLong()) }
|
||||
check(DiagnosticLog.snapshot().size==before+1)
|
||||
DiagnosticLog.state("bounded_test","action","owner=action frame=240",10_000)
|
||||
DiagnosticLog.state("bounded_test","conversation","owner=conversation frame=96",10_001)
|
||||
check(DiagnosticLog.snapshot().size==before+3)
|
||||
repeat(600) { DiagnosticLog.record("bounded_ring","fixed_enum=sample") }
|
||||
check(DiagnosticLog.snapshot().size==500)
|
||||
println("PASS: bounded runtime diagnostics: state changes +10s monotonic summaries, no per-frame churn,500-entry ring")
|
||||
}
|
||||
|
||||
@@ -138,6 +138,53 @@ fun actualMediaViewCheck() {
|
||||
check(statuses.size==before);cases++
|
||||
actionView.dispose();TestScheduler.advanceBy(100)
|
||||
}
|
||||
// Ten seconds of real production held-renderer callbacks must never steal
|
||||
// the movie TextureView. Native/codec/record ports remain deterministic doubles.
|
||||
for(mode in listOf("complete", "cancel", "failed", "background", "newturn")) {
|
||||
reset()
|
||||
val base=mediaFixtureIndex()
|
||||
val original=base.actionPack!!.assets.first()
|
||||
val media=original.media!!.copy(ptsUs=List(241) { it*1_000_000L/24 },durationUs=10_041_667,
|
||||
sourceFrame=0,returnFrame=96)
|
||||
val asset=original.copy(durationMs=10_042,media=media)
|
||||
val index=base.copy(actionPack=base.actionPack.copy(assets=listOf(asset,asset.copy(id="asset_02"))))
|
||||
val (v,b,trace)=rig(index)
|
||||
var confirmation: ((Boolean)->Unit)?=null
|
||||
val statuses=mutableListOf<ActionStatus>()
|
||||
val controller=ActionController(index.actionPack,b,{TestScheduler.now},{confirmation=it},statuses::add)
|
||||
check(controller.offer(ActionPlan("z".repeat(24),7,"a".repeat(64),25000)))
|
||||
confirmation!!(true);val player=MediaPlayer.created.single();val prepared=player.prepared!!
|
||||
prepared(player);TestScheduler.until { player.started }
|
||||
val textures=v.children.filterIsInstance<TextureView>()
|
||||
fun latch(pts: Long) { val t=textures[3].surfaceTexture!!;t.timestamp=pts*1000;textures[3].surfaceTextureListener!!.onSurfaceTextureUpdated(t) }
|
||||
val owner=driverField.get(v) as ConversationMediaDriver
|
||||
// Delayed first frame leaves the last valid body visible, with ACTION owning it.
|
||||
TestScheduler.advanceBy(80);check(owner.layerOwner==ConversationMediaDriver.LayerOwner.ACTION && textures[3].alpha==0f);cases++
|
||||
latch(0);TestScheduler.advanceBy(21)
|
||||
check(textures[3].alpha==1f && textures.take(3).all { it.alpha==0f } && player.started);cases++
|
||||
prepared(player) // Duplicated ready cannot start/reclaim again.
|
||||
for(i in 1..240) {
|
||||
TestScheduler.advanceBy(42);latch(media.ptsUs[i])
|
||||
check(textures[3].alpha==1f && textures.take(3).all { it.alpha==0f } && owner.layerOwner==ConversationMediaDriver.LayerOwner.ACTION);cases++
|
||||
if(i==120) { v.render(true);check(driverField.get(v)===owner);cases++ } // Settings continuity.
|
||||
}
|
||||
check(statuses.none { it.status=="completed" });cases++ // Time alone is insufficient.
|
||||
when(mode) {
|
||||
"complete" -> { player.completion!!(player);player.completion!!(player)
|
||||
TestScheduler.until { statuses.last().status=="completed" }
|
||||
check(player.released && owner.layerOwner==ConversationMediaDriver.LayerOwner.CONVERSATION && trace.last().clipId.startsWith("f96_"));cases++ }
|
||||
"failed" -> { player.error!!(player,1,2);TestScheduler.until { !controller.active } }
|
||||
"background" -> { controller.cancel();v.render(false);TestScheduler.until { !controller.active } }
|
||||
"newturn" -> { b.beginTurn(8);controller.cancel();TestScheduler.until { !controller.active } }
|
||||
else -> { controller.cancel();TestScheduler.until { !controller.active } }
|
||||
}
|
||||
val before=statuses.size;val alphas=textures.map { it.alpha }
|
||||
prepared(player);player.completion!!(player);player.error!!(player,1,2)
|
||||
check(statuses.size==before && textures.map { it.alpha }==alphas && player.released);cases++
|
||||
v.dispose();TestScheduler.advanceBy(100)
|
||||
check(owner.layerOwner==ConversationMediaDriver.LayerOwner.STOPPED);cases++
|
||||
}
|
||||
|
||||
// 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) }) }
|
||||
@@ -146,11 +193,15 @@ fun actualMediaViewCheck() {
|
||||
check(idleTrace.all { it.actual=="body_neutral" });cases++
|
||||
TestScheduler.until(15_000) { idleBinding.currentPackageId in setOf("happy","sad") }
|
||||
val firstIdle=idleBinding.currentPackageId
|
||||
// New turns on the actual displayed variant must retain its legal rotation.
|
||||
val turnBefore=idleTrace.size
|
||||
repeat(4) { i -> idleBinding.beginTurn(8L+i);idleBinding.intent(null,false);TestScheduler.advanceBy(200) }
|
||||
check(idleBinding.currentPackageId==firstIdle && idleTrace.drop(turnBefore).none { it.actual=="body_neutral" });cases++
|
||||
check(idleTrace.any { it.actual=="bridge" } && idleBinding.visualStatus=="neutral_idle_variant");cases++
|
||||
TestScheduler.until(15_000) { idleBinding.currentPackageId=="neutral" }
|
||||
TestScheduler.until(15_000) { idleBinding.currentPackageId in setOf("happy","sad") }
|
||||
check(idleBinding.currentPackageId!=firstIdle && idleTrace.none { it.actual=="media_failed" });cases++
|
||||
idleBinding.intent(mediaReply(RoleEmotion.NEUTRAL),true)
|
||||
idleBinding.intent(mediaReply(RoleEmotion.NEUTRAL,turn=11),true)
|
||||
TestScheduler.until(15_000) { idleBinding.currentPackageId=="neutral" }
|
||||
val speechStart=idleTrace.size;TestScheduler.advanceBy(9000)
|
||||
check(idleTrace.drop(speechStart).all { it.actual=="body_neutral" });cases++
|
||||
@@ -177,5 +228,5 @@ fun actualMediaViewCheck() {
|
||||
renderer.close();TestScheduler.advanceBy(50)
|
||||
check(GLFixture.deleted>=126 && CodecFixture.releases==1);cases++
|
||||
CodecFixture.reset();MediaPlayer.created.clear()
|
||||
println("PASS: $cases actual EmotionActionAvatarView/binding/held GLES renderer/MediaPlayer callback cases: hidden header/final mismatch, final slight,97→49→121 and24→30fps/native loops, real bridge frames/latest turn, settings continuity, mic-confirm/cancel-pending/failure gate, safe exit/music first+last PTS/native end/release/idle-A, completion order, cancel/error/background/stale callbacks; deterministic Android doubles, device/naturalness not_run")
|
||||
println("PASS: $cases actual EmotionActionAvatarView/binding/held GLES renderer/MediaPlayer callback assertions: hidden header/final mismatch, final slight,97→49→121 and24→30fps/native loops, real bridge frames/latest turn, settings continuity, mic-confirm/cancel-pending/failure gate, safe exit/music first+last PTS/native end/release/idle-A, completion order, cancel/error/background/stale callbacks; deterministic Android doubles, device/naturalness not_run")
|
||||
}
|
||||
|
||||
@@ -210,6 +210,28 @@ class PackageTests(unittest.TestCase):
|
||||
self.assertEqual(pack.next_version(['one.apk','two.apk']),20)
|
||||
self.assertEqual(pack.next_version([]),17)
|
||||
|
||||
def test_runtime_fix_preserves_all_frozen_avatar_bytes(self):
|
||||
import zipfile
|
||||
old=self.base/'frozen18.apk';new=self.base/'runtime19.apk'
|
||||
payload={'assets/'+pack.ASSET_ROOT+'manifest.json':b'exact index',
|
||||
'assets/'+pack.ASSET_ROOT+'own.png':b'own frame patch',
|
||||
'assets/avatar/legacy/body.mp4':b'rollback media'}
|
||||
def write(path,data):
|
||||
with zipfile.ZipFile(path,'w') as z:
|
||||
for name,value in data.items(): z.writestr(name,value)
|
||||
write(old,payload);write(new,payload)
|
||||
pin=pack.sha(b'exact index')
|
||||
with patch.object(pack,'CODE18',old),patch.object(pack,'CODE18_SHA',pack.file_sha(old)),patch.object(pack,'RUNTIME_FIX_PIN',pin):
|
||||
self.assertEqual(pack.verify_runtime_fix_assets(new,pin),2)
|
||||
for kind in ('bytes','missing','extra','pin'):
|
||||
changed=dict(payload)
|
||||
if kind=='bytes': changed['assets/'+pack.ASSET_ROOT+'own.png']=b'changed'
|
||||
if kind=='missing': del changed['assets/avatar/legacy/body.mp4']
|
||||
if kind=='extra': changed['assets/'+pack.ASSET_ROOT+'review.png']=b'not runtime'
|
||||
write(new,changed)
|
||||
with self.subTest(kind=kind),self.assertRaises(ValueError):
|
||||
pack.verify_runtime_fix_assets(new,'0'*64 if kind=='pin' else pin)
|
||||
|
||||
def test_cli_no_pin_no_import_no_output(self):
|
||||
self.manifest.write_text(json.dumps(self.index));out=self.base/'no-pin-output'
|
||||
result=subprocess.run([sys.executable,str(ROOT/'scripts/package-avatar-emotion.py'),
|
||||
|
||||
@@ -82,7 +82,7 @@ fun runChecks() {
|
||||
event("auth"); check(socket.sent.size == 1)
|
||||
event("hello")
|
||||
check(statuses == listOf(ConnectionStatus.CONNECTED))
|
||||
check(logs.filterNot { it.startsWith("listen ") || it.startsWith("ws control skipped") } == listOf("ws open", "auth ok", "hello sent", "hello received"))
|
||||
check(logs.filterNot { it.startsWith("listen ") || it.startsWith("ws control skipped") } == listOf("ws open", "auth ok", "hello sent action_offer=none generation=0", "hello received action_pack=unknown generation=0"))
|
||||
check(client.listen(true))
|
||||
event("hello"); check(statuses.count { it == ConnectionStatus.CONNECTED } == 1)
|
||||
event("history"); check(events.last() == EventKind.HISTORY)
|
||||
@@ -96,9 +96,18 @@ fun runChecks() {
|
||||
Handler.drain()
|
||||
check(socket.sent == listOf("hello"))
|
||||
check(statuses == listOf(ConnectionStatus.CONNECTED))
|
||||
check(logs == listOf("auth ok", "hello sent", "ws open", "hello received"))
|
||||
check(logs == listOf("auth ok", "hello sent action_offer=none generation=0", "ws open", "hello received action_pack=unknown generation=0"))
|
||||
close()
|
||||
}
|
||||
for((hello,expected) in listOf("hello" to "unknown","hello available" to "accepted","hello unavailable" to "unavailable")) {
|
||||
Fixture().apply {
|
||||
event("auth");event(hello);check(client.actionNegotiation==expected)
|
||||
// Old-generation HELLO cannot overwrite the negotiated connection.
|
||||
client.callbacks(-1).onMessage(socket,"hello unavailable");Handler.drain()
|
||||
check(client.actionNegotiation==expected)
|
||||
close();check(client.actionNegotiation=="disconnected")
|
||||
}
|
||||
}
|
||||
Fixture().apply {
|
||||
event("hello"); check(statuses.isEmpty() && !client.listen(true))
|
||||
handshake(); check(statuses.last() == ConnectionStatus.CONNECTED)
|
||||
@@ -243,7 +252,7 @@ fun runChecks() {
|
||||
check(states.last().connection == ConnectionStatus.CONNECTING)
|
||||
cb.onMessage(current, "hello"); Handler.drain()
|
||||
check(states.last().connection == ConnectionStatus.CONNECTED)
|
||||
check(listOf("auth ok", "hello sent", "hello received").all { it in logs })
|
||||
check(listOf("auth ok", "hello sent action_offer=none generation=1", "hello received action_pack=unknown generation=1").all { it in logs })
|
||||
session.startVoice()
|
||||
session.background(showDisconnectReason = true)
|
||||
check(states.last().connection == ConnectionStatus.DISCONNECTED && !states.last().voiceActive)
|
||||
@@ -471,7 +480,7 @@ fun runChecks() {
|
||||
session.release(); barrier.countDown(); Handler.drain()
|
||||
}
|
||||
check(DebugLogUpload.records.any { it.first == "connect" && it.second.startsWith("state=connected reason=") })
|
||||
check(DebugLogUpload.records.any { it == "auth" to "hello received" })
|
||||
check(DebugLogUpload.records.any { it == "auth" to "hello received action_pack=unknown generation=0" })
|
||||
check(DebugLogUpload.records.any { it == "ws" to "ws event=history" })
|
||||
check(DebugLogUpload.records.none { (_, message) -> "auth_ready" in message })
|
||||
check(DebugLogUpload.records.any { (_, message) -> "finish reason=control_send_failure stack=" in message })
|
||||
|
||||
@@ -24,6 +24,8 @@ object DialogueProtocol {
|
||||
fun parseEvent(text: String) = when (text) {
|
||||
"auth" -> ServerEvent("auth", EventKind.AUTH, Payload())
|
||||
"auth failed" -> ServerEvent("auth", EventKind.AUTH, Payload(false))
|
||||
"hello available" -> ServerEvent("hello", EventKind.HELLO, Payload(fields=mapOf("action_available" to true)))
|
||||
"hello unavailable" -> ServerEvent("hello", EventKind.HELLO, Payload(fields=mapOf("action_available" to false)))
|
||||
"hello" -> ServerEvent("hello", EventKind.HELLO, Payload())
|
||||
"error" -> ServerEvent("error", EventKind.ERROR, Payload())
|
||||
"unknown" -> ServerEvent("auth_ready", EventKind.UNKNOWN, Payload())
|
||||
|
||||
Reference in New Issue
Block a user