103 lines
4.0 KiB
Python
103 lines
4.0 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
import scenario_acceptance_policy as sap
|
|
|
|
|
|
class ScenarioAcceptancePolicyTests(unittest.TestCase):
|
|
def test_marks_partial_when_selected_object_and_temporal_p0_findings_exist(self) -> None:
|
|
spec = {
|
|
"scenario_id": "demo_phase7",
|
|
"domain": "inventory_demo",
|
|
"title": "Demo",
|
|
"steps": [
|
|
{
|
|
"step_id": "step_01",
|
|
"title": "Selected object supplier",
|
|
"question_template": 'По выбранному объекту "Стол": кто поставил?',
|
|
"criticality": "critical",
|
|
"expected_intents": ["inventory_purchase_provenance_for_item"],
|
|
}
|
|
],
|
|
}
|
|
scenario_state = {
|
|
"session_id": "asst-demo",
|
|
"step_outputs": {
|
|
"step_01": {
|
|
"review_status": "fail",
|
|
"reply_type": "factual",
|
|
"detected_intent": "inventory_on_hand_as_of_date",
|
|
"capability_id": "confirmed_inventory_on_hand_as_of_date",
|
|
"review_findings": [
|
|
{"code": "wrong_intent", "severity": "critical"},
|
|
{"code": "wrong_filter:as_of_date", "severity": "critical"},
|
|
],
|
|
}
|
|
},
|
|
}
|
|
review_summary = {
|
|
"review_source": "live_strict_replay",
|
|
"overall_status": "fail",
|
|
"steps_total": 1,
|
|
"steps_passed": 0,
|
|
"steps_with_warning": 0,
|
|
"steps_failed": 1,
|
|
}
|
|
|
|
acceptance_matrix = sap.build_scenario_acceptance_matrix(spec, scenario_state, review_summary)
|
|
pack_state = sap.derive_truth_harness_pack_state(spec, scenario_state, review_summary, acceptance_matrix)
|
|
|
|
self.assertEqual(pack_state["final_status"], "partial")
|
|
self.assertFalse(pack_state["invariants"]["selected_object_continuity_ok"])
|
|
self.assertFalse(pack_state["invariants"]["temporal_honesty_ok"])
|
|
self.assertEqual(pack_state["unresolved_p0_count"], 2)
|
|
|
|
def test_accepts_when_all_review_and_acceptance_invariants_are_green(self) -> None:
|
|
spec = {
|
|
"scenario_id": "demo_phase7_green",
|
|
"domain": "inventory_demo",
|
|
"title": "Demo green",
|
|
"steps": [
|
|
{
|
|
"step_id": "step_01",
|
|
"title": "Inventory root",
|
|
"question_template": "какие остатки на складе на март 2021",
|
|
"criticality": "critical",
|
|
"expected_intents": ["inventory_on_hand_as_of_date"],
|
|
}
|
|
],
|
|
}
|
|
scenario_state = {
|
|
"session_id": "asst-green",
|
|
"step_outputs": {
|
|
"step_01": {
|
|
"review_status": "pass",
|
|
"reply_type": "factual",
|
|
"detected_intent": "inventory_on_hand_as_of_date",
|
|
"capability_id": "confirmed_inventory_on_hand_as_of_date",
|
|
"review_findings": [],
|
|
}
|
|
},
|
|
}
|
|
review_summary = {
|
|
"review_source": "live_strict_replay",
|
|
"overall_status": "pass",
|
|
"steps_total": 1,
|
|
"steps_passed": 1,
|
|
"steps_with_warning": 0,
|
|
"steps_failed": 0,
|
|
}
|
|
|
|
acceptance_matrix = sap.build_scenario_acceptance_matrix(spec, scenario_state, review_summary)
|
|
pack_state = sap.derive_truth_harness_pack_state(spec, scenario_state, review_summary, acceptance_matrix)
|
|
|
|
self.assertEqual(pack_state["final_status"], "accepted")
|
|
self.assertTrue(pack_state["acceptance_gate_passed"])
|
|
self.assertTrue(pack_state["critical_path_green"])
|
|
self.assertTrue(all(pack_state["invariants"].values()))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|