mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
fix(gateway): unblock task claim; full Phase 0/1/2 remediation
Resolves the 100% claim-failure rate introduced by the gateway rewrite
(commit 62bda0c plus 78 follow-ups). Live smoke runs hit
`404 /api/v2/flow/developer/...` on every dev verb plus a manifest
fallback that silently exposed off-role verbs to PMs — confirmed
firing simultaneously in NAS agent logs (be-dev-1, be-pm, main-pm).
Audit reports under docs/internal/audit_2026_05_04/ catalogue 49
defects across gateway, services, prompts, MCP transport, substrate,
and tests (8 detail reports + master synthesis). Six smoking guns;
three proven in production logs.
Phase 0 — unblock claim:
- URL prefix /api/v2/flow/dev → /developer; slug-map board roles
(product_owner, head_marketing) → /board (D-01)
- _i_will_work_on AttributeError on None across pending /
needs_revision / claimed re-entry branches (D-02)
- Seed last_heartbeat_at in _qa_or_doc_claim (D-03)
- Drop misleading i_have_committed verb; dev flow uses commit() (D-04)
- Manifest mount via compose; flow_server + do_server fail loud
instead of exposing all-verbs fallback (D-12)
- MCP _post() surfaces envelope body on 4xx so agents see remediate
hints (D-13)
on git failure so retries aren't blocked by half-state (S-01)
Phase 1 — lifecycle stability:
- _resolve_skill falls back to AgentTable.capabilities (D-06)
- main_pm_complete uses kwargs for escalate_to_ceo (D-07)
- i_am_done auto-runs submit_verification when in_progress (D-08)
- active_claimant_id wired in claim/unclaim paths — single-claimant
invariant now functional (D-05)
- qa_pass/qa_fail assert claimed_by parity with qa_agent_id (D-18)
- Prompt-drift sweep: fail() shape, i_am_done(task_id, notes),
subtask cap (12 hard / 8 soft), error-code symbology rewritten in
base.md + per-role anti-patterns (D-10/11/29/30/31, D-37)
Phase 2 — invariants + architecture:
- Real-DB integration test exercising claim → in_progress → commit
→ submit_for_qa → i_am_done → awaiting_qa (P2-1)
- choreographer.py → package; 3 of 6 role mixins extracted
(board, doc, qa). _impl.py 2,526 → 2,080 lines (-18%). Continuation
plan in docs/internal/audit_2026_05_04/p2_2_decompose_plan.md (P2-2)
- Closure guards consolidated via _subtasks_not_terminal_envelope (P2-3)
- TaskService.unclaim_for_reaper routed through canonical
_validate_and_set_status; in_progress → pending added to
VALID_TRANSITIONS (P2-4)
- Dead code removed: i_am_done_with_catchup verb, _run_catch_up helper
(P2-5)
- 6 state-machine invariants asserted via property test (P2-6)
- attempt_id (uuid4) stamped on every gateway.rejected audit row (P2-7)
- _reconcile_orphan_claims_on_startup rolls back tasks left CLAIMED
with branch_name=NULL from prior crashes (P2-8)
- scripts/regenerate_verb_tables.py introspects Pydantic schemas +
role_config; compose_prompt injects per-role tables as a layer.
Eliminates the prompt-drift class structurally (P2-9)
Other:
- D-48: orchestrator mounts host's ~/.claude.json when present so
agents don't boot from backup recovery on every spawn
- D-49: dev dispatcher rejects role-mismatched spawns (e.g. doc task
assigned to dev agent)
Tests: 553 pass · ruff + mypy clean. Live NAS smoke verification
pending — needs the stack brought back up.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Unit tests for /api/v2/flow/dev/* endpoints.
|
||||
"""Unit tests for /api/v2/flow/developer/* endpoints.
|
||||
|
||||
Uses a minimal FastAPI test client built from the new router only.
|
||||
No DB required — Choreographer is mocked.
|
||||
@@ -40,13 +40,13 @@ def _build_app(mock_choreographer: MagicMock) -> FastAPI:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_give_me_work_returns_envelope() -> None:
|
||||
"""POST /api/v2/flow/dev/give_me_work returns 200 with envelope shape."""
|
||||
"""POST /api/v2/flow/developer/give_me_work returns 200 with envelope shape."""
|
||||
mock_chore = MagicMock()
|
||||
mock_chore.give_me_work = AsyncMock(return_value=_make_envelope(status="idle"))
|
||||
client = TestClient(_build_app(mock_chore))
|
||||
|
||||
resp = client.post(
|
||||
"/api/v2/flow/dev/give_me_work",
|
||||
"/api/v2/flow/developer/give_me_work",
|
||||
json={},
|
||||
headers=_HEADERS,
|
||||
)
|
||||
@@ -59,7 +59,7 @@ async def test_give_me_work_returns_envelope() -> None:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_will_work_on_dispatches_task_id() -> None:
|
||||
"""POST /api/v2/flow/dev/i_will_work_on forwards task_id and plan."""
|
||||
"""POST /api/v2/flow/developer/i_will_work_on forwards task_id and plan."""
|
||||
mock_chore = MagicMock()
|
||||
mock_chore.i_will_work_on = AsyncMock(
|
||||
return_value=_make_envelope(status="in_progress", task_id=_TASK_ID)
|
||||
@@ -67,7 +67,7 @@ async def test_i_will_work_on_dispatches_task_id() -> None:
|
||||
client = TestClient(_build_app(mock_chore))
|
||||
|
||||
resp = client.post(
|
||||
"/api/v2/flow/dev/i_will_work_on",
|
||||
"/api/v2/flow/developer/i_will_work_on",
|
||||
json={"task_id": _TASK_ID, "plan": "implement the feature"},
|
||||
headers=_HEADERS,
|
||||
)
|
||||
@@ -82,29 +82,9 @@ async def test_i_will_work_on_dispatches_task_id() -> None:
|
||||
assert call_args.args[2] == "implement the feature"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_have_committed_dispatches_message() -> None:
|
||||
"""POST /api/v2/flow/dev/i_have_committed forwards commit message."""
|
||||
mock_chore = MagicMock()
|
||||
mock_chore.i_have_committed = AsyncMock(
|
||||
return_value=_make_envelope(status="in_progress")
|
||||
)
|
||||
client = TestClient(_build_app(mock_chore))
|
||||
|
||||
resp = client.post(
|
||||
"/api/v2/flow/dev/i_have_committed",
|
||||
json={"message": "add auth endpoint"},
|
||||
headers=_HEADERS,
|
||||
)
|
||||
|
||||
assert resp.status_code == _HTTP_200
|
||||
mock_chore.i_have_committed.assert_awaited_once()
|
||||
assert mock_chore.i_have_committed.call_args.args[1] == "add auth endpoint"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_am_done_dispatches_task_and_notes() -> None:
|
||||
"""POST /api/v2/flow/dev/i_am_done forwards task_id and notes."""
|
||||
"""POST /api/v2/flow/developer/i_am_done forwards task_id and notes."""
|
||||
mock_chore = MagicMock()
|
||||
mock_chore.i_am_done = AsyncMock(
|
||||
return_value=_make_envelope(status="awaiting_qa", task_id=_TASK_ID)
|
||||
@@ -112,7 +92,7 @@ async def test_i_am_done_dispatches_task_and_notes() -> None:
|
||||
client = TestClient(_build_app(mock_chore))
|
||||
|
||||
resp = client.post(
|
||||
"/api/v2/flow/dev/i_am_done",
|
||||
"/api/v2/flow/developer/i_am_done",
|
||||
json={"task_id": _TASK_ID, "notes": "all tests pass"},
|
||||
headers=_HEADERS,
|
||||
)
|
||||
@@ -125,7 +105,7 @@ async def test_i_am_done_dispatches_task_and_notes() -> None:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_am_blocked_dispatches_reason() -> None:
|
||||
"""POST /api/v2/flow/dev/i_am_blocked forwards task_id and reason."""
|
||||
"""POST /api/v2/flow/developer/i_am_blocked forwards task_id and reason."""
|
||||
mock_chore = MagicMock()
|
||||
mock_chore.i_am_blocked = AsyncMock(
|
||||
return_value=_make_envelope(status="blocked", task_id=_TASK_ID)
|
||||
@@ -133,7 +113,7 @@ async def test_i_am_blocked_dispatches_reason() -> None:
|
||||
client = TestClient(_build_app(mock_chore))
|
||||
|
||||
resp = client.post(
|
||||
"/api/v2/flow/dev/i_am_blocked",
|
||||
"/api/v2/flow/developer/i_am_blocked",
|
||||
json={"task_id": _TASK_ID, "reason": "waiting for design spec"},
|
||||
headers=_HEADERS,
|
||||
)
|
||||
@@ -145,13 +125,13 @@ async def test_i_am_blocked_dispatches_reason() -> None:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_am_idle_dispatches_agent_id() -> None:
|
||||
"""POST /api/v2/flow/dev/i_am_idle delegates to Choreographer.i_am_idle."""
|
||||
"""POST /api/v2/flow/developer/i_am_idle delegates to Choreographer.i_am_idle."""
|
||||
mock_chore = MagicMock()
|
||||
mock_chore.i_am_idle = AsyncMock(return_value=_make_envelope(status="idle"))
|
||||
client = TestClient(_build_app(mock_chore))
|
||||
|
||||
resp = client.post(
|
||||
"/api/v2/flow/dev/i_am_idle",
|
||||
"/api/v2/flow/developer/i_am_idle",
|
||||
json={},
|
||||
headers=_HEADERS,
|
||||
)
|
||||
@@ -162,27 +142,13 @@ async def test_i_am_idle_dispatches_agent_id() -> None:
|
||||
mock_chore.i_am_idle.assert_awaited_once()
|
||||
|
||||
|
||||
def test_i_have_committed_rejects_empty_message() -> None:
|
||||
"""POST i_have_committed rejects empty message (min_length=1)."""
|
||||
mock_chore = MagicMock()
|
||||
client = TestClient(_build_app(mock_chore))
|
||||
|
||||
resp = client.post(
|
||||
"/api/v2/flow/dev/i_have_committed",
|
||||
json={"message": ""},
|
||||
headers=_HEADERS,
|
||||
)
|
||||
|
||||
assert resp.status_code == _HTTP_422
|
||||
|
||||
|
||||
def test_i_am_blocked_rejects_empty_reason() -> None:
|
||||
"""POST i_am_blocked rejects empty reason (min_length=1)."""
|
||||
mock_chore = MagicMock()
|
||||
client = TestClient(_build_app(mock_chore))
|
||||
|
||||
resp = client.post(
|
||||
"/api/v2/flow/dev/i_am_blocked",
|
||||
"/api/v2/flow/developer/i_am_blocked",
|
||||
json={"task_id": _TASK_ID, "reason": ""},
|
||||
headers=_HEADERS,
|
||||
)
|
||||
|
||||
@@ -27,6 +27,9 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import importlib
|
||||
import json
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from uuid import UUID
|
||||
@@ -95,7 +98,7 @@ def test_route_stamps_request_correlation_id_onto_envelope() -> None:
|
||||
app, _ = _build_app()
|
||||
client = TestClient(app)
|
||||
r = client.post(
|
||||
"/api/v2/flow/dev/give_me_work",
|
||||
"/api/v2/flow/developer/give_me_work",
|
||||
json={},
|
||||
headers={**_DEV_AGENT_HEADERS, "X-Correlation-ID": "trace-xyz"},
|
||||
)
|
||||
@@ -109,7 +112,7 @@ def test_route_stamps_generated_correlation_id_when_header_missing() -> None:
|
||||
app, _ = _build_app()
|
||||
client = TestClient(app)
|
||||
r = client.post(
|
||||
"/api/v2/flow/dev/give_me_work",
|
||||
"/api/v2/flow/developer/give_me_work",
|
||||
json={},
|
||||
headers=_DEV_AGENT_HEADERS,
|
||||
)
|
||||
@@ -132,10 +135,45 @@ def _reload_mcp_module(monkeypatch: pytest.MonkeyPatch, dotted: str) -> ModuleTy
|
||||
import; we have to re-import after monkey-patching so the test sees
|
||||
the patched values. The reload itself is the lazy import — keeping
|
||||
importlib at the top-level keeps PLC0415 happy.
|
||||
|
||||
Also writes a stub manifest file and points the MCP server at it,
|
||||
since both servers now refuse to register any tools without one
|
||||
(audit P0-5 / D-12).
|
||||
"""
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000001")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "developer")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
manifest_path = Path(tempfile.mkdtemp()) / "tool-manifest.json"
|
||||
manifest_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"agent_id": "00000000-0000-0000-0000-000000000001",
|
||||
"role": "developer",
|
||||
"team": "backend",
|
||||
"workspace_path": "/tmp/test",
|
||||
"flow_tools": [
|
||||
"give_me_work",
|
||||
"i_will_work_on",
|
||||
"submit_for_qa",
|
||||
"i_am_done",
|
||||
"i_am_blocked",
|
||||
"unclaim",
|
||||
"resume",
|
||||
"i_am_idle",
|
||||
],
|
||||
"do_tools": ["commit", "note", "say", "dm", "evidence"],
|
||||
"read_tools": [],
|
||||
"write_tools": [],
|
||||
"bash_allowed": True,
|
||||
"subagent_allowed": False,
|
||||
"subagent_model": None,
|
||||
"env": {},
|
||||
}
|
||||
)
|
||||
)
|
||||
monkeypatch.setenv("ROBOCO_TOOL_MANIFEST_PATH", str(manifest_path))
|
||||
|
||||
module = importlib.import_module(dotted)
|
||||
return importlib.reload(module)
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ def _build_app() -> FastAPI:
|
||||
def test_dev_route_rejects_qa_role() -> None:
|
||||
client = TestClient(_build_app())
|
||||
r = client.post(
|
||||
"/api/v2/flow/dev/give_me_work",
|
||||
"/api/v2/flow/developer/give_me_work",
|
||||
json={},
|
||||
headers={
|
||||
"X-Agent-ID": "00000000-0000-0000-0000-000000000001",
|
||||
@@ -48,7 +48,7 @@ def test_dev_route_rejects_qa_role() -> None:
|
||||
def test_dev_route_accepts_developer_role() -> None:
|
||||
client = TestClient(_build_app())
|
||||
r = client.post(
|
||||
"/api/v2/flow/dev/give_me_work",
|
||||
"/api/v2/flow/developer/give_me_work",
|
||||
json={},
|
||||
headers={
|
||||
"X-Agent-ID": "00000000-0000-0000-0000-000000000001",
|
||||
@@ -62,7 +62,7 @@ def test_dev_route_accepts_developer_role() -> None:
|
||||
def test_dev_route_accepts_developer_role_case_insensitive() -> None:
|
||||
client = TestClient(_build_app())
|
||||
r = client.post(
|
||||
"/api/v2/flow/dev/give_me_work",
|
||||
"/api/v2/flow/developer/give_me_work",
|
||||
json={},
|
||||
headers={
|
||||
"X-Agent-ID": "00000000-0000-0000-0000-000000000001",
|
||||
@@ -75,7 +75,7 @@ def test_dev_route_accepts_developer_role_case_insensitive() -> None:
|
||||
def test_dev_route_rejects_missing_role_header() -> None:
|
||||
client = TestClient(_build_app())
|
||||
r = client.post(
|
||||
"/api/v2/flow/dev/give_me_work",
|
||||
"/api/v2/flow/developer/give_me_work",
|
||||
json={},
|
||||
headers={"X-Agent-ID": "00000000-0000-0000-0000-000000000001"},
|
||||
)
|
||||
|
||||
@@ -96,64 +96,6 @@ async def test_pm_cannot_execute_code_writes_audit_row() -> None:
|
||||
assert args.kwargs["details"]["reason"] == "not_authorized"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# tracing_gap path: i_have_committed with no plan
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_have_committed_missing_plan_writes_audit_row() -> None:
|
||||
"""Tracing-gap rejection (missing plan) should also be audited."""
|
||||
aid = uuid4()
|
||||
tid = uuid4()
|
||||
task_with_no_plan = MagicMock(
|
||||
id=tid,
|
||||
status="in_progress",
|
||||
assigned_to=aid,
|
||||
plan=None,
|
||||
)
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get_active_task_for_agent.return_value = task_with_no_plan
|
||||
audit_svc = AsyncMock()
|
||||
deps = _make_deps(task=task_svc, audit=audit_svc)
|
||||
c = Choreographer(deps)
|
||||
|
||||
env = await c.i_have_committed(aid, "wip")
|
||||
|
||||
assert env.error == "tracing_gap"
|
||||
audit_svc.log_event.assert_awaited()
|
||||
args = audit_svc.log_event.await_args
|
||||
assert args.kwargs["event_type"] == "gateway.rejected"
|
||||
assert args.kwargs["details"]["verb"] == "i_have_committed"
|
||||
assert args.kwargs["details"]["reason"] == "tracing_gap"
|
||||
assert "plan" in args.kwargs["details"]["missing"]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# invalid_state path: i_have_committed with no active task
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_have_committed_no_active_task_writes_audit_row() -> None:
|
||||
"""invalid_state rejection (no active task) is audited."""
|
||||
aid = uuid4()
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get_active_task_for_agent.return_value = None
|
||||
audit_svc = AsyncMock()
|
||||
deps = _make_deps(task=task_svc, audit=audit_svc)
|
||||
c = Choreographer(deps)
|
||||
|
||||
env = await c.i_have_committed(aid, "wip")
|
||||
|
||||
assert env.error == "invalid_state"
|
||||
audit_svc.log_event.assert_awaited()
|
||||
args = audit_svc.log_event.await_args
|
||||
assert args.kwargs["event_type"] == "gateway.rejected"
|
||||
assert args.kwargs["details"]["verb"] == "i_have_committed"
|
||||
assert args.kwargs["details"]["reason"] == "invalid_state"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# not_found path: unknown task id
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -212,15 +154,17 @@ async def test_successful_verb_does_not_write_audit_row() -> None:
|
||||
async def test_audit_log_event_failure_does_not_propagate() -> None:
|
||||
"""If log_event raises, the verb still returns the rejection envelope."""
|
||||
aid = uuid4()
|
||||
tid = uuid4()
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get_active_task_for_agent.return_value = None
|
||||
# Unknown task id triggers not_found rejection on i_am_done.
|
||||
task_svc.get.return_value = None
|
||||
audit_svc = AsyncMock()
|
||||
audit_svc.log_event.side_effect = RuntimeError("audit DB down")
|
||||
deps = _make_deps(task=task_svc, audit=audit_svc)
|
||||
c = Choreographer(deps)
|
||||
|
||||
# Must not raise; the rejection envelope should still come back.
|
||||
env = await c.i_have_committed(aid, "wip")
|
||||
env = await c.i_am_done(aid, tid, notes="x")
|
||||
|
||||
assert env.error == "invalid_state"
|
||||
assert env.error == "not_found"
|
||||
audit_svc.log_event.assert_awaited()
|
||||
|
||||
@@ -210,189 +210,9 @@ async def test_i_will_work_on_invalid_state_returns_invalid_state() -> None:
|
||||
assert "completed" in body["message"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_have_committed_records_progress() -> None:
|
||||
agent_id = uuid4()
|
||||
task_id = uuid4()
|
||||
active = MagicMock(
|
||||
id=task_id, status="in_progress", assigned_to=agent_id, plan={"x": 1}
|
||||
)
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get_active_task_for_agent.return_value = active
|
||||
deps = _make_deps(task=task_svc)
|
||||
c = Choreographer(deps)
|
||||
|
||||
env = await c.i_have_committed(agent_id, "feat(api): add /healthz endpoint")
|
||||
assert env.error is None
|
||||
task_svc.add_progress.assert_awaited_once_with(
|
||||
task_id, agent_id, "feat(api): add /healthz endpoint"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_have_committed_no_active_task_returns_invalid_state() -> None:
|
||||
agent_id = uuid4()
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get_active_task_for_agent.return_value = None
|
||||
deps = _make_deps(task=task_svc)
|
||||
c = Choreographer(deps)
|
||||
|
||||
env = await c.i_have_committed(agent_id, "feat: x")
|
||||
body = env.as_dict()
|
||||
assert body["error"] == "invalid_state"
|
||||
assert "give_me_work" in body["remediate"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_have_committed_no_plan_returns_tracing_gap() -> None:
|
||||
agent_id = uuid4()
|
||||
task_id = uuid4()
|
||||
active = MagicMock(
|
||||
id=task_id, status="in_progress", assigned_to=agent_id, plan=None
|
||||
)
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get_active_task_for_agent.return_value = active
|
||||
deps = _make_deps(task=task_svc)
|
||||
c = Choreographer(deps)
|
||||
|
||||
env = await c.i_have_committed(agent_id, "feat: x")
|
||||
body = env.as_dict()
|
||||
assert body["error"] == "tracing_gap"
|
||||
assert "plan" in body["missing"]
|
||||
task_svc.add_progress.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_am_done_with_catchup_full_chain() -> None:
|
||||
"""The catch-up convenience verb auto-runs verify/push/PR/submit_qa.
|
||||
|
||||
Strict ``i_am_done`` requires the dev to have done these steps already
|
||||
(Gate Set E). When the dev wants the gateway to drive the chain, they
|
||||
call the explicit catch-up verb.
|
||||
"""
|
||||
agent_id = uuid4()
|
||||
task_id = uuid4()
|
||||
branch = "feature/backend/abc--def"
|
||||
ws_id = uuid4()
|
||||
initial = MagicMock(
|
||||
id=task_id,
|
||||
status="in_progress",
|
||||
assigned_to=agent_id,
|
||||
plan={"x": 1},
|
||||
branch_name=branch,
|
||||
work_session_id=ws_id,
|
||||
self_verified=False,
|
||||
pr_number=None,
|
||||
pr_url=None,
|
||||
team="backend",
|
||||
progress_updates=[{"message": "did x"}],
|
||||
acceptance_criteria=["AC1"],
|
||||
acceptance_criteria_status=[
|
||||
{"criterion": "AC1", "referencing_artifact_id": "c1"}
|
||||
],
|
||||
commits=[],
|
||||
documents=[],
|
||||
dev_notes="",
|
||||
)
|
||||
after_verify = MagicMock(
|
||||
id=task_id,
|
||||
status="verifying",
|
||||
assigned_to=agent_id,
|
||||
plan={"x": 1},
|
||||
branch_name=branch,
|
||||
work_session_id=ws_id,
|
||||
self_verified=True,
|
||||
pr_number=None,
|
||||
pr_url=None,
|
||||
team="backend",
|
||||
progress_updates=[{"message": "did x"}],
|
||||
acceptance_criteria=["AC1"],
|
||||
acceptance_criteria_status=[
|
||||
{"criterion": "AC1", "referencing_artifact_id": "c1"}
|
||||
],
|
||||
commits=[],
|
||||
documents=[],
|
||||
dev_notes="",
|
||||
)
|
||||
after_pr = MagicMock(
|
||||
id=task_id,
|
||||
status="verifying",
|
||||
assigned_to=agent_id,
|
||||
plan={"x": 1},
|
||||
branch_name=branch,
|
||||
work_session_id=ws_id,
|
||||
self_verified=True,
|
||||
pr_number=8,
|
||||
pr_url="https://x/pr/8",
|
||||
team="backend",
|
||||
progress_updates=[{"message": "did x"}],
|
||||
acceptance_criteria=["AC1"],
|
||||
acceptance_criteria_status=[
|
||||
{"criterion": "AC1", "referencing_artifact_id": "c1"}
|
||||
],
|
||||
commits=[],
|
||||
documents=[],
|
||||
dev_notes="",
|
||||
)
|
||||
after_submit = MagicMock(
|
||||
id=task_id,
|
||||
status="awaiting_qa",
|
||||
assigned_to=agent_id,
|
||||
plan={"x": 1},
|
||||
branch_name=branch,
|
||||
work_session_id=ws_id,
|
||||
self_verified=True,
|
||||
pr_number=8,
|
||||
pr_url="https://x/pr/8",
|
||||
team="backend",
|
||||
progress_updates=[{"message": "did x"}],
|
||||
acceptance_criteria=["AC1"],
|
||||
acceptance_criteria_status=[
|
||||
{"criterion": "AC1", "referencing_artifact_id": "c1"}
|
||||
],
|
||||
commits=[],
|
||||
documents=[],
|
||||
dev_notes="",
|
||||
)
|
||||
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get.side_effect = [initial, after_pr] # initial fetch + post-PR refresh
|
||||
task_svc.submit_verification.return_value = after_verify
|
||||
task_svc.submit_qa.return_value = after_submit
|
||||
task_svc.qa_agent_for_team.return_value = MagicMock(
|
||||
id=uuid4(), skills=[{"id": "code_review"}]
|
||||
)
|
||||
|
||||
work_svc = AsyncMock()
|
||||
work_svc.has_unpushed_commits.return_value = True
|
||||
work_svc.files_changed.return_value = ["README.md"]
|
||||
|
||||
git_svc = AsyncMock()
|
||||
git_svc.create_pr.return_value = {"pr_number": 8, "pr_url": "https://x/pr/8"}
|
||||
|
||||
a2a_svc = AsyncMock()
|
||||
|
||||
journal_svc = AsyncMock()
|
||||
journal_svc.has_reflect_for_task.return_value = True
|
||||
|
||||
deps = _make_deps(
|
||||
task=task_svc,
|
||||
work_session=work_svc,
|
||||
git=git_svc,
|
||||
a2a=a2a_svc,
|
||||
journal=journal_svc,
|
||||
)
|
||||
deps.evidence_repo.journal_highlights_for_task.return_value = []
|
||||
c = Choreographer(deps)
|
||||
|
||||
env = await c.i_am_done_with_catchup(agent_id, task_id, "all done")
|
||||
assert env.error is None
|
||||
assert env.status == "awaiting_qa"
|
||||
git_svc.push_branch.assert_awaited_once_with(branch)
|
||||
git_svc.create_pr.assert_awaited_once()
|
||||
a2a_svc.send.assert_awaited_once()
|
||||
body = env.as_dict()
|
||||
assert body["evidence"]["pr_url"] == "https://x/pr/8"
|
||||
# test_i_am_done_with_catchup_full_chain removed (audit P2-5/D-16):
|
||||
# i_am_done_with_catchup verb deleted. submit_for_qa now does push + PR
|
||||
# explicitly; i_am_done auto-runs submit_verification + submit_qa.
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -78,28 +78,44 @@ def _ready_task(task_id: Any, agent_id: Any) -> MagicMock:
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# E.1 NOT_SELF_VERIFIED
|
||||
# E.1 self_verified is no longer a gate (audit P1-3/D-08)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_am_done_blocks_when_not_self_verified() -> None:
|
||||
async def test_i_am_done_auto_runs_submit_verification_when_in_progress() -> None:
|
||||
"""Strict i_am_done auto-runs submit_verification (in_progress→verifying)
|
||||
so the dev doesn't need a separate verb. The previous NOT_SELF_VERIFIED
|
||||
gate required submit_for_verification which wasn't on any manifest.
|
||||
"""
|
||||
agent_id = uuid4()
|
||||
task_id = uuid4()
|
||||
t = _ready_task(task_id, agent_id)
|
||||
t.self_verified = False
|
||||
t.status = "in_progress"
|
||||
after_verify = MagicMock(
|
||||
**{**t.__dict__, "self_verified": True, "status": "verifying"}
|
||||
)
|
||||
after_submit = MagicMock(**{**after_verify.__dict__, "status": "awaiting_qa"})
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get.return_value = t
|
||||
task_svc.submit_verification.return_value = after_verify
|
||||
task_svc.submit_qa.return_value = after_submit
|
||||
task_svc.qa_agent_for_team.return_value = MagicMock(
|
||||
id=uuid4(), skills=[{"id": "code_review"}]
|
||||
)
|
||||
journal_svc = AsyncMock()
|
||||
journal_svc.has_reflect_for_task.return_value = True
|
||||
deps = _make_deps(task=task_svc, journal=journal_svc)
|
||||
work_svc = AsyncMock()
|
||||
work_svc.files_changed.return_value = ["foo.py"]
|
||||
deps = _make_deps(task=task_svc, journal=journal_svc, work_session=work_svc)
|
||||
c = Choreographer(deps)
|
||||
|
||||
env = await c.i_am_done(agent_id, task_id, "done")
|
||||
body = env.as_dict()
|
||||
assert body["error"] == "tracing_gap"
|
||||
assert "NOT_SELF_VERIFIED" in body["missing"] or "self_verified" in body["missing"]
|
||||
task_svc.submit_qa.assert_not_awaited()
|
||||
assert body["error"] is None
|
||||
task_svc.submit_verification.assert_awaited_once()
|
||||
task_svc.submit_qa.assert_awaited_once()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -188,6 +204,11 @@ async def test_i_am_done_proceeds_when_all_gates_pass() -> None:
|
||||
agent_id = uuid4()
|
||||
task_id = uuid4()
|
||||
t = _ready_task(task_id, agent_id)
|
||||
# Pre-verifying state (caller already ran submit_for_verification or
|
||||
# task is already in `verifying`). i_am_done skips the auto-verify
|
||||
# step and goes straight to submit_qa.
|
||||
t.status = "verifying"
|
||||
t.self_verified = True
|
||||
after_submit = MagicMock(
|
||||
**{**t.__dict__, "status": "awaiting_qa"},
|
||||
)
|
||||
@@ -209,61 +230,17 @@ async def test_i_am_done_proceeds_when_all_gates_pass() -> None:
|
||||
assert body["error"] is None
|
||||
assert body["status"] == "awaiting_qa"
|
||||
task_svc.submit_qa.assert_awaited_once()
|
||||
# Strict path must NOT call submit_verification, push, or create_pr —
|
||||
# those are catch-up side effects which are now opt-in only.
|
||||
# Already-verifying status: no auto-call to submit_verification.
|
||||
task_svc.submit_verification.assert_not_awaited()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# E.6 i_am_done_with_catchup retains the smart-catch-up convenience.
|
||||
# E.6 — Removed: i_am_done_with_catchup verb deleted (audit P2-5/D-16).
|
||||
# Its functionality is now split between submit_for_qa (push + PR) and
|
||||
# i_am_done (auto-run submit_verification then submit_qa).
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_am_done_with_catchup_runs_full_chain() -> None:
|
||||
agent_id = uuid4()
|
||||
task_id = uuid4()
|
||||
initial = _ready_task(task_id, agent_id)
|
||||
initial.self_verified = False
|
||||
initial.pr_number = None
|
||||
after_verify = MagicMock(
|
||||
**{**initial.__dict__, "self_verified": True, "status": "verifying"}
|
||||
)
|
||||
after_pr_refresh = MagicMock(
|
||||
**{**after_verify.__dict__, "pr_number": 8, "pr_url": "https://x/pr/8"}
|
||||
)
|
||||
after_submit = MagicMock(**{**after_pr_refresh.__dict__, "status": "awaiting_qa"})
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get.side_effect = [initial, after_pr_refresh]
|
||||
task_svc.submit_verification.return_value = after_verify
|
||||
task_svc.submit_qa.return_value = after_submit
|
||||
task_svc.qa_agent_for_team.return_value = MagicMock(
|
||||
id=uuid4(), skills=[{"id": "code_review"}]
|
||||
)
|
||||
work_svc = AsyncMock()
|
||||
work_svc.has_unpushed_commits.return_value = True
|
||||
work_svc.files_changed.return_value = ["foo.py"]
|
||||
git_svc = AsyncMock()
|
||||
git_svc.create_pr.return_value = {"pr_number": 8, "pr_url": "https://x/pr/8"}
|
||||
journal_svc = AsyncMock()
|
||||
journal_svc.has_reflect_for_task.return_value = True
|
||||
deps = _make_deps(
|
||||
task=task_svc,
|
||||
journal=journal_svc,
|
||||
work_session=work_svc,
|
||||
git=git_svc,
|
||||
)
|
||||
c = Choreographer(deps)
|
||||
|
||||
env = await c.i_am_done_with_catchup(agent_id, task_id, "all done")
|
||||
body = env.as_dict()
|
||||
assert body["error"] is None
|
||||
assert body["status"] == "awaiting_qa"
|
||||
task_svc.submit_verification.assert_awaited_once()
|
||||
git_svc.push_branch.assert_awaited_once()
|
||||
git_svc.create_pr.assert_awaited_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_am_done_blocks_unauthorized() -> None:
|
||||
"""Existing not_authorized check still applies."""
|
||||
|
||||
@@ -24,7 +24,6 @@ def _make_deps(**overrides: AsyncMock) -> ContentActionsDeps:
|
||||
task.get_active_task_for_agent.return_value = None
|
||||
|
||||
# commit() now checks caller role; default to developer.
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
task.agent_for.return_value = MagicMock(role="developer")
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ def _make_deps(**overrides: AsyncMock) -> ContentActionsDeps:
|
||||
# commit() checks caller role server-side; default-created mocks
|
||||
# need a default developer role so existing tests pass through.
|
||||
# Caller-supplied mocks must set agent_for themselves.
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
task.agent_for.return_value = MagicMock(role="developer")
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ def _make_deps(**overrides: AsyncMock) -> ContentActionsDeps:
|
||||
task.get_active_task_for_agent.return_value = None
|
||||
|
||||
# commit() now checks caller role; default to developer.
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
task.agent_for.return_value = MagicMock(role="developer")
|
||||
|
||||
|
||||
@@ -74,21 +74,6 @@ async def test_i_will_work_on_calls_heartbeat() -> None:
|
||||
task_svc.heartbeat.assert_awaited_with(tid)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_have_committed_calls_heartbeat() -> None:
|
||||
aid = uuid4()
|
||||
tid = uuid4()
|
||||
t = MagicMock(id=tid, status="in_progress", assigned_to=aid, plan="x")
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get_active_task_for_agent.return_value = t
|
||||
deps = _make_deps(task=task_svc)
|
||||
c = Choreographer(deps)
|
||||
|
||||
await c.i_have_committed(aid, "did the thing")
|
||||
|
||||
task_svc.heartbeat.assert_awaited_with(tid)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_i_am_done_calls_heartbeat() -> None:
|
||||
aid = uuid4()
|
||||
|
||||
@@ -2,16 +2,40 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
# Same pattern as test_flow_server: do_server now refuses to start without
|
||||
# a manifest (audit P0-5 / D-12). The test fixture writes a stub manifest
|
||||
# with the full do-tool superset; production manifests are role-scoped.
|
||||
_DO_TEST_MANIFEST = {
|
||||
"agent_id": "00000000-0000-0000-0000-000000000001",
|
||||
"role": "developer",
|
||||
"team": "backend",
|
||||
"workspace_path": "/tmp/test",
|
||||
"flow_tools": [],
|
||||
"do_tools": ["commit", "note", "say", "dm", "notify", "evidence"],
|
||||
"read_tools": [],
|
||||
"write_tools": [],
|
||||
"bash_allowed": True,
|
||||
"subagent_allowed": False,
|
||||
"subagent_model": None,
|
||||
"env": {},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def do_module(monkeypatch): # type: ignore[no-untyped-def]
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000001")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "developer")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
manifest_path = Path(tempfile.mkdtemp()) / "tool-manifest.json"
|
||||
manifest_path.write_text(json.dumps(_DO_TEST_MANIFEST))
|
||||
monkeypatch.setenv("ROBOCO_TOOL_MANIFEST_PATH", str(manifest_path))
|
||||
import importlib
|
||||
|
||||
import roboco.mcp.do_server as srv
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import json
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
@@ -10,14 +11,60 @@ import pytest
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
_FULL_MANIFEST = {
|
||||
"agent_id": "00000000-0000-0000-0000-000000000001",
|
||||
"role": "developer",
|
||||
"team": "backend",
|
||||
"workspace_path": "/tmp/test",
|
||||
# Test fixture provides every flow verb so per-verb URL/path tests work
|
||||
# against a single fixture. Production manifests are role-scoped.
|
||||
"flow_tools": [
|
||||
"give_me_work",
|
||||
"i_will_work_on",
|
||||
"submit_for_qa",
|
||||
"i_am_done",
|
||||
"i_am_blocked",
|
||||
"unclaim",
|
||||
"resume",
|
||||
"i_am_idle",
|
||||
"claim_review",
|
||||
"pass",
|
||||
"fail",
|
||||
"claim_doc_task",
|
||||
"i_documented",
|
||||
"triage",
|
||||
"triage_all",
|
||||
"unblock",
|
||||
"complete",
|
||||
"escalate_up",
|
||||
"i_will_plan",
|
||||
"delegate",
|
||||
"submit_up",
|
||||
"escalate_to_ceo",
|
||||
],
|
||||
"do_tools": ["commit", "note", "say", "dm", "evidence"],
|
||||
"read_tools": ["Read", "Glob", "Grep"],
|
||||
"write_tools": ["Edit", "Write"],
|
||||
"bash_allowed": True,
|
||||
"subagent_allowed": False,
|
||||
"subagent_model": None,
|
||||
"env": {},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def flow_module(monkeypatch: pytest.MonkeyPatch) -> types.ModuleType:
|
||||
"""Import the flow_server module with controlled env vars."""
|
||||
def flow_module(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> types.ModuleType:
|
||||
"""Import the flow_server module with controlled env vars + manifest."""
|
||||
manifest_path = tmp_path / "tool-manifest.json"
|
||||
manifest_path.write_text(json.dumps(_FULL_MANIFEST))
|
||||
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000001")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "developer")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
monkeypatch.setenv("ROBOCO_TOOL_MANIFEST_PATH", str(manifest_path))
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
@@ -36,6 +83,33 @@ def _make_fake_client(return_value: dict[str, Any]) -> MagicMock:
|
||||
return fake_client
|
||||
|
||||
|
||||
def _reload_for_role(
|
||||
monkeypatch: pytest.MonkeyPatch, role: str, agent_id: str
|
||||
) -> types.ModuleType:
|
||||
"""Set env + write manifest for the given role; reload flow_server.
|
||||
|
||||
The manifest provides the full verb superset so role-specific tests
|
||||
aren't blocked by the manifest filter; the role-scoped URL routing
|
||||
is what's under test in these per-role cases.
|
||||
"""
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
manifest_path = Path(tempfile.mkdtemp()) / "tool-manifest.json"
|
||||
payload = {**_FULL_MANIFEST, "role": role, "agent_id": agent_id}
|
||||
manifest_path.write_text(json.dumps(payload))
|
||||
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", agent_id)
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", role)
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
monkeypatch.setenv("ROBOCO_TOOL_MANIFEST_PATH", str(manifest_path))
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
return srv
|
||||
|
||||
|
||||
def test_role_path_uses_agent_role(flow_module: types.ModuleType) -> None:
|
||||
expected = "/api/v2/flow/developer/give_me_work"
|
||||
assert flow_module._role_path("give_me_work") == expected
|
||||
@@ -80,17 +154,6 @@ def test_i_will_work_on_plan_defaults_to_none(flow_module: types.ModuleType) ->
|
||||
assert kwargs["json"] == {"task_id": "task-uuid", "plan": None}
|
||||
|
||||
|
||||
def test_i_have_committed_sends_message(flow_module: types.ModuleType) -> None:
|
||||
fake_client = _make_fake_client({"status": "recorded"})
|
||||
|
||||
with patch("httpx.Client", return_value=fake_client):
|
||||
result = flow_module.i_have_committed("fix: typo in handler")
|
||||
|
||||
assert result == {"status": "recorded"}
|
||||
_, kwargs = fake_client.post.call_args
|
||||
assert kwargs["json"] == {"message": "fix: typo in handler"}
|
||||
|
||||
|
||||
def test_i_am_done_sends_task_id_and_notes(flow_module: types.ModuleType) -> None:
|
||||
fake_client = _make_fake_client({"status": "awaiting_qa"})
|
||||
|
||||
@@ -138,13 +201,7 @@ def test_i_am_idle_posts_empty_body(flow_module: types.ModuleType) -> None:
|
||||
|
||||
def test_claim_review_posts_to_qa_path(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When AGENT_ROLE=qa, claim_review forwards to /api/v2/flow/qa/claim_review."""
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000002")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "qa")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(monkeypatch, "qa", "00000000-0000-0000-0000-000000000002")
|
||||
|
||||
fake_client = _make_fake_client({"status": "claimed", "evidence": {}})
|
||||
|
||||
@@ -158,13 +215,7 @@ def test_claim_review_posts_to_qa_path(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def test_pass_review_passes_notes(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000002")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "qa")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(monkeypatch, "qa", "00000000-0000-0000-0000-000000000002")
|
||||
|
||||
fake_client = _make_fake_client({"status": "awaiting_documentation"})
|
||||
|
||||
@@ -178,13 +229,7 @@ def test_pass_review_passes_notes(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def test_fail_review_passes_issues_list(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000002")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "qa")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(monkeypatch, "qa", "00000000-0000-0000-0000-000000000002")
|
||||
|
||||
fake_client = _make_fake_client({"status": "needs_revision"})
|
||||
|
||||
@@ -201,13 +246,9 @@ def test_claim_doc_task_posts_to_documenter_path(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""When AGENT_ROLE=documenter, claim_doc_task forwards to documenter flow."""
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000003")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "documenter")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(
|
||||
monkeypatch, "documenter", "00000000-0000-0000-0000-000000000003"
|
||||
)
|
||||
|
||||
fake_client = _make_fake_client({"status": "claimed"})
|
||||
|
||||
@@ -221,13 +262,9 @@ def test_claim_doc_task_posts_to_documenter_path(
|
||||
|
||||
|
||||
def test_i_documented_passes_notes_and_files(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000003")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "documenter")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(
|
||||
monkeypatch, "documenter", "00000000-0000-0000-0000-000000000003"
|
||||
)
|
||||
|
||||
fake_client = _make_fake_client({"status": "awaiting_pm_review"})
|
||||
|
||||
@@ -245,13 +282,9 @@ def test_i_documented_passes_notes_and_files(monkeypatch: pytest.MonkeyPatch) ->
|
||||
|
||||
|
||||
def test_triage_uses_role_path(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000004")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "cell_pm")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(
|
||||
monkeypatch, "cell_pm", "00000000-0000-0000-0000-000000000004"
|
||||
)
|
||||
|
||||
fake_client = _make_fake_client({"status": "blocked"})
|
||||
|
||||
@@ -265,13 +298,9 @@ def test_triage_uses_role_path(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def test_triage_all_uses_role_path(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000005")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "main_pm")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(
|
||||
monkeypatch, "main_pm", "00000000-0000-0000-0000-000000000005"
|
||||
)
|
||||
|
||||
fake_client = _make_fake_client({"status": "idle"})
|
||||
|
||||
@@ -285,13 +314,9 @@ def test_triage_all_uses_role_path(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def test_unblock_with_restore_true(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000004")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "cell_pm")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(
|
||||
monkeypatch, "cell_pm", "00000000-0000-0000-0000-000000000004"
|
||||
)
|
||||
|
||||
fake_client = _make_fake_client({"status": "in_progress"})
|
||||
|
||||
@@ -305,13 +330,9 @@ def test_unblock_with_restore_true(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def test_unblock_with_restore_false(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000004")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "cell_pm")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(
|
||||
monkeypatch, "cell_pm", "00000000-0000-0000-0000-000000000004"
|
||||
)
|
||||
|
||||
fake_client = _make_fake_client({"status": "in_progress"})
|
||||
|
||||
@@ -324,13 +345,9 @@ def test_unblock_with_restore_false(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def test_complete_passes_notes(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000004")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "cell_pm")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(
|
||||
monkeypatch, "cell_pm", "00000000-0000-0000-0000-000000000004"
|
||||
)
|
||||
|
||||
fake_client = _make_fake_client({"status": "completed"})
|
||||
|
||||
@@ -344,13 +361,9 @@ def test_complete_passes_notes(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def test_escalate_up_passes_reason(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000004")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "cell_pm")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(
|
||||
monkeypatch, "cell_pm", "00000000-0000-0000-0000-000000000004"
|
||||
)
|
||||
|
||||
fake_client = _make_fake_client({"status": "blocked"})
|
||||
|
||||
@@ -368,13 +381,9 @@ def test_escalate_up_passes_reason(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
def test_escalate_to_ceo_passes_reason(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Board / Main PM verb forwards to /api/v2/flow/<role>/escalate_to_ceo."""
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ID", "00000000-0000-0000-0000-000000000005")
|
||||
monkeypatch.setenv("ROBOCO_AGENT_ROLE", "product_owner")
|
||||
monkeypatch.setenv("ROBOCO_ORCHESTRATOR_URL", "http://test-orchestrator:8000")
|
||||
|
||||
import roboco.mcp.flow_server as srv
|
||||
|
||||
importlib.reload(srv)
|
||||
srv = _reload_for_role(
|
||||
monkeypatch, "product_owner", "00000000-0000-0000-0000-000000000005"
|
||||
)
|
||||
|
||||
fake_client = _make_fake_client({"status": "awaiting_ceo_approval"})
|
||||
|
||||
@@ -383,7 +392,9 @@ def test_escalate_to_ceo_passes_reason(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
assert result["status"] == "awaiting_ceo_approval"
|
||||
args, kwargs = fake_client.post.call_args
|
||||
assert "/api/v2/flow/product_owner/escalate_to_ceo" in args[0]
|
||||
# Board route serves PO + Head Marketing under one prefix; the slug
|
||||
# map in flow_server translates product_owner → board.
|
||||
assert "/api/v2/flow/board/escalate_to_ceo" in args[0]
|
||||
assert kwargs["json"] == {
|
||||
"task_id": "task-uuid",
|
||||
"reason": "strategic decision needed",
|
||||
|
||||
@@ -42,7 +42,7 @@ def test_blocks_internal_curl_to_orchestrator() -> None:
|
||||
|
||||
|
||||
def test_blocks_internal_curl_to_localhost() -> None:
|
||||
assert _run("curl http://localhost:8000/api/v2/flow/dev/i_am_done") == _DENIED
|
||||
assert _run("curl http://localhost:8000/api/v2/flow/developer/i_am_done") == _DENIED
|
||||
|
||||
|
||||
def test_blocks_internal_curl_to_127() -> None:
|
||||
|
||||
@@ -442,27 +442,34 @@ async def test_doc_claim_sets_assignment_on_awaiting_documentation() -> None:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_qa_pass_delegates_to_pass_qa() -> None:
|
||||
svc = TaskService(MagicMock())
|
||||
pass_qa_mock = AsyncMock(return_value=MagicMock())
|
||||
_bind(svc, "pass_qa", pass_qa_mock)
|
||||
qa_id = uuid4()
|
||||
task_id = uuid4()
|
||||
await svc.qa_pass(uuid4(), task_id, "looks good")
|
||||
task = _build_task(id=task_id, claimed_by=qa_id)
|
||||
svc = TaskService(MagicMock(flush=AsyncMock()))
|
||||
pass_qa_mock = AsyncMock(return_value=MagicMock())
|
||||
_bind(svc, "get", AsyncMock(return_value=task))
|
||||
_bind(svc, "pass_qa", pass_qa_mock)
|
||||
await svc.qa_pass(qa_id, task_id, "looks good")
|
||||
pass_qa_mock.assert_awaited_once_with(task_id, notes="looks good", agent_role="qa")
|
||||
# active_claimant_id cleared so the documenter can claim cleanly.
|
||||
assert task.active_claimant_id is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_qa_fail_appends_issues_to_dev_notes() -> None:
|
||||
task = _build_task(dev_notes=None)
|
||||
qa_id = uuid4()
|
||||
task = _build_task(dev_notes=None, claimed_by=qa_id)
|
||||
svc = TaskService(MagicMock(flush=AsyncMock()))
|
||||
fail_qa_mock = AsyncMock(return_value=task)
|
||||
_bind(svc, "get", AsyncMock(return_value=task))
|
||||
_bind(svc, "fail_qa", fail_qa_mock)
|
||||
issues = ["missing test", "no docstring"]
|
||||
await svc.qa_fail(uuid4(), task.id, "blocking", issues)
|
||||
await svc.qa_fail(qa_id, task.id, "blocking", issues)
|
||||
assert task.dev_notes is not None
|
||||
assert "missing test" in task.dev_notes
|
||||
assert "no docstring" in task.dev_notes
|
||||
fail_qa_mock.assert_awaited_once_with(task.id, notes="blocking", agent_role="qa")
|
||||
assert task.active_claimant_id is None
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user