Buckets:
squaredcuber/loss-aware-dro-repro-artifacts / bundle /v0 /tests /test_scientific_canary_validator.py
| from __future__ import annotations | |
| import importlib.util | |
| import json | |
| import shutil | |
| from pathlib import Path | |
| LANE = Path(__file__).resolve().parents[1] | |
| SPEC = importlib.util.spec_from_file_location("scientific_canary_validator", LANE / "scripts" / "validate_scientific_canary.py") | |
| assert SPEC and SPEC.loader | |
| VALIDATOR = importlib.util.module_from_spec(SPEC) | |
| SPEC.loader.exec_module(VALIDATOR) | |
| def test_historical_manifest_bound_canary_detects_live_source_drift(): | |
| errors = VALIDATOR.validate( | |
| LANE / ".openresearch" / "artifacts" / "scientific-canary-v12", | |
| LANE / ".openresearch" / "control" / "scientific-risk-sensitivity-manifest-v3.json", | |
| ) | |
| assert "live source/config/input tree differs from receipt" in errors | |
| assert "plan byte hash mismatch" in errors | |
| def test_empty_or_forged_trace_fails_closed(tmp_path): | |
| source = LANE / ".openresearch" / "artifacts" / "scientific-canary-v12" | |
| forged = tmp_path / "scientific-canary-v12" | |
| shutil.copytree(source, forged) | |
| (forged / "trace.jsonl").write_text("", encoding="utf-8") | |
| errors = VALIDATOR.validate( | |
| forged, | |
| LANE / ".openresearch" / "control" / "scientific-risk-sensitivity-manifest-v3.json", | |
| ) | |
| assert "trace must be nonempty" in errors | |
| assert "trace hash mismatch" in errors | |
| assert "manifest must bind exactly one run to this receipt" in errors | |
| def test_terminal_and_selected_config_tampering_fail_closed(tmp_path): | |
| source = LANE / ".openresearch" / "artifacts" / "scientific-canary-v12" | |
| forged = tmp_path / "scientific-canary-v12" | |
| shutil.copytree(source, forged) | |
| receipt_path = forged / "receipt.json" | |
| receipt = json.loads(receipt_path.read_text(encoding="utf-8")) | |
| receipt["optimization"]["terminal_solver_status"] = "forged" | |
| receipt["scientific_inputs"]["config_sha256"] = "0" * 64 | |
| receipt_path.write_text(json.dumps(receipt), encoding="utf-8") | |
| errors = VALIDATOR.validate( | |
| forged, | |
| LANE / ".openresearch" / "control" / "scientific-risk-sensitivity-manifest-v3.json", | |
| ) | |
| assert "selected config byte hash mismatch" in errors | |
| assert "terminal solver status is not accepted" in errors | |
Xet Storage Details
- Size:
- 2.24 kB
- Xet hash:
- 1b14a600186c4dffb8f3fab8aba3a237a7c7abe70c66cdb416e56f186b3a33d9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.