import yaml from ml_porosity.paths import REPO_ROOT CONFIGS = REPO_ROOT / "configs" def test_d2_p3_generator_matches_p2(): """protocol_p3 uses the protocol_p2 D2 generator: only the regimes block may be added.""" p2 = yaml.safe_load((CONFIGS / "d2_synth.yaml").read_text()) p3 = yaml.safe_load((CONFIGS / "d2_synth_p3.yaml").read_text()) regimes = p3.pop("regimes") assert p3 == p2 assert all(set(r) == {"snr_db", "anchor_density"} for r in regimes.values()) def test_p3_regimes_and_realizations(): P = yaml.safe_load((CONFIGS / "protocol_p3.yaml").read_text()) regimes = yaml.safe_load((REPO_ROOT / P["inputs"]["d2_config"]["path"]).read_text())["regimes"] assert set(P["grid"]["regimes"]) <= set(regimes) p2 = yaml.safe_load((CONFIGS / "protocol_p2.yaml").read_text())["grid"] used = set(p2["realizations"]) | set(p2["dev_realizations"]) assert not used & set(P["grid"]["realizations"]) def test_locked_protocols_match_sha256(): """Locked protocols must not change after locking (a change needs a new version).""" import hashlib for name in ["protocol_p2", "protocol_p3"]: sha, path = (CONFIGS / f"{name}.sha256").read_text().split() assert hashlib.sha256((REPO_ROOT / path).read_bytes()).hexdigest() == sha def test_p3_inputs_match_sha256(): import hashlib P = yaml.safe_load((CONFIGS / "protocol_p3.yaml").read_text()) for key in ["d2_config", "budgets", "warp_prior", "wavelet"]: f = REPO_ROOT / P["inputs"][key]["path"] if not f.exists(): # outputs/ is not versioned continue assert hashlib.sha256(f.read_bytes()).hexdigest() == P["inputs"][key]["sha256"], key