From f715147b2372df714f31ff46663206cf3a8e0a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6lnberger?= <159939812+ProfRandom92@users.noreply.github.com> Date: Tue, 19 May 2026 08:07:12 -0700 Subject: [PATCH] Add deterministic benchmark artifact reproducibility test --- tests/test_artifact_reproducibility.py | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/test_artifact_reproducibility.py diff --git a/tests/test_artifact_reproducibility.py b/tests/test_artifact_reproducibility.py new file mode 100644 index 0000000..3be9bfa --- /dev/null +++ b/tests/test_artifact_reproducibility.py @@ -0,0 +1,46 @@ +from __future__ import annotations + +import json +from collections.abc import Callable +from dataclasses import dataclass +from pathlib import Path + +from scripts.generate_layered_admissibility_artifact import ( + generate_layered_admissibility_artifact, +) + + +@dataclass(frozen=True) +class DeterministicArtifactSpec: + """Configuration for a reproducible committed artifact check.""" + + name: str + committed_path: Path + regenerate: Callable[[Path], Path] + + +ARTIFACT_SPECS: tuple[DeterministicArtifactSpec, ...] = ( + DeterministicArtifactSpec( + name="layered_admissibility_results", + committed_path=Path("artifacts/layered_admissibility_results.json"), + regenerate=generate_layered_admissibility_artifact, + ), +) + + +def _load_json(path: Path) -> object: + return json.loads(path.read_text(encoding="utf-8")) + + +def test_committed_deterministic_artifacts_are_reproducible(tmp_path: Path) -> None: + for spec in ARTIFACT_SPECS: + regenerated_path = tmp_path / spec.committed_path.name + spec.regenerate(regenerated_path) + + regenerated_payload = _load_json(regenerated_path) + committed_payload = _load_json(spec.committed_path) + + assert regenerated_payload == committed_payload, ( + f"Deterministic artifact drift detected for '{spec.name}'. " + f"Regenerate with: python scripts/generate_layered_admissibility_artifact.py" + )