Files
roboco/tests/unit/gateway/test_remediation.py
T
23ae0ca217 fix(gateway): covers_parent_criteria hint that teaches the shape; CEO pause/resume (#686)
* fix(gateway): teach the delegate remediate + PM prompt the covers_parent_criteria shape; allow CEO through the plain pause route

- A child draft rejected for missing covers_parent_criteria now gets a
  copy-pasteable corrected skeleton with the parent's real criteria
  inlined, and the PM delegation guidance shows the field as part of
  every child draft — a PM no longer loops on a rejection that named
  the field but never showed the shape.
- The plain pause route now authorizes the CEO tier like its sibling
  lifecycle routes; agent-side pause restrictions are unchanged.

* fix(gateway): delegate-coverage hint heals and degrades on legacy parents

- The coverage-reject path self-heals a criteria-bearing parent whose
  ids are empty or out of length before rendering the hint, so the
  skeleton always shows real references; the renderer itself also
  falls back to quoted criterion texts for any criterion without an
  id instead of emitting a placeholder or truncating the listing.
- The remediate names both legal reference forms (id or exact text)
  again.
- Route comments state the pause/resume check as deliberately
  CEO-only instead of claiming a precedent whose role set is wider.

* test(gateway): real TaskTable rows in the remediation hint round-trips

mypy over tests/ rejects a SimpleNamespace where unknown_ac_refs takes a
TaskTable; instantiating the ORM row directly needs no session and types
cleanly.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-07-24 17:10:20 +02:00

91 lines
3.1 KiB
Python

"""Tests for remediation hint generation."""
from __future__ import annotations
from roboco.db.tables import TaskTable
from roboco.services.gateway.remediation import (
hint_for_missing_ac_coverage,
hint_for_missing_progress,
hint_for_missing_reflect,
hint_for_unaddressed_acceptance_criteria,
)
from roboco.services.task import TaskService
def test_missing_progress_hint() -> None:
h = hint_for_missing_progress()
assert "commit" in h.lower() or "progress" in h.lower()
def test_missing_reflect_hint() -> None:
h = hint_for_missing_reflect(task_id="xyz-789")
assert "note(scope='reflect'" in h
assert "xyz-789" in h
def test_unaddressed_criteria_hint() -> None:
h = hint_for_unaddressed_acceptance_criteria(
criteria=["criterion 1", "criterion 3"], task_id="t-1"
)
assert "criterion 1" in h
assert "criterion 3" in h
assert "t-1" in h
def test_missing_ac_coverage_hint_shows_call_shape_and_real_ids() -> None:
h = hint_for_missing_ac_coverage(
ids=["id-a", "id-b"],
texts=["Criterion A", "Criterion B"],
title="Orphan slice",
)
assert "delegate(title='Orphan slice'" in h
assert "covers_parent_criteria=['id-a']" in h
assert 'id-a="Criterion A"' in h
assert 'id-b="Criterion B"' in h
def test_missing_ac_coverage_hint_names_both_legal_reference_forms() -> None:
"""The remediate names both legal ``covers_parent_criteria`` forms —
a criterion's id or its exact text — not just id."""
h = hint_for_missing_ac_coverage(ids=["id-a"], texts=["Criterion A"], title="X")
assert "id(s) or exact text(s)" in h
def test_missing_ac_coverage_hint_handles_no_criteria() -> None:
h = hint_for_missing_ac_coverage(ids=[], texts=[], title="X")
assert "<id>" in h
def test_missing_ac_coverage_hint_empty_ids_uses_quoted_text() -> None:
"""A legacy/unhealed parent whose ids are empty must still get a real,
copy-pasteable reference for every criterion — never a `'<id>'`
placeholder, and never a truncated listing."""
texts = ["Criterion A", "Criterion B", "Criterion C"]
h = hint_for_missing_ac_coverage(ids=[], texts=texts, title="Orphan slice")
assert "'<id>'" not in h
for text in texts:
assert text in h
parent = TaskTable(acceptance_criteria_ids=[], acceptance_criteria=texts)
for text in texts:
assert TaskService.unknown_ac_refs(parent, [text]) == []
def test_missing_ac_coverage_hint_drifted_ids_shorter_than_criteria() -> None:
"""1 id against 3 criteria: every criterion is listed (id for the
first, quoted text for the rest) — zip's `strict=False` used to drop
the tail criteria silently."""
texts = ["Criterion A", "Criterion B", "Criterion C"]
h = hint_for_missing_ac_coverage(ids=["id-a"], texts=texts, title="Orphan slice")
assert "'<id>'" not in h
assert 'id-a="Criterion A"' in h
for text in texts[1:]:
assert text in h
parent = TaskTable(acceptance_criteria_ids=["id-a"], acceptance_criteria=texts)
assert TaskService.unknown_ac_refs(parent, ["id-a"]) == []
for text in texts[1:]:
assert TaskService.unknown_ac_refs(parent, [text]) == []