66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
from __future__ import annotations
|
||
|
||
import sys
|
||
import unittest
|
||
from pathlib import Path
|
||
|
||
|
||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||
|
||
import save_agent_semantic_run as saver
|
||
|
||
|
||
class SaveAgentSemanticRunTests(unittest.TestCase):
|
||
def test_extract_questions_resolves_scenario_pack_bindings(self) -> None:
|
||
spec = {
|
||
"schema_version": "domain_scenario_pack_v1",
|
||
"bindings": {
|
||
"main_organization": "ООО Альтернатива Плюс",
|
||
"control_year": "2020",
|
||
"svk_counterparty": "Группа СВК",
|
||
},
|
||
"scenarios": [
|
||
{
|
||
"scenario_id": "biz",
|
||
"steps": [
|
||
{
|
||
"question": "Дай обзор {{bindings.main_organization}} за {{bindings.control_year}} год.",
|
||
"semantic_tags": ["business_overview", "money"],
|
||
},
|
||
{
|
||
"question": "Отдельно по {{bindings.svk_counterparty}} покажи документы.",
|
||
"semantic_tags": ["counterparty", "documents"],
|
||
},
|
||
],
|
||
}
|
||
],
|
||
}
|
||
|
||
questions = saver.extract_questions_from_spec(spec)
|
||
|
||
self.assertEqual(
|
||
questions,
|
||
[
|
||
"Дай обзор ООО Альтернатива Плюс за 2020 год.",
|
||
"Отдельно по Группа СВК покажи документы.",
|
||
],
|
||
)
|
||
self.assertFalse(any("{{bindings." in question for question in questions))
|
||
self.assertEqual(
|
||
saver.extract_semantic_tags(spec),
|
||
["business_overview", "counterparty", "documents", "money"],
|
||
)
|
||
|
||
def test_extract_questions_refuses_unresolved_bindings(self) -> None:
|
||
spec = {
|
||
"questions": ["Что с НДС за {{bindings.control_year}} год?"],
|
||
"bindings": {},
|
||
}
|
||
|
||
with self.assertRaisesRegex(RuntimeError, "unresolved bindings"):
|
||
saver.extract_questions_from_spec(spec)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|