Files
AgentLab/backend/tests/test_architecture_investigation.py
T
ThearchyHelios 9d8b41430e 完善口径管理、主动调查与后台任务,修复通用问题
- 完善口径编辑、只读试运行、统一质量验证与执行语义指纹
- 增加可执行指标约束、有预算的主动调查和过程评测
- 提取发布检查、证据读取与起草服务,支持任务停止、重试和检查点恢复
- 增加版本传递影响分析,修复并发覆盖、敏感值遮罩、异常评分及页面状态问题
- 修复 SQLite 复合查询追溯和 microVM 可选依赖缺失处理
- 纳入当前设计文档及部署配置调整

验证:相关主回归 3822 项通过,4 项跳过、8 项预期失败;补充回归通过。
前端构建、文案检查及 git diff --check 通过。
全量检查仍有环境权限、PostgreSQL 可选依赖和既有部署配置、SQLite 文件基线差异导致的未通过项。
2026-11-06 17:14:45 +08:00

53 lines
2.8 KiB
Python

"""真实 Agent 循环:模型提前结束时继续调查,不能补齐证据时明确降级。"""
from langchain_core.messages import AIMessage, HumanMessage, ToolMessage
from app.core import artifact_store
from app.engine.evidence_reader import read_sealed
from app.eval.score import read_answer
from app.providers import mock_model
from tests.test_analysis_tools import (DECOMPOSE, DECOMPOSE_ARGS, SQL, TOOL, agent_graph, engine_up,
events, run_graph, shop)
async def test_runtime_continues_after_premature_answer_then_records_the_remaining_gap(monkeypatch, shop):
calls = [(TOOL, {"sql": SQL}), (DECOMPOSE, DECOMPOSE_ARGS)]
nudges = []
def decide(model, messages):
continued = [m for m in messages if isinstance(m, HumanMessage) and "调查尚未完成" in str(m.content)]
nudges[:] = continued
if not continued:
return AIMessage(content="销售额下降。")
done = sum(isinstance(m, ToolMessage) for m in messages)
if done < len(calls):
name, args = calls[done]
return AIMessage(content="", tool_calls=[{"id": f"c{done}", "name": name, "args": args}])
return AIMessage(content="已按地区拆解,仍需核对总数。")
monkeypatch.setattr(mock_model.MockChatModel, "_decide", decide)
row = await run_graph(agent_graph(max_steps=8))
sealed = await read_sealed(row.id)
bot = artifact_store.load(sealed.outputs["bot"])
assert len(nudges) == 2
assert [c["tool"] for c in bot["tool_calls"]] == [TOOL, DECOMPOSE]
assert bot["investigation"]["status"] == "partial"
assert bot["investigation"]["stage"] == "closure"
assert bot["investigation"]["stop_reason"] == "evidence_insufficient"
assert "现有证据不足以确认根因" in bot["text"]
assert any(e.get("code") == "investigation_incomplete" for e in await events(row.id, "log", "bot"))
answer = await read_answer(row.id)
assert answer.investigations[0]["query_count"] == 1
async def test_unfinished_investigation_cannot_receive_formal_issuance(monkeypatch, shop):
monkeypatch.setattr(mock_model.MockChatModel, "_decide", lambda *_: AIMessage(content="尚未取得证据。"))
graph = agent_graph(max_steps=4)
graph["nodes"].insert(-1, {"id": "card", "type": "metrics", "data": {"config": {
"caliber": "调查", "metrics": [{"id": "n", "expression": "1"}]}}})
graph["edges"] = [{"source": a["id"], "target": b["id"]}
for a, b in zip(graph["nodes"], graph["nodes"][1:])]
graph["nodes"][-1]["data"]["config"]["contract"] = {"metrics_from": "card"}
row = await run_graph(graph)
assert row.output["_issuance"]["tier"] != "formal"
assert any("异常调查未完成" in g for g in row.output["_issuance"]["gaps"])