Leak fixes, gate green again, uv/CI hardening, e2e lifecycle smoke harness (#294)

* test: align phase1 smoke mock with the armed team-match gate

The 8e5f84c4 sweep fixed 13 test files' inconsistent-team mocks but ran
only the gateway/foundation/runtime subsets; the full gate caught this
integration mock whose parent task carried an auto-generated MagicMock
team and died on not_authorized before the incomplete_input assertion.

* fix(runtime): attribute every agent.spawned audit to its dispatcher

A rogue spawner could not be identified live (2026-07-02): agent.spawned
rows carry container/model but not which dispatch loop launched them.
spawn_agent now takes spawned_by, stamps it into the spawned/spawn_failed
audit details, every call site passes its loop name, and an AST sweep
test holds future callers to it.

* fix(api): admin-complete refuses when the task's PR is still open

PATCH status=completed on a task with an OPEN PR stranded its commits
unmerged (bit the CEO twice live 2026-07-02). The override now refuses
with the PR number/URL and the consequence before the generic hatch
text; force:true stays the deliberate, audited escape.

* fix(panel): awaiting_ceo_approval offers the working ceo-approve path

The header's only approve action was Approve & Merge (POST
/approve-and-merge, no notes) which 400s NO_PR on a branchless MegaTask
umbrella — the CEO's approve button just failed. Primary action is now
Approve & Complete via the CeoApproveDialog (POST /ceo-approve, notes
>=20 chars, proven live); Approve & Merge stays for PR-bearing tasks.

* test: stop leaking self-heal + rate-limit state into live Redis

Two test files wrote real keys into a developer's localhost Redis:
self-heal originate tests left self_heal:notified:* (2h TTL) and the
i_am_blocked rate-limited tests left a NO-TTL 'anthropic rate-limited'
tracker blob — order/state-dependent poison for anything reading the
real tracker, and the prime suspect class for the one-off
test_self_heal_engine full-run failure (not reproduced in 5x dir runs,
adversarial orders, and a green full gate). Both files now point the
computed redis_url at an unreachable port; the engines' fail-open paths
keep every assertion intact. Leaked keys scrubbed live.

* docs: changelog + map delta for the leak-fix batch; mypy-clean attribution test

The attribution test's direct method assignments tripped the full gate's
mypy (method-assign) — switched to the house monkeypatch idiom, no
suppressions.

* fix(gate): clear the ten xenon C-ranks; isolate all tests from live Redis

Master CI has been red at the phase1 smoke test, so neither CI nor a
local full gate had reached the xenon step since the team-match sweep —
whose inline 'agent_team=str(agent.team) if ...' kwarg pushed nine verb
bodies from B(10) to C(11-12) unseen. A shared actor_context_fields()
(_protocol.py) computes (actor_slug, agent_team) once per verb, restoring
all nine to B with zero behavior change; the new admin-complete override
helper extraction does the same for routes/tasks.py.

tests/conftest.py gains an autouse fixture pointing the computed
redis_url at an unreachable port for every test — the root fix for the
three families caught writing live-Redis keys (self-heal dedupe,
rate-limit tracker, notification purpose-dedupe); no test uses a real
Redis, and every production path is fail-open by design.

* refactor(runtime): delete the never-wired dispatch-time spawn cooldown

_safe_spawn / gateway_pre_spawn_check / trigger_filter had no caller in
the repo's entire history (87ef42bf only flipped the flag). Its five
rules are superseded: provider parking runs inside spawn_agent, claim
freshness is the guards+reaper, runaway respawns are the progress-aware
breaker + notification cooldown; the per-task cooldown rule would
queue-stall every normal stage handoff if wired today. gateway_triggers
table kept inert. Ratified by the CEO over wiring it.

* build: serialize uv — gate recipes never implicitly sync the venv

Every uv run re-syncs implicitly, so a background make quality plus any
foreground uv run raced two writers on one .venv and tore site-packages
apart (the recurring rich/pip/bandit ImportError corruption; bit twice
today, four times on 2026-07-02's first session). UV_NO_SYNC=1 is now
exported Makefile-wide and quality/quality-fast/gate depend on one
explicit up-front sync step.

* fix(git): PR/merge/branch REST calls honor github_api_base_url

Fifteen sites hardcoded https://api.github.com while the CI-run and
open-PR-list calls already read settings.github_api_base_url — a GHE or
test override silently applied to half the surface. One _api_base()
helper keeps them uniform; default behavior unchanged.

* ci: split the monolith — backend CI, Panel CI, E2E Smoke

ci.yml keeps its file name and the backend quality job only (self-heal /
ci-watch / release-readiness default to the ci.yml workflow); the panel
job moves to panel-ci.yml scoped to panel/**, and the new scripted-agent
lifecycle smoke gets e2e-smoke.yml + a make e2e-smoke target (env-gated
out of the default pytest run). Trade: a panel-only red now lands on
Panel CI, which the ci.yml-pinned watch engines don't see.

* feat(tests): e2e lifecycle smoke harness — scripted agents, real gates

tests/e2e_smoke stands up the real API (flow/do routers + middleware on
uvicorn) over the ephemeral test Postgres, a local bare origin standing
in for GitHub, and a fake GitHub REST layer whose merges are real git
merges. A deterministic driver reloads the real MCP flow/do modules per
agent and walks claim (real clone + worktree) -> tracing-gap -> note ->
plan gate -> commit -> PR -> the full i_am_done ladder -> QA verdicts ->
documenter -> awaiting_pm_review in ~5s. Runs via make e2e-smoke + its
own CI workflow; skipped (env-gated) in the default suite. The
freeze-lift condition's first half: scenario 1 green.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
This commit is contained in:
Renzo F
2026-07-02 18:28:07 +02:00
committed by GitHub
co-authored by Renn F
parent fe67a630ac
commit 1c87a4e4e4
35 changed files with 1661 additions and 835 deletions
@@ -18,10 +18,28 @@ from __future__ import annotations
from unittest.mock import AsyncMock, MagicMock, patch
from uuid import uuid4
import pytest
from roboco.config import settings as cfg
from roboco.models.events import EventType
from roboco.services.gateway.choreographer import Choreographer, ChoreographerDeps
from structlog.testing import capture_logs
@pytest.fixture(autouse=True)
def _unreachable_redis(monkeypatch: pytest.MonkeyPatch) -> None:
"""Point the tracker at an unreachable Redis for every test here.
The real RateLimitStateTracker otherwise wrote a NO-TTL "anthropic
rate-limited" state blob into a developer's live localhost Redis on
every run — order/state-dependent poison for anything reading the real
tracker. activate() failing is fine: the parking handler catches and
logs it, and these tests assert orchestrator parking, not the write.
(redis_url is a computed property — patch its inputs.)
"""
monkeypatch.setattr(cfg, "redis_host", "127.0.0.1")
monkeypatch.setattr(cfg, "redis_port", 1)
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
-252
View File
@@ -1,252 +0,0 @@
"""Tests for stale-trigger cleanup + cooldown decisions."""
from __future__ import annotations
from datetime import UTC, datetime, timedelta
from unittest.mock import MagicMock
from uuid import UUID, uuid4
from roboco.services.gateway.trigger_filter import (
SpawnConfig,
SpawnDecision,
TriggerContext,
TriggerKind,
decide_spawn,
)
_DEFAULT_CONFIG = SpawnConfig(
cooldown_seconds=60,
role_rate_per_minute=6,
claim_stale_seconds=180,
)
def _task(
status: str,
active_claimant_id: UUID | None = None,
last_heartbeat_at: datetime | None = None,
) -> MagicMock:
t = MagicMock()
t.id = uuid4()
t.status = status
t.active_claimant_id = active_claimant_id
t.last_heartbeat_at = last_heartbeat_at
return t
def _trigger( # noqa: PLR0913
kind: TriggerKind,
skill: str | None = None,
recent_spawns_for_task: int = 0,
recent_spawns_for_role: int = 0,
provider: str | None = None,
provider_rate_limited: bool = False,
) -> TriggerContext:
return TriggerContext(
kind=kind,
skill=skill,
recent_spawns_for_task=recent_spawns_for_task,
recent_spawns_for_role=recent_spawns_for_role,
provider=provider,
provider_rate_limited=provider_rate_limited,
)
class TestStaleTriggerCleanup:
def test_a2a_code_review_for_completed_task_dropped(self) -> None:
t = _task(status="completed")
decision = decide_spawn(
task=t,
trigger=_trigger(TriggerKind.A2A, skill="code_review"),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.DROP
assert "stale" in decision.reason.lower()
def test_a2a_code_review_for_paused_task_dropped(self) -> None:
"""Line 79-82: non-relevant non-terminal status (paused) → drop."""
t = _task(status="paused")
decision = decide_spawn(
task=t,
trigger=_trigger(TriggerKind.A2A, skill="code_review"),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.DROP
assert "code_review" in decision.reason
def test_a2a_code_review_for_awaiting_qa_spawns(self) -> None:
t = _task(status="awaiting_qa")
decision = decide_spawn(
task=t,
trigger=_trigger(TriggerKind.A2A, skill="code_review"),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.SPAWN
def test_notification_for_terminal_task_dropped(self) -> None:
t = _task(status="cancelled")
decision = decide_spawn(
task=t,
trigger=_trigger(TriggerKind.NOTIFICATION),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.DROP
class TestSingleClaimantQueue:
def test_active_fresh_claimant_queues(self) -> None:
recent = datetime.now(tz=UTC)
t = _task(
status="in_progress",
active_claimant_id=uuid4(),
last_heartbeat_at=recent,
)
decision = decide_spawn(
task=t,
trigger=_trigger(TriggerKind.NOTIFICATION),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.QUEUE
assert "claimant" in decision.reason.lower()
def test_stale_claimant_does_not_queue(self) -> None:
old = datetime.now(tz=UTC) - timedelta(seconds=600)
t = _task(
status="awaiting_qa",
active_claimant_id=uuid4(),
last_heartbeat_at=old,
)
decision = decide_spawn(
task=t,
trigger=_trigger(TriggerKind.A2A, skill="code_review"),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.SPAWN
class TestCooldown:
def test_per_task_cooldown_queues(self) -> None:
t = _task(status="awaiting_qa")
decision = decide_spawn(
task=t,
trigger=_trigger(
TriggerKind.A2A,
skill="code_review",
recent_spawns_for_task=1,
),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.QUEUE
assert "cooldown" in decision.reason.lower()
def test_role_rate_limit_queues(self) -> None:
t = _task(status="awaiting_qa")
decision = decide_spawn(
task=t,
trigger=_trigger(
TriggerKind.A2A,
skill="code_review",
recent_spawns_for_role=6,
),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.QUEUE
assert "rate" in decision.reason.lower()
class TestProviderRateLimitGate:
"""Rule 2: provider rate-limit gate fires before claimant-lock/cooldown."""
def test_queues_when_provider_rate_limited(self) -> None:
"""QUEUE outcome when provider_rate_limited=True."""
t = _task(status="in_progress")
decision = decide_spawn(
task=t,
trigger=_trigger(
TriggerKind.NOTIFICATION,
provider="anthropic",
provider_rate_limited=True,
),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.QUEUE
assert "provider anthropic rate-limited" in decision.reason
def test_reason_contains_provider_name(self) -> None:
"""Reason string must contain the provider name."""
t = _task(status="pending")
decision = decide_spawn(
task=t,
trigger=_trigger(
TriggerKind.SCAN,
provider="ollama_cloud",
provider_rate_limited=True,
),
config=_DEFAULT_CONFIG,
)
assert "ollama_cloud" in decision.reason
def test_reason_contains_unknown_when_no_provider_name(self) -> None:
"""When provider is None, reason still contains 'unknown'."""
t = _task(status="in_progress")
decision = decide_spawn(
task=t,
trigger=_trigger(
TriggerKind.NOTIFICATION,
provider=None,
provider_rate_limited=True,
),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.QUEUE
assert "unknown" in decision.reason
def test_no_queue_injection_when_not_rate_limited(self) -> None:
"""SPAWN when provider_rate_limited=False and all other gates clear."""
t = _task(status="in_progress")
decision = decide_spawn(
task=t,
trigger=_trigger(
TriggerKind.NOTIFICATION,
provider="anthropic",
provider_rate_limited=False,
),
config=_DEFAULT_CONFIG,
)
assert decision.outcome == SpawnDecision.SPAWN
def test_stale_drop_fires_before_rate_limit_gate(self) -> None:
"""Rule 1 (stale-drop) fires before rule 2 (rate-limit gate)."""
t = _task(status="completed")
decision = decide_spawn(
task=t,
trigger=_trigger(
TriggerKind.NOTIFICATION,
provider="anthropic",
provider_rate_limited=True,
),
config=_DEFAULT_CONFIG,
)
# Rule 1 fires first — outcome must be DROP, not QUEUE
assert decision.outcome == SpawnDecision.DROP
def test_rate_limit_gate_fires_before_claimant_lock(self) -> None:
"""Rule 2 (rate-limit gate) fires before rule 3 (single-claimant invariant)."""
recent = datetime.now(tz=UTC)
t = _task(
status="in_progress",
active_claimant_id=uuid4(),
last_heartbeat_at=recent,
)
decision = decide_spawn(
task=t,
trigger=_trigger(
TriggerKind.NOTIFICATION,
provider="anthropic",
provider_rate_limited=True,
),
config=_DEFAULT_CONFIG,
)
# Both gates would QUEUE but reason must come from rate-limit (rule 2)
assert decision.outcome == SpawnDecision.QUEUE
assert "rate-limited" in decision.reason