56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from techviz.document import build_context
|
|
from techviz.prompt import build_agent_prompt
|
|
from techviz.reference_catalog import select_reference_cases
|
|
from techviz.spec import validate_raw_spec
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class PromptTests(unittest.TestCase):
|
|
def test_embedded_vizspec_scaffold_is_valid_and_context_bound(self) -> None:
|
|
context = build_context(
|
|
ROOT / "examples/docs/payment-flow.md",
|
|
marker_id="payment-request",
|
|
)
|
|
prompt = build_agent_prompt(context)
|
|
section_start = prompt.index("## VizSpec 1.1 shape")
|
|
json_start = prompt.index("{\n", section_start)
|
|
json_end = prompt.index("\n\n## Final self-check", json_start)
|
|
scaffold = json.loads(prompt[json_start:json_end])
|
|
|
|
validate_raw_spec(scaffold)
|
|
self.assertEqual(scaffold["version"], "1.1")
|
|
self.assertTrue(scaffold["composition"]["diagram_only"])
|
|
self.assertTrue(scaffold["composition"]["reference_ids"])
|
|
self.assertEqual(
|
|
scaffold["source_context"],
|
|
{
|
|
"document": context["document"],
|
|
"document_sha256": context["document_sha256"],
|
|
"anchor": context["anchor"],
|
|
},
|
|
)
|
|
self.assertFalse(scaffold["groups"])
|
|
self.assertFalse(scaffold["legend"])
|
|
self.assertIn("disconnected rounded cards", prompt)
|
|
self.assertIn("diagram-only", prompt)
|
|
|
|
def test_reference_selection_is_context_sensitive(self) -> None:
|
|
context = {
|
|
"numbered_context": "1 | Port와 Adapter를 통해 hexagonal core에 의존한다.",
|
|
"current_section": {"text": "Inbound adapter와 outbound port를 분리한다."},
|
|
}
|
|
selected = select_reference_cases(context, limit=2)
|
|
self.assertEqual(selected[0].profile, "ports-adapters")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|