fix(8249): test groups come smallest first, and a big one is read as a feature area
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 2m14s
CI & Build / integration (push) Successful in 2m28s
CI & Build / Build & push image (push) Successful in 35s

A group is the set of tests reaching the same code from different files. A
test that drives a feature through its one entry point reaches exactly that
entry point whatever it checks, so the largest groups are a feature tested
from many files, not copies. Listing them first buried the two- and
three-test groups where one-for-one duplicates are. The readout, the tool and
the panel now list smallest first; each group says copies or area and how
many files it spans, and the panel tells an area to fold its scattered cases
into one file. Plugin 2026.12.01.0748.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 02:49:06 -05:00
co-authored by Claude Opus 5.5
parent 70ca2e8a11
commit 7c7a1a7ab9
6 changed files with 62 additions and 9 deletions
+24 -5
View File
@@ -382,7 +382,9 @@ def same_guard_groups(
"""Tests that guard exactly the same non-empty set of shapes from more
than one file: `tests` are (test shape id, path, guarded shape ids).
Within one file a shared subject is a table of cases, so a group must
span files. Largest first."""
span files. Smallest first: two or three tests reaching the same code
from different files are the likeliest one-for-one copies, while a big
group is usually one feature tested from many files (`group_kind`)."""
by_set: dict[frozenset[int], list[tuple[int, str]]] = defaultdict(list)
for tid, path, guarded in tests:
if guarded:
@@ -392,10 +394,24 @@ def same_guard_groups(
for guarded, members in by_set.items()
if len({p for _t, p in members}) > 1
]
out.sort(key=lambda g: (-len(g[1]), g[1][0]))
out.sort(key=lambda g: (len(g[1]), g[1][0]))
return out
# A group of more tests than this is read as a feature AREA rather than as
# candidate copies: a test that drives a feature through its one public
# entry point reaches exactly that entry point whatever behaviour it checks,
# so every test of the feature lands in one group. Its useful verdict is
# usually merging the scattered files' cases into the feature's own file.
SMALL_GROUP = 3
def group_kind(n_tests: int) -> str:
""""copies" for a group small enough to read as possible duplicates,
"area" for one feature tested from several files."""
return "copies" if n_tests <= SMALL_GROUP else "area"
# --- the ledger side ---------------------------------------------------------
# Statuses whose test has had its verdict: it leaves every group.
@@ -501,9 +517,10 @@ def _shape_ref(row) -> dict:
async def guard_groups(project_id: int, *, top: int = GROUPS_SHOWN) -> dict:
"""Tests that guard exactly the same shapes from more than one file, and
have not been reviewed as distinct: {"count", "groups": [...]}, largest
first. Each group carries what its tests guard and, per test, its weak
signals, status and the key a review is recorded under."""
have not been reviewed as distinct: {"count", "groups": [...]}, smallest
first. Each group carries its `kind` ("copies" or "area", see
`group_kind`), how many files it spans, what its tests guard and, per
test, its weak signals, status and the key a review is recorded under."""
from sqlalchemy import select
from grimoire.models import async_session
@@ -543,6 +560,8 @@ async def guard_groups(project_id: int, *, top: int = GROUPS_SHOWN) -> dict:
continue
out.append({
"key": key,
"kind": group_kind(len(members)),
"files": len({by_id[t].path for t in members}),
"guards": sorted((_shape_ref(by_id[x]) for x in g), key=lambda d: (d["path"], d["symbol"])),
"tests": [
{**_shape_ref(by_id[t]), "status": by_id[t].status,