fix(perception): require joint clock readiness before source activation

This commit is contained in:
DCCONSTRUCTIONS
2026-09-02 21:03:33 +03:00
parent 93ae1edbb4
commit 48835a0499
11 changed files with 558 additions and 112 deletions
+52 -1
View File
@@ -4,11 +4,62 @@ from dataclasses import replace
import pytest
from k1link.perception.streaming_clock import ClockMappingError, ClockProbe, ClockWindow
from k1link.perception.streaming_clock import (
ClockBounds,
ClockMappingError,
ClockProbe,
ClockWindow,
)
BASE = 10**16 # Deliberately above IEEE754 exact-integer range.
@pytest.mark.parametrize(
"fault",
[
None,
"float",
"integer",
"plus",
"leading",
"negative_zero",
"extra",
"missing",
"flags",
"wide",
"schema",
],
)
def test_bounds_wire_exact_closed_and_signed(fault):
bounds = window().add(probe())
document = bounds.to_dict()
if fault is None:
assert ClockBounds.from_dict(document) == bounds
return
if fault == "float":
document["measured_at_ns"] = float(bounds.measured_at_ns)
elif fault == "integer":
document["measured_at_ns"] = bounds.measured_at_ns
elif fault == "plus":
document["offset_upper_ns"] = "+1"
elif fault == "leading":
document["measured_at_ns"] = "0" + document["measured_at_ns"]
elif fault == "negative_zero":
document["offset_upper_ns"] = "-0"
elif fault == "extra":
document["ready"] = True
elif fault == "missing":
del document["samples"]
elif fault == "flags":
document["conditional_rate_error_envelope"] = 1
elif fault == "wide":
document["offset_upper_ns"] = str(2**63)
else:
document["schema_version"] = "old"
with pytest.raises(ClockMappingError):
ClockBounds.from_dict(document)
def probe(number=1, *, outbound=1_000_000, inbound=2_000_000, offset=-(10**12)):
sent = BASE + number * 100_000_000
return ClockProbe(