aps-agent/tests/golden/test_guidance.py

82 lines
2.8 KiB
Python

# ============================================================
# AG-07 主动引导黄金测试
# ============================================================
from __future__ import annotations
from server.agent_core.intent import parse_fast
from server.aps_domain.guidance import build_guidance
from server.aps_domain.workflow import handle_intent
from server.contracts import IntentResult
from server.state.seed import seed_world
class _MemStore:
def __init__(self, data):
self.data = data
def next_id(self, kind: str) -> int:
key = f"_c_{kind}"
self.data[key] = self.data.get(key, 9000) + 1
return self.data[key]
def save(self):
pass
def test_guidance_empty_schedule():
world = seed_world()
world["scheduleVersions"] = []
g = build_guidance(world)
cmds = {s["command"] for s in g["suggestions"]}
assert any(s["id"] == "no_version" for s in g["signals"])
assert "试排一版交期优先" in cmds
def test_guidance_knowledge_miss_context():
world = seed_world()
g = build_guidance(world, context="knowledge_miss")
cmds = {s["command"] for s in g["suggestions"]}
assert "知识库" in cmds
assert any(s["id"] == "knowledge_miss" for s in g["signals"])
def test_guidance_high_conflict():
world = seed_world()
world["scheduleVersions"] = [{
"id": 1, "versionNo": "V1", "status": "DRAFT", "conflictCount": 8,
"poCount": 1, "woCount": 1, "totalTardiness": 0, "avgUtilization": 0.5,
"createdAt": "2026-07-22 10:00", "engineType": "RULE", "strategy": "COMPREHENSIVE",
}]
g = build_guidance(world, context="high_conflict")
cmds = {s["command"] for s in g["suggestions"]}
assert "查看冲突" in cmds
assert "多策略方案对比" in cmds
def test_intent_guidance_next():
hit = parse_fast("下一步建议", seed_world())
assert hit and hit.intent == "guidance.next"
def test_workflow_guidance_and_kb_miss():
import asyncio
store = _MemStore(seed_world())
store.data["scheduleVersions"] = []
async def _run():
reply = await handle_intent(
store, "test", IntentResult(intent="guidance.next", params={}, confidence=1.0, source="RULE_FAST"))
assert reply.blocks and reply.blocks[0].type == "guidance"
assert "试排" in reply.text or any(
"试排" in s.get("command", "") for s in reply.blocks[0].props.get("suggestions", []))
miss = await handle_intent(
store, "test",
IntentResult(intent="knowledge.query", params={"query": "完全不存在的zzz知识xyz"},
confidence=1.0, source="RULE_FAST"))
assert "不编造" in miss.text
assert miss.blocks and miss.blocks[0].type == "guidance"
assert miss.blocks[0].props.get("context") == "knowledge_miss"
asyncio.run(_run())