EdwardoSunny's picture
Pipeline code snapshot (rubric_gen + gke) matching commit bee1bd2
f45837e verified
Raw History Blame Contribute Delete
4.67 kB
"""The split and the leakage guard.
These are the tests that matter most in this repo. Every claim about the
rubrics being untainted reduces to `assert_minable` being correct and being
called, so both are tested directly rather than assumed.
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
import split as split_mod
@pytest.fixture(scope="module")
def sp():
return split_mod.Split(split_mod.load_manifest())
def test_uses_the_frozen_development_split(sp):
assert len(sp.source) == 5
assert len(sp.evaluation) == 15
def test_split_is_disjoint(sp):
assert not set(sp.source) & set(sp.evaluation)
def test_source_fraction_is_one_quarter(sp):
assert sp.train_fraction == pytest.approx(0.25)
def test_every_tier_is_represented_in_train():
"""A train set missing a whole difficulty class would silently bias the
rubrics toward whatever complexity survived the sample."""
manifest = split_mod.load_manifest()
tiers = {e["tier"] for e in manifest["source_competitions"]}
assert tiers == {"low", "medium", "high"}
def test_eval_competition_is_refused(sp):
victim = sp.evaluation[0]
with pytest.raises(SystemExit, match="LEAKAGE"):
sp.assert_minable(victim)
def test_every_eval_competition_is_refused(sp):
"""Not a spot check. All held-out development competitions are unreachable."""
for comp in sp.evaluation:
with pytest.raises(SystemExit):
sp.assert_minable(comp)
def test_every_train_competition_is_allowed(sp):
for comp in sp.source:
sp.assert_minable(comp)
def test_unknown_competition_is_refused(sp):
"""Allow-list, not deny-list: a typo or a renamed slug must fail closed."""
with pytest.raises(SystemExit, match="LEAKAGE GUARD"):
sp.assert_minable("titanic")
with pytest.raises(SystemExit, match="LEAKAGE GUARD"):
sp.assert_minable("dog-breed-identificatio") # one char short
def test_guard_normalizes_paths_and_case(sp):
comp = sp.source[0]
sp.assert_minable(comp.upper())
sp.assert_minable(f" {comp} ")
sp.assert_minable(f"/some/data/dir/{comp}/")
victim = sp.evaluation[0]
with pytest.raises(SystemExit):
sp.assert_minable(f"/data/{victim.upper()}/prepared")
def test_overlapping_manifest_is_rejected():
"""A broken manifest must fail loudly at construction, not mine quietly."""
bad = {"source_competitions": [{"id": "a"}, {"id": "b"}],
"evaluation_competitions": [{"id": "b"}], "frozen": True}
with pytest.raises(SystemExit, match="SPLIT IS BROKEN"):
split_mod.Split(bad)
def test_unfrozen_manifest_is_refused_in_strict_mode(tmp_path, monkeypatch):
manifest = split_mod.load_manifest()
manifest["frozen"] = False
path = tmp_path / "thawed.json"
path.write_text(json.dumps(manifest))
monkeypatch.setattr(split_mod, "MANIFEST", path)
monkeypatch.setattr(split_mod, "_SPLIT", None)
with pytest.raises(SystemExit, match="not frozen"):
split_mod.get(strict=True)
def test_default_manifest_is_the_canonical_experiment_manifest():
from shared.protocol import SPLIT_MANIFEST
assert split_mod.MANIFEST.resolve() == SPLIT_MANIFEST.resolve()
# ------------------------------------------- the mirror guard, for measuring
def test_train_competition_is_refused_by_the_measurement_guard(sp):
"""Scoring rubrics on the competitions they were mined from would report
memorization as transfer -- and it would look like a great result."""
for comp in sp.source:
with pytest.raises(SystemExit, match="CONTAMINATED MEASUREMENT"):
sp.assert_evaluation_only(comp)
def test_every_eval_competition_is_allowed_for_measurement(sp):
for comp in sp.evaluation:
sp.assert_evaluation_only(comp)
def test_unknown_competition_is_refused_by_both_guards(sp):
with pytest.raises(SystemExit):
sp.assert_evaluation_only("titanic")
with pytest.raises(SystemExit):
sp.assert_minable("titanic")
def test_the_two_guards_are_exact_complements(sp):
"""No competition may pass both, and none of the 75 may fail both."""
for comp in sp.source + sp.evaluation:
passed_mine = passed_eval = False
try:
sp.assert_minable(comp); passed_mine = True
except SystemExit:
pass
try:
sp.assert_evaluation_only(comp); passed_eval = True
except SystemExit:
pass
assert passed_mine != passed_eval, f"{comp} passed {passed_mine=} {passed_eval=}"