-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_artifact_reproducibility.py
More file actions
54 lines (41 loc) · 1.73 KB
/
Copy pathtest_artifact_reproducibility.py
File metadata and controls
54 lines (41 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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,
)
from scripts.generate_multi_family_admissibility_artifact import (
generate_multi_family_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,
),
DeterministicArtifactSpec(
name="multi_family_admissibility_results",
committed_path=Path("artifacts/multi_family_admissibility_results.json"),
regenerate=generate_multi_family_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"
)