sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)
This commit is contained in:
1 parent
4f7f07504a
commit
8bc8b0e082
1651 files changed
+278599
-11416
No files matched your search
@@ -12,7 +12,7 @@ from app.report_collaboration.planning.selector import AgentSelector
|
||||
from app.report_collaboration.planning.service import PlanProposalService
|
||||
from app.report_collaboration.planning.validator import validate_assembled_plan
|
||||
from deerflow.config.report_collaboration_config import ReportCollaborationConfig
|
||||
from deerflow.persistence.report_collaboration import MemoryReportCollaborationStore
|
||||
from deerflow.persistence.report_collaboration import MemoryReportCollaborationStore, ReportCollaborationValidationError
|
||||
|
||||
|
||||
class _AgentStore:
|
||||
@@ -135,6 +135,26 @@ def test_validator_rejects_unknown_agent_id() -> None:
|
||||
asyncio.run(_run())
|
||||
|
||||
|
||||
class _DesignFakeLLM:
|
||||
"""规划师工作流设计假模型:返回单份合法定制方案。"""
|
||||
|
||||
_payload = (
|
||||
'{"reply": "我按需求设计了两条研究线汇写再审的定制工作流。",'
|
||||
'"strategy": "custom", "title": "定制方案", "summary": "两线并行汇写再审",'
|
||||
'"rationale": "贴合需求", "estimated_duration_seconds": 1200,'
|
||||
'"estimated_cost_level": "medium", "quality_gate_ids": ["cite_required"],'
|
||||
'"nodes": ['
|
||||
'{"slot_id": "research-a", "agent_id": "ag-research", "role_key": "researcher", "display_name": "研究节点", "angle": "市场", "mission": "检索市场证据", "depends_on": [], "output_artifact_type": "EvidenceBundle"},'
|
||||
'{"slot_id": "write-main", "agent_id": "ag-writer", "role_key": "writer", "display_name": "撰写节点", "mission": "成稿", "depends_on": ["research-a"], "output_artifact_type": "ReportSectionDraft"}'
|
||||
']}'
|
||||
)
|
||||
|
||||
async def ainvoke(self, messages):
|
||||
from types import SimpleNamespace
|
||||
|
||||
return SimpleNamespace(content=self._payload)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_service_writes_plans_without_starting_a_run() -> None:
|
||||
store = MemoryReportCollaborationStore()
|
||||
@@ -146,15 +166,33 @@ async def test_service_writes_plans_without_starting_a_run() -> None:
|
||||
status="clarifying",
|
||||
)
|
||||
command = await store.enqueue_plan_request(session["id"], idempotency_key="ik-plan", expected_revision=1)
|
||||
saved = await PlanProposalService(store).fulfill(session["id"], user_id="u1", command_id=command["command_id"], idempotency_key="ik-plan")
|
||||
agent_store = _AgentStore(
|
||||
[
|
||||
{"id": "ag-research", "name": "新能源汽车情报员", "description": "检索并分析新能源汽车市场信息"},
|
||||
{"id": "ag-writer", "name": "战略报告撰稿人", "description": "把研究成果写成面向管理层的报告"},
|
||||
]
|
||||
)
|
||||
saved = await PlanProposalService(
|
||||
store,
|
||||
agent_store=agent_store,
|
||||
llm_factory=lambda: _DesignFakeLLM(),
|
||||
).fulfill(
|
||||
session["id"], user_id="u1", command_id=command["command_id"], idempotency_key="ik-plan"
|
||||
)
|
||||
assert len(saved) == 3
|
||||
snapshot = await store.get_snapshot(session["id"])
|
||||
assert snapshot["session"]["status"] == "proposal_ready"
|
||||
assert snapshot["session"]["selected_plan_id"] is None
|
||||
assert snapshot["run"] is None
|
||||
assert {item["strategy"] for item in snapshot["plans"]} == {"balanced_review", "parallel_depth", "focused_fast"}
|
||||
assert snapshot["plans"][0]["strategy"] == "custom"
|
||||
custom_nodes = snapshot["plans"][0]["nodes"]
|
||||
assert [item["agent_id"] for item in custom_nodes] == ["ag-research", "ag-writer"]
|
||||
assert [item["role_display_name"] for item in custom_nodes] == ["新能源汽车情报员", "战略报告撰稿人"]
|
||||
assert all(item["requirement_revision"] == 1 for item in snapshot["plans"])
|
||||
assert snapshot["session"]["active_run_id"] is None
|
||||
ai = [item for item in snapshot["messages"] if item["role"] == "ai"][-1]
|
||||
assert ai["metadata"]["plan_source"] == "planner_agent"
|
||||
assert "定制工作流" in ai["content"]
|
||||
|
||||
selected = await store.select_plan(session["id"], saved[0]["id"], idempotency_key="ik-select", expected_revision=1)
|
||||
after_select = await store.get_snapshot(session["id"])
|
||||
@@ -163,6 +201,24 @@ async def test_service_writes_plans_without_starting_a_run() -> None:
|
||||
assert after_select["session"]["active_run_id"] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_service_raises_when_planner_unavailable() -> None:
|
||||
store = MemoryReportCollaborationStore()
|
||||
session = await store.create_session(owner_id="u1", title="", idempotency_key="s1b")
|
||||
await store.save_requirement_state(
|
||||
session["id"],
|
||||
requirement_json={"snapshot": _requirement().model_dump(), "clarifications": [], "assumptions": [], "clarification_round": 1, "ready_to_plan": True},
|
||||
requirement_revision=1,
|
||||
status="clarifying",
|
||||
)
|
||||
command = await store.enqueue_plan_request(session["id"], idempotency_key="ik-plan2", expected_revision=1)
|
||||
with pytest.raises(ReportCollaborationValidationError) as exc:
|
||||
await PlanProposalService(store, llm_factory=lambda: None).fulfill(
|
||||
session["id"], user_id="u1", command_id=command["command_id"], idempotency_key="ik-plan2"
|
||||
)
|
||||
assert exc.value.code == "PLANNER_UNAVAILABLE"
|
||||
|
||||
|
||||
def test_cycle_is_rejected() -> None:
|
||||
cfg = ReportCollaborationConfig()
|
||||
candidate_nodes_cycle = AssembledPlan.model_validate(
|
||||
|
||||
Reference in new issue
Block a user