mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
feat(routing): cost-tiered complexity routing + saved presets (#656)
The 08-31 lever: model_assignments gains one compound rung —
AGENT_SLUG > ROLE('{role}:{complexity}') > ROLE > GLOBAL — so a
low-complexity task can route to a cheaper tier while coordinators stay
pinned. Structurally opt-in: zero rows means byte-identical routing
(pinned by a named test across every precedence case), the cost_tiered
apply-mode (seeds developer:low→haiku) is reachable only from the
explicit PM-gated endpoint — verified no startup path can apply it.
Overrides are downgrade-only (input-price comparator), allowlisted to
{developer, qa, documenter} — cell_pm excluded per the org's own
coordinator definition and its documented weak-model incidents — and
validated at write time (disabled/unconfigured provider rejected with
remediation; cross-provider-family overrides warn explicitly).
Per adversarial review: the four mode-switch applies now spare compound
rows exactly like agent pins (the 2026-07-17 unscoped-wipe class, new
victim, same fix extended via one shared wipe helper) with panel cache
invalidation + truthful confirm dialogs; preset apply validates the
entire payload BEFORE the wipe (validate-all-first), with a savepoint
crash test proving rollback.
Presets (CEO request): routing_presets table (migration 082) snapshots
the full mix — mode, per-agent overrides, complexity rows — with
save/apply/delete endpoints and a panel preset bar; applying skips
since-removed models with per-entry notes, never silently.
Task complexity threads task_id through _resolve_agent_route at both
call sites; taskless spawns unchanged. 235 backend + 23 panel tests.
Co-authored-by: Renn F <rennf93@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
"""Migration 082 tests — routing_presets table.
|
||||
|
||||
Verifies the DB-level contract the migration establishes: a unique
|
||||
constraint on `name` (so `save_routing_preset`'s duplicate-name 409 has a
|
||||
real backstop, not just an app-level pre-check) and a JSONB `payload` column
|
||||
that round-trips a nested dict/list structure faithfully.
|
||||
|
||||
NOT a real alembic round-trip — the suite builds the test DB via
|
||||
Base.metadata.create_all (see conftest); a real `alembic upgrade head` +
|
||||
`downgrade -1` round trip against a scratch Postgres (:55432) was run
|
||||
manually and confirmed clean (create + drop, no errors) as part of building
|
||||
this migration. See `alembic/versions/082_routing_presets.py`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
from roboco.db.tables import RoutingPresetTable
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_routing_preset_name_is_unique(db_session: AsyncSession) -> None:
|
||||
"""The `uq_routing_presets_name` constraint rejects a duplicate name at
|
||||
the DB level — the backstop behind the service's pre-check 409."""
|
||||
db_session.add(RoutingPresetTable(name="dup-name", payload={"assignments": []}))
|
||||
await db_session.flush()
|
||||
|
||||
db_session.add(RoutingPresetTable(name="dup-name", payload={"assignments": []}))
|
||||
with pytest.raises(IntegrityError):
|
||||
await db_session.flush()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_routing_preset_payload_round_trips_nested_structure(
|
||||
db_session: AsyncSession,
|
||||
) -> None:
|
||||
"""The JSONB payload column stores/returns a nested dict/list structure
|
||||
(the shape `save_routing_preset` writes) byte-for-byte."""
|
||||
payload = {
|
||||
"mode": "mix",
|
||||
"assignments": [
|
||||
{
|
||||
"scope": "agent_slug",
|
||||
"scope_value": "be-dev-1",
|
||||
"provider_type": "anthropic",
|
||||
"model_name": "sonnet",
|
||||
},
|
||||
{
|
||||
"scope": "role",
|
||||
"scope_value": "developer:low",
|
||||
"provider_type": "anthropic",
|
||||
"model_name": "haiku",
|
||||
},
|
||||
],
|
||||
}
|
||||
row = RoutingPresetTable(name="round-trip-preset", payload=payload)
|
||||
db_session.add(row)
|
||||
await db_session.flush()
|
||||
await db_session.refresh(row)
|
||||
|
||||
assert row.payload == payload
|
||||
assert row.created_at is not None
|
||||
Reference in New Issue
Block a user