Files
NODEDC_MISSION_CORE/tests/test_semantic_transfer_gates.py
DCCONSTRUCTIONS 25dc0a1b44 feat(semantics): add portable annotation, learning and review contracts
Add portable corpus, annotation provenance, admission, review and bounded agent-cycle contracts. Preserve dataset ownership and explicit research acceptance limits.
2026-10-29 09:10:00 +03:00

52 lines
1.7 KiB
Python

import importlib.util
from pathlib import Path
import pytest
spec = importlib.util.spec_from_file_location(
"transfer_gates",
Path(__file__).resolve().parents[1] / "simulation/semantic-learning/transfer_gates.py",
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
def row(arm, recall, fpr, group="a"):
return dict(
phase="development",
arm=arm,
held_out=group,
fitted_groups=["other"],
completed=True,
metrics=dict(recall=recall, fpr=fpr),
)
def test_lower_average_error_cannot_hide_lost_paint_and_negative_only_has_no_recall():
rows = [
row("base", 1.0, 0.2),
row("candidate", 0.95, 0.01),
row("base", None, 0.1, "negative"),
row("candidate", None, 0.0, "negative"),
]
result = module.component_regressions(rows, "base", ["candidate"])
assert not result["all_components_non_regressing"]
assert [(r["group"], r["metric"]) for r in result["regressions"]] == [("a", "recall")]
def test_unpaired_or_exposed_control_rows_cannot_define_future_gate():
rows = [row("base", 1.0, 0.2), row("candidate", 1.0, 0.1)]
assert module.component_regressions(rows, "base", ["candidate"])[
"all_components_non_regressing"
]
with pytest.raises(ValueError, match="Development"):
module.component_regressions(
[dict(rows[0], phase="regression"), rows[1]], "base", ["candidate"]
)
with pytest.raises(ValueError, match="Unmatched"):
module.component_regressions([rows[0]], "base", ["candidate"])
with pytest.raises(ValueError, match="Leaked"):
module.component_regressions(
[dict(rows[0], fitted_groups=["a"]), rows[1]], "base", ["candidate"]
)