forked from ChelseaKR/habitable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_golden.py
More file actions
47 lines (36 loc) · 1.9 KB
/
Copy pathtest_golden.py
File metadata and controls
47 lines (36 loc) · 1.9 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
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright 2026 Chelsea Kelly-Reif
"""Backward-compatibility guard: every packet version we have emitted must verify.
`tests/golden/packet-vN/` holds a committed, self-contained packet for each format
version. These must keep verifying forever — a change that breaks them is the
definition of a backward-incompatible regression and is caught here, not in prose.
"""
from __future__ import annotations
import json
import shutil
from pathlib import Path
from habitable.verify import SUPPORTED_PACKET_VERSION, _check_packet_version, verify_packet
_GOLDEN = Path(__file__).resolve().parent / "golden"
def test_every_golden_packet_verifies() -> None:
corpus = sorted(_GOLDEN.glob("packet-v*"))
assert corpus, "no golden packets committed"
for packet in corpus:
report = verify_packet(packet)
assert report.ok, f"{packet.name}: {report.summary()} {report.problems}"
assert report.signature_ok and report.custody_ok
assert report.verified_items >= 1
def test_unknown_newer_version_is_rejected_not_crashed(tmp_path: Path) -> None:
src = _GOLDEN / "packet-v1"
dst = tmp_path / "future"
shutil.copytree(src, dst)
bundle = json.loads((dst / "bundle.json").read_text())
bundle["packet_version"] = SUPPORTED_PACKET_VERSION + 999 # a format from the future
(dst / "bundle.json").write_text(json.dumps(bundle))
report = verify_packet(dst) # must not raise
assert not report.ok
assert any("newer than supported" in p for p in report.problems)
def test_version_check_unit() -> None:
assert _check_packet_version({"packet_version": SUPPORTED_PACKET_VERSION}) is None
assert _check_packet_version({}) is not None # missing
assert _check_packet_version({"packet_version": True}) is not None # bool is not a version
assert _check_packet_version({"packet_version": SUPPORTED_PACKET_VERSION + 1}) is not None