Files
lhl 838a93720e 聊天式交互改造(Web UI 升级)
- 前端由分步表单页升级为 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%,覆盖率红线达标
2026-08-27 05:11:40 +08:00

39 lines
1.6 KiB
Python

"""C1:聊天消息存储 + pending_intent 测试(store.py 扩展)。"""
from __future__ import annotations
from genesis.server.store import SessionStore
def test_add_and_list_messages(tmp_path):
store = SessionStore(db_path=str(tmp_path / "s.db"))
sid = store.create_session("u1").session_id
store.add_message(sid, "user", "生成概要设计书", action="generate")
store.add_message(sid, "assistant", "影响调查完成,请确认", action=None)
msgs = store.list_messages(sid)
assert len(msgs) == 2
assert msgs[0]["role"] == "user"
assert msgs[0]["content"] == "生成概要设计书"
assert msgs[0]["action"] == "generate"
assert msgs[1]["role"] == "assistant"
def test_messages_isolated_per_session(tmp_path):
store = SessionStore(db_path=str(tmp_path / "s.db"))
a = store.create_session("u1").session_id
b = store.create_session("u1").session_id
store.add_message(a, "user", "msg-a")
store.add_message(b, "user", "msg-b")
assert [m["content"] for m in store.list_messages(a)] == ["msg-a"]
assert [m["content"] for m in store.list_messages(b)] == ["msg-b"]
def test_pending_intent_persisted(tmp_path):
store = SessionStore(db_path=str(tmp_path / "s.db"))
sid = store.create_session("u1").session_id
assert store.get_session(sid).pending_intent == ""
store.update_session(sid, pending_intent="generate")
assert store.get_session(sid).pending_intent == "generate"
# 重开 db 仍在
store2 = SessionStore(db_path=str(tmp_path / "s.db"))
assert store2.get_session(sid).pending_intent == "generate"