feat(maf): complete resilient roundtable workflow
This commit is contained in:
1 parent
bd4131b4e2
commit
21c4c898e7
23 files changed
+4810
-312
No files matched your search
@@ -22,6 +22,7 @@ Additionally covers:
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import itertools
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, patch
|
||||
@@ -869,8 +870,9 @@ async def test_audit_event_failure_prevents_external_write(store):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_deerflow_task_error_marks_run_failed(store):
|
||||
"""P1: when the DeerFlow agent run raises, the MAF run is marked failed
|
||||
(not completed), with a sanitized error message."""
|
||||
"""P3: when a DeerFlow seat turn raises, the seat is soft-failed
|
||||
(``partial_failure``) and the structured run still completes degraded;
|
||||
secrets must not appear in persisted seat / run errors."""
|
||||
svc = _svc(store)
|
||||
s = await svc.create_session(
|
||||
user_id="u1",
|
||||
@@ -890,9 +892,20 @@ async def test_deerflow_task_error_marks_run_failed(store):
|
||||
await runner.execute(s, run)
|
||||
|
||||
final_run = await svc.get_run(run_id=run["id"], user_id="u1")
|
||||
assert final_run["status"] == "failed"
|
||||
assert final_run["status"] == "completed"
|
||||
assert final_run["finished_at"] is not None
|
||||
assert "sk-secret-12345" not in (final_run.get("error_message_safe") or "")
|
||||
ckpt = final_run.get("maf_checkpoint") or {}
|
||||
assert ckpt.get("partial_failure") is True
|
||||
outcome = (ckpt.get("seat_outcomes") or {}).get("boom-seat") or {}
|
||||
assert outcome.get("status") in ("failed", "error")
|
||||
persisted = " ".join(
|
||||
[
|
||||
str(final_run.get("error_message_safe") or ""),
|
||||
str(outcome.get("error") or ""),
|
||||
str(ckpt),
|
||||
]
|
||||
)
|
||||
assert "sk-secret-12345" not in persisted
|
||||
|
||||
|
||||
# ── 13. Secrets never in events / errors / logs ──────────────────────────
|
||||
@@ -1200,3 +1213,107 @@ async def test_capability_snapshot_drives_seat_config(store):
|
||||
|
||||
caps3 = _agent_capabilities_from_snapshot(None, "seat-1")
|
||||
assert caps3 == {}
|
||||
|
||||
|
||||
# ── 22. P1-3: Real WorkflowBuilder manager stages via WorkflowRunner ─────────
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_real_workflow_manager_stages_persisted(store):
|
||||
"""P1-3: drive a REAL MAF WorkflowRunner (real WorkflowBuilder, real SQLite
|
||||
repository, real adapter + seat-run store) through a structured run with a
|
||||
manager + 2 seats. Only the runtime client is faked (no real LLM).
|
||||
|
||||
Asserts:
|
||||
- manager has planner, cross_review, finalizer seat-run rows
|
||||
- cross_review.turn_index == finalizer.turn_index
|
||||
- cross_review.execution_stage != finalizer.execution_stage
|
||||
"""
|
||||
svc = _svc(store)
|
||||
s = await svc.create_session(
|
||||
user_id="u1",
|
||||
body={
|
||||
"task_text": "分析市场趋势",
|
||||
"mode": "structured",
|
||||
"manager_agent_id": "manager-1",
|
||||
"participants": [
|
||||
{"agent_id": "manager-1", "role": "manager"},
|
||||
{"agent_id": "seat-a", "role": "seat"},
|
||||
{"agent_id": "seat-b", "role": "seat"},
|
||||
],
|
||||
},
|
||||
)
|
||||
run = await svc.create_run(session_id=s["id"], user_id="u1")
|
||||
|
||||
app = _make_app(store)
|
||||
runner = WorkflowRunner(app, service=svc, user_id="u1")
|
||||
|
||||
manager_responses = iter([
|
||||
"分工:seat-a 负责需求分析,seat-b 负责竞品分析",
|
||||
json.dumps({
|
||||
"summary": "审查通过,证据充分",
|
||||
"evidence_ok": True,
|
||||
"confirmed_candidates": [],
|
||||
}),
|
||||
"最终结论:市场看好,建议推进",
|
||||
])
|
||||
seat_responses = {
|
||||
"seat-a": json.dumps({"summary": "需求旺盛", "findings": ["增长10%"]}),
|
||||
"seat-b": json.dumps({"summary": "竞品A领先", "findings": ["份额30%"]}),
|
||||
}
|
||||
|
||||
call_log: list[dict] = []
|
||||
thread_counter = itertools.count()
|
||||
created_threads: list[str] = []
|
||||
latest_agent_by_thread: dict[str, str] = {}
|
||||
|
||||
async def fake_create_thread(principal):
|
||||
thread_id = f"thread-{principal.session_id[:8]}-{next(thread_counter)}"
|
||||
created_threads.append(thread_id)
|
||||
return thread_id
|
||||
|
||||
async def fake_start_agent_run(principal, *, thread_id, agent_id, message, **kwargs):
|
||||
latest_agent_by_thread[thread_id] = agent_id
|
||||
call_log.append({"agent_id": agent_id, "thread_id": thread_id, "message": message})
|
||||
return _FakeRunRecord(run_id=f"df-{agent_id}-{len(call_log)}")
|
||||
|
||||
async def fake_read_messages(principal, thread_id):
|
||||
agent_id = latest_agent_by_thread[thread_id]
|
||||
if agent_id == "manager-1":
|
||||
content = next(manager_responses)
|
||||
else:
|
||||
content = seat_responses[agent_id]
|
||||
return [{"type": "ai", "content": content, "usage_metadata": {"input_tokens": 5, "output_tokens": 5}}]
|
||||
|
||||
runner.adapter._client.create_thread = fake_create_thread
|
||||
runner.adapter._client.start_agent_run = fake_start_agent_run
|
||||
runner.adapter._client.read_thread_messages = fake_read_messages
|
||||
runner.adapter._client.cancel_run = AsyncMock(return_value=True)
|
||||
|
||||
await runner.execute(s, run)
|
||||
|
||||
final_run = await svc.get_run(run_id=run["id"], user_id="u1")
|
||||
assert final_run["status"] == "completed"
|
||||
|
||||
seat_runs = await store.seat_runs.get_by_maf_run(run["id"])
|
||||
mgr_rows = [r for r in seat_runs if r["agent_id"] == "manager-1"]
|
||||
mgr_stages = {r["execution_stage"] for r in mgr_rows}
|
||||
assert {"planner", "cross_review", "finalizer"}.issubset(mgr_stages), \
|
||||
f"manager stages missing; got {mgr_stages}"
|
||||
|
||||
cr_rows = [r for r in mgr_rows if r["execution_stage"] == "cross_review"]
|
||||
fin_rows = [r for r in mgr_rows if r["execution_stage"] == "finalizer"]
|
||||
assert len(cr_rows) == 1 and len(fin_rows) == 1
|
||||
assert cr_rows[0]["turn_index"] == fin_rows[0]["turn_index"]
|
||||
assert cr_rows[0]["execution_stage"] != fin_rows[0]["execution_stage"]
|
||||
|
||||
assert len(created_threads) == 3
|
||||
assert len(set(created_threads)) == 3
|
||||
|
||||
ckpt = final_run["maf_checkpoint"]
|
||||
assert "最终结论:市场看好" in str(ckpt)
|
||||
assert any(
|
||||
r.get("agent_id") == "seat-a"
|
||||
and (r.get("structured_output") or {}).get("summary") == "需求旺盛"
|
||||
for r in ckpt["turn_results"]
|
||||
)
|
||||
Reference in new issue
Block a user