Skip to content

Commit 279c8a3

Browse files
committed
test(buyer): reject failed optional evidence manifests
1 parent 6cebecc commit 279c8a3

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import hashlib
2+
import importlib.util
3+
import json
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
9+
def _load_packet_builder():
10+
script = Path(__file__).resolve().parents[1] / "scripts" / "build_buyer_packet.py"
11+
spec = importlib.util.spec_from_file_location("build_buyer_packet_optional_status", script)
12+
assert spec is not None
13+
module = importlib.util.module_from_spec(spec)
14+
assert spec.loader is not None
15+
spec.loader.exec_module(module)
16+
return module
17+
18+
19+
def _write_json(path: Path, payload: dict[str, object]) -> Path:
20+
path.parent.mkdir(parents=True, exist_ok=True)
21+
path.write_text(json.dumps(payload), encoding="utf-8")
22+
return path
23+
24+
25+
def _write_html(path: Path) -> str:
26+
path.parent.mkdir(parents=True, exist_ok=True)
27+
path.write_text("<!doctype html><title>evidence</title>", encoding="utf-8")
28+
return hashlib.sha256(path.read_bytes()).hexdigest()
29+
30+
31+
def _base_paths(tmp_path: Path) -> tuple[Path, Path, Path, Path]:
32+
repo_root = tmp_path / "repo"
33+
repo_root.mkdir()
34+
acceptance_path = _write_json(
35+
tmp_path / "acceptance" / "acceptance_summary.json",
36+
{"status": "ok", "steps": []},
37+
)
38+
sales_path = _write_json(
39+
tmp_path / "acceptance" / "sales_readiness_manifest.json",
40+
{"status": "ok"},
41+
)
42+
dist_dir = tmp_path / "dist"
43+
dist_dir.mkdir()
44+
return repo_root, acceptance_path, sales_path, dist_dir
45+
46+
47+
def test_collect_files_rejects_failed_benchmark_report(
48+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
49+
) -> None:
50+
"""A supplied failed benchmark must not enter an otherwise valid buyer packet."""
51+
module = _load_packet_builder()
52+
monkeypatch.setattr(module, "PRODUCT_DOCS", [])
53+
monkeypatch.setattr(module, "PRODUCT_MANIFESTS", [])
54+
repo_root, acceptance_path, sales_path, dist_dir = _base_paths(tmp_path)
55+
html_path = tmp_path / "benchmark" / "benchmark_report.html"
56+
html_sha = _write_html(html_path)
57+
benchmark_path = _write_json(
58+
tmp_path / "benchmark" / "benchmark_report.json",
59+
{
60+
"status": "failed",
61+
"html_report_file": str(html_path),
62+
"html_report_sha256": html_sha,
63+
},
64+
)
65+
66+
with pytest.raises(RuntimeError, match="benchmark report status is not ok"):
67+
module._collect_files(
68+
repo_root=repo_root,
69+
acceptance_path=acceptance_path,
70+
sales_readiness_path=sales_path,
71+
dist_dir=dist_dir,
72+
benchmark_report_path=benchmark_path,
73+
)
74+
75+
76+
def test_collect_files_rejects_failed_release_evidence_index(
77+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
78+
) -> None:
79+
"""A supplied failed release index must not enter an otherwise valid buyer packet."""
80+
module = _load_packet_builder()
81+
monkeypatch.setattr(module, "PRODUCT_DOCS", [])
82+
monkeypatch.setattr(module, "PRODUCT_MANIFESTS", [])
83+
repo_root, acceptance_path, sales_path, dist_dir = _base_paths(tmp_path)
84+
html_path = tmp_path / "release" / "release_evidence_index.html"
85+
html_sha = _write_html(html_path)
86+
release_index_path = _write_json(
87+
tmp_path / "release" / "release_evidence_index.json",
88+
{
89+
"status": "failed",
90+
"html_report_file": str(html_path),
91+
"html_report_sha256": html_sha,
92+
},
93+
)
94+
95+
with pytest.raises(RuntimeError, match="release evidence index status is not ok"):
96+
module._collect_files(
97+
repo_root=repo_root,
98+
acceptance_path=acceptance_path,
99+
sales_readiness_path=sales_path,
100+
dist_dir=dist_dir,
101+
release_evidence_index_path=release_index_path,
102+
)

0 commit comments

Comments
 (0)