feat(position-roundtable): add delivery rejection workflow
This commit is contained in:
1 parent
2ca8a23102
commit
1cd99a5a90
9 files changed
+1422
-148
No files matched your search
@@ -139,6 +139,176 @@ async def test_node_updates_are_user_scoped_and_keep_thread_out_of_messages(stor
|
||||
assert await store.get_node(created["id"], nodes[0]["node_key"], "user-b") is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reject_node_marks_current_and_invalidates_later_stages(store):
|
||||
created = await store.create_session("user-a", external_task_id=None, task_snapshot={})
|
||||
_, nodes = await store.activate_session(
|
||||
created["id"],
|
||||
"user-a",
|
||||
chain_id="chain-a",
|
||||
chain_snapshot={"id": "chain-a"},
|
||||
nodes=[
|
||||
{
|
||||
"node_key": "stage-1-seat-1-agent-a",
|
||||
"stage_index": 0,
|
||||
"seat_index": 0,
|
||||
"agent_id": "agent-a",
|
||||
"position_id": "planning",
|
||||
"status": "ready",
|
||||
},
|
||||
{
|
||||
"node_key": "stage-2-seat-1-agent-b",
|
||||
"stage_index": 1,
|
||||
"seat_index": 0,
|
||||
"agent_id": "agent-b",
|
||||
"position_id": "solution",
|
||||
"status": "ready",
|
||||
},
|
||||
{
|
||||
"node_key": "stage-3-seat-1-agent-c",
|
||||
"stage_index": 2,
|
||||
"seat_index": 0,
|
||||
"agent_id": "agent-c",
|
||||
"position_id": "command",
|
||||
"status": "ready",
|
||||
},
|
||||
],
|
||||
)
|
||||
await store.update_node(
|
||||
created["id"],
|
||||
nodes[0]["node_key"],
|
||||
"user-a",
|
||||
status="done",
|
||||
latest_answer="第一阶段产物",
|
||||
increment_revision=True,
|
||||
)
|
||||
await store.update_node(
|
||||
created["id"],
|
||||
nodes[1]["node_key"],
|
||||
"user-a",
|
||||
status="done",
|
||||
latest_answer="第二阶段产物",
|
||||
increment_revision=True,
|
||||
)
|
||||
|
||||
rejected = await store.reject_node(
|
||||
created["id"],
|
||||
nodes[0]["node_key"],
|
||||
"user-a",
|
||||
title="依据不足",
|
||||
reason="第一阶段判断依据需要补充。",
|
||||
rejected_by="user-a",
|
||||
)
|
||||
|
||||
assert rejected is not None
|
||||
_, rejected_nodes = rejected
|
||||
by_key = {node["node_key"]: node for node in rejected_nodes}
|
||||
first = by_key[nodes[0]["node_key"]]
|
||||
second = by_key[nodes[1]["node_key"]]
|
||||
third = by_key[nodes[2]["node_key"]]
|
||||
assert first["status"] == "rejected"
|
||||
assert first["rejection_count"] == 1
|
||||
assert first["last_rejection"]["title"] == "依据不足"
|
||||
assert first["invalidated_by"] is None
|
||||
assert second["status"] == "stale"
|
||||
assert second["latest_answer"] == "第二阶段产物"
|
||||
assert second["invalidated_by"] == nodes[0]["node_key"]
|
||||
assert third["status"] == "locked"
|
||||
assert third["invalidated_by"] == nodes[0]["node_key"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_builtin_summary_and_action_plan_snapshots_are_invalidated_by_reject(store):
|
||||
created = await store.create_session(
|
||||
"user-a",
|
||||
external_task_id=None,
|
||||
task_snapshot={
|
||||
"title": "测试任务",
|
||||
"description": "形成协同方案",
|
||||
"direction": "态势研判",
|
||||
},
|
||||
)
|
||||
await store.update_session(
|
||||
created["id"],
|
||||
"user-a",
|
||||
intent_snapshot={"objective": "明确处置意图", "constraints": ["时间紧"]},
|
||||
)
|
||||
chain = {
|
||||
"id": "chain-a",
|
||||
"seats": [
|
||||
{"agent_id": "agent-a", "name": "研判智能体", "position_id": "planning"},
|
||||
{"agent_id": "agent-b", "name": "处置智能体", "position_id": "solution"},
|
||||
],
|
||||
}
|
||||
_, nodes = await store.activate_session(
|
||||
created["id"],
|
||||
"user-a",
|
||||
chain_id="chain-a",
|
||||
chain_snapshot=chain,
|
||||
nodes=[
|
||||
{
|
||||
"node_key": "stage-1-seat-1-agent-a",
|
||||
"stage_index": 0,
|
||||
"seat_index": 0,
|
||||
"agent_id": "agent-a",
|
||||
"position_id": "planning",
|
||||
"status": "ready",
|
||||
},
|
||||
{
|
||||
"node_key": "stage-2-seat-1-agent-b",
|
||||
"stage_index": 1,
|
||||
"seat_index": 0,
|
||||
"agent_id": "agent-b",
|
||||
"position_id": "solution",
|
||||
"status": "ready",
|
||||
},
|
||||
],
|
||||
)
|
||||
for node in nodes:
|
||||
await store.update_node(
|
||||
created["id"],
|
||||
node["node_key"],
|
||||
"user-a",
|
||||
status="done",
|
||||
latest_answer=f"{node['agent_id']} 产物",
|
||||
increment_revision=True,
|
||||
)
|
||||
session = await store.get_session(created["id"], "user-a")
|
||||
assert session is not None
|
||||
nodes = await store.list_nodes(created["id"], "user-a") or []
|
||||
summary = position_roundtable_router._build_summary_snapshot(session, nodes)
|
||||
assert "岗位会商方案总结报告" in summary["content"]
|
||||
assert "研判智能体" in summary["content"]
|
||||
session = await store.update_session(created["id"], "user-a", summary_snapshot=summary)
|
||||
assert session is not None
|
||||
action_plan = position_roundtable_router._build_action_plan_snapshot(session, nodes)
|
||||
session = await store.update_session(
|
||||
created["id"],
|
||||
"user-a",
|
||||
action_plan_snapshot=action_plan,
|
||||
status="completed",
|
||||
)
|
||||
assert session is not None
|
||||
assert session["summary_snapshot"]["status"] == "done"
|
||||
assert session["action_plan_snapshot"]["status"] == "done"
|
||||
|
||||
rejected = await store.reject_node(
|
||||
created["id"],
|
||||
nodes[0]["node_key"],
|
||||
"user-a",
|
||||
title="重做第一阶段",
|
||||
reason="前序依据变化",
|
||||
rejected_by="user-a",
|
||||
)
|
||||
assert rejected is not None
|
||||
rejected_session, _ = rejected
|
||||
assert rejected_session["status"] == "active"
|
||||
assert rejected_session["summary_snapshot"]["status"] == "stale"
|
||||
assert rejected_session["summary_snapshot"]["invalidated_by"] == nodes[0]["node_key"]
|
||||
assert rejected_session["action_plan_snapshot"]["status"] == "stale"
|
||||
assert rejected_session["action_plan_snapshot"]["invalidated_by"] == nodes[0]["node_key"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handoff_context_inlines_only_upstream_thread_text_artifacts(tmp_path, monkeypatch):
|
||||
artifact = tmp_path / "handoff.md"
|
||||
@@ -188,6 +358,18 @@ async def test_handoff_context_inlines_only_upstream_thread_text_artifacts(tmp_p
|
||||
"latest_answer": None,
|
||||
"artifact_manifest": [],
|
||||
},
|
||||
{
|
||||
"node_key": "stage-1-seat-2-agent-stale",
|
||||
"stage_index": 0,
|
||||
"seat_index": 1,
|
||||
"agent_id": "agent-stale",
|
||||
"position_id": "planning",
|
||||
"thread_id": "stale-thread",
|
||||
"status": "stale",
|
||||
"revision": 1,
|
||||
"latest_answer": "失效上游产物",
|
||||
"artifact_manifest": [],
|
||||
},
|
||||
]
|
||||
|
||||
async def resolve(thread_id: str, path: str):
|
||||
@@ -207,6 +389,7 @@ async def test_handoff_context_inlines_only_upstream_thread_text_artifacts(tmp_p
|
||||
)
|
||||
|
||||
upstream = context["upstream_nodes"][0]
|
||||
assert len(context["upstream_nodes"]) == 1
|
||||
assert upstream["latest_answer"] == "上游问答结果"
|
||||
assert upstream["artifacts"][0]["content"] == "上游产物正文:可供下一岗位直接参考。"
|
||||
assert "content" not in upstream["artifacts"][1]
|
||||
|
||||
Reference in new issue
Block a user