from __future__ import annotations import json import tempfile import unittest from copy import deepcopy from pathlib import Path from techviz.batch_audit import audit_batch, discover_specs ROOT = Path(__file__).resolve().parents[1] class BatchAuditTests(unittest.TestCase): def test_runtime_profiles_do_not_collapse(self) -> None: paths = discover_specs(ROOT / "examples/runtime-profiles") audits, findings = audit_batch(paths) self.assertEqual(len(audits), 10) self.assertFalse(any(item.code == "batch-template-collapse" for item in findings), findings) def test_repeated_template_is_rejected(self) -> None: source = json.loads( (ROOT / "examples/runtime-profiles/10-comparison/spec.json").read_text(encoding="utf-8") ) with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) for index in range(6): data = deepcopy(source) data["id"] = f"copy-{index}" folder = root / f"item-{index}" folder.mkdir() (folder / "spec.json").write_text( json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8", ) audits, findings = audit_batch(discover_specs(root)) self.assertEqual(len(audits), 6) self.assertTrue(any(item.code == "batch-template-collapse" and item.severity == "error" for item in findings), findings) if __name__ == "__main__": unittest.main()