test(perception): add bounded clock-only route and scheduler diagnostics
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
"""Small diagnostic contract tests; no synthetic load on the operator Mac."""
|
||||
|
||||
# ruff: noqa: F811 -- shared fixtures
|
||||
import asyncio
|
||||
import importlib
|
||||
import json
|
||||
from dataclasses import replace
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from test_perception_network_graph_adapter import adapter # noqa: F401
|
||||
from test_perception_source_clock import sample
|
||||
from test_perception_streaming_control_grpc import controlled
|
||||
from test_perception_streaming_grpc import tls # noqa: F401
|
||||
|
||||
from k1link.perception.streaming_clock import ClockReceipt, ClockWindow
|
||||
from k1link.perception.streaming_source_clock import SourceClockMonitor
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fault", [None, "wide", "expired"])
|
||||
def test_diagnostic_uses_both_original_bounds_without_retiming(adapter, fault):
|
||||
module = importlib.import_module("pilot_clock_route_probe")
|
||||
probe = sample()
|
||||
own = ClockWindow("source", "worker", rate_ppm=500, timestamp_error_ns=50_000).add(probe)
|
||||
t5 = probe.local_receive_ns + 10**12 + 1_000_000
|
||||
peer = ClockWindow("worker", "source", rate_ppm=500, timestamp_error_ns=50_000).add(
|
||||
ClockReceipt(probe, t5)
|
||||
)
|
||||
now = probe.local_receive_ns + 2_000_000
|
||||
if fault == "wide":
|
||||
peer = replace(
|
||||
peer, offset_lower_ns=-(10**12) - 6_000_000, offset_upper_ns=-(10**12) + 6_000_000
|
||||
)
|
||||
elif fault == "expired":
|
||||
peer = replace(peer, expires_at_ns=t5 + 1)
|
||||
result = module.assessment(own, peer, now)
|
||||
assert result["ready"] == (fault is None)
|
||||
assert result["own_bounds"] == own.to_dict() and result["peer_bounds"] == peer.to_dict()
|
||||
if fault == "wide":
|
||||
assert int(result["peer_at_use_uncertainty_ns"]) > 5_000_000
|
||||
if fault == "expired":
|
||||
assert result["peer_at_use_uncertainty_ns"] is None
|
||||
|
||||
|
||||
def test_clock_only_client_has_no_source_anchor_data_grant_or_hidden_load(tmp_path, tls, adapter):
|
||||
module = importlib.import_module("pilot_clock_route_probe")
|
||||
|
||||
async def check():
|
||||
async with controlled(tmp_path, tls) as (_, _, server, client, pending, port):
|
||||
pending[0] = None
|
||||
monitor = SourceClockMonitor("worker", 10**12)
|
||||
server.observe = monitor.observe
|
||||
certificate, bootstrap = tmp_path / "cert.pem", tmp_path / "bootstrap.json"
|
||||
certificate.write_bytes(tls[0])
|
||||
module.write_control(
|
||||
bootstrap,
|
||||
{
|
||||
"activation": client.ticket.activation.to_dict(),
|
||||
"token": client.ticket.token,
|
||||
"remote_clock_id": "worker",
|
||||
},
|
||||
)
|
||||
args = SimpleNamespace(
|
||||
role="client",
|
||||
target=f"localhost:{port}",
|
||||
samples=8,
|
||||
bootstrap=bootstrap,
|
||||
certificate=certificate,
|
||||
output=tmp_path / "client.json",
|
||||
)
|
||||
assert await module.run(args) == 0
|
||||
report = json.loads(args.output.read_text())
|
||||
assert len(report["samples"]) == 8 and report["error"] is None
|
||||
assert monitor.ended and monitor.anchor is None
|
||||
assert report["models"] == report["data_payloads"] == 0
|
||||
assert not report["gpu_lease"] and not report["source_started"]
|
||||
assert report["scheduler_witness"]
|
||||
assert all(int(r["t4_ns"]) <= int(r["t6_ns"]) for r in report["samples"])
|
||||
with pytest.raises(ValueError, match="immutable"):
|
||||
await module.run(args)
|
||||
|
||||
asyncio.run(check())
|
||||
Reference in New Issue
Block a user