Files
roboco/tests/unit/runtime/test_briefing_tool_load_block.py
T
718d7dd83e Fix: open findings cleanup (#122)
* refactor(usage): remove the unconsumed per-agent USAGE_UPDATE event

USAGE_UPDATE was published per active agent each sweep, bridged, and
broadcast to /ws/system, but no panel client ever consumed it — the
dashboard reads only the aggregate USAGE_SNAPSHOT. Every emission was
wasted event-bus and WebSocket traffic.

Drop the UsageUpdate payload, publish_usage_update and its throttle, the
EventType member, and the bridge subscription. Keep USAGE_SNAPSHOT, which
already carries the per-agent breakdown, so no live data is lost.

* refactor(prompter): remove the legacy local-LLM HTTP endpoints

The panel uses only the live SDK-intake path (/prompter/live/*); the legacy
/prompter/chat, /draft and /sessions/* endpoints — backed by the local Ollama
LLM with hardcoded prompts — had no remaining caller. Remove the router, its
mount in app.py, and its integration test. The live router and the shared
draft-confirmation service are untouched.

* refactor(prompter): drop the dead legacy local-LLM service + schemas

With the legacy HTTP endpoints gone, the local-LLM chat/draft/session methods,
their prompt constants, the ConfirmOverrides/TurnResult dataclasses, and the
entire prompter schema module had no production caller (only their own tests).
Remove them, keeping the live-intake path: create_task_from_draft /
confirm_live_draft, the enum/priority/team coercion, and the pure
description/readiness helpers.

* refactor(agents): stop granting the Task sub-agent tool to roles

Every agent role was granted the built-in Task tool, but no role prompt or
workflow uses it and there are no custom sub-agent definitions — so a Task call
only spawns a context-blind generic sub-agent that burns budget (ToolSearch,
the comment's stated use, is MCP-only and not callable in agent containers).

Drop Task from all three grant points in lockstep: the --tools spawn flag and
both _ROLE_BUILTIN_TOOLS maps (system-prompt + briefing layers), with a
regression guard added to each layer's test.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-06-12 23:10:21 +02:00

100 lines
3.5 KiB
Python

"""#167: the briefing's _build_tool_load_block must not push ToolSearch.
Earlier (smoke-8) the block instructed agents to run a ToolSearch call
to "activate deferred built-in tools". That premise was false —
ToolSearch is MCP-only, never gates built-ins, and is not callable in
the agent runtime — so weak models chased a nonexistent tool and fell
back to destructive shell file-writes. The real cause of "Edit not
enabled in this context" was a permission bug fixed separately.
The block now affirms the role's built-in tools are loaded and ready,
tells the agent NOT to call ToolSearch, and (for authoring roles)
steers away from whole-file shell redirection.
"""
from __future__ import annotations
from unittest.mock import patch
from roboco.runtime.orchestrator import AgentOrchestrator
def _orch() -> AgentOrchestrator:
with patch.object(AgentOrchestrator, "__init__", return_value=None):
orch = AgentOrchestrator.__new__(AgentOrchestrator)
orch._TOOL_LOAD_CACHE = {}
return orch
def _tool_names(block: str) -> list[str]:
"""Exact tool tokens (so 'TodoWrite' is not mistaken for 'Write')."""
line = next(ln for ln in block.splitlines() if "available now:" in ln)
seg = line.split("available now: ", 1)[1]
return seg.split(".", 1)[0].split(", ")
def test_developer_block_affirms_tools_no_toolsearch_call() -> None:
block = _orch()._build_tool_load_block("developer")
assert "Your tools are ready" in block
assert "ToolSearch(query=" not in block
assert "are deferred" not in block
names = _tool_names(block)
assert "Edit" in names and "Write" in names
def test_developer_block_steers_away_from_shell_redirection() -> None:
block = _orch()._build_tool_load_block("developer")
assert "shell redirection" in block
assert "Edit/Write" in block
def test_documenter_block_lists_edit_and_write() -> None:
names = _tool_names(_orch()._build_tool_load_block("documenter"))
assert "Edit" in names and "Write" in names
def test_qa_block_excludes_edit_and_write() -> None:
block = _orch()._build_tool_load_block("qa")
assert "Your tools are ready" in block
names = _tool_names(block)
assert "Edit" not in names and "Write" not in names
assert "Read" in names and "Bash" in names
def test_pm_blocks_exclude_edit_and_write() -> None:
for role in ("main_pm", "cell_pm", "product_owner", "head_marketing", "auditor"):
names = _tool_names(_orch()._build_tool_load_block(role))
assert "Edit" not in names, f"{role} must not list Edit"
assert "Write" not in names, f"{role} must not list Write"
def test_no_role_block_lists_the_task_subagent_tool() -> None:
"""Task (sub-agent dispatch) is dropped from the briefing tool grant.
No role uses Task and there are no custom sub-agent definitions, so it only
spawns a context-blind generic sub-agent that burns budget.
"""
for role in (
"developer",
"documenter",
"qa",
"main_pm",
"cell_pm",
"product_owner",
"head_marketing",
"auditor",
):
names = _tool_names(_orch()._build_tool_load_block(role))
assert "Task" not in names, f"{role} must not list Task: {names}"
def test_unknown_role_returns_empty() -> None:
assert _orch()._build_tool_load_block("nonexistent") == ""
def test_role_cache_works() -> None:
orch = _orch()
first = orch._build_tool_load_block("developer")
second = orch._build_tool_load_block("developer")
assert first is second