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
+67
View File
@@ -227,6 +227,73 @@ async def refresh_coverage_route(project_id: int):
return jsonify({"coverage": coverage})
@projects_bp.route("/<int:project_id>/test-guards", methods=["GET"])
@login_required
async def test_guard_groups_route(project_id: int):
"""Tests that guard the same thing from different files, not yet
reviewed — the coverage card's merge-or-remove queue."""
from grimoire.services import test_guards
uid = get_current_user_id()
if await get_project_for_user(uid, project_id) is None:
return not_found("Project")
return jsonify(await test_guards.guard_groups(project_id))
@projects_bp.route("/<int:project_id>/test-guards/review", methods=["POST"])
@login_required
async def review_test_group_route(project_id: int):
"""Keep every test in a group: body {"test_ids": [...], "reason": "..."}."""
from grimoire.services import test_guards
uid = get_current_user_id()
data = await request.get_json() or {}
try:
review = await test_guards.review_group(
uid, project_id, data.get("test_ids") or [],
reason=data.get("reason") or "", by="person",
)
except ValueError as exc:
return jsonify({"error": str(exc)}), 400
return jsonify(review)
@projects_bp.route("/<int:project_id>/test-guards/redundant", methods=["POST"])
@login_required
async def mark_test_redundant_route(project_id: int):
"""Judge one test redundant: body {"test_id", "covered_by_id", "reason"}.
The same verdict classify_shapes records, made by a person."""
from sqlalchemy import select
from grimoire.models import async_session
from grimoire.models.code_shape import CodeShape
from grimoire.services import shape_ledger
from grimoire.services import access
uid = get_current_user_id()
if not await access.can_write_project(uid, project_id):
return not_found("Project")
data = await request.get_json() or {}
ids = [int(data.get("test_id") or 0), int(data.get("covered_by_id") or 0)]
async with async_session() as session:
rows = {r.id: r for r in (await session.execute(
select(CodeShape).where(CodeShape.project_id == project_id, CodeShape.id.in_(ids))
)).scalars().all()}
if any(i not in rows for i in ids):
return jsonify({"error": "both tests must be live shapes of this project"}), 400
test, cover = rows[ids[0]], rows[ids[1]]
try:
out = await shape_ledger.classify_shapes(uid, project_id, [{
"path": test.path, "symbol": test.symbol, "kind": test.kind,
"status": "redundant", "reason": data.get("reason") or "",
"covered_by": {"path": cover.path, "symbol": cover.symbol},
}], via="person")
except ValueError as exc:
return jsonify({"error": str(exc)}), 400
return jsonify(out)
@projects_bp.route("/<int:project_id>/forge", methods=["PUT"])
@login_required
async def set_project_forge_route(project_id: int):