"""C2:意图解析测试(chat/intent.py)。""" from __future__ import annotations from genesis.chat.intent import INTENT_SCHEMA, parse_intent_fake, Intent def test_schema_defines_actions(): enums = INTENT_SCHEMA["properties"]["action"]["enum"] assert {"parse", "impact", "generate", "qa", "status", "confirm", "reject", "unknown"} <= set(enums) def test_parse_generate_keywords(): assert parse_intent_fake("请生成概要设计书").action == "generate" assert parse_intent_fake("开始生成吧").action == "generate" assert parse_intent_fake("生成中文设计书").params.get("output_language") == "zh" def test_parse_parse_and_impact(): assert parse_intent_fake("开始解析").action == "parse" assert parse_intent_fake("做影响调查").action == "impact" def test_parse_qa_status(): assert parse_intent_fake("运行QA校验").action == "qa" assert parse_intent_fake("现在什么状态").action == "status" def test_parse_confirm_reject(): assert parse_intent_fake("确认").action == "confirm" assert parse_intent_fake("可以,继续").action == "confirm" assert parse_intent_fake("打回,重新影响调查").action == "reject" def test_parse_unknown(): it = parse_intent_fake("今天天气怎么样") assert it.action == "unknown" def test_intent_language_detection_zh_ja(): assert parse_intent_fake("用中文生成").params.get("output_language") == "zh" assert parse_intent_fake("日本語で生成して").params.get("output_language") == "ja" class _Engine: def __init__(self, data, status="ok"): self.data = data self.status = status def chat_structured(self, *, session_id, prompt, variables, schema, retry_count=2): from types import SimpleNamespace return SimpleNamespace(data=self.data, status=self.status) def test_parse_intent_llm_ok(): from genesis.chat.intent import parse_intent_llm eng = _Engine({"action": "generate", "params": {"output_language": "zh"}}) it = parse_intent_llm(eng, "s1", "生成", "context") assert it.action == "generate" assert it.params.get("output_language") == "zh" def test_parse_intent_llm_failed_falls_to_unknown(): from genesis.chat.intent import parse_intent_llm eng = _Engine({}, status="failed") it = parse_intent_llm(eng, "s1", "生成", "context") assert it.action == "unknown"