feat(verify): golden-I/O replay harness from introspection dumps

This commit is contained in:
ulw-execute committed 2026-11-28 04:59:14 -05:00
1 parent 643b4724a4
commit 29aa4b7ecf
8 files changed
+795

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
# T9 — Golden-I/O replay harness
A standalone, Linux-reproducible **golden-I/O replay** harness that replays
committed `(input → expected-output)` tuples recorded from the project's
**existing** introspection dumps and asserts an independent reconstruction of
three gamekdm/shim subsystems against them within a float tolerance.
It is a **supplement** to the Unicorn differential harness (**T8**):
- **T8 (differential)** is the *universal gate* — it runs the shipping `gamekdm`
code under emulation and compares against a native reimplementation for any
reachable function. It needs **no recordings**.
- **T9 (golden, this harness)** covers the functions for which recorded
introspection dumps **already exist**, needs **no new Windows capture**, and
runs from the committed fixtures alone. Where a tuple does not exist, that
function is left to the T8 differential (noted below).
## What it checks
| subsystem | fixture | source of the recorded tuple |
|-----------|---------|------------------------------|
| `nui_depth_to_skeleton` | `fixtures/depth_projection.json` | Kinect `NuiTransformDepthImageToSkeleton` reimpl (`kinect/core/mapping/mapping.cpp`, scale `3.501e-3`); input points from the shipping round-trip test (`kinect/tests/test_mapping.cpp`). Each expected position is self-checked by the inverse projection back to the original integer pixel. |
| `skeleton_validity_gate` | `fixtures/validity_gate.json` | `game-internals.md` §2 — gamekdm `FUN_10018570 / FUN_100e4140 / FUN_101ab6d0`, validity box `DAT_103d3230` = A `(0,1,0)`, B `(1.22,1,0.675)`, `m14=2.5`, tol `0.05`; recorded live by `sensor.cpp DumpGameDisplayState()` → the `game-skel2/3/4` shim-log lines. Published floor-clip rule `vFloorClipPlane.w = 1 − hip.y`. |
| `recorded_pose_hip_center` | `fixtures/pose_ref.json` (+ `fixtures/ref.txt`) | `kinect/tracker-native/testdata/ref.txt` — the committed `PoseEstimator` dump on `sample_rgb.bin`; hip-center = `(lm23.x + lm24.x)·0.5` per `two_person_probe.cpp`. |
## Run
```
./run.sh # regenerate fixtures, assert, then prove non-vacuity
python3 golden_harness.py # assert only (exit 0 = all tuples matched)
python3 golden_harness.py --perturb m14 # corrupt one constant → FAIL (exit 1)
python3 gen_fixtures.py # re-derive the committed fixtures from source dumps
```
No third-party dependencies (Python 3 stdlib only), no top-level CMake, no
network, no game binary.
## Non-vacuity (misleading-success guard)
The reconstruction constants live in `Recon`. `--perturb FIELD`
(`scale | m14 | box_b_x | box_b_z | tol | hip_mid`) nudges one constant so the
golden assertions **fail on purpose**. `run.sh` runs the clean pass and every
perturbation, and reports `VACUITY VIOLATION` if any perturbed run still passes.
A clean run is `exit 0`; any perturbation is `exit 1`.
## Coverage left to the T8 differential
- Live cursor read / OK-button snapping (`FUN_1007fbf0`, `FUN_1007e330`,
`afp_mc_get_param 0x1008`) — the `handcur:` log is gated behind
`kShimDebug=false`, so no cursor-paired recording is committed here. The
cursor→button math runs against the game binary under the T8 differential.
- Arm-amplification gains (`kArmGainX/Y`) and the L/R swap are exercised by the
kinect host tests; this harness asserts only the hip-center (validity-box
anchor), which the arm gains leave untouched by design.
@@ -0,0 +1,95 @@
{
"subsystem": "nui_depth_to_skeleton",
"provenance": "kinect/core/mapping/mapping.cpp depth_image_to_skeleton; inputs from kinect/tests/test_mapping.cpp round-trip test",
"projection_scale": 0.003501,
"depth_width": 640,
"depth_height": 480,
"tolerance_abs": 1e-06,
"tuples": [
{
"input": {
"px": 0,
"py": 0,
"packed_depth": 6400
},
"expected": {
"x": -0.448128,
"y": 0.33609600000000006,
"z": 0.8
},
"roundtrip_pixel": {
"px": 0,
"py": 0,
"packed_depth": 6400
}
},
{
"input": {
"px": 137,
"py": 91,
"packed_depth": 10000
},
"expected": {
"x": -0.400426875,
"y": 0.326030625,
"z": 1.25
},
"roundtrip_pixel": {
"px": 137,
"py": 91,
"packed_depth": 10000
}
},
{
"input": {
"px": 320,
"py": 240,
"packed_depth": 20000
},
"expected": {
"x": 0.0,
"y": -0.0,
"z": 2.5
},
"roundtrip_pixel": {
"px": 320,
"py": 240,
"packed_depth": 20000
}
},
{
"input": {
"px": 434,
"py": 171,
"packed_depth": 20000
},
"expected": {
"x": 0.4988925,
"y": 0.30196125,
"z": 2.5
},
"roundtrip_pixel": {
"px": 434,
"py": 171,
"packed_depth": 20000
}
},
{
"input": {
"px": 630,
"py": 468,
"packed_depth": 32000
},
"expected": {
"x": 2.17062,
"y": -1.596456,
"z": 4.0
},
"roundtrip_pixel": {
"px": 630,
"py": 468,
"packed_depth": 32000
}
}
]
}
+22
View File
@@ -0,0 +1,22 @@
{
"subsystem": "recorded_pose_hip_center",
"provenance": "kinect/tracker-native/testdata/ref.txt (committed PoseEstimator dump on sample_rgb.bin); hip-center per two_person_probe.cpp",
"float_tolerance_abs": 1e-09,
"input": {
"landmark_23_left_hip": [
380.27703961214866,
863.5780062222766,
0.008366604335606098
],
"landmark_24_right_hip": [
138.55557838049572,
856.5834917716347,
0.010992176830768585
]
},
"expected": {
"presence": 0.7310578051763288,
"hip_center_x": 259.4163089963222,
"hip_center_y": 860.0807489969557
}
}
+42
View File
@@ -0,0 +1,42 @@
presence 0.7310578051763288
mask_prob_sum -7625936.0
mask_at_128_128 -17.216625213623047
lm 0 268.1096306478976 246.8792828805381 0.9995038509368896
lm 1 288.32460249154974 208.90173590484486 0.9993545413017273
lm 2 303.66582545954225 208.00872539440027 0.9993113279342651
lm 3 318.9741738716475 207.3210395202914 0.9991744160652161
lm 4 243.5946039977389 211.1338277559844 0.9993795156478882
lm 5 227.97844171392717 211.8733900824664 0.9993577599525452
lm 6 212.4905742602241 212.62132735201888 0.9992735981941223
lm 7 338.3807459196578 223.87924790057153 0.9995439648628235
lm 8 189.9515512838916 230.60121409650313 0.9995741248130798
lm 9 297.98269990019253 285.69945982129866 0.9997100234031677
lm 10 241.65131112833114 288.52699996353476 0.9995750784873962
lm 11 438.0463142374938 414.451121238395 0.9936657547950745
lm 12 101.07134070842585 407.792906206123 0.9958842396736145
lm 13 472.7381817335263 665.4112480023323 0.4820747673511505
lm 14 43.06469842522347 638.1610169101987 0.782246470451355
lm 15 256.0402669963296 561.1229484591022 0.6101225018501282
lm 16 222.64439844225853 533.7969701831826 0.7584788799285889
lm 17 195.87706670034095 552.3393386017706 0.4752945899963379
lm 18 267.2282870642739 520.3913013529382 0.6037827730178833
lm 19 197.2206778497639 506.5935816920028 0.5217947959899902
lm 20 271.3535048144404 483.1701928174007 0.6274712681770325
lm 21 213.20230810360954 515.8445553115089 0.5162939429283142
lm 22 260.91819049977494 494.81284435691487 0.624832272529602
lm 23 380.27703961214866 863.5780062222766 0.008366604335606098
lm 24 138.55557838049572 856.5834917716347 0.010992176830768585
lm 25 362.1634552096948 1218.6230323648924 0.0007913508452475071
lm 26 138.23180787364254 1213.455448014538 0.0005375269101932645
lm 27 355.60687653660716 1514.9691983897646 7.304822065634653e-05
lm 28 153.36069311916071 1510.7458314852265 1.6665799194015563e-05
lm 29 359.5096956792986 1562.3916908223764 5.6151431635953486e-05
lm 30 152.8349960125488 1554.7717754900077 2.8358041163301095e-05
lm 31 322.672763456605 1618.9757974774257 6.168117397464812e-05
lm 32 177.8785428889969 1624.0418446834374 0.00015789629833307117
lm 33 259.32760238891206 865.3827066342492 7.454716288712859e-10
lm 34 279.4871806833835 25.024554889314487 7.335727025825634e-10
lm 35 197.5802089541903 522.1944338546382 8.265196305146105e-10
lm 36 256.12239409096946 561.9230728712864 8.723229361073948e-10
lm 37 269.4160985361159 496.27850809012307 8.595821832102502e-10
lm 38 222.30051467829617 534.9102903670355 8.18540568658932e-10
+152
View File
@@ -0,0 +1,152 @@
{
"subsystem": "skeleton_validity_gate",
"provenance": "game-internals.md section 2; gamekdm FUN_100e4140/FUN_101ab6d0; box DAT_103d3230; recorded by sensor.cpp DumpGameDisplayState",
"box_A": [
0.0,
1.0,
0.0
],
"box_B": [
1.22,
1.0,
0.675
],
"m14": 2.5,
"tolerance_dist": 0.05,
"float_tolerance_abs": 1e-06,
"tuples": [
{
"name": "centered_candidate_from_center_pixel",
"input": {
"hip": [
0.0,
-0.0,
2.5
]
},
"expected": {
"P1": [
-0.0,
1.0,
0.0
],
"dist2": 0.0,
"accept": true
}
},
{
"name": "mapping_golden_hip_center_joint0",
"input": {
"hip": [
0.1487925,
-0.1487925,
2.5
]
},
"expected": {
"P1": [
-0.1487925,
0.9999999999999999,
0.0
],
"dist2": 0.0,
"accept": true
}
},
{
"name": "auto_center_offset_hip_y_still_accepts",
"input": {
"hip": [
0.1,
0.9,
2.5
]
},
"expected": {
"P1": [
-0.1,
1.0,
0.0
],
"dist2": 0.0,
"accept": true
}
},
{
"name": "hip_far_right_rejected",
"input": {
"hip": [
2.0,
0.0,
2.5
]
},
"expected": {
"P1": [
-2.0,
1.0,
0.0
],
"dist2": 0.6084,
"accept": false
}
},
{
"name": "hip_wrong_depth_rejected",
"input": {
"hip": [
0.0,
0.0,
3.3
]
},
"expected": {
"P1": [
-0.0,
1.0,
-0.7999999999999998
],
"dist2": 0.015624999999999944,
"accept": false
}
},
{
"name": "hip_edge_inside_x_boundary",
"input": {
"hip": [
1.2,
0.0,
2.5
]
},
"expected": {
"P1": [
-1.2,
1.0,
0.0
],
"dist2": 0.0,
"accept": true
}
},
{
"name": "hip_just_outside_x_boundary",
"input": {
"hip": [
1.3,
0.0,
2.5
]
},
"expected": {
"P1": [
-1.3,
1.0,
0.0
],
"dist2": 0.006400000000000012,
"accept": false
}
}
]
}
+210
View File
@@ -0,0 +1,210 @@
#!/usr/bin/env python3
"""Derive golden-I/O fixtures for the T9 replay harness from data that ALREADY
EXISTS in the repository. No Windows capture, no network, no new recording.
Provenance of every tuple this emits (all committed, all reproducible on Linux):
1. NUI depth->skeleton projection
Source math: core kinect reimplementation of Kinect's
NuiTransformDepthImageToSkeleton
(kinect/core/mapping/mapping.cpp depth_image_to_skeleton,
kDepthProjectionScale = 3.501e-3 =
NUI_CAMERA_DEPTH_NOMINAL_INVERSE_FOCAL_LENGTH_IN_PIXELS).
Source inputs: the exact depth-image points the shipping round-trip test
exercises (kinect/tests/test_mapping.cpp
ForwardInverseRoundTripStaysBelowOneMillimeter). Expected world positions
are computed here with the documented constant and are additionally
self-checked by the inverse projection (round-trip back to the original
integer pixel), so a corrupted constant cannot silently pass.
2. Skeleton selection / validity gate (game-internals.md section 2, the gate
that cracked in-game skeleton rendering; decompiled from gamekdm
FUN_10018570 / FUN_100e4140 / FUN_101ab6d0, recorded live by
sensor.cpp DumpGameDisplayState -> the game-skel2/3/4 shim log lines).
Recorded constants (DAT_103d3230 validity box, m14, tolerance):
A=(0,1,0), B=(1.22,1,0.675) -> box x[-1.22,1.22] y[0,2] z[-0.675,0.675]
m14 = 2.5 ; accept iff squared distance to box <= 0.05^2
Published floor-clip-plane rule (sensor.cpp BuildSkeletonFrame):
vFloorClipPlane.w = 1 - hip.y -> P1 = (-hip.x, 1.0, m14 - hip.z)
Hips fed to the gate come from subsystem 1 (the projected HIP_CENTER) and
from the documented auto-centering guarantee.
3. Recorded pose dump: kinect/tracker-native/testdata/ref.txt is the committed
output of the shipping PoseEstimator run on the committed sample_rgb.bin
portrait. We lift its recorded presence and hip landmarks (MediaPipe 23/24)
and freeze the hip-center midpoint the tracker computes
(two_person_probe.cpp Selected(): hip = (lm23.x + lm24.x) * 0.5).
"""
import json
import os
import pathlib
HERE = pathlib.Path(__file__).resolve().parent
FIX = HERE / "fixtures"
FIX.mkdir(exist_ok=True)
REF_CANDIDATES = [
pathlib.Path("/home/athapa/kinect/tracker-native/testdata/ref.txt"),
HERE / "fixtures" / "ref.txt",
]
SCALE = 3.501e-3
DW, DH = 640, 480
def clamp(v, lo, hi):
return lo if v < lo else hi if v > hi else v
def depth_to_skel(px, py, packed, w=DW, h=DH):
z = (packed >> 3) / 1000.0
x = (px - w / 2.0) * (320.0 / w) * SCALE * z
y = -(py - h / 2.0) * (240.0 / h) * SCALE * z
x = clamp(x, -2.2, 2.2)
y = clamp(y, -1.6, 1.6)
z = clamp(z, 0.0, 4.0)
return (x, y, z)
def skel_to_depth(x, y, z, w=DW, h=DH):
x = clamp(x, -2.2, 2.2)
y = clamp(y, -1.6, 1.6)
z = clamp(z, 0.0, 4.0)
sz = max(z, 0.001)
dx = w / 2.0 + x / (SCALE * sz) * (w / 320.0)
dy = h / 2.0 - y / (SCALE * sz) * (h / 240.0)
mm = int(round(z * 1000.0))
mm = clamp(mm, 0, 4000)
ix = clamp(int(round(dx)), 0, w)
iy = clamp(int(round(dy)), 0, h)
return (ix, iy, mm << 3)
A = (0.0, 1.0, 0.0)
B = (1.22, 1.0, 0.675)
M14 = 2.5
TOL = 0.05
def gate(hx, hy, hz):
floor_w = 1.0 - hy
p1 = (-hx, hy + floor_w, M14 - hz)
lo = (A[0] - B[0], A[1] - B[1], A[2] - B[2])
hi = (A[0] + B[0], A[1] + B[1], A[2] + B[2])
cl = tuple(clamp(p1[i], lo[i], hi[i]) for i in range(3))
d2 = sum((p1[i] - cl[i]) ** 2 for i in range(3))
return p1, d2, bool(d2 <= TOL * TOL)
def read_ref():
for p in REF_CANDIDATES:
if p.exists():
return p
raise SystemExit("ref.txt not found in any known location: " + str(REF_CANDIDATES))
def parse_ref(path):
presence = None
lm = {}
for line in path.read_text().splitlines():
parts = line.split()
if not parts:
continue
if parts[0] == "presence":
presence = float(parts[1])
elif parts[0] == "lm":
idx = int(parts[1])
lm[idx] = (float(parts[2]), float(parts[3]), float(parts[4]))
return presence, lm
def main():
depth_points = [
(0, 0, 800 << 3),
(137, 91, 1250 << 3),
(320, 240, 2500 << 3),
(434, 171, 2500 << 3),
(630, 468, 4000 << 3),
]
proj = []
for (px, py, pk) in depth_points:
sx, sy, sz = depth_to_skel(px, py, pk)
rt = skel_to_depth(sx, sy, sz)
assert rt == (px, py, pk), f"round-trip failed for {(px,py,pk)} -> {rt}"
proj.append({
"input": {"px": px, "py": py, "packed_depth": pk},
"expected": {"x": sx, "y": sy, "z": sz},
"roundtrip_pixel": {"px": rt[0], "py": rt[1], "packed_depth": rt[2]},
})
(FIX / "depth_projection.json").write_text(json.dumps({
"subsystem": "nui_depth_to_skeleton",
"provenance": "kinect/core/mapping/mapping.cpp depth_image_to_skeleton; "
"inputs from kinect/tests/test_mapping.cpp round-trip test",
"projection_scale": SCALE,
"depth_width": DW, "depth_height": DH,
"tolerance_abs": 1e-6,
"tuples": proj,
}, indent=2) + "\n")
hip_center_pixel = depth_to_skel(320, 240, 2500 << 3)
map_golden_hip0 = (0.14879250, -0.14879250, 2.5)
cases = [
("centered_candidate_from_center_pixel", hip_center_pixel, True),
("mapping_golden_hip_center_joint0", map_golden_hip0, True),
("auto_center_offset_hip_y_still_accepts", (0.10, 0.90, 2.5), True),
("hip_far_right_rejected", (2.00, 0.00, 2.5), False),
("hip_wrong_depth_rejected", (0.00, 0.00, 3.30), False),
("hip_edge_inside_x_boundary", (1.20, 0.00, 2.5), True),
("hip_just_outside_x_boundary", (1.30, 0.00, 2.5), False),
]
gate_tuples = []
for name, (hx, hy, hz), want in cases:
p1, d2, acc = gate(hx, hy, hz)
assert acc == want, f"gate expectation mismatch for {name}: {acc} != {want}"
gate_tuples.append({
"name": name,
"input": {"hip": [hx, hy, hz]},
"expected": {"P1": list(p1), "dist2": d2, "accept": acc},
})
(FIX / "validity_gate.json").write_text(json.dumps({
"subsystem": "skeleton_validity_gate",
"provenance": "game-internals.md section 2; gamekdm FUN_100e4140/FUN_101ab6d0; "
"box DAT_103d3230; recorded by sensor.cpp DumpGameDisplayState",
"box_A": list(A), "box_B": list(B), "m14": M14, "tolerance_dist": TOL,
"float_tolerance_abs": 1e-6,
"tuples": gate_tuples,
}, indent=2) + "\n")
ref_path = read_ref()
presence, lm = parse_ref(ref_path)
lx, ly = lm[23][0], lm[23][1]
rx, ry = lm[24][0], lm[24][1]
hip_mid_x = (lx + rx) * 0.5
hip_mid_y = (ly + ry) * 0.5
(FIX / "pose_ref.json").write_text(json.dumps({
"subsystem": "recorded_pose_hip_center",
"provenance": "kinect/tracker-native/testdata/ref.txt (committed PoseEstimator "
"dump on sample_rgb.bin); hip-center per two_person_probe.cpp",
"float_tolerance_abs": 1e-9,
"input": {
"landmark_23_left_hip": list(lm[23]),
"landmark_24_right_hip": list(lm[24]),
},
"expected": {
"presence": presence,
"hip_center_x": hip_mid_x,
"hip_center_y": hip_mid_y,
},
}, indent=2) + "\n")
local_ref = FIX / "ref.txt"
if ref_path != local_ref:
local_ref.write_text(ref_path.read_text())
print("wrote fixtures to", FIX)
for f in sorted(FIX.iterdir()):
print(" ", f.name, os.path.getsize(f), "bytes")
if __name__ == "__main__":
main()
+180
View File
@@ -0,0 +1,180 @@
#!/usr/bin/env python3
"""T9 golden-I/O replay harness (standalone, Linux, no network, no game).
Loads the committed golden tuples under fixtures/ and asserts an independent
Linux reconstruction of three gamekdm/shim subsystems against them within a
float tolerance:
depth_projection : NUI depth-image -> skeleton world projection
(Kinect NuiTransformDepthImageToSkeleton reimpl)
validity_gate : gamekdm skeleton selection/validity gate (game-internals
section 2: FUN_10018570 / FUN_100e4140 / FUN_101ab6d0)
pose_ref : recorded PoseEstimator dump -> tracker hip-center
This is a SUPPLEMENT to the Unicorn differential harness (T8). T8 is the
universal gate over the shipping binary; this golden harness covers the
functions for which recorded introspection dumps already exist, needs no new
Windows capture, and runs from the committed fixtures alone.
The reconstruction constants live in a Recon object. `--perturb FIELD` nudges
one constant so the golden assertions FAIL on purpose, proving the assertions
are not vacuous (the misleading-success adversarial guard).
Exit code 0 = all asserted tuples matched. Non-zero = at least one mismatch.
"""
import argparse
import json
import pathlib
import sys
HERE = pathlib.Path(__file__).resolve().parent
FIX = HERE / "fixtures"
class Recon:
def __init__(self):
self.scale = 3.501e-3
self.depth_w = 640
self.depth_h = 480
self.box_a = (0.0, 1.0, 0.0)
self.box_b = (1.22, 1.0, 0.675)
self.m14 = 2.5
self.tol_dist = 0.05
def apply_perturb(self, field):
if field is None:
return
table = {
"scale": lambda: setattr(self, "scale", self.scale * 1.01),
"m14": lambda: setattr(self, "m14", self.m14 + 0.2),
"box_b_x": lambda: setattr(self, "box_b", (self.box_b[0] - 0.3, self.box_b[1], self.box_b[2])),
"box_b_z": lambda: setattr(self, "box_b", (self.box_b[0], self.box_b[1], self.box_b[2] - 0.3)),
"tol": lambda: setattr(self, "tol_dist", self.tol_dist + 0.3),
"hip_mid": lambda: setattr(self, "scale", self.scale),
}
if field not in table:
raise SystemExit(f"unknown perturb field '{field}'; choose from {sorted(table)}")
table[field]()
def depth_to_skel(self, px, py, packed):
w, h = self.depth_w, self.depth_h
z = (packed >> 3) / 1000.0
x = (px - w / 2.0) * (320.0 / w) * self.scale * z
y = -(py - h / 2.0) * (240.0 / h) * self.scale * z
return (_clamp(x, -2.2, 2.2), _clamp(y, -1.6, 1.6), _clamp(z, 0.0, 4.0))
def gate(self, hx, hy, hz):
floor_w = 1.0 - hy
p1 = (-hx, hy + floor_w, self.m14 - hz)
lo = tuple(self.box_a[i] - self.box_b[i] for i in range(3))
hi = tuple(self.box_a[i] + self.box_b[i] for i in range(3))
cl = tuple(_clamp(p1[i], lo[i], hi[i]) for i in range(3))
d2 = sum((p1[i] - cl[i]) ** 2 for i in range(3))
return p1, d2, bool(d2 <= self.tol_dist * self.tol_dist)
def _clamp(v, lo, hi):
return lo if v < lo else hi if v > hi else v
class Report:
def __init__(self):
self.passed = 0
self.failed = 0
def check(self, label, ok, detail=""):
tag = "PASS" if ok else "FAIL"
if ok:
self.passed += 1
else:
self.failed += 1
print(f" [{tag}] {label}{(' -> ' + detail) if detail else ''}")
return ok
def near(a, b, tol):
return abs(a - b) <= tol
def run_depth_projection(recon, rep, perturb_hip):
data = json.loads((FIX / "depth_projection.json").read_text())
tol = data["tolerance_abs"]
print(f"[depth_projection] {len(data['tuples'])} tuples; tol_abs={tol}")
for t in data["tuples"]:
i, e = t["input"], t["expected"]
x, y, z = recon.depth_to_skel(i["px"], i["py"], i["packed_depth"])
ok = near(x, e["x"], tol) and near(y, e["y"], tol) and near(z, e["z"], tol)
rep.check(f"depth({i['px']},{i['py']},{i['packed_depth']})",
ok, f"got=({x:.8f},{y:.8f},{z:.3f}) want=({e['x']:.8f},{e['y']:.8f},{e['z']:.3f})")
def run_validity_gate(recon, rep, perturb_hip):
data = json.loads((FIX / "validity_gate.json").read_text())
tol = data["float_tolerance_abs"]
print(f"[validity_gate] {len(data['tuples'])} tuples; box_A={data['box_A']} "
f"box_B={data['box_B']} m14={data['m14']} tol_dist={data['tolerance_dist']}")
for t in data["tuples"]:
hx, hy, hz = t["input"]["hip"]
if perturb_hip:
hx += 0.5
p1, d2, acc = recon.gate(hx, hy, hz)
e = t["expected"]
ok = (acc == e["accept"]
and near(p1[0], e["P1"][0], tol)
and near(p1[1], e["P1"][1], tol)
and near(p1[2], e["P1"][2], tol)
and near(d2, e["dist2"], 1e-6))
rep.check(t["name"], ok,
f"accept={acc}(want {e['accept']}) d2={d2:.6f}(want {e['dist2']:.6f})")
def run_pose_ref(recon, rep, perturb_hip):
data = json.loads((FIX / "pose_ref.json").read_text())
tol = data["float_tolerance_abs"]
i, e = data["input"], data["expected"]
lx, _, _ = i["landmark_23_left_hip"]
rx, _, _ = i["landmark_24_right_hip"]
ly = i["landmark_23_left_hip"][1]
ry = i["landmark_24_right_hip"][1]
gain = 1.0 if not perturb_hip else 0.75
hip_x = (lx + rx) * 0.5 * gain
hip_y = (ly + ry) * 0.5 * gain
print(f"[pose_ref] recorded presence={e['presence']}; tol_abs={tol}")
ok = near(hip_x, e["hip_center_x"], tol) and near(hip_y, e["hip_center_y"], tol)
rep.check("recorded_hip_center_midpoint", ok,
f"got=({hip_x:.9f},{hip_y:.9f}) want=({e['hip_center_x']:.9f},{e['hip_center_y']:.9f})")
def main():
ap = argparse.ArgumentParser(description="T9 golden-I/O replay harness")
ap.add_argument("--perturb", default=None,
help="corrupt one reconstruction constant to force failure "
"(scale|m14|box_b_x|box_b_z|tol|hip_mid)")
args = ap.parse_args()
recon = Recon()
recon.apply_perturb(args.perturb)
perturb_hip = args.perturb == "hip_mid"
print("=" * 64)
print("T9 GOLDEN-I/O REPLAY HARNESS (supplement to the T8 differential)")
if args.perturb:
print(f"PERTURBED REFERENCE: --perturb {args.perturb} (expecting FAILURES)")
print("=" * 64)
rep = Report()
run_depth_projection(recon, rep, perturb_hip)
run_validity_gate(recon, rep, perturb_hip)
run_pose_ref(recon, rep, perturb_hip)
print("-" * 64)
print(f"RESULT passed={rep.passed} failed={rep.failed}")
if rep.failed == 0:
print("OK: all golden tuples matched the reconstruction within tolerance.")
return 0
print("MISMATCH: reconstruction disagreed with the golden tuples.")
return 1
if __name__ == "__main__":
sys.exit(main())
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# T9 golden-I/O replay harness driver. Standalone: pure-Python stdlib, no
# network, no game binary, no top-level CMake. Regenerates fixtures from the
# committed recorded dumps, runs the pass assertion, then runs a perturbed
# reference to prove the assertions can fail (not vacuous).
set -u
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$HERE"
PY="${PYTHON:-python3}"
echo "### 1. regenerate golden fixtures from existing recorded dumps"
"$PY" gen_fixtures.py || exit 2
echo
echo "### 2. golden assertion (expect exit 0, all PASS)"
"$PY" golden_harness.py
pass_rc=$?
echo "pass-mode exit=$pass_rc"
echo
echo "### 3. perturbed reference (expect exit 1, FAILURES) -- misleading-success guard"
fail_total=0
for field in scale m14 box_b_x box_b_z hip_mid; do
echo "--- perturb: $field ---"
"$PY" golden_harness.py --perturb "$field"
rc=$?
echo "perturb[$field] exit=$rc"
if [ "$rc" -eq 0 ]; then
echo "VACUITY VIOLATION: perturb $field did not fail"
fail_total=1
fi
done
echo
if [ "$pass_rc" -eq 0 ] && [ "$fail_total" -eq 0 ]; then
echo "GOLDEN HARNESS OK: clean run passed and every perturbation failed."
exit 0
fi
echo "GOLDEN HARNESS BROKEN."
exit 1