- 前端由分步表单页升级为 DeepSeek 式聊天页(static/chat.html)
- 新增 chat 包:意图识别(intent.py)+ ChatAgent(agent.py)自动驱动
解析→影响→生成→QA 整条工作流,影响确认节点反问、错误分支兜底
- store.py 扩展 pending_intent 字段与 chat_messages 表
- app.py 新增 POST/GET /api/chat/{sid}/messages,GET / 返回聊天页
- README/design.md 同步聊天模式说明;测试 4 文件覆盖
- 全量 pytest 522 passed / 99.03%,覆盖率红线达标
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
"""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"
|