mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
[F002] retype board-routed MegaTask root-subtasks code->planning on activation
_activate_batch_root_subtasks flipped a held root-subtask to team=MAIN_PM but left task_type=code (intake only coerces main_pm-team drafts, so a board-routed code root reached activation still code-typed). The main_pm+code combo re-introduces the 2026-06-27 meltdown. Mirror approve_and_start's own retype via main_pm_cannot_own_code so the activated child is a planning-typed coordination root. TDD: RED test_activate_batch_root_subtasks_retypes_code_to_planning watched fail (task_type stayed CODE), then GREEN after the retype. ruff+mypy clean; 125 batch/umbrella/approve tests green, no regressions.
This commit is contained in:
@@ -1607,6 +1607,95 @@ async def test_submit_for_pm_review_advances_with_notes(
|
||||
assert out.status == TaskStatus.AWAITING_PM_REVIEW
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_submit_for_pm_review_waives_branch_pr_for_batch_umbrella(
|
||||
task_setup: dict, db_session: AsyncSession
|
||||
) -> None:
|
||||
"""F001: a MegaTask umbrella is branchless by design (no branch/PR) yet
|
||||
must walk in_progress -> awaiting_pm_review so main_pm_complete can
|
||||
escalate it to the CEO. submit_for_pm_review must waive the branch+PR
|
||||
requirement for a batch umbrella, or umbrella completion deadlocks in
|
||||
in_progress forever (the Main PM loops on `complete` -> invalid_state)."""
|
||||
svc = task_setup["svc"]
|
||||
task = await svc.create(_req(task_setup))
|
||||
task.status = TaskStatus.IN_PROGRESS
|
||||
task.project_id = None # umbrella: branchless, no repo, no PR
|
||||
task.product_id = None
|
||||
task.batch_id = uuid4()
|
||||
task.parent_task_id = None # umbrella is top-level
|
||||
task.branch_name = None
|
||||
task.pr_created = False
|
||||
task.pr_number = None
|
||||
await db_session.flush()
|
||||
out = await svc.submit_for_pm_review(task.id, agent_role="main_pm")
|
||||
assert out is not None
|
||||
assert out.status == TaskStatus.AWAITING_PM_REVIEW
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_activate_batch_root_subtasks_retypes_code_to_planning(
|
||||
task_setup: dict, db_session: AsyncSession
|
||||
) -> None:
|
||||
"""F002: a board-routed MegaTask root-subtask is created in BACKLOG with
|
||||
team=board and task_type=code (intake only coerces main_pm-team drafts, so a
|
||||
board-routed code root-subtask reaches activation still code-typed). When
|
||||
the CEO approves the umbrella, _activate_batch_root_subtasks flips the held
|
||||
child to team=main_pm — but if it leaves task_type=code the combo
|
||||
re-introduces the 2026-06-27 main_pm+code meltdown. The activation must
|
||||
retype code->planning, mirroring approve_and_start's own retype."""
|
||||
svc = task_setup["svc"]
|
||||
# approve_and_start resolves the main-pm agent by slug — seed it.
|
||||
main_pm = AgentTable(
|
||||
id=uuid4(),
|
||||
name="Main PM",
|
||||
slug="main-pm",
|
||||
role=AgentRole.MAIN_PM,
|
||||
team=Team.MAIN_PM,
|
||||
status=AgentStatus.ACTIVE,
|
||||
model_config={},
|
||||
system_prompt="main-pm",
|
||||
capabilities=[],
|
||||
permissions={},
|
||||
metrics={},
|
||||
)
|
||||
db_session.add(main_pm)
|
||||
await db_session.flush()
|
||||
|
||||
batch = uuid4()
|
||||
# Umbrella: board-routed, pending, board review complete, branchless.
|
||||
umbrella = await svc.create(_req(task_setup, title="umbrella"))
|
||||
umbrella.status = TaskStatus.PENDING
|
||||
umbrella.team = cast("Any", Team.BOARD)
|
||||
umbrella.board_review_complete = True
|
||||
umbrella.project_id = None
|
||||
umbrella.product_id = None
|
||||
umbrella.batch_id = batch
|
||||
umbrella.parent_task_id = None
|
||||
umbrella.task_type = cast("Any", TaskType.PLANNING)
|
||||
await db_session.flush()
|
||||
|
||||
# Root-subtask: held in BACKLOG on the board, code-typed (the danger case).
|
||||
child = await svc.create(
|
||||
_req(task_setup, title="root-sub", parent_task_id=umbrella.id)
|
||||
)
|
||||
child.status = TaskStatus.BACKLOG
|
||||
child.team = cast("Any", Team.BOARD)
|
||||
child.batch_id = batch
|
||||
child.parent_task_id = umbrella.id
|
||||
child.task_type = cast("Any", TaskType.CODE)
|
||||
await db_session.flush()
|
||||
|
||||
approved = await svc.approve_and_start(umbrella.id)
|
||||
assert approved is not None
|
||||
|
||||
refreshed = await svc.get(child.id)
|
||||
assert refreshed is not None
|
||||
assert refreshed.status == TaskStatus.PENDING
|
||||
assert refreshed.team == Team.MAIN_PM
|
||||
# The fix: a main_pm team may not own a code task -> retype to planning.
|
||||
assert refreshed.task_type == TaskType.PLANNING
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# docs_complete: full path including descendants check
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -359,3 +359,72 @@ async def test_main_pm_complete_handles_escalate_returning_none() -> None:
|
||||
env = await c.main_pm_complete(pm_id, umbrella_id, "ready for CEO sign-off")
|
||||
assert env.error == "invalid_state"
|
||||
assert "escalate_to_ceo" in env.as_dict()["message"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_complete_escalates_batch_umbrella_from_in_progress() -> None:
|
||||
"""F001: a MegaTask umbrella is branchless by design and sits in
|
||||
in_progress with no branch/PR. The ``complete`` verb's spec gate
|
||||
(``complete`` action source_statuses={AWAITING_PM_REVIEW}) must NOT
|
||||
reject it — the Main PM routes through main_pm_complete, which walks
|
||||
in_progress -> awaiting_pm_review -> awaiting_ceo_approval. Calling the
|
||||
``complete`` ENTRY point (not main_pm_complete directly) must succeed
|
||||
and escalate to the CEO. This exercises the real spec gate
|
||||
(can_invoke_intent is pure) — the prior test mocked submit_pm_review and
|
||||
called main_pm_complete directly, bypassing the gate (false green)."""
|
||||
pm_id = uuid4()
|
||||
umbrella_id = uuid4()
|
||||
batch_id = uuid4()
|
||||
t = MagicMock(
|
||||
id=umbrella_id,
|
||||
status="in_progress",
|
||||
assigned_to=pm_id,
|
||||
parent_task_id=None,
|
||||
batch_id=batch_id,
|
||||
branch_name=None,
|
||||
pr_number=None,
|
||||
pr_created=False,
|
||||
pr_url=None,
|
||||
team="main_pm",
|
||||
)
|
||||
after_review = MagicMock(
|
||||
id=umbrella_id,
|
||||
status="awaiting_pm_review",
|
||||
assigned_to=pm_id,
|
||||
parent_task_id=None,
|
||||
batch_id=batch_id,
|
||||
branch_name=None,
|
||||
team="main_pm",
|
||||
)
|
||||
escalated = MagicMock(
|
||||
id=umbrella_id,
|
||||
status="awaiting_ceo_approval",
|
||||
assigned_to=pm_id,
|
||||
parent_task_id=None,
|
||||
batch_id=batch_id,
|
||||
branch_name=None,
|
||||
team="main_pm",
|
||||
)
|
||||
task_svc = AsyncMock()
|
||||
task_svc.get.return_value = t
|
||||
task_svc.agent_for.return_value = MagicMock(role="main_pm", slug="main-pm")
|
||||
task_svc.all_subtasks_terminal.return_value = True
|
||||
task_svc.get_subtasks.return_value = []
|
||||
task_svc.submit_pm_review.return_value = after_review
|
||||
task_svc.escalate_to_ceo.return_value = escalated
|
||||
task_svc.reassign = AsyncMock()
|
||||
journal_svc = AsyncMock()
|
||||
journal_svc.has_decision_for_task.return_value = True
|
||||
journal_svc.latest_decision_at.return_value = datetime.now(UTC)
|
||||
journal_svc.has_reflect_for_task.return_value = True
|
||||
deps = _make_deps(task=task_svc, journal=journal_svc)
|
||||
c = Choreographer(deps)
|
||||
|
||||
env = await c.complete(
|
||||
pm_id, umbrella_id, notes="every root-subtask terminal; MegaTask ready for CEO"
|
||||
)
|
||||
body = env.as_dict()
|
||||
assert body.get("error") is None, body
|
||||
assert body["status"] == "awaiting_ceo_approval"
|
||||
task_svc.submit_pm_review.assert_awaited_once()
|
||||
task_svc.escalate_to_ceo.assert_awaited_once()
|
||||
|
||||
Reference in New Issue
Block a user