#!/usr/bin/env python3 """Tests for S6-03 authoritative CoreXY kinematics evidence.""" 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_authoritative_kinematics_s6 ROOT = Path(__file__).resolve().parents[1] REPORT = ROOT / "coverage/authoritative-kinematics-s6.report.json" class AuthoritativeKinematicsS6Tests(unittest.TestCase): def test_contract(self): report = json.loads(REPORT.read_text(encoding="utf-8")) self.assertEqual(report["schema"], "authoritative-kinematics-s6.v1") self.assertEqual(report["task_id"], "S6-03") self.assertEqual(report["status"], "verified") self.assertEqual(report["scope"]["kinematics"], "corexy") self.assertEqual(report["scope"]["joints"], [6, 2, 3]) self.assertEqual(report["scope"]["unsupported_error"], "authoritative_kinematics_unsupported") self.assertTrue(all(item["golden_diff"]["byte_identical"] for item in report["native_wasm"].values())) self.assertTrue(report["worker"]["sample"]["parity"]["recovery"]["equal"]) 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_authoritative_kinematics_s6.canonical(unsigned).encode()).hexdigest()) def test_deterministic(self): with tempfile.TemporaryDirectory() as directory: first = generate_authoritative_kinematics_s6.generate(ROOT, Path(directory) / "one.json") second = generate_authoritative_kinematics_s6.generate(ROOT, Path(directory) / "two.json") self.assertEqual(first, second) if __name__ == "__main__": unittest.main()