Files
roboco/tests/unit/services/test_content_notes.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

155 lines
5.1 KiB
Python

"""Tests for the apply_structured_note chokepoint."""
from __future__ import annotations
from datetime import datetime
from types import SimpleNamespace
import pytest
from roboco.foundation.policy.content import ContentValidationError, PrReviewContent
from roboco.services.content_notes import apply_structured_note, content_type_for_role
def _task() -> SimpleNamespace:
return SimpleNamespace(
notes_structured=None,
dev_notes=None,
qa_notes=None,
auditor_notes=None,
doc_notes=None,
pr_reviewer_notes=None,
quick_context=None,
)
def test_pr_review_lands_in_own_slot_not_qa() -> None:
t = _task()
t.qa_notes = "QA already wrote this"
model = apply_structured_note(
t,
"pr_review",
{
"summary": "Guard missing on the 422 path here.",
"verdict": "changes_requested",
"findings": [
{
"file": "git.py",
"severity": "blocker",
"expected": "retry as COMMENT",
"actual": "raises",
}
],
},
)
assert isinstance(model, PrReviewContent)
assert t.notes_structured["pr_review"]["verdict"] == "changes_requested"
assert t.pr_reviewer_notes == model.render_markdown()
# QA's slot is untouched.
assert t.qa_notes == "QA already wrote this"
def test_qa_mirror_regenerated() -> None:
t = _task()
apply_structured_note(
t,
"qa",
{
"summary": "Verified every acceptance criterion.",
"ac_verdicts": [
{"criterion": "AC1", "status": "verified", "how": "test passes"}
],
"verdict": "passed",
},
)
assert t.notes_structured["qa"]["verdict"] == "passed"
assert "## Acceptance Criteria" in t.qa_notes
def test_resumption_writes_quick_context() -> None:
t = _task()
apply_structured_note(
t, "resumption", {"done": "schema landed", "next": "wire the gateway"}
)
assert "## Done" in t.quick_context
assert t.notes_structured["resumption"]["next"] == "wire the gateway"
def test_doc_writes_doc_notes() -> None:
t = _task()
apply_structured_note(t, "doc", {"summary": "Documented the new endpoints."})
assert "## Summary" in t.doc_notes
def test_invalid_payload_leaves_task_untouched() -> None:
t = _task()
with pytest.raises(ContentValidationError):
apply_structured_note(t, "pr_review", {"verdict": "approved"}) # no summary
assert t.notes_structured is None
assert t.pr_reviewer_notes is None
def test_notes_structured_reassigned_for_dirty_tracking() -> None:
t = _task()
t.notes_structured = {"developer": {"summary": "x"}}
before = t.notes_structured
apply_structured_note(t, "doc", {"summary": "Documented the endpoints fully."})
assert t.notes_structured is not before # new dict object
assert "developer" in t.notes_structured # prior entry preserved
assert "doc" in t.notes_structured
def test_content_type_for_role_maps_section_roles() -> None:
"""Each role with a dedicated section routes to its content type."""
assert content_type_for_role("developer") == "developer"
assert content_type_for_role("qa") == "qa"
assert content_type_for_role("documenter") == "doc"
assert content_type_for_role("pr_reviewer") == "pr_review"
assert content_type_for_role("auditor") == "auditor"
assert content_type_for_role("cell_pm") == "resumption"
assert content_type_for_role("main_pm") == "resumption"
def test_content_type_for_role_none_for_sectionless_roles() -> None:
"""Board / advisory / on-demand roles have no dedicated section."""
assert content_type_for_role("product_owner") is None
assert content_type_for_role("head_marketing") is None
assert content_type_for_role("ceo") is None
assert content_type_for_role("prompter") is None
def test_sections_carry_written_at_stamp() -> None:
"""Every persisted section carries an ISO written_at — traces without
timestamps were unusable for reconstructing WHEN a note landed (CEO
reMarkable item, 2026-07-02)."""
t = _task()
apply_structured_note(
t,
"developer",
{
"summary": (
"Built the greeting module end to end; single additive file "
"on the task branch with the PR open against the base."
)
},
)
stored = (t.notes_structured or {})["developer"]
assert "written_at" in stored, stored
# Parseable, timezone-aware ISO-8601.
parsed = datetime.fromisoformat(stored["written_at"])
assert parsed.tzinfo is not None
def test_written_at_refreshes_on_rewrite() -> None:
t = _task()
payload = {
"summary": (
"First pass of the notes section, long enough to validate "
"against the dev section's minimum content length."
)
}
apply_structured_note(t, "developer", payload)
first = (t.notes_structured or {})["developer"]["written_at"]
apply_structured_note(t, "developer", payload)
second = (t.notes_structured or {})["developer"]["written_at"]
assert second >= first