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
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:
@@ -459,6 +459,15 @@ async def test_guard_groups(project_id: int, top: int = 10) -> dict:
|
||||
tests whose sets match exactly across files. Within one file a shared
|
||||
subject is a table of cases, so it never forms a group.
|
||||
|
||||
Groups come smallest first, each with a `kind`. "copies" (three tests
|
||||
or fewer) is where one test most often checks nothing another does not.
|
||||
"area" is one feature tested from several files: a test that drives a
|
||||
feature through its entry point reaches exactly that entry point,
|
||||
whatever behaviour it checks, so the group gathers the feature's
|
||||
tests. Its usual verdict is to fold the scattered files' cases into
|
||||
the feature's own test file, and to remove only the ones another
|
||||
test already covers.
|
||||
|
||||
A group is a candidate, not a verdict. Read the tests, then either:
|
||||
- classify_shapes one of them `redundant` with `covered_by` naming the
|
||||
test that checks everything it checks, and a reason — then delete it;
|
||||
@@ -472,10 +481,11 @@ async def test_guard_groups(project_id: int, top: int = 10) -> dict:
|
||||
|
||||
Args:
|
||||
project_id: The project whose suite to read.
|
||||
top: How many groups to return, largest first; `count` says how many
|
||||
top: How many groups to return, smallest first; `count` says how many
|
||||
there are.
|
||||
|
||||
Returns {"count": N, "groups": [{"key", "guards": [{id, path, symbol}],
|
||||
Returns {"count": N, "groups": [{"key", "kind", "files",
|
||||
"guards": [{id, path, symbol}],
|
||||
"tests": [{id, path, symbol, status, signals}]}]}.
|
||||
"""
|
||||
from grimoire.services import access
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user