Files
roboco/tests/unit/gateway/test_tracing_gap_hints.py
T
aa15dc40cc Feature/video artifact verification (#537)
* fix(release): CI wait polls the prod rung; escape the header tooltip apostrophe

get_latest_ci_conclusion defaults to the ladder's head rung, so
wait_for_ci searched slave for a release commit that lives on master
and timed out after 40 minutes with the run already green. The wait
now passes the prod branch explicitly. Also fixes the
react/no-unescaped-entities error that turned master's Panel CI red.

* fix(panel,video): dead dialog triggers behind tooltips; dotted composition ids render

HelpTip nested inside a Dialog/AlertDialog trigger puts the trigger's
click handler on the Tooltip root, which renders no DOM — the agents
Spawn item and the KB Reindex-All / Delete-index confirms were dead.
Tooltips now wrap the triggers. The video renderer accepts interior
single dots in composition ids (release-0.25.0) with '..' still
unrepresentable, and propose_video refuses an unrenderable id at
authoring time.

* fix(dispatch): restart-safe PM review turns

A leaf task in awaiting_pm_review had no periodic pickup: the closure
dispatcher bailed on childless tasks and skipped PR-bearing review
tasks as already-promoted, assuming the submit-time PM session was
still alive — an assumption every restart breaks. Proven live on the
docs-sync leaf after the 0.25.0 redeploy, which also dependency-blocked
its sibling dev task. Childless awaiting_pm_review tasks now flow to
the PM's review turn, and the merge turn respawns its PM when none is
active.

* feat(video): verify the rendered artifact, not the source

The 14s release-0.25.0 cut shipped with only one of four scenes visibly
registering: the dev authored DOM, the smoke asserted DOM, QA read code —
nobody consumed the rendered MP4 before the CEO did. Close that loop, and
the reject loop behind it:

- sidecar frames mode: POST /render with frames=1..32 renders the cut,
  ffprobes the REAL duration, extracts midpoint-sampled keyframe PNGs
  (timestamps in filenames), streams a tar.gz back with X-Video-Duration
- request_render do-verb (developer/QA, request_sandbox's shape): renders
  the caller's ACTUAL composition — dev's own worktree (head_sha/dirty
  provenance), QA a read-only git-archive export of the assembled branch —
  extracts frames to the container-shared .previews/ path, stamps the
  render_preview marker, returns the paths as envelope evidence
- gate: i_am_done on a source=video task refuses without a stamped
  render_preview (Requirement.RENDER_VERIFIED; canonical source string
  moved to foundation as markers.VIDEO_TASK_SOURCE; mirrored in the
  possibilities-matrix fast path so it cannot bypass the check)
- QA claim_review evidence carries video_context (composition id, the
  dev's preview, a re-render instruction) so review checks output
- dev spawn prompt block + a 4th authoring AC order Read-every-frame
  verification before submitting
- reject -> re-author: a CEO reject with a reason opens a fresh authoring
  task carrying the verbatim feedback + a revise-in-place pointer at the
  existing composition (best-effort, never fails the reject) — rejection
  feedback no longer dies on the cancelled draft

E2E: rendered the committed release-0.25.0 composition through the new
frames mode locally — the returned keyframes show exactly the reported
failure (blank frame at 5.8s, only 'Env ladder' by 12.8s), the check the
fleet was missing.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-07-16 19:49:26 +02:00

186 lines
6.6 KiB
Python

"""Task #159: tracing-gap remediate covers every missing requirement.
Pre-fix:
`journal:during_work>=1` (and a handful of other tokens) had no entry
in `_hint_for_missing_key`'s `simple_hints` dict. When the
requirement was missing, the agent saw the token in `missing[]` but
the `remediate` string contained NO instruction for how to satisfy
it. The agent fixed the items with hints, retried, hit the same
rejection again on the unhinted token, and looped.
Fix:
Register hints for the previously-unhinted tokens
(`journal:during_work>=1`, `journal:struggle`, `commits>=1`,
`pr_open`, `self_verified`). Multi-hint remediate switches to a
numbered list so the model sees each requirement as a distinct
instruction instead of a semicolon-blob.
"""
from __future__ import annotations
from unittest.mock import AsyncMock
from uuid import uuid4
import pytest
from roboco.services.gateway.choreographer import Choreographer, ChoreographerDeps
_MIN_HINT_LEN = 10
def _build_choreographer() -> Choreographer:
deps = ChoreographerDeps(
task=AsyncMock(),
work_session=AsyncMock(),
git=AsyncMock(),
a2a=AsyncMock(),
journal=AsyncMock(),
audit=AsyncMock(),
evidence_repo=AsyncMock(),
)
repo = deps.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 = []
return Choreographer(deps)
# ---------------------------------------------------------------------------
# Hint registration — every previously-unhinted token now has a hint
# ---------------------------------------------------------------------------
@pytest.mark.parametrize(
"token",
[
"journal:during_work>=1",
"journal:struggle",
"commits>=1",
"pr_open",
"self_verified",
"render_preview",
],
)
def test_hint_registered_for_previously_unhinted_token(token: str) -> None:
"""Every requirement token must have a non-empty hint so the agent
knows how to satisfy it."""
hint = Choreographer._hint_for_missing_key(token, uuid4())
assert hint is not None, (
f"requirement token {token!r} has no hint; agent will see the "
f"token in `missing[]` but no actionable instruction"
)
assert len(hint) > _MIN_HINT_LEN, (
f"hint for {token!r} is suspiciously short: {hint!r}"
)
def test_during_work_hint_warns_reflect_doesnt_count() -> None:
"""The during_work hint must explicitly say reflect doesn't satisfy
it — that's the exact confusion smoke-10's be-dev-1 hit."""
hint = Choreographer._hint_for_missing_key("journal:during_work>=1", uuid4())
assert hint is not None
lower = hint.lower()
assert "reflect" in lower and (
"does not count" in lower
or "doesn't count" in lower
or "do not count" in lower
or "not count" in lower
), f"during_work hint must warn that scope='reflect' doesn't satisfy this: {hint!r}"
def test_render_preview_hint_mentions_request_render() -> None:
"""The render_preview hint must name the exact next call (request_render)."""
hint = Choreographer._hint_for_missing_key("render_preview", uuid4())
assert hint is not None
assert "request_render" in hint
# ---------------------------------------------------------------------------
# Multi-hint remediate — numbered list, not semicolon-joined
# ---------------------------------------------------------------------------
@pytest.mark.asyncio
async def test_single_missing_remediate_is_plain_string() -> None:
"""One missing item: remediate is the hint itself, no numbering."""
c = _build_choreographer()
env = await c._build_tracing_gap(uuid4(), uuid4(), ["journal:reflect"])
body = env.as_dict()
assert body["error"] == "tracing_gap"
assert body["missing"] == ["journal:reflect"]
assert "Multiple requirements missing" not in (body["remediate"] or "")
assert "1." not in (body["remediate"] or "")
@pytest.mark.asyncio
async def test_multi_missing_remediate_is_numbered_list() -> None:
"""Multiple missing items: remediate must be a numbered list so the
agent treats each as a distinct step."""
c = _build_choreographer()
env = await c._build_tracing_gap(
uuid4(),
uuid4(),
["journal:reflect", "journal:during_work>=1", "commits>=1"],
)
body = env.as_dict()
remediate = body["remediate"] or ""
assert "Multiple requirements missing" in remediate, remediate
assert "1." in remediate
assert "2." in remediate
assert "3." in remediate
# All three hints must be substring-present (proves each was emitted).
assert "reflect" in remediate.lower()
assert "during" in remediate.lower() or "decision" in remediate.lower()
assert "commit" in remediate.lower()
@pytest.mark.asyncio
async def test_unhinted_token_still_appears_in_remediate() -> None:
"""If a future requirement is added without a hint (defense), the
agent at least sees the literal token in the remediate — not silently
dropped."""
c = _build_choreographer()
env = await c._build_tracing_gap(
uuid4(),
uuid4(),
["unknown_future_requirement"],
)
body = env.as_dict()
remediate = body["remediate"] or ""
assert "unknown_future_requirement" in remediate, (
f"unhinted token must surface in remediate as fallback. Got: {remediate!r}"
)
@pytest.mark.asyncio
async def test_acceptance_criteria_grouped_into_one_hint() -> None:
"""Acceptance criteria entries collapse into a single hint regardless
of how many criteria are missing (so 5 unaddressed criteria don't
produce 5 separate numbered items)."""
c = _build_choreographer()
task_id = uuid4()
env = await c._build_tracing_gap(
uuid4(),
task_id,
[
"acceptance_criterion:Branch named correctly",
"acceptance_criterion:Commit prefix present",
"acceptance_criterion:PR opened",
],
)
body = env.as_dict()
remediate = body["remediate"] or ""
# All three criterion names should appear in the SAME hint section
# (collapsed into one hint, not three separate numbered items).
assert "Branch named correctly" in remediate
assert "Commit prefix present" in remediate
assert "PR opened" in remediate
# Single-hint case → no "Multiple requirements" preamble.
assert "Multiple requirements missing" not in remediate