Files
NODEDC_MISSION_CORE/tests/test_gaussian_candidate_qualification.py
DCCONSTRUCTIONS d0e5f90952 Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
2026-10-08 09:59:51 +03:00

98 lines
3.7 KiB
Python

"""Candidate episodes must pin new identities without rewriting old evidence."""
import copy
import importlib
from pathlib import Path
import pytest
@pytest.fixture
def qualifier(monkeypatch):
monkeypatch.syspath_prepend(str(Path(__file__).parents[1] / "simulation/ai-polygon"))
return importlib.import_module("qualify_gaussian_episode")
def reference():
return {
"run_id": "airun-" + "b" * 32,
"world": {
"sha256": "c" * 64,
"collider_sha256": "d" * 64,
"settings": {
"heading_degrees": 90,
"spawn_xy": [20, 30],
"max_speed_mps": 0.3,
"camera_height_m": 0.8,
"route_xy": [[20, 50]],
},
},
"request": {
"composition": {
"schema_version": "missioncore.observatory-ai-composition/v1",
"selections": [
{
"group": group,
"module_id": module,
"module_sha256": "0" * 64,
"parameters": {"environment": "park"} if group == "policy" else {},
}
for group, module in (
("segmentation", "simulation-ddrnet-goose"),
("detection", "simulation-rf-detr"),
("policy", "simulation-waypoint-mission"),
("motion", "simulation-cmu-navigation"),
)
],
}
},
"worker": {"runtime_sources": {"scene": "old"}},
"plan": {"sha256": "old", "robot_sha256": "old"},
}
def test_candidate_pins_actual_robot_and_composition_without_mutating_reference(qualifier):
from k1link.simulation.ai_polygon.composition import compose
original = reference()
before = copy.deepcopy(original)
run = qualifier.prepare_run(original, "airun-" + "a" * 32, 180, 4.2, {"a": "b"})
assert original == before
assert run["robot"]["physics"]["contact_model"] == "tracks"
assert run["robot"]["sha256"] == run["request"]["robot_sha256"]
assert run["robot"]["sha256"] == run["plan"]["robot_sha256"]
assert run["plan"]["sha256"] != "old"
assert run["worker"]["runtime_sources"]["scene"] != "old"
graph = compose(qualifier.ROOT, run["request"]["composition"])
assert graph.sha256 == run["qualification"]["composition_sha256"]
assert run["world"]["settings"]["route_xy"][-1] == pytest.approx([20, 34.2])
assert run["world"]["settings"]["max_speed_mps"] == 0.15
@pytest.mark.parametrize(
"identity,seconds,length",
[
("old-run", 180, 4.2),
("airun-" + "a" * 32, 601, 4.2),
("airun-" + "a" * 32, 180, float("nan")),
("airun-" + "a" * 32, 180, 40),
],
)
def test_unbounded_or_ambiguous_episode_is_rejected(qualifier, identity, seconds, length):
with pytest.raises(ValueError):
qualifier.prepare_run(reference(), identity, seconds, length, {})
def test_challenge_is_pinned_separately_from_robot_world_and_model(qualifier):
original = reference()
before = copy.deepcopy(original)
base = qualifier.prepare_run(original, "airun-" + "a" * 32, 180, 4.2, {})
fault = qualifier.prepare_run(original, "airun-" + "c" * 32, 180, 4.2, {}, "observation-loss")
assert original == before
assert base["robot"] == fault["robot"] and base["world"] == fault["world"]
assert "scenario" not in base["qualification"]
assert fault["qualification"]["scenario"]["name"] == "observation-loss"
assert len(fault["qualification"]["scenario"]["sha256"]) == 64
with pytest.raises(ValueError):
qualifier.prepare_run(original, "airun-" + "a" * 32, 180, 4.2, {}, "unknown")