From fad59e9a57342d571d9e7fd9bdabddbf32b0b321 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 6 Aug 2026 23:42:13 +0000 Subject: [PATCH 2/2] =?UTF-8?q?test(diag):=20cross-language=20wire-format?= =?UTF-8?q?=20golden=20=E2=80=94=20lock=20BlackBox=20codec=20=E2=87=84=20p?= =?UTF-8?q?ython=20decoder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Golden fingerprint (payload hex + luma bit-placement CRC) computed by the offline python decoder (scratchpad/blackbox/bb.py, verified end-to-end through real H.264: 30/30 frames exact at crf 23 and 28, fail-closed). This test asserts the Kotlin encoder reproduces it byte-for-byte, so the on-device overlay and the agent's decoder cannot silently drift apart. --- .../mofe/diag/BlackBoxWireFormatTest.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 common/src/commonTest/kotlin/com/aether/mofe/diag/BlackBoxWireFormatTest.kt diff --git a/common/src/commonTest/kotlin/com/aether/mofe/diag/BlackBoxWireFormatTest.kt b/common/src/commonTest/kotlin/com/aether/mofe/diag/BlackBoxWireFormatTest.kt new file mode 100644 index 0000000..5c0d04d --- /dev/null +++ b/common/src/commonTest/kotlin/com/aether/mofe/diag/BlackBoxWireFormatTest.kt @@ -0,0 +1,33 @@ +package com.aether.mofe.diag + +import kotlin.test.Test +import kotlin.test.assertEquals + +/** + * Cross-language golden: locks the black-box wire format so the on-device Kotlin encoder and the agent's + * offline python decoder (scratchpad/blackbox/bb.py) stay byte-identical. The golden values were computed by + * the python port for the FIXED state below; if a future change to [BlackBoxCodec]/[BlackBoxSchema] drifts the + * format, this fails and the python decoder would silently mis-read real captures. Integer fields only ⇒ exact. + */ +class BlackBoxWireFormatTest { + @Test + fun wire_format_matches_the_cross_language_golden() { + val s = BlackBoxState( + frameIdx = 7, tEngineMicros = 1234567890123L, + ranges = listOf(BbRange("85b92d", distanceMm = 3697, sq = 90, rssiDbm = -91, azCentiDeg = 27010, elCentiDeg = 220)), + imu = listOf(BbImu(dtMicros = 5000, axMilli = 120, ayMilli = -30, azMilli = 9810, gxMilli = 5, gyMilli = -4, gzMilli = 2)), + pose = BbPose(xMm = 812, yMm = -1503, zMm = 1100, qwE4 = 9998, qxE4 = 100, qyE4 = -50, qzE4 = 30), + ) + val payload = BlackBoxState.encode(s) + assertEquals( + "01000000070000011f71fb04cb010185b92d0e715aa5698200dc0113880078ffe226520005fffc0002032cfa21044c270e0064ffce001e", + payload.joinToString("") { (it.toInt() and 0xFF).toString(16).padStart(2, '0') }, + "schema wire format drifted from the python decoder golden", + ) + val luma = BlackBoxCodec.encodeToLuma(payload, cols = 80, rows = 130, repeat = 5) + assertEquals(930, luma.count { it == 255 }, "luma set-cell count drifted") + val lumaBytes = ByteArray(luma.size) { (luma[it] and 0xFF).toByte() } + assertEquals(0xc16edcfc.toInt(), BlackBoxCodec.crc32(lumaBytes), "luma bit-placement drifted from the golden") + assertEquals(s, BlackBoxState.decode(BlackBoxCodec.decodeFromLuma(luma, 80, 130, 5)!!), "must self-decode") + } +} -- 2.43.0