feat(8246): the code index links each test to what it guards, and can say redundant or unused
CI & Build / Plugin hooks (push) Successful in 20s
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 41s
CI & Build / Python tests (push) Failing after 2m8s
CI & Build / integration (push) Successful in 2m24s
CI & Build / Build & push image (push) Skipped

Every coverage refresh now reads, for each test in a bound repo, which product
shapes its body exercises: through module aliases and imports, following test
helpers, with mocked names left out and shapes most test files reach dropped as
hubs. Tests in different files that guard exactly the same set form a group.
The project page lists the groups and a person can mark one test redundant,
naming the test that covers it, or keep them all with a reason. Agents get
test_guard_groups and review_test_group, and classify_shapes takes the two new
removal verdicts, redundant (with covered_by) and unused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 21:17:48 -05:00
co-authored by Claude Opus 5.5
parent 134dd68274
commit 865465ce8f
19 changed files with 1412 additions and 27 deletions
+37 -4
View File
@@ -301,6 +301,7 @@ async def provisional_row(
async def _judge(
session, row: CodeShape, *, status: str, snippet_id: int | None,
by: str | None, reason: str | None, at: datetime, reason_code: str | None = None,
covered_by_id: int | None = None,
) -> None:
"""Apply a judgment to a row — the ONE place a status is set — and write
its history. Clears what a judgment settles: the standing proposal, the
@@ -310,6 +311,7 @@ async def _judge(
withdrawal too."""
row.status = status
row.snippet_id = snippet_id if status in _NEEDS_TARGET else None
row.covered_by_id = covered_by_id if status == "redundant" else None
row.reason = (reason or "").strip() or None
row.reason_code = (reason_code or "").strip() or None
row.classified_by = by if status != "unclassified" else None
@@ -621,12 +623,19 @@ async def live_rows(project_id: int) -> list[CodeShape]:
# Statuses an explicit classification may set. All five: setting a row back to
# `unclassified` is how a judgment is deliberately withdrawn.
_SETTABLE = ("canonical", "instance", "variant", "exempt", "unclassified")
_SETTABLE = (
"canonical", "instance", "variant", "exempt", "redundant", "unused", "unclassified",
)
# Statuses that are a verdict on the shape itself and take a reason: a
# deliberate departure, a one-off, and the two removal verdicts.
_NEEDS_REASON = ("variant", "exempt", "redundant", "unused")
# Who may appear as the classifier on this path. `hook` and `mechanical` are
# server-internal feeds (steps 5-6) — a caller claiming them would launder a
# judgment as machinery.
_CALLER_VIAS = ("agent", "audit", "import")
# The web UI's own judgments, which only the routes may claim.
_PERSON_VIA = "person"
def validate_classifications(items: list[dict]) -> str | None:
@@ -657,11 +666,21 @@ def validate_classifications(items: list[dict]) -> str | None:
f"classifications[{i}]: status {status!r} needs snippet_id (or idea_id) — "
"the snippet this shape is (or departs from)"
)
if status in ("variant", "exempt") and not (item.get("reason") or "").strip():
if status in _NEEDS_REASON and not (item.get("reason") or "").strip():
return (
f"classifications[{i}]: status {status!r} needs a reason — "
"the WHY is the record"
)
cover = item.get("covered_by")
if status == "redundant":
if not isinstance(cover, dict) or not (cover.get("path") or "").strip() \
or not (cover.get("symbol") or "").strip():
return (
f"classifications[{i}]: status 'redundant' needs covered_by "
"{path, symbol} — the shape that already does its job"
)
if (cover["path"].strip(), cover["symbol"].strip()) == (path, symbol):
return f"classifications[{i}]: a shape cannot be covered by itself"
code = (item.get("reason_code") or "").strip()
if code and code not in REASON_CODES:
return (
@@ -708,7 +727,7 @@ async def classify_shapes(
from grimoire.services import access
from grimoire.services import snippets as snippets_svc
if via not in _CALLER_VIAS:
if via not in _CALLER_VIAS and via != _PERSON_VIA:
raise ValueError(f"via must be one of: {', '.join(_CALLER_VIAS)}")
classifications = await _resolve_ideas(user_id, classifications)
error = validate_classifications(classifications)
@@ -779,13 +798,27 @@ async def classify_shapes(
})
continue
status = item["status"]
cover_id = None
if status == "redundant":
# The cover is a live row of this project, resolved exactly
# like the shape being judged; a cover no row matches is an
# error, because a redundant verdict without its cover is the
# one claim nobody can check.
cover = item["covered_by"]
covers = by_key.get((cover["path"].strip(), cover["symbol"].strip())) or []
if not covers:
raise ValueError(
f"covered_by {cover['path']}::{cover['symbol']} matches no live shape "
f"in project {project_id}"
)
cover_id = covers[0].id
for row in matches:
touched.update(x for x in (row.snippet_id, item.get("snippet_id")) if x)
await _judge(
session, row, status=status,
snippet_id=int(item["snippet_id"]) if status in _NEEDS_TARGET else None,
by=via, reason=item.get("reason"), at=now,
reason_code=item.get("reason_code"),
reason_code=item.get("reason_code"), covered_by_id=cover_id,
)
if item.get("uses"):
await record_uses(session, row, item["uses"], basis=via,