mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
* 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>
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
"""Unit tests for roboco.services.usage_events.
|
|
|
|
Covers the publish_usage_snapshot helper. No real Redis or event bus is
|
|
needed — we use AsyncMock to assert that bus.publish is called with the right
|
|
payload and type.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
from roboco.services.usage_events import UsageSnapshot, publish_usage_snapshot
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# publish_usage_snapshot
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_publish_usage_snapshot_always_publishes() -> None:
|
|
"""publish_usage_snapshot has no throttle — always publishes."""
|
|
bus = MagicMock()
|
|
bus.publish = AsyncMock()
|
|
expected_input = 500
|
|
expected_cost = 0.0025
|
|
expected_agents = 2
|
|
|
|
await publish_usage_snapshot(
|
|
bus,
|
|
UsageSnapshot(
|
|
period="live",
|
|
totals={"input_tokens": expected_input, "output_tokens": 200},
|
|
cost_estimate=expected_cost,
|
|
by_agent=[
|
|
{
|
|
"agent_id": "be-dev-1",
|
|
"input_tokens": 300,
|
|
"output_tokens": 100,
|
|
"model": "sonnet",
|
|
"cost_estimate": 0.0015,
|
|
},
|
|
{
|
|
"agent_id": "be-dev-2",
|
|
"input_tokens": 200,
|
|
"output_tokens": 100,
|
|
"model": "sonnet",
|
|
"cost_estimate": 0.0010,
|
|
},
|
|
],
|
|
),
|
|
)
|
|
|
|
bus.publish.assert_awaited_once()
|
|
event = bus.publish.await_args.args[0]
|
|
assert event.type.value == "usage.snapshot"
|
|
assert event.data["period"] == "live"
|
|
assert event.data["totals"]["input_tokens"] == expected_input
|
|
assert event.data["cost_estimate"] == expected_cost
|
|
assert len(event.data["by_agent"]) == expected_agents
|
|
assert "timestamp" in event.data
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_publish_usage_snapshot_twice_both_published() -> None:
|
|
"""No throttle on snapshot: two rapid calls both publish."""
|
|
bus = MagicMock()
|
|
bus.publish = AsyncMock()
|
|
expected_calls = 2
|
|
|
|
for _ in range(expected_calls):
|
|
await publish_usage_snapshot(
|
|
bus,
|
|
UsageSnapshot(
|
|
period="live",
|
|
totals={"input_tokens": 0, "output_tokens": 0},
|
|
cost_estimate=0.0,
|
|
by_agent=[],
|
|
),
|
|
)
|
|
|
|
assert bus.publish.await_count == expected_calls
|