55 lines
2.3 KiB
Python
55 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Tests for the S5-07 full config startup matrix report."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
import generate_linuxcnc_source_config_s5
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
REPORT = ROOT / "coverage/linuxcnc-source-config-s5.report.json"
|
|
|
|
|
|
class LinuxCncSourceConfigS5Tests(unittest.TestCase):
|
|
def test_report_contract(self):
|
|
report = json.loads(REPORT.read_text(encoding="utf-8"))
|
|
self.assertEqual(report["schema"], "linuxcnc-source-config-execution.v1")
|
|
self.assertEqual(report["task_id"], "S5-07")
|
|
self.assertEqual(report["status"], "verified")
|
|
self.assertEqual(report["counts"], {"BLOCKED": 208, "READY": 56, "sim_configs": 216, "test_configs": 48, "total": 264})
|
|
self.assertEqual(len(report["entrypoints"]), 264)
|
|
self.assertTrue(all(row["source_sha256"] for row in report["entrypoints"]))
|
|
self.assertTrue(report["workflow"]["native_wasm_worker_startup_report"]["compatibility"] == "passed")
|
|
|
|
def test_status_diagnostics(self):
|
|
report = json.loads(REPORT.read_text(encoding="utf-8"))
|
|
blocked = [row for row in report["entrypoints"] if row["status"] == "BLOCKED"]
|
|
ready = [row for row in report["entrypoints"] if row["status"] == "READY"]
|
|
self.assertEqual(len(blocked), 208)
|
|
self.assertEqual(len(ready), 56)
|
|
self.assertTrue(all(row["diagnostic_code"] for row in blocked))
|
|
self.assertTrue(all(row["diagnostic_code"] is None for row in ready))
|
|
|
|
def test_self_hash(self):
|
|
report = json.loads(REPORT.read_text(encoding="utf-8"))
|
|
unsigned = {key: value for key, value in report.items() if key != "report_sha256"}
|
|
self.assertEqual(report["report_sha256"], hashlib.sha256(generate_linuxcnc_source_config_s5.canonical(unsigned).encode()).hexdigest())
|
|
|
|
def test_deterministic(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
first = generate_linuxcnc_source_config_s5.generate(ROOT, Path(directory) / "one.json")
|
|
second = generate_linuxcnc_source_config_s5.generate(ROOT, Path(directory) / "two.json")
|
|
self.assertEqual(first, second)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|