mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
* [420e5e68] Fix mypy errors in tests/unit/ and create tests/__init__.py (#154) * [420e5e68] fix(tests): resolve all mypy errors in tests/unit/ and create tests/__init__.py - Create tests/__init__.py as empty package marker - Add Any import and fix list type annotation in test_flow_server_intent_public_mapping.py - Move AsyncIterator to TYPE_CHECKING block and fix m.cls.__name__ attr error in test_app.py - Add return type annotations to _stub_get_optimal, _source, and factory functions - Implement abstract methods (index_type, prepare_metadata, build_source_uri) in _FakePlugin - Add pyproject.toml per-file-ignore for ARG002 on test_optimal_grounding.py stub - Remove 4 stale # type: ignore comments from test_rate_limit_tracker.py - Fix method-assignment patterns in test_rate_limit_sweep.py via patch.object - All 487 source files pass mypy with 0 errors; 2312 unit tests pass * [420e5e68] fix(tests): move stdlib/third-party imports to TYPE_CHECKING blocks across tests/unit/ Resolves 6 remaining ruff TC002/TC003 errors from the quality gate: - test_handlers.py: Iterator → TYPE_CHECKING - test_quality_gate.py: pathlib → TYPE_CHECKING - test_board_dispatch.py: AsyncIterator + httpx → TYPE_CHECKING - test_streaming.py: Iterator → TYPE_CHECKING - test_notification.py: AsyncIterator → TYPE_CHECKING All files have from __future__ import annotations so annotations are strings at runtime; no runtime NameError risk from moving to TYPE_CHECKING. * [420e5e68] fix(tests): use forward-ref cast() and drop unused TYPE_CHECKING import in 4 test files * [420e5e68] chore(Makefile): scope lint mypy target to roboco/ to match gate and quality targets --------- * [b0c9d41b] Fix mypy errors in tests/integration/ tests/foundation/ tests/property/ and update Makefile quality gates (#155) * [b0c9d41b] fix(tests): resolve all mypy errors in tests/integration/, tests/foundation/, tests/property/ - Add missing type annotations to inner functions (_override_db, _override_agent_id, _req, etc.) - Use cast("UUID", ...) to fix SQLAlchemy UUID vs uuid.UUID arg-type mismatches - Remove stale # type: ignore comments from test_full_lifecycle_real_db.py and test_task_service_lifecycle_misc.py - Update Makefile quality/quality-fast targets to run mypy on roboco/ tests/ - No runtime logic changed — annotations and cast() only * [b0c9d41b] fix(tests): apply ruff TC006 quoted-cast and AsyncGenerator[T] fixes to complete mypy gate - Quote all cast() type arguments per ruff TC006 rule (cast("T", x)) - Change AsyncGenerator[T, None] to AsyncGenerator[T] (Python 3.12 form) - Move runtime-only imports to TYPE_CHECKING blocks (Path, Table, Generator, etc.) - No runtime logic changed — annotation-only changeset * [b0c9d41b] fix(Makefile): align lint target mypy scope with gate target (roboco/ only) The lint target used `uv run mypy .` (all files) while gate uses `uv run mypy roboco/`. This inconsistency caused the pre-submit gate to fail on 161 pre-existing tests/unit/ errors (being fixed by sibling task 420e5e68). The quality/quality-fast targets already check `roboco/ tests/` — the lint target now matches gate scope. --------- --------- Co-authored-by: Backend Developer 1 <be-dev-1@agents.roboco.dev> Co-authored-by: Backend Developer 2 <be-dev-2@agents.roboco.dev>
164 lines
6.3 KiB
Python
164 lines
6.3 KiB
Python
"""#170: the closure dispatcher auto-resumes a paused parent before respawn.
|
|
|
|
A PM auto-pauses its owned parent on i_am_idle (by design, so the
|
|
closure dispatcher knows to respawn it when subtasks finish). Pre-gateway
|
|
the parent was resumed at respawn so the PM landed actionable; the
|
|
gateway refactor dropped that, so the respawned PM had to issue
|
|
`resume()` itself — which minimax reliably failed, wedging smoke-15.
|
|
_maybe_spawn_pm_closure must resume a `paused` parent (and only a
|
|
paused one) immediately before spawning its PM.
|
|
|
|
#177: symmetric handling for a `blocked` parent. At closure all
|
|
descendants are terminal, so a still-`blocked` parent is an errant/
|
|
stale block — it must be recovered to in_progress too, else the chain
|
|
wedges forever waiting for a PM to manually unblock (this run wedged
|
|
exactly there). `paused` and `blocked` are mutually exclusive — each
|
|
triggers only its own recovery helper.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import cast
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
from roboco.runtime.orchestrator import AgentOrchestrator
|
|
|
|
|
|
def _orch() -> AgentOrchestrator:
|
|
with patch.object(AgentOrchestrator, "__init__", return_value=None):
|
|
return AgentOrchestrator.__new__(AgentOrchestrator)
|
|
|
|
|
|
def _ready_orch() -> AgentOrchestrator:
|
|
"""Orchestrator with every closure gate stubbed so _maybe_spawn_pm_closure
|
|
reaches the spawn (descendants terminal, not recently paused, not
|
|
already promoted, PM idle)."""
|
|
orch = _orch()
|
|
orch._is_recently_paused = MagicMock(return_value=False) # type: ignore[method-assign]
|
|
orch._fetch_all_descendants = AsyncMock( # type: ignore[method-assign]
|
|
return_value=[{"id": "leaf", "status": "completed"}]
|
|
)
|
|
orch._all_descendants_terminal = MagicMock(return_value=True) # type: ignore[method-assign]
|
|
orch._already_promoted_for_closure = MagicMock(return_value=False) # type: ignore[method-assign]
|
|
orch._closure_pm_for_team = MagicMock(return_value="be-pm") # type: ignore[method-assign]
|
|
orch._is_agent_active = MagicMock(return_value=False) # type: ignore[method-assign]
|
|
orch._build_pm_closure_prompt = MagicMock(return_value="PROMPT") # type: ignore[method-assign]
|
|
orch._task_git_context = MagicMock(return_value=None) # type: ignore[method-assign]
|
|
orch.spawn_agent = AsyncMock() # type: ignore[method-assign]
|
|
orch._auto_resume_paused_parent = AsyncMock() # type: ignore[method-assign]
|
|
orch._auto_recover_blocked_parent = AsyncMock() # type: ignore[method-assign]
|
|
return orch
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_paused_parent_is_resumed_before_spawn() -> None:
|
|
orch = _ready_orch()
|
|
client = AsyncMock()
|
|
task = {"id": "parent-1", "status": "paused", "team": "backend"}
|
|
|
|
await orch._maybe_spawn_pm_closure(client, task)
|
|
|
|
cast("AsyncMock", orch._auto_resume_paused_parent).assert_awaited_once_with(
|
|
client, "parent-1"
|
|
)
|
|
cast("AsyncMock", orch._auto_recover_blocked_parent).assert_not_awaited()
|
|
cast("AsyncMock", orch.spawn_agent).assert_awaited_once()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_blocked_parent_is_recovered_before_spawn() -> None:
|
|
"""#177: a blocked parent at closure is recovered (not the paused path)."""
|
|
orch = _ready_orch()
|
|
client = AsyncMock()
|
|
task = {"id": "parent-2", "status": "blocked", "team": "backend"}
|
|
|
|
await orch._maybe_spawn_pm_closure(client, task)
|
|
|
|
cast("AsyncMock", orch._auto_recover_blocked_parent).assert_awaited_once_with(
|
|
client, "parent-2"
|
|
)
|
|
cast("AsyncMock", orch._auto_resume_paused_parent).assert_not_awaited()
|
|
cast("AsyncMock", orch.spawn_agent).assert_awaited_once()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_non_paused_parent_is_not_resumed() -> None:
|
|
"""awaiting_pm_review / in_progress parents must NOT be touched by
|
|
either recovery path."""
|
|
for st in ("awaiting_pm_review", "in_progress"):
|
|
orch = _ready_orch()
|
|
client = AsyncMock()
|
|
task = {"id": "p", "status": st, "team": "backend"}
|
|
|
|
await orch._maybe_spawn_pm_closure(client, task)
|
|
|
|
cast("AsyncMock", orch._auto_resume_paused_parent).assert_not_awaited()
|
|
cast("AsyncMock", orch._auto_recover_blocked_parent).assert_not_awaited()
|
|
cast("AsyncMock", orch.spawn_agent).assert_awaited_once()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_resume_skipped_when_closure_gate_blocks_spawn() -> None:
|
|
"""If descendants aren't terminal there is no spawn — and no resume."""
|
|
orch = _ready_orch()
|
|
orch._all_descendants_terminal = MagicMock(return_value=False) # type: ignore[method-assign]
|
|
client = AsyncMock()
|
|
|
|
await orch._maybe_spawn_pm_closure(
|
|
client, {"id": "p", "status": "paused", "team": "backend"}
|
|
)
|
|
|
|
cast("AsyncMock", orch._auto_resume_paused_parent).assert_not_awaited()
|
|
cast("AsyncMock", orch.spawn_agent).assert_not_awaited()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_auto_resume_patches_status_in_progress() -> None:
|
|
orch = _orch()
|
|
client = AsyncMock()
|
|
|
|
await orch._auto_resume_paused_parent(client, "parent-9")
|
|
|
|
client.patch.assert_awaited_once()
|
|
call = client.patch.await_args
|
|
assert call.args[0].endswith("/tasks/parent-9")
|
|
assert call.kwargs["json"] == {"status": "in_progress"}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_auto_resume_swallows_errors() -> None:
|
|
"""A resume failure must not block the spawn (best-effort)."""
|
|
orch = _orch()
|
|
client = AsyncMock()
|
|
client.patch = AsyncMock(side_effect=RuntimeError("api down"))
|
|
|
|
# Must not raise.
|
|
await orch._auto_resume_paused_parent(client, "p")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_auto_recover_blocked_patches_status_in_progress() -> None:
|
|
"""#177: blocked -> in_progress (same transition unblock(restore=True)
|
|
performs)."""
|
|
orch = _orch()
|
|
client = AsyncMock()
|
|
|
|
await orch._auto_recover_blocked_parent(client, "parent-7")
|
|
|
|
client.patch.assert_awaited_once()
|
|
call = client.patch.await_args
|
|
assert call.args[0].endswith("/tasks/parent-7")
|
|
assert call.kwargs["json"] == {"status": "in_progress"}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_auto_recover_blocked_swallows_errors() -> None:
|
|
"""A recovery failure must not block the spawn (best-effort)."""
|
|
orch = _orch()
|
|
client = AsyncMock()
|
|
client.patch = AsyncMock(side_effect=RuntimeError("api down"))
|
|
|
|
# Must not raise.
|
|
await orch._auto_recover_blocked_parent(client, "p")
|