63 lines
2.8 KiB
Python
63 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Regression checks for the fail-closed release evidence gate."""
|
|
|
|
import copy
|
|
import importlib.util
|
|
import json
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
import unittest
|
|
|
|
|
|
SCRIPT = Path(__file__).with_name("check-conformance.py")
|
|
spec = importlib.util.spec_from_file_location("check_conformance", SCRIPT)
|
|
gate = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(gate)
|
|
MANIFEST = json.loads(Path(__file__).with_name("conformance.json").read_text())
|
|
TARGETS = {(row["board"], row["chip"]) for row in MANIFEST["targets"]}
|
|
|
|
|
|
class ConformanceGateTest(unittest.TestCase):
|
|
def test_placeholder_matrix_cannot_pass_without_current_run_artifacts(self):
|
|
manifest = copy.deepcopy(MANIFEST)
|
|
for row in manifest["targets"]:
|
|
row.update(sdk_image_sha256="0" * 64,
|
|
stock_image_sha256="0" * 64,
|
|
simulator_trace_sha256="0" * 64,
|
|
stock_result="mines",
|
|
alkane_share_accept_capture="does-not-exist.json",
|
|
bench_validation="not-run")
|
|
with TemporaryDirectory() as directory:
|
|
errors = gate.validate(manifest, TARGETS, Path(directory), "123",
|
|
"a" * 40, "b" * 64)
|
|
self.assertEqual(len(errors), 64)
|
|
self.assertTrue(all("evidence invalid" in error for error in errors))
|
|
|
|
def test_stale_source_identity_is_rejected(self):
|
|
row = copy.deepcopy(MANIFEST["targets"][0])
|
|
row["stock_result"] = "mines"
|
|
with TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
report = root / "123" / row["board"] / f"{row['chip']}.json"
|
|
report.parent.mkdir(parents=True)
|
|
report.write_text(json.dumps({"schema": 1, "run_id": "123",
|
|
"source_commit": "f" * 40,
|
|
"os_binary_sha256": "b" * 64,
|
|
"board": row["board"], "chip": row["chip"],
|
|
"stock_firmware_modified": False}))
|
|
with self.assertRaisesRegex(ValueError, "different run, source"):
|
|
gate.verify_cell(row, root, "123", "a" * 40, "b" * 64)
|
|
|
|
def test_share_accept_requires_real_difficulty_one_work(self):
|
|
capture = {"nonce_source": "real_silicon_capture",
|
|
"header80": "00" * 80,
|
|
"pool_target_le": "ff" * 32, "nonce": 0,
|
|
"submission": {"id": 4, "method": "mining.submit"},
|
|
"pool_response": {"id": 4, "result": True, "error": None}}
|
|
with self.assertRaisesRegex(ValueError, "below difficulty one"):
|
|
gate.verify_accept(capture)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|