岗位会商
This commit is contained in:
1 parent
1cd99a5a90
commit
1bc203b5cd
23 files changed
+2230
-401
No files matched your search
@@ -9,6 +9,8 @@ import pytest_asyncio
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
|
||||
from app.gateway import services as gateway_services
|
||||
from app.gateway.routers import intent as intent_router
|
||||
from app.gateway.routers import position_roundtable as position_roundtable_router
|
||||
from deerflow.persistence.base import Base
|
||||
from deerflow.persistence.position_roundtable import PositionRoundtableRepository
|
||||
@@ -79,6 +81,39 @@ async def test_session_activation_freezes_chain_and_creates_nodes_once(store):
|
||||
assert [node["node_key"] for node in repeated_nodes] == [node["node_key"] for node in created_nodes]
|
||||
|
||||
|
||||
def test_task_external_context_reaches_agent_runtime_context():
|
||||
"""岗位会商的左侧任务快照不能在网关白名单中丢失。"""
|
||||
task_context = {
|
||||
"task": {
|
||||
"title": "重点区域态势研判与协同处置方案",
|
||||
"description": "梳理风险信号并形成协同处置建议",
|
||||
}
|
||||
}
|
||||
config: dict = {"configurable": {}, "context": {}}
|
||||
|
||||
gateway_services.merge_run_context_overrides(
|
||||
config,
|
||||
{"task_external_context": task_context},
|
||||
)
|
||||
|
||||
assert config["configurable"]["task_external_context"] == task_context
|
||||
assert config["context"]["task_external_context"] == task_context
|
||||
|
||||
|
||||
def test_position_intent_thread_metadata_keeps_parent_and_child_task_ids():
|
||||
metadata = intent_router._intent_thread_metadata(
|
||||
{
|
||||
"task": {"id": "task-100"},
|
||||
"current_position": {"id": "intelligence"},
|
||||
}
|
||||
)
|
||||
|
||||
assert metadata["taskId"] == "task-100"
|
||||
assert metadata["position_roundtable_task_id"] == "task-100"
|
||||
assert metadata["position_task_id"] == "task-100:intelligence"
|
||||
assert metadata["position_id"] == "intelligence"
|
||||
|
||||
|
||||
def test_chain_node_activation_rejects_missing_agent_ids():
|
||||
chain = {
|
||||
"id": "chain-a",
|
||||
@@ -99,6 +134,58 @@ def test_chain_node_activation_rejects_missing_agent_ids():
|
||||
assert "缺少可用智能体" in str(error.value.detail)
|
||||
|
||||
|
||||
def test_intent_position_nodes_complete_from_confirmed_intent_and_unlock_next_stage():
|
||||
nodes = [
|
||||
{
|
||||
"node_key": "stage-1-seat-1-intent-agent",
|
||||
"stage_index": 0,
|
||||
"seat_index": 0,
|
||||
"agent_id": "intent-agent",
|
||||
"position_id": "intelligence",
|
||||
"status": "ready",
|
||||
},
|
||||
{
|
||||
"node_key": "stage-2-seat-1-plan-agent",
|
||||
"stage_index": 1,
|
||||
"seat_index": 0,
|
||||
"agent_id": "plan-agent",
|
||||
"position_id": "planning",
|
||||
"status": "locked",
|
||||
},
|
||||
]
|
||||
|
||||
primed = position_roundtable_router._prime_intent_nodes(
|
||||
nodes,
|
||||
{"objective": "识别用户想要形成协同方案", "constraints": ["两天内完成"]},
|
||||
)
|
||||
|
||||
assert [node["status"] for node in primed] == ["done", "ready"]
|
||||
assert primed[0]["revision"] == 1
|
||||
assert "识别用户想要形成协同方案" in primed[0]["latest_answer"]
|
||||
|
||||
|
||||
def test_all_nodes_delivered_requires_markdown_for_non_intent_nodes():
|
||||
assert not position_roundtable_router._all_nodes_delivered(
|
||||
[
|
||||
{
|
||||
"position_id": "planning",
|
||||
"status": "done",
|
||||
"artifact_manifest": [{"name": "plain.txt", "path": "mnt/user-data/outputs/plain.txt"}],
|
||||
}
|
||||
]
|
||||
)
|
||||
assert position_roundtable_router._all_nodes_delivered(
|
||||
[
|
||||
{"position_id": "intelligence", "status": "done", "artifact_manifest": []},
|
||||
{
|
||||
"position_id": "planning",
|
||||
"status": "done",
|
||||
"artifact_manifest": [{"name": "report.md", "path": "mnt/user-data/outputs/report.md"}],
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_node_updates_are_user_scoped_and_keep_thread_out_of_messages(store):
|
||||
created = await store.create_session("user-a", external_task_id=None, task_snapshot={})
|
||||
@@ -276,15 +363,55 @@ async def test_builtin_summary_and_action_plan_snapshots_are_invalidated_by_reje
|
||||
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)
|
||||
revisions = position_roundtable_router._source_revisions(nodes)
|
||||
summary = position_roundtable_router._build_builtin_snapshot(
|
||||
kind="summary",
|
||||
thread_id="summary-thread",
|
||||
content="# 岗位会商方案总结报告\n\n研判智能体的关键结论。",
|
||||
artifacts=[
|
||||
{
|
||||
"name": "岗位会商方案总结报告.md",
|
||||
"path": "mnt/user-data/outputs/岗位会商方案总结报告.md",
|
||||
"mime_type": "text/markdown",
|
||||
"modified_at": "2026-07-21T00:00:00+00:00",
|
||||
"size_bytes": 100,
|
||||
}
|
||||
],
|
||||
source_revisions=revisions,
|
||||
model="test-model",
|
||||
)
|
||||
assert "岗位会商方案总结报告" in summary["content"]
|
||||
assert "研判智能体" in summary["content"]
|
||||
session = await store.update_session(created["id"], "user-a", summary_snapshot=summary)
|
||||
session = await store.update_session(
|
||||
created["id"], "user-a", summary_thread_id="summary-thread", summary_snapshot=summary
|
||||
)
|
||||
assert session is not None
|
||||
action_plan = position_roundtable_router._build_action_plan_snapshot(session, nodes)
|
||||
action_plan = position_roundtable_router._build_builtin_snapshot(
|
||||
kind="action_plan",
|
||||
thread_id="action-plan-thread",
|
||||
content="# 岗位会商行动规划\n\n## 子任务拆解",
|
||||
artifacts=[
|
||||
{
|
||||
"name": "行动规划报告.md",
|
||||
"path": "mnt/user-data/outputs/行动规划报告.md",
|
||||
"mime_type": "text/markdown",
|
||||
"modified_at": "2026-07-21T00:01:00+00:00",
|
||||
"size_bytes": 100,
|
||||
},
|
||||
{
|
||||
"name": "action-plan-subtasks.json",
|
||||
"path": "mnt/user-data/outputs/action-plan-subtasks.json",
|
||||
"mime_type": "application/json",
|
||||
"modified_at": "2026-07-21T00:01:00+00:00",
|
||||
"size_bytes": 200,
|
||||
},
|
||||
],
|
||||
source_revisions=revisions,
|
||||
model="test-model",
|
||||
)
|
||||
session = await store.update_session(
|
||||
created["id"],
|
||||
"user-a",
|
||||
action_plan_thread_id="action-plan-thread",
|
||||
action_plan_snapshot=action_plan,
|
||||
status="completed",
|
||||
)
|
||||
@@ -309,6 +436,30 @@ async def test_builtin_summary_and_action_plan_snapshots_are_invalidated_by_reje
|
||||
assert rejected_session["action_plan_snapshot"]["invalidated_by"] == nodes[0]["node_key"]
|
||||
|
||||
|
||||
def test_rejected_or_stale_node_requires_a_new_markdown_delivery() -> None:
|
||||
old = [
|
||||
{
|
||||
"name": "report.md",
|
||||
"path": "mnt/user-data/outputs/report.md",
|
||||
"modified_at": "2026-07-21T00:00:00+00:00",
|
||||
"size_bytes": 100,
|
||||
}
|
||||
]
|
||||
assert not position_roundtable_router._markdown_delivery_changed(old, old)
|
||||
assert position_roundtable_router._markdown_delivery_changed(
|
||||
old,
|
||||
[{**old[0], "modified_at": "2026-07-21T00:05:00+00:00", "size_bytes": 120}],
|
||||
)
|
||||
|
||||
|
||||
def test_activation_requires_a_structured_intent_snapshot() -> None:
|
||||
assert not position_roundtable_router._has_confirmed_intent({"objective": "只有目标"})
|
||||
assert not position_roundtable_router._has_confirmed_intent({"constraints": []})
|
||||
assert position_roundtable_router._has_confirmed_intent(
|
||||
{"objective": "明确任务目标", "constraints": []}
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handoff_context_inlines_only_upstream_thread_text_artifacts(tmp_path, monkeypatch):
|
||||
artifact = tmp_path / "handoff.md"
|
||||
|
||||
Reference in new issue
Block a user