"""The design advisor's fan-out to one advisor per architecture-framework pillar.""" import pytest from app.agents.fake_runtime import Call, FakeAgentRuntime from app.agents.roles import PILLAR_ADVISOR from app.agents.runtime import RoleSpec, ToolSpec from app.execution.pillars import CONSULT_TOOL, pillar_consultation_tool from app.execution.toolkit import make_tool_factory pytestmark = pytest.mark.asyncio PILLARS = { "security": "waf-security", "reliability": "waf-reliability", "sustainability": "waf-sustainability", } ADVISOR = RoleSpec(PILLAR_ADVISOR, "Advise on one pillar.", budget=5) def advice(pillar: str) -> list[Call]: return [Call("submit_advice", {"content": f"Use strong defaults for {pillar}."})] def turn_for_pillar(task): return advice(task.context["pillar"]) async def consult(tool: ToolSpec, **args): return await tool.handler(**args) async def test_consults_every_pillar_with_only_its_skill(): runtime = FakeAgentRuntime({PILLAR_ADVISOR: [turn_for_pillar] * 3}) tool = pillar_consultation_tool(runtime, ADVISOR, PILLARS) result = await consult(tool, brief="Event ingestion on serverless compute.") assert result.outcome is None for pillar in PILLARS: assert f"## {pillar}" in result.message assert f"Use strong defaults for {pillar}." in result.message runs = {run.task.context["pillar"]: run for run in runtime.runs} assert set(runs) == set(PILLARS) assert ( runs["security"].task.context["brief"] == "Event ingestion on serverless compute." ) assert runtime.runs[0].tools == ("submit_advice",) async def test_advisors_are_scoped_to_their_pillar_skill(): seen: dict[str, tuple[str, ...]] = {} class RecordingRuntime(FakeAgentRuntime): async def run(self, role, task, tools): seen[task.context["pillar"]] = role.skills return await super().run(role, task, tools) runtime = RecordingRuntime({PILLAR_ADVISOR: [turn_for_pillar] * 3}) await consult(pillar_consultation_tool(runtime, ADVISOR, PILLARS), brief="b") assert seen == {pillar: (skill,) for pillar, skill in PILLARS.items()} async def test_a_subset_of_pillars_can_be_consulted(): runtime = FakeAgentRuntime({PILLAR_ADVISOR: [turn_for_pillar]}) tool = pillar_consultation_tool(runtime, ADVISOR, PILLARS) result = await consult(tool, brief="b", pillars=["reliability"]) assert "## reliability" in result.message assert "## security" not in result.message async def test_unknown_pillars_are_refused(): tool = pillar_consultation_tool(FakeAgentRuntime({}), ADVISOR, PILLARS) result = await consult(tool, brief="b", pillars=["speed"]) assert result.message.startswith("Refused") assert "security" in result.message async def test_an_advisor_that_fails_is_reported_without_losing_the_others(): def maybe_fail(task): if task.context["pillar"] == "reliability": return [Call("submit_advice", {"content": ""})] return advice(task.context["pillar"]) runtime = FakeAgentRuntime({PILLAR_ADVISOR: [maybe_fail] * 3}) result = await consult( pillar_consultation_tool(runtime, ADVISOR, PILLARS), brief="b" ) assert "Use strong defaults for security." in result.message assert "## reliability\n\nNo guidance:" in result.message async def test_tool_factory_gives_the_consultation_only_to_the_design_advisor(): roles = {PILLAR_ADVISOR: ADVISOR} factory = make_tool_factory(FakeAgentRuntime({}), roles, PILLARS) design = factory(RoleSpec("design-advisor", "", budget=5), "design_recommendations") other = factory(RoleSpec("decomposer", "", budget=5), "technical_decomposition") assert [tool.name for tool in design] == [CONSULT_TOOL] assert list(other) == []