Expose face presence diagnostics and bound camera readiness recovery
This commit is contained in:
@@ -1,6 +1,37 @@
|
||||
import com.gorios.lanvoice.expression.*
|
||||
|
||||
fun main() {
|
||||
val fence=CameraCallbackFence()
|
||||
val initial=fence.nextBinding()
|
||||
check(fence.accepts(initial))
|
||||
fence.invalidate();check(!fence.accepts(initial))
|
||||
val recovered=fence.nextBinding()
|
||||
check(fence.accepts(recovered) && !fence.accepts(initial))
|
||||
fence.close();check(!fence.accepts(recovered))
|
||||
check(runCatching { fence.nextBinding() }.isFailure)
|
||||
val boot=CameraAnalysisDiagnostics()
|
||||
boot.stage(CameraStage.MODEL_LOADING,100)
|
||||
check(cameraTimeout(boot.snapshot(),15099)==CameraFailure.NONE)
|
||||
check(cameraTimeout(boot.snapshot(),15100)==CameraFailure.MODEL_TIMEOUT)
|
||||
boot.stage(CameraStage.PROVIDER_WAIT,20000)
|
||||
check(cameraTimeout(boot.snapshot(),28000)==CameraFailure.PROVIDER_TIMEOUT)
|
||||
boot.stage(CameraStage.WAITING_FRAME,30000)
|
||||
check(cameraTimeout(boot.snapshot(),34999)==CameraFailure.NONE)
|
||||
check(canRecoverFirstFrame(boot.snapshot(),cameraTimeout(boot.snapshot(),35000)))
|
||||
boot.recovering();boot.stage(CameraStage.WAITING_FRAME,35000)
|
||||
check(!canRecoverFirstFrame(boot.snapshot(),cameraTimeout(boot.snapshot(),40000)))
|
||||
boot.received(39000)
|
||||
check(boot.snapshot().stage==CameraStage.WAITING_RESULT)
|
||||
check(cameraTimeout(boot.snapshot(),44000)==CameraFailure.RESULT_TIMEOUT)
|
||||
boot.processed(0,FaceCueObservation(reason=FaceCueReason.NO_FACE),10,40000)
|
||||
check(boot.snapshot().stage==CameraStage.READY && boot.snapshot().processed==1)
|
||||
check(cameraTimeout(boot.snapshot(),44000)==CameraFailure.FRAME_TIMEOUT)
|
||||
boot.received(44500)
|
||||
check(cameraTimeout(boot.snapshot(),45000)==CameraFailure.RESULT_TIMEOUT)
|
||||
boot.stage(CameraStage.OFF,45000)
|
||||
check(cameraTimeout(boot.snapshot(),100000)==CameraFailure.NONE)
|
||||
boot.failed(CameraFailure.FRAME_TIMEOUT)
|
||||
check(cameraTimeout(boot.snapshot(),100000)==CameraFailure.NONE)
|
||||
val camera = CameraAnalysisDiagnostics()
|
||||
check(camera.snapshot().reason == FaceCueReason.NO_FRAME)
|
||||
var summaries = 0
|
||||
@@ -29,5 +60,5 @@ fun main() {
|
||||
send.record(FaceSendReason.STALE)
|
||||
check(send.snapshot().attempts == 3 && send.snapshot().sent == 1 && send.snapshot().clears == 1 && send.snapshot().failures == 1)
|
||||
check(send.summary(0) != null && send.summary(9999) == null && send.summary(10000) != null)
|
||||
println("PASS: enum-only camera/frame/send snapshots, failure counters, 10s rate bound, no-face/stable/stale/clear accounting")
|
||||
println("PASS: production camera readiness deadlines/one bounded first-frame recovery/no-frame vs no-result/stale/stop; enum-only counters and 10s summaries")
|
||||
}
|
||||
|
||||
@@ -7,6 +7,17 @@ spec=importlib.util.spec_from_file_location('presence_package',ROOT/'scripts/pac
|
||||
pack=importlib.util.module_from_spec(spec);spec.loader.exec_module(pack)
|
||||
|
||||
class PresencePackageTests(unittest.TestCase):
|
||||
def test_face_diagnostics_release_preserves_startup_and_presence_and_uses_new_code(self):
|
||||
def stop_build(command,**kwargs):
|
||||
if command[0]=='python3':return
|
||||
self.assertIn('-PfaceDiagnosticsFix=true',command)
|
||||
self.assertIn('-PpresenceCandidate=true',command)
|
||||
self.assertIn('-PavatarStartupFix=true',command)
|
||||
self.assertIn('-PactionVersionCode=24',command)
|
||||
raise RuntimeError('build_sentinel')
|
||||
with patch.object(pack,'tested_source'),patch.object(pack,'packaging_tests_current'),patch.object(pack,'read_json',return_value={'edges':[{'nativeLoop':True}]}),patch.object(pack,'next_version',return_value=24),patch.object(pack.subprocess,'run',side_effect=stop_build):
|
||||
with self.assertRaises(ValueError):pack.publish({'manifest_sha256':pack.RUNTIME_FIX_PIN},None,24,full=True,startup_fix=True,face_diagnostics_fix=True)
|
||||
with self.assertRaisesRegex(RuntimeError,'build_sentinel'):pack.publish({'manifest_sha256':pack.RUNTIME_FIX_PIN},None,24,full=True,startup_fix=True,presence_candidate=True,face_diagnostics_fix=True)
|
||||
def test_fresh_presence_version_requires_startup_and_frozen_pack(self):
|
||||
report={'manifest_sha256':pack.RUNTIME_FIX_PIN}
|
||||
def stop_build(command,**kwargs):
|
||||
|
||||
@@ -9,6 +9,10 @@ fun presenceCheck() {
|
||||
val rules=PresenceRules()
|
||||
for(t in 0L..19_900L step 100) expect(rules.sample(false,t,1,true)==null)
|
||||
expect(rules.sample(false,19_999,1,true)==null)
|
||||
val before=rules.snapshot(19_999)
|
||||
expect(before.observation==PresenceObservation.ABSENT && before.absentElapsedMs==19_999L)
|
||||
expect(rules.snapshot(20_400).observation==PresenceObservation.UNKNOWN)
|
||||
expect(rules.snapshot(19_999).absentElapsedMs==19_999L) // Snapshot never consumes an episode or changes clocks.
|
||||
expect(rules.sample(false,20_000,1,true)?.kind==PresenceKind.ABSENT)
|
||||
for(t in 20_100L..45_000L step 100) expect(rules.sample(false,t,1,true)==null)
|
||||
expect(rules.sample(true,45_100,1,true)==null)
|
||||
@@ -53,7 +57,13 @@ private fun checkPresenceSessionCallbacks() {
|
||||
eventMethod.invoke(session,ServerEvent(if(kind==EventKind.PRESENCE) "presence.status" else kind.name.lowercase(),kind,Payload(turn=turn,reason=reason,state=state,fields=fields)))
|
||||
}
|
||||
session.startVoice();event(EventKind.HELLO,1,mapOf("presence_greeting_version" to 1))
|
||||
check(session.presenceDiagnosticsSnapshot().block==PresenceBlock.DISABLED)
|
||||
session.setPresence(true,false)
|
||||
check(session.presenceDiagnosticsSnapshot().block==PresenceBlock.CAMERA_INACTIVE)
|
||||
session.setPresence(true,true)
|
||||
field("lastSpeechAt",android.os.SystemClock.elapsedRealtime()-1000)
|
||||
session.observePresence(false,android.os.SystemClock.elapsedRealtime()-500)
|
||||
check(session.presenceDiagnosticsSnapshot().block==PresenceBlock.STALE_SAMPLE)
|
||||
fun primeAndSend(): Long {
|
||||
val now=android.os.SystemClock.elapsedRealtime()
|
||||
val rules=get("presenceRules") as PresenceRules
|
||||
@@ -65,16 +75,21 @@ private fun checkPresenceSessionCallbacks() {
|
||||
return sent.split('/')[1].toLong()
|
||||
}
|
||||
val id=primeAndSend()
|
||||
check(session.presenceDiagnosticsSnapshot().outcome==PresenceOutcome.SENT && session.presenceDiagnosticsSnapshot().sent==1)
|
||||
event(EventKind.ABORT,2,mapOf("request_id" to id),reason="presence_greeting")
|
||||
event(EventKind.PRESENCE,2,mapOf("request_id" to id),state="accepted")
|
||||
event(EventKind.PRESENCE,2,mapOf("request_id" to id),state="accepted")
|
||||
check(session.presenceDiagnosticsSnapshot().accepted==1)
|
||||
check(states.last().turnId==2L && get("presenceRequest")!=null)
|
||||
event(EventKind.TTS,2,state="start")
|
||||
val frames=session.javaClass.getDeclaredMethod("onFrame",DownlinkFrame::class.java).apply { isAccessible=true }
|
||||
frames.invoke(session,DownlinkFrame(2))
|
||||
check(states.last().phase==VoicePhase.ANSWERING)
|
||||
check(session.presenceDiagnosticsSnapshot().block==PresenceBlock.REQUEST_ACTIVE)
|
||||
checkNotNull(AudioPlayback.lastDrained)(2,0);Handler.drain();check(get("presenceRequest")==null)
|
||||
val id2=primeAndSend();session.setPresence(false,true)
|
||||
check(socket.sent.count { it=="presence_cancel/$id2" }==1)
|
||||
check(session.presenceDiagnosticsSnapshot().cancelled==1)
|
||||
val before=AudioPlayback.enqueued
|
||||
event(EventKind.ABORT,3,mapOf("request_id" to id2),reason="presence_greeting")
|
||||
frames.invoke(session,DownlinkFrame(3));check(AudioPlayback.enqueued==before)
|
||||
@@ -83,5 +98,6 @@ private fun checkPresenceSessionCallbacks() {
|
||||
session.setPresence(true,true);val id3=primeAndSend()
|
||||
event(EventKind.VAD,4,mapOf("event" to Payload(fields=mapOf("type" to "speech.start"))))
|
||||
check(get("presenceRequest")==null && socket.sent.any { it=="presence_cancel/$id3" })
|
||||
check(session.presenceDiagnosticsSnapshot().block==PresenceBlock.USER_SPEAKING)
|
||||
session.background();session.release();Handler.drain()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user