Files
llm-wiki/harness/tests/test_workflow_connection_check.py
T

58 lines
2.6 KiB
Python

from __future__ import annotations
from pathlib import Path
import sys
import tempfile
import unittest
RUNTIME = Path(__file__).resolve().parents[1] / "runtime"
sys.path.insert(0, str(RUNTIME))
import workflow_connection_check # noqa: E402
class WorkflowConnectionCheckTest(unittest.TestCase):
def setUp(self) -> None:
self.tempdir = tempfile.TemporaryDirectory()
self.addCleanup(self.tempdir.cleanup)
self.root = Path(self.tempdir.name)
bodies = self.root / "harness/source/agents/bodies"
bodies.mkdir(parents=True)
writer_contract = "\n".join(workflow_connection_check.WRITER_REQUIRED) + "\n"
for relative in workflow_connection_check.WRITER_SOURCES:
path = self.root / relative
path.write_text(writer_contract, encoding="utf-8")
semantic_contract = "\n".join(workflow_connection_check.SEMANTIC_REQUIRED) + "\n"
for relative in workflow_connection_check.SEMANTIC_WORKFLOW_SOURCES:
path = self.root / relative
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(semantic_contract, encoding="utf-8")
parent = self.root / workflow_connection_check.PARENT_CERTIFICATE_SOURCE
parent.parent.mkdir(parents=True, exist_ok=True)
parent.write_text("\n".join(workflow_connection_check.PARENT_CERTIFICATE_REQUIRED) + "\n", encoding="utf-8")
report_contract = "§7.1\n" + "\n".join(workflow_connection_check.REPORT_REQUIRED) + "\n"
(bodies / "reporter.md").write_text(report_contract, encoding="utf-8")
global_source = self.root / workflow_connection_check.GLOBAL_REPORT_SOURCE
global_source.parent.mkdir(parents=True)
global_source.write_text(report_contract, encoding="utf-8")
def test_complete_connections_pass(self) -> None:
result = workflow_connection_check.check(self.root)
self.assertEqual(result["status"], "PASS")
self.assertEqual(result["writer_sources"], 2)
self.assertEqual(result["semantic_workflow_sources"], 4)
self.assertEqual(result["report_sources"], 2)
def test_missing_token_and_legacy_direct_write_fail(self) -> None:
author = self.root / workflow_connection_check.WRITER_SOURCES[0]
author.write_text("**C4. Parent hub Cluster 갱신**\n", encoding="utf-8")
result = workflow_connection_check.check(self.root)
codes = {finding["code"] for finding in result["findings"]}
self.assertEqual(result["status"], "FAIL")
self.assertIn("MISSING_REQUIRED_CONNECTION", codes)
self.assertIn("FORBIDDEN_DIRECT_WRITE_CONTRACT", codes)
if __name__ == "__main__":
unittest.main()