test: preserve scalar receipts when optional shear probes fail

This commit is contained in:
TRON Bot committed 2026-10-18 20:22:23 -07:00
1 parent caa573f978
commit 1f64f7eb11
4 files changed
+69 -11

No files matched your search

+15 -4
View File
@@ -107,6 +107,12 @@ def residuals(trace):
return out
def validate_row(row, probe_count):
"""Reject an invalid optional sample before it can enter a scalar receipt."""
if len(row) != 3 * probe_count or not all(math.isfinite(v) for v in row):
raise ValueError("malformed or nonfinite trace row")
def validate(trace):
"""Exact schedule, finite values, fixed probe count and byte cap."""
import json
@@ -114,10 +120,15 @@ def validate(trace):
raise ValueError("trace steps differ from the fixed schedule")
if len(trace["probes"]) != len(NORMAL_COORDS) * len(TRANSECTS):
raise ValueError("unexpected probe count")
width = 3 * len(trace["probes"])
if any(len(r) != width or not all(math.isfinite(v) for v in r) for r in trace["values"]):
raise ValueError("malformed or nonfinite trace row")
size = len(json.dumps(trace, allow_nan=False).encode())
for row in trace["values"]:
validate_row(row, len(trace["probes"]))
# Include the final byte-count field itself, including its number of digits.
size = 0
while True:
final_size = len(json.dumps(dict(trace, bytes=size), allow_nan=False).encode())
if final_size == size:
break
size = final_size
if size > TRACE_MAX_BYTES:
raise ValueError(f"trace exceeds {TRACE_MAX_BYTES} bytes ({size})")
return size