Files
roboco/tests/e2e_smoke/test_pm_merge_chain.py
T
d1cf6ecbf3 Wave 1: PR-gate turn cut, task search, trace timestamps, Secretary edits + e2e scenarios 2–3 (#295)
* feat(tests): e2e scenario 2 — the PM merge chain through the PR gate

Shared arcs extracted (arcs.py: canonical-company seeding + dev/qa/doc
segments); scenario 2 seeds a root->cell->dev hierarchy mid-flight, rides
the child through the scenario-1 arc into the cell branch (real squash
via the fake GitHub), then submit_up -> claim_gate_review/pr_pass ->
dispatcher re-claim (mirrored) -> PM complete merging cell->root. This is
the exact PM->reviewer->PM turn sequence the wave-1 turn cut shortens —
the BEFORE-net. Learned seams scripted: commit-subject validator (>=20
chars), reviewer learning-note gate, pr_pass clears ownership by design.

* feat(runtime): PR-gate turn cut — assembled parents auto-submit to the reviewer

When every child of an assembled parent is terminal, the closure
dispatcher now runs the real submit_up/submit_root through the internal
API as the owning PM (_try_auto_submit) instead of spawning the PM for
that turn — the submit's substance is deterministic gate code. Any gate
refusal falls back to the classic PM closure spawn; pr_fail routing and
the PM's final merge turn are unchanged; umbrellas never auto-submit.
ROBOCO_PR_GATE_AUTO_SUBMIT_ENABLED default-on; task.auto_submitted audit
row per cut. Proven by e2e scenario 2b (real API, real gates, real git)
against scenario 2 as the before-net.

* feat(notes): structured note sections carry a written_at trace stamp

Sections are overwrite-in-place, so without a stamp there was no way to
reconstruct WHEN a dev/qa/doc/reviewer note landed (CEO reMarkable item:
trace TIMESTAMPS). apply_structured_note stamps ISO written_at beside
the model fields; the panel notes tab renders it next to each card
title (pre-stamp rows render nothing). Progress updates, commits, and
journal entries already carried timestamps — this was the one gap.

* feat(tasks): server-side task search — title, details, and id prefix

The task list's search box only matched titles client-side, and the
trimmed summary payload deliberately carries no description — so
keyword/details/id search was impossible in the browser by design.
GET /tasks/summary gains q (ILIKE over title+description, id-prefix
match, composed with team/status and the view-permission scoping);
the panel debounces the box into the summary fetch and drops the
title-only client filter that would have hidden description matches.

* feat(wave-1): trace timestamps, real task search, Secretary task edits

- apply_structured_note stamps written_at per section; the panel notes
  tab shows it (the one trace surface without a timestamp).
- GET /tasks/summary?q= searches title+description+id-prefix server-side
  (summaries carry no description by design); panel debounces into the
  fetch and drops the title-only client filter.
- Secretary control_task gains a CEO-gated edit action over the content
  allowlist, and GET /secretary/tasks?q= resolves task names to ids for
  the chat. PM-side expansion deferred per the CEO's 'not that much'.

* fix(workspace): dep-update probe scrubs the inherited venv pin

Under uv run the orchestrator's process tree carries VIRTUAL_ENV, and a
uv-based dep_update_command in the throwaway probe clone would target
that venv instead of the clone's — the same hazard _uv_subprocess_env
already guards on the install path.

* build: private per-repo uv cache — isolate from machine-wide uvx servers

Root cause of the recurring rich/pip/bandit rot, with evidence: uv cache
clean timed out on the ~/.cache/uv lock ('is another uv process
running?') — three uvx mcp-server-fetch processes (Claude Code fetch MCP,
one alive since Wednesday) share that cache and race repo syncs on it;
poisoned entries then survive venv rebuilds because rm -rf .venv never
touches the cache, and every re-link reproduces the breakage. UV_CACHE_DIR
now pins <repo>/.uv-cache (gitignored). The earlier UV_NO_SYNC
serialization stays as defense-in-depth but was not the whole story.

* feat(tests): e2e scenario 3 — pr_fail revision loop + root→CEO chain

3a: reviewer pr_fail with a concrete issue -> needs_revision ->
i_will_plan re-entry (full plan gates) -> real fix lands on the cell
branch (the unchanged-PR hard gate refuses resubmit until it does) ->
clean second pass -> merge. 3b: submit_root -> gate -> Main PM complete
escalates the root to the CEO -> the REAL approve-and-merge endpoint
squash-merges to the origin's master. Harness gains the tasks router, a
seeded CEO identity, origin_commit, and a fake GitHub whose head.sha is
recomputed live (real-GitHub semantics the unchanged gate reads). Seeds
now encode the real shape: delivery roots are team=main_pm and
planning-typed.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-07-02 21:05:50 +02:00

176 lines
5.9 KiB
Python

"""Scenarios 2 + 2b: the PM merge chain, with and without the submit turn.
Scenario 2 (the BEFORE-net): the classic chain — the cell PM completes the
child, calls ``submit_up`` itself, the reviewer gate-passes, the PM merges.
Scenario 2b (the turn cut): the child lands the same way, but the SUBMIT
turn never happens as an agent call — the orchestrator's
``_try_auto_submit`` runs the real submit verb through the real API as the
owning PM, and the chain continues reviewer → PM merge. One PM turn fewer
per assembled parent, with every gate intact.
"""
from __future__ import annotations
import asyncio
from typing import TYPE_CHECKING
import httpx
from tests.e2e_smoke.arcs import (
dev_arc,
dispatcher_assign,
doc_arc,
origin_file,
qa_arc,
reviewer_gate_pass_arc,
seed_company,
seed_hierarchy,
seed_project,
task_state,
)
from tests.e2e_smoke.harness import ScriptedAgent, expect_ok
if TYPE_CHECKING:
import pytest
from tests.e2e_smoke.arcs import Company
from tests.e2e_smoke.harness import E2EStack
def _land_child(
stack: E2EStack, company: Company, project_slug: str, h: dict
) -> ScriptedAgent:
"""Run the child through dev→QA→doc and the PM's child-completion merge."""
dev_arc(
stack,
company,
project_slug,
h["child_id"],
work=("hello.txt", "Hello from the merge chain!\n"),
)
qa_arc(stack, company, h["child_id"])
doc_arc(stack, company, h["child_id"], filename="hello.txt")
# The child's PR must target the CELL branch (ancestor resolution) —
# branch NAMES derive from the task-id chain, so assert on the base ref.
child = task_state(stack, h["child_id"])
child_pr = stack.github.prs[child["pr_number"]]
assert child_pr["base"]["ref"] == h["cell_branch"], (
f"child PR should target the cell branch: {child_pr['base']} / {child}"
)
pm = ScriptedAgent(stack, company.cell_pm_id, "be-pm", "cell_pm")
expect_ok(
pm.flow(
"complete",
task_id=str(h["child_id"]),
notes=(
"Child verified: QA passed with per-criterion verdicts and "
"docs are complete; merging the leaf PR into the cell branch."
),
),
"pm complete child",
)
assert task_state(stack, h["child_id"])["status"] == "completed"
assert origin_file(stack, h["cell_branch"], "hello.txt"), (
"child merge did not land hello.txt on the cell branch"
)
return pm
def _pm_merges_cell(
stack: E2EStack, company: Company, pm: ScriptedAgent, h: dict
) -> None:
"""Dispatcher re-claim (mirrored) + the PM's final merge turn."""
dispatcher_assign(stack, h["cell_id"], company.cell_pm_id)
expect_ok(
pm.flow(
"complete",
task_id=str(h["cell_id"]),
notes=(
"Gate passed; merging the assembled cell PR into the root "
"branch and closing the cell task."
),
),
"pm complete cell",
)
assert task_state(stack, h["cell_id"])["status"] == "completed"
assert origin_file(stack, h["root_branch"], "hello.txt"), (
"cell merge did not land hello.txt on the root branch"
)
def test_pm_merge_chain_to_root_branch(e2e_stack: E2EStack) -> None:
stack = e2e_stack
company = seed_company(stack)
project_id, project_slug = seed_project(stack, company)
h = seed_hierarchy(stack, company, project_id)
pm = _land_child(stack, company, project_slug, h)
# --- cell PM: submit the assembled cell PR (the turn 2b cuts) -----------
expect_ok(
pm.flow(
"submit_up",
task_id=str(h["cell_id"]),
notes=(
"All children terminal and merged into the cell branch; "
"assembling the cell PR against the root branch for the "
"in-path review gate."
),
),
"pm submit_up",
)
cell = task_state(stack, h["cell_id"])
assert cell["status"] == "awaiting_pr_review", cell
assert cell["pr_number"], cell
reviewer_gate_pass_arc(stack, company, h["cell_id"])
_pm_merges_cell(stack, company, pm, h)
def test_auto_submit_cuts_the_pm_turn(
e2e_stack: E2EStack, monkeypatch: pytest.MonkeyPatch
) -> None:
"""The wave-1 turn cut, end to end: no agent calls submit_up — the
orchestrator's ``_try_auto_submit`` drives the REAL submit verb through
the REAL API as the owning PM, and the gate chain continues unchanged."""
from roboco.config import settings
from roboco.runtime.orchestrator import AgentOrchestrator
stack = e2e_stack
company = seed_company(stack)
project_id, project_slug = seed_project(stack, company)
h = seed_hierarchy(stack, company, project_id)
pm = _land_child(stack, company, project_slug, h)
# --- the cut: the orchestrator submits system-side ----------------------
monkeypatch.setattr(settings, "api_url", stack.base_url)
monkeypatch.setattr(settings, "pr_gate_auto_submit_enabled", True)
orch = AgentOrchestrator.__new__(AgentOrchestrator)
orch._tick_handled_tasks = set()
orch._bg_tasks = set()
cell_task_dict = {
"id": str(h["cell_id"]),
"team": "backend",
"branch_name": h["cell_branch"],
"project_id": str(project_id),
"assigned_to": str(company.cell_pm_id),
"status": "in_progress",
}
async def _go() -> bool:
async with httpx.AsyncClient(timeout=60) as client:
return await orch._try_auto_submit(client, cell_task_dict, "be-pm")
assert asyncio.run(_go()) is True, "auto-submit should accept a clean parent"
cell = task_state(stack, h["cell_id"])
assert cell["status"] == "awaiting_pr_review", cell
assert cell["pr_number"], cell
# --- unchanged tail: reviewer gate + the PM's one remaining turn ---------
reviewer_gate_pass_arc(stack, company, h["cell_id"])
_pm_merges_cell(stack, company, pm, h)