feat(maf): add secure roundtable workflow runtime

This commit is contained in:
董宏凯 committed 2026-08-01 17:51:53 +08:00
1 parent e690475e6e
commit bd4131b4e2
52 files changed
+10315 -96

No files matched your search

@@ -0,0 +1,88 @@
"""P0-1: trusted capability snapshot builder tests."""
from __future__ import annotations
import pytest
from maf_test_helpers import FakeAgentStore
from app.maf_roundtable.capability_snapshot import (
AgentNotAccessibleError,
build_trusted_capability_snapshot,
)
from deerflow.config import get_app_config
from deerflow.tools.tool_metadata import resolve_tool_metadata
@pytest.mark.asyncio
async def test_client_forged_side_effect_not_stored(monkeypatch):
app_config = get_app_config()
def _fake_build_seat(*, app_config, agent_id, session_model_name, session_reasoning_effort, requested_excluded):
meta = resolve_tool_metadata("write_file")
return (["write_file"], [], [meta])
monkeypatch.setattr(
"app.maf_roundtable.capability_snapshot._seat_tools_for_agent",
_fake_build_seat,
)
snap = await build_trusted_capability_snapshot(
user_id="u1",
participants=[
{
"agent_id": "seat-a",
"role": "seat",
"excluded_tools": [],
# Client forgery ??must be ignored (field not read).
"capability_snapshot": {
"tools": [{"name": "write_file", "side_effect": "read", "risk_level": "R0"}],
},
}
],
app_config=app_config,
agent_store=FakeAgentStore(),
)
tool = snap["agents"][0]["tools"][0]
assert tool["side_effect"] == "write"
assert tool["risk_level"] == "R3"
@pytest.mark.asyncio
async def test_frozen_allow_list_excludes_registry_only_tool(monkeypatch):
app_config = get_app_config()
def _fake_build_seat(*, app_config, agent_id, session_model_name, session_reasoning_effort, requested_excluded):
return (["tool_a"], [], [resolve_tool_metadata("tool_a")])
monkeypatch.setattr(
"app.maf_roundtable.capability_snapshot._seat_tools_for_agent",
_fake_build_seat,
)
snap = await build_trusted_capability_snapshot(
user_id="u1",
participants=[{"agent_id": "seat-a", "role": "seat"}],
app_config=app_config,
agent_store=FakeAgentStore(),
)
assert snap["agents"][0]["allowed_tool_names"] == ["tool_a"]
assert "tool_b" not in snap["agents"][0]["allowed_tool_names"]
@pytest.mark.asyncio
async def test_inaccessible_agent_rejected():
app_config = get_app_config()
class _DenyStore:
async def get_visible(self, agent_id: str, user_id: str):
return None
with pytest.raises(AgentNotAccessibleError):
await build_trusted_capability_snapshot(
user_id="u1",
participants=[{"agent_id": "missing-agent", "role": "seat"}],
app_config=app_config,
agent_store=_DenyStore(),
)