|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import json |
| 4 | +from collections.abc import Callable |
| 5 | +from dataclasses import dataclass |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +from scripts.generate_layered_admissibility_artifact import ( |
| 9 | + generate_layered_admissibility_artifact, |
| 10 | +) |
| 11 | + |
| 12 | + |
| 13 | +@dataclass(frozen=True) |
| 14 | +class DeterministicArtifactSpec: |
| 15 | + """Configuration for a reproducible committed artifact check.""" |
| 16 | + |
| 17 | + name: str |
| 18 | + committed_path: Path |
| 19 | + regenerate: Callable[[Path], Path] |
| 20 | + |
| 21 | + |
| 22 | +ARTIFACT_SPECS: tuple[DeterministicArtifactSpec, ...] = ( |
| 23 | + DeterministicArtifactSpec( |
| 24 | + name="layered_admissibility_results", |
| 25 | + committed_path=Path("artifacts/layered_admissibility_results.json"), |
| 26 | + regenerate=generate_layered_admissibility_artifact, |
| 27 | + ), |
| 28 | +) |
| 29 | + |
| 30 | + |
| 31 | +def _load_json(path: Path) -> object: |
| 32 | + return json.loads(path.read_text(encoding="utf-8")) |
| 33 | + |
| 34 | + |
| 35 | +def test_committed_deterministic_artifacts_are_reproducible(tmp_path: Path) -> None: |
| 36 | + for spec in ARTIFACT_SPECS: |
| 37 | + regenerated_path = tmp_path / spec.committed_path.name |
| 38 | + spec.regenerate(regenerated_path) |
| 39 | + |
| 40 | + regenerated_payload = _load_json(regenerated_path) |
| 41 | + committed_payload = _load_json(spec.committed_path) |
| 42 | + |
| 43 | + assert regenerated_payload == committed_payload, ( |
| 44 | + f"Deterministic artifact drift detected for '{spec.name}'. " |
| 45 | + f"Regenerate with: python scripts/generate_layered_admissibility_artifact.py" |
| 46 | + ) |
0 commit comments