Files
roboco/tests/unit/services/test_content_notes.py
T
Renn F 8cf697816f feat(content): obligate role note sections like journals
Completes the note(scope='handoff') write-path (WIP 23e6ee57): every role
with a dedicated note section is now obligated to populate it, the same way
journals are obligated.

Obligations (foundation.policy.tracing):
- DEV_NOTES / PR_REVIEWER_NOTES / QUICK_CONTEXT_MIN_CHARS requirements +
  checkers, wired onto i_am_done (dev_notes), delegate (quick_context), and
  pr_pass / pr_fail / post_pr_review (pr_reviewer_notes).
- Fixes a latent bug: the docs-notes checker read dev_notes instead of
  doc_notes (the documenter's section); the i_documented shim now feeds
  doc_notes to match.

Auditor: a session-scoped note obligation on i_am_idle — the auditor owns no
delivery task and has no delivery verb, so it must have recorded an
observation within the window before going idle (JournalService.has_recent_entry).

Write-then-gate: persisted sections (dev_notes / quick_context) are
pre-written by the agent's note(scope='handoff') before the gated verb;
argument-borne sections (doc_notes / pr_reviewer_notes) are checked through a
SimpleNamespace shim, the same pattern qa_notes already uses.

Config: dev/pr_reviewer/quick_context min-chars (40/40/30), panel-tunable.
Plus per-gap remediation hints and full coverage (write-path routing,
ownership, validation->remediation, each obligation, the doc_notes fix).

Full make-quality green: 9777 passed, 95.6% coverage.
2026-06-21 20:31:42 +02:00

117 lines
3.9 KiB
Python

"""Tests for the apply_structured_note chokepoint."""
from __future__ import annotations
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