81 lines
3.2 KiB
Python
81 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
import jsonschema
|
|
|
|
from claridoc.models import Brief, Outline, PipelineConfig, SourcePack
|
|
from claridoc.structures import create_outline
|
|
from tests.helpers import brief_dict, make_sources
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
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_readme_is_accepted_by_brief_and_outline_schemas(self) -> None:
|
|
brief_data = brief_dict("readme")
|
|
brief_schema = json.loads(
|
|
(ROOT / "schemas" / "brief.schema.json").read_text(encoding="utf-8")
|
|
)
|
|
outline_schema = json.loads(
|
|
(ROOT / "schemas" / "outline.schema.json").read_text(encoding="utf-8")
|
|
)
|
|
|
|
jsonschema.Draft202012Validator(brief_schema).validate(brief_data)
|
|
brief = Brief.from_dict(brief_data)
|
|
outline = create_outline(brief, make_sources())
|
|
jsonschema.Draft202012Validator(outline_schema).validate(outline.to_dict())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|