NODEDC_1C/scripts/test_agent_semantic_pack_bu...

93 lines
4.3 KiB
Python

from __future__ import annotations
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import agent_semantic_pack_builder as builder
class AgentSemanticPackBuilderTests(unittest.TestCase):
def test_build_source_catalog_finds_reusable_meta_and_selected_object_tags(self) -> None:
catalog = builder.build_source_catalog()
summary = catalog["summary"]
self.assertGreater(summary["truth_harness_steps_total"], 0)
self.assertIn("meta_scope", summary["reusable_truth_harness_tags"])
self.assertIn("selected_object_supplier", summary["reusable_truth_harness_tags"])
self.assertIn("counterparty_documents", summary["reusable_truth_harness_tags"])
self.assertIn("planner_catalog_alignment", summary["reusable_truth_harness_tags"])
phase32_net_entry = next(
(
entry
for entry in catalog["truth_harness_entries"]
if entry["entry_id"]
== "address_truth_harness_phase32_planner_selected_chain_end_to_end:step_04_net_after_payout"
),
None,
)
self.assertIsNotNone(phase32_net_entry)
self.assertEqual(phase32_net_entry["expected_catalog_alignment_status"], "selected_matches_top")
self.assertEqual(phase32_net_entry["expected_catalog_chain_top_match"], "value_flow_comparison")
self.assertIs(phase32_net_entry["expected_catalog_selected_matches_top"], True)
self.assertIn("planner_catalog_alignment", phase32_net_entry["semantic_tags"])
def test_build_recipe_spec_creates_mixed_phase7_pack(self) -> None:
catalog = builder.build_source_catalog()
spec = builder.build_recipe_spec(catalog, "turnaround_11_phase7_meta_domain_mix")
self.assertEqual(spec["scenario_id"], "address_truth_harness_phase7_meta_domain_mix")
self.assertGreaterEqual(len(spec["steps"]), 10)
all_tags = {tag for step in spec["steps"] for tag in step.get("semantic_tags", [])}
self.assertIn("meta_scope", all_tags)
self.assertIn("meta_capability", all_tags)
self.assertIn("selected_object_supplier", all_tags)
self.assertIn("same_date_restore", all_tags)
self.assertIn("settlements_receivables", all_tags)
def test_build_recipe_spec_creates_planner_brain_alignment_pack(self) -> None:
catalog = builder.build_source_catalog()
spec = builder.build_recipe_spec(catalog, "turnaround_11_planner_brain_alignment_mix")
self.assertEqual(spec["scenario_id"], "address_truth_harness_phase83_planner_brain_alignment_mix")
self.assertEqual(len(spec["steps"]), 20)
all_tags = {tag for step in spec["steps"] for tag in step.get("semantic_tags", [])}
self.assertIn("planner_catalog_alignment", all_tags)
self.assertIn("value_flow_comparison", all_tags)
self.assertIn("value_flow_ranking", all_tags)
self.assertIn("broad_business_evaluation", all_tags)
self.assertIn("catalog_drilldown", all_tags)
self.assertIn("off_domain_living_chat", all_tags)
catalog_checked_steps = [
step for step in spec["steps"] if step.get("expected_catalog_chain_top_match")
]
self.assertEqual(len(catalog_checked_steps), 15)
def test_classify_truth_harness_step_preserves_route_candidate_expectations(self) -> None:
entry = builder.classify_truth_harness_step(
builder.ORCHESTRATION_DIR / "demo_route_candidate.json",
{"title": "Route candidate demo", "scenario_id": "demo", "domain": "demo"},
{
"step_id": "step_01",
"title": "Needs organization",
"question": "show open-world route candidate",
"expected_route_candidate_status": "needs_user_scope",
"expected_route_candidate_executable_now": False,
"expected_route_candidate_missing_axes": ["organization"],
},
)
self.assertEqual(entry["expected_route_candidate_status"], "needs_user_scope")
self.assertIs(entry["expected_route_candidate_executable_now"], False)
self.assertEqual(entry["expected_route_candidate_missing_axes"], ["organization"])
self.assertIn("route_candidate_handoff", entry["semantic_tags"])
if __name__ == "__main__":
unittest.main()