init: document-haness 하네스 설계

This commit is contained in:
DongHyeonka
2026-07-24 13:58:08 +09:00
parent d6f78f92a0
commit c39406bbdd
219 changed files with 7010 additions and 20052 deletions
+50 -58
View File
@@ -1,70 +1,62 @@
from __future__ import annotations
import json
import sys
import unittest
from pathlib import Path
import pytest
from claridoc.models import Brief, Outline, PipelineConfig, SourcePack
ROOT = Path(__file__).resolve().parents[1]
SKILL = ROOT / "skills" / "technical-doc-flow"
sys.path.insert(0, str(SKILL / "scripts"))
from harness_common import InputError, load_rules, validate_with_schema # noqa: E402
def test_all_bundled_json_and_schemas_parse() -> None:
paths = [*SKILL.rglob("*.json"), ROOT / "harness.json"]
assert paths
for path in paths:
value = json.loads(path.read_text(encoding="utf-8"))
assert isinstance(value, dict), path
class SchemaTests(unittest.TestCase):
def test_all_schema_documents_are_well_formed_draft_2020_12(self) -> None:
schema_paths = sorted((ROOT / "schemas").glob("*.schema.json"))
self.assertEqual(len(schema_paths), 5)
for path in schema_paths:
with self.subTest(path=path.name):
data = json.loads(path.read_text(encoding="utf-8"))
self.assertEqual(data["$schema"], "https://json-schema.org/draft/2020-12/schema")
self.assertEqual(data["type"], "object")
def test_examples_match_runtime_contracts(self) -> None:
brief_data = json.loads(
(ROOT / "examples" / "briefs" / "retry-policy-blog.json").read_text(encoding="utf-8")
)
sources_data = json.loads(
(ROOT / "examples" / "sources" / "retry-policy-sources.json").read_text(encoding="utf-8")
)
mock_config_data = json.loads((ROOT / "config" / "pipeline.mock.json").read_text(encoding="utf-8"))
multi_config_data = json.loads(
(ROOT / "config" / "pipeline.multi-agent.example.json").read_text(encoding="utf-8")
)
self.assertTrue(Brief.from_dict(brief_data).title)
self.assertGreaterEqual(len(SourcePack.from_dict(sources_data).sources), 1)
self.assertEqual(PipelineConfig.from_dict(mock_config_data).writer.provider, "mock")
self.assertEqual(PipelineConfig.from_dict(multi_config_data).writer.provider, "claude")
def test_outline_schema_covers_runtime_outline_shape(self) -> None:
sample = {
"title": "Example",
"document_type": "technical_blog",
"sections": [
{
"id": "01-promise",
"intent": "promise",
"title": "Decision",
"reader_question": "What should I do?",
"purpose": "State the useful conclusion.",
"must_include": ["scope"],
"evidence_ids": ["S1"],
"transition_to_next": "Explain why.",
}
],
}
outline = Outline.from_dict(sample)
self.assertEqual(outline.sections[0].intent, "promise")
def test_quality_rules_have_unique_ids_and_every_runtime_threshold() -> None:
rules = load_rules()
ids = [item["id"] for item in rules["rules"]]
assert len(ids) == len(set(ids))
assert {
"DOC-H001",
"DOC-M002",
"DOC-L003",
"DOC-T009",
"DOC-F005",
"DOC-M004",
"FNL-001",
} <= set(ids)
assert rules["thresholds"]["route"]["light"]["requires_existing_draft"] is True
assert rules["thresholds"]["finalization"]["max_change_rate"] == 0.0
def test_artifact_contract_schema_names_exist() -> None:
expected = {
"run.schema.json",
"sources.schema.json",
"reader-contract.schema.json",
"evidence-map.schema.json",
"logic-map.schema.json",
"term-ledger.schema.json",
"review.schema.json",
"lint-report.schema.json",
"final-report.schema.json",
"chunk-manifest.schema.json",
"quality-rules.schema.json",
"runtime-contract.schema.json",
}
actual = {path.name for path in (SKILL / "schemas").glob("*.json")}
assert expected <= actual
def test_reader_contract_rejects_whitespace_values_and_undeclared_fields() -> None:
fixture = ROOT / "tests" / "fixtures" / "good" / "reader-contract.json"
reader = json.loads(fixture.read_text(encoding="utf-8"))
reader["non_goals"] = [" "]
with pytest.raises(InputError):
validate_with_schema(reader, "reader-contract.schema.json", "reader")
reader = json.loads(fixture.read_text(encoding="utf-8"))
reader["undeclared"] = True
with pytest.raises(InputError):
validate_with_schema(reader, "reader-contract.schema.json", "reader")
if __name__ == "__main__":
unittest.main()