NODEDC_1C/scripts/test_domain_truth_harness.py

81 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import domain_truth_harness as dth
class DomainTruthHarnessTests(unittest.TestCase):
def test_required_organization_filter_accepts_quoted_legal_name(self) -> None:
step = dth.normalize_step_spec(
1,
{
"step_id": "step_01",
"title": "Inventory root",
"question_template": "что там на складе по остаткам",
"required_filters": {"organization": "ООО Альтернатива Плюс"},
},
)
reviewed = dth.evaluate_truth_step(
step=step,
step_state={
"question_resolved": "что там на складе по остаткам",
"reply_type": "factual",
"assistant_text": "На складе подтверждено 11 позиций.",
"extracted_filters": {"organization": 'ООО "Альтернатива Плюс"'},
},
step_results={},
bindings={},
runtime_bindings={},
)
self.assertEqual(reviewed["review_status"], "pass")
self.assertFalse(
[
finding
for finding in reviewed["review_findings"]
if finding.get("code") == "wrong_filter:organization"
]
)
def test_forbidden_organization_filter_matches_quoted_legal_name(self) -> None:
step = dth.normalize_step_spec(
1,
{
"step_id": "step_01",
"title": "Wrong organization scope",
"question_template": "что там на складе по остаткам",
"forbidden_filter_values": {"organization": ["ООО Альтернатива Плюс"]},
},
)
reviewed = dth.evaluate_truth_step(
step=step,
step_state={
"question_resolved": "что там на складе по остаткам",
"reply_type": "factual",
"assistant_text": "На складе подтверждено 11 позиций.",
"extracted_filters": {"organization": 'ООО "Альтернатива Плюс"'},
},
step_results={},
bindings={},
runtime_bindings={},
)
self.assertEqual(reviewed["review_status"], "fail")
self.assertTrue(
[
finding
for finding in reviewed["review_findings"]
if finding.get("code") == "forbidden_filter_value:organization"
]
)
if __name__ == "__main__":
unittest.main()