mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
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.
235 lines
8.1 KiB
Python
235 lines
8.1 KiB
Python
"""Gateway delegate must return Envelope.incomplete_input when fields missing.
|
|
|
|
Pre-migration: services/gateway/choreographer/_impl.py:1852 used
|
|
``acceptance_criteria=inputs.acceptance_criteria or []`` which let ``[]``
|
|
through and was caught later (or, before that fix, silently substituted
|
|
by services/task.py:5061). Now the gateway rejects at the boundary
|
|
with ``Envelope.incomplete_input``, so the agent receives a structured
|
|
field-by-field guide (the spec §5.2.1 interrogation pattern).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
from typing import Any
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
from roboco.services.gateway.choreographer import (
|
|
Choreographer,
|
|
ChoreographerDeps,
|
|
DelegateInputs,
|
|
)
|
|
|
|
|
|
def _make_deps(**overrides: Any) -> ChoreographerDeps:
|
|
base: dict[str, Any] = {
|
|
"task": AsyncMock(),
|
|
"work_session": AsyncMock(),
|
|
"git": AsyncMock(),
|
|
"a2a": AsyncMock(),
|
|
"journal": AsyncMock(),
|
|
"audit": AsyncMock(),
|
|
"evidence_repo": AsyncMock(),
|
|
}
|
|
base.update(overrides)
|
|
repo = base["evidence_repo"]
|
|
for method in (
|
|
"list_unread_a2a",
|
|
"list_unread_mentions",
|
|
"list_pending_notifications",
|
|
"task_metadata_gaps",
|
|
"recent_team_activity",
|
|
"blockers_in_lane",
|
|
"journal_highlights_for_task",
|
|
):
|
|
getattr(repo, method).return_value = []
|
|
# C8: default-fresh journal:decision so PM-decision gate passes.
|
|
# Tests that exercise the gate boundary stub their own value.
|
|
# The check matches MagicMock and AsyncMock (the two default sentinel
|
|
# types pytest's unittest.mock leaves on un-stubbed return_values).
|
|
_ldef = base["journal"].latest_decision_at.return_value
|
|
if type(_ldef).__name__ in ("MagicMock", "AsyncMock"):
|
|
base["journal"].latest_decision_at.return_value = datetime.now(UTC)
|
|
return ChoreographerDeps(**base)
|
|
|
|
|
|
def _parent_in_progress(pm_id: Any) -> MagicMock:
|
|
return MagicMock(
|
|
id=uuid4(),
|
|
project_id=uuid4(),
|
|
status="in_progress",
|
|
assigned_to=pm_id,
|
|
priority=2,
|
|
# delegate obligates the PM's quick_context resumption section.
|
|
quick_context="Decomposition planned; cells implement their slice next.",
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delegate_returns_incomplete_input_when_acceptance_criteria_empty() -> (
|
|
None
|
|
):
|
|
"""Empty acceptance_criteria triggers the incomplete_input envelope."""
|
|
pm_id = uuid4()
|
|
parent = _parent_in_progress(pm_id)
|
|
task_svc = AsyncMock()
|
|
task_svc.get.return_value = parent
|
|
task_svc.agent_for.return_value = MagicMock(role="cell_pm", team="backend")
|
|
task_svc.get_subtasks.return_value = []
|
|
deps = _make_deps(task=task_svc)
|
|
c = Choreographer(deps)
|
|
|
|
env = await c.delegate(
|
|
pm_id,
|
|
parent.id,
|
|
DelegateInputs(
|
|
title="Implement endpoint",
|
|
description="Add /v1/foo endpoint with passing tests please",
|
|
assigned_to="be-dev-1",
|
|
team="backend",
|
|
task_type="code",
|
|
nature="technical",
|
|
acceptance_criteria=[], # under-filled — must trigger interrogation
|
|
),
|
|
)
|
|
body = env.as_dict()
|
|
assert body["error"] == "incomplete_input", body
|
|
assert "acceptance_criteria" in body["missing"]
|
|
assert "acceptance_criteria" in body["field_hints"]
|
|
assert "verifiable" in body["field_hints"]["acceptance_criteria"].lower()
|
|
task_svc.create_subtask.assert_not_awaited()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delegate_returns_incomplete_input_when_acceptance_criteria_none() -> (
|
|
None
|
|
):
|
|
"""None acceptance_criteria (missing field) triggers the same envelope."""
|
|
pm_id = uuid4()
|
|
parent = _parent_in_progress(pm_id)
|
|
task_svc = AsyncMock()
|
|
task_svc.get.return_value = parent
|
|
task_svc.agent_for.return_value = MagicMock(role="cell_pm", team="backend")
|
|
task_svc.get_subtasks.return_value = []
|
|
deps = _make_deps(task=task_svc)
|
|
c = Choreographer(deps)
|
|
|
|
env = await c.delegate(
|
|
pm_id,
|
|
parent.id,
|
|
DelegateInputs(
|
|
title="Implement endpoint",
|
|
description="Add /v1/foo endpoint with passing tests please",
|
|
assigned_to="be-dev-1",
|
|
team="backend",
|
|
task_type="code",
|
|
nature="technical",
|
|
acceptance_criteria=None,
|
|
),
|
|
)
|
|
body = env.as_dict()
|
|
assert body["error"] == "incomplete_input", body
|
|
assert "acceptance_criteria" in body["missing"]
|
|
task_svc.create_subtask.assert_not_awaited()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delegate_rejects_silent_fallback_phrase() -> None:
|
|
"""The denylist catches the legacy 'completed and reviewed by assignee' string."""
|
|
pm_id = uuid4()
|
|
parent = _parent_in_progress(pm_id)
|
|
task_svc = AsyncMock()
|
|
task_svc.get.return_value = parent
|
|
task_svc.agent_for.return_value = MagicMock(role="cell_pm", team="backend")
|
|
task_svc.get_subtasks.return_value = []
|
|
deps = _make_deps(task=task_svc)
|
|
c = Choreographer(deps)
|
|
|
|
env = await c.delegate(
|
|
pm_id,
|
|
parent.id,
|
|
DelegateInputs(
|
|
title="Implement endpoint",
|
|
description="Add /v1/foo endpoint with passing tests please",
|
|
assigned_to="be-dev-1",
|
|
team="backend",
|
|
task_type="code",
|
|
nature="technical",
|
|
acceptance_criteria=["completed and reviewed by assignee"],
|
|
),
|
|
)
|
|
body = env.as_dict()
|
|
assert body["error"] == "incomplete_input", body
|
|
assert "acceptance_criteria" in body["missing"]
|
|
# The denylist hint should mention the placeholder/legacy fallback.
|
|
hint = body["field_hints"]["acceptance_criteria"].lower()
|
|
assert "placeholder" in hint or "legacy" in hint or "rejected" in hint
|
|
task_svc.create_subtask.assert_not_awaited()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delegate_returns_incomplete_input_when_nature_missing() -> None:
|
|
"""Missing nature is also caught by task_completeness check."""
|
|
pm_id = uuid4()
|
|
parent = _parent_in_progress(pm_id)
|
|
task_svc = AsyncMock()
|
|
task_svc.get.return_value = parent
|
|
task_svc.agent_for.return_value = MagicMock(role="cell_pm", team="backend")
|
|
task_svc.get_subtasks.return_value = []
|
|
deps = _make_deps(task=task_svc)
|
|
c = Choreographer(deps)
|
|
|
|
env = await c.delegate(
|
|
pm_id,
|
|
parent.id,
|
|
DelegateInputs(
|
|
title="Implement endpoint",
|
|
description="Add /v1/foo endpoint with passing tests please",
|
|
assigned_to="be-dev-1",
|
|
team="backend",
|
|
task_type="code",
|
|
nature=None, # not declared
|
|
acceptance_criteria=["GET /v1/foo returns 200 with body"],
|
|
),
|
|
)
|
|
body = env.as_dict()
|
|
assert body["error"] == "incomplete_input", body
|
|
assert "nature" in body["missing"]
|
|
task_svc.create_subtask.assert_not_awaited()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delegate_passes_when_payload_complete() -> None:
|
|
"""Fully-populated payload still creates the subtask (no regression)."""
|
|
pm_id = uuid4()
|
|
parent = _parent_in_progress(pm_id)
|
|
new_task = MagicMock(id=uuid4())
|
|
task_svc = AsyncMock()
|
|
task_svc.get.return_value = parent
|
|
task_svc.agent_for.return_value = MagicMock(role="cell_pm", team="backend")
|
|
task_svc.get_subtasks.return_value = []
|
|
task_svc.create_subtask.return_value = new_task
|
|
deps = _make_deps(task=task_svc)
|
|
c = Choreographer(deps)
|
|
|
|
env = await c.delegate(
|
|
pm_id,
|
|
parent.id,
|
|
DelegateInputs(
|
|
title="Implement endpoint",
|
|
description="Add /v1/foo endpoint with passing tests please",
|
|
assigned_to="be-dev-1",
|
|
team="backend",
|
|
task_type="code",
|
|
nature="technical",
|
|
acceptance_criteria=["GET /v1/foo returns 200 with body"],
|
|
),
|
|
)
|
|
assert env.error is None, env.as_dict()
|
|
task_svc.create_subtask.assert_awaited_once()
|
|
# Verify nature threaded through to TaskCreateRequest.
|
|
req = task_svc.create_subtask.call_args.args[0]
|
|
assert str(req.nature) == "technical" or req.nature.value == "technical"
|