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:
@@ -21,6 +21,8 @@ interface GroupTest extends ShapeRef {
|
||||
}
|
||||
interface Group {
|
||||
key: string;
|
||||
kind: "copies" | "area";
|
||||
files: number;
|
||||
guards: ShapeRef[];
|
||||
tests: GroupTest[];
|
||||
}
|
||||
@@ -145,6 +147,10 @@ watch(() => props.projectId, load);
|
||||
</p>
|
||||
<ul v-else class="tg-list">
|
||||
<li v-for="g in groups" :key="g.key" class="tg-group">
|
||||
<p v-if="g.kind === 'area'" class="tg-kind">
|
||||
One feature tested from {{ g.files }} files: fold the scattered
|
||||
cases into its own test file, and remove only what another test covers.
|
||||
</p>
|
||||
<div class="tg-guards">
|
||||
<span class="tg-label">Guard</span>
|
||||
<code v-for="s in g.guards" :key="s.id" :title="s.path">{{ s.symbol }}</code>
|
||||
@@ -199,7 +205,8 @@ watch(() => props.projectId, load);
|
||||
</li>
|
||||
</ul>
|
||||
<p v-if="count > groups.length" class="tg-note">
|
||||
Showing {{ groups.length }} of {{ count }}, largest first.
|
||||
Showing {{ groups.length }} of {{ count }}, smallest first: the
|
||||
smallest groups are the likeliest copies.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -229,6 +236,7 @@ watch(() => props.projectId, load);
|
||||
}
|
||||
.tg-guards, .tg-test { display: flex; flex-wrap: wrap; align-items: center; gap: var(--fs-space-2); }
|
||||
.tg-label { color: var(--fs-text-tertiary); }
|
||||
.tg-kind { margin: 0; color: var(--fs-text-secondary); }
|
||||
code { font-family: var(--fs-font-mono); color: var(--fs-text-primary); }
|
||||
.tg-signal {
|
||||
padding: 0 var(--fs-space-2);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "grimoire",
|
||||
"description": "Grimoire for Claude Code: connects the grimoire MCP server, adds the hooks that deliver live project state and relevant records at the right moment, ships the shared client-neutral Grimoire skills (using-grimoire, writing-plans, reporting-back, systematic-debugging, verification, brainstorming, reusing-code, shape-accounting, family-canon, reviewing-tests), and syncs your saved Grimoire Processes as skills (/grimoire:sync).",
|
||||
"version": "2026.12.01.0344",
|
||||
"version": "2026.12.01.0748",
|
||||
"author": {
|
||||
"name": "Bryan Van Deusen"
|
||||
},
|
||||
|
||||
@@ -47,6 +47,12 @@ finish it before starting the next. In each area:
|
||||
with its `signals`: `signature` (pins how code is declared), `mock-only`
|
||||
(asserts only that mocks were called), `source-text` (reads source as
|
||||
text). Signals point at what to read first; they never decide a verdict.
|
||||
Groups come smallest first. A `copies` group (three tests or fewer) is
|
||||
where one-for-one duplicates hide. An `area` group is one feature
|
||||
tested from several files, since every test that drives a feature
|
||||
through its entry point reaches the same code. Read it as one area: fold
|
||||
the scattered cases into the feature's own file, and remove only what
|
||||
another test already checks.
|
||||
2. **Read every test** and give it one verdict:
|
||||
- **keep** — it protects something a user or caller relies on, and
|
||||
nothing else in the suite protects it;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -131,6 +131,16 @@ def test_a_group_spans_files_and_one_file_never_forms_one():
|
||||
assert groups == [(same, [10, 11])]
|
||||
|
||||
|
||||
def test_the_smallest_groups_come_first_and_a_big_one_reads_as_a_feature_area():
|
||||
pair, area = frozenset({1}), frozenset({2})
|
||||
tests = [(10, "tests/test_a.py", pair), (11, "tests/test_b.py", pair)]
|
||||
tests += [(20 + i, f"tests/test_{i % 2}.py", area) for i in range(6)]
|
||||
groups = tg.same_guard_groups(tests)
|
||||
assert [g for g, _members in groups] == [pair, area]
|
||||
assert tg.group_kind(len(groups[0][1])) == "copies"
|
||||
assert tg.group_kind(len(groups[1][1])) == "area"
|
||||
|
||||
|
||||
def test_a_group_is_named_by_its_members_in_any_order():
|
||||
a = tg.group_key([("tests/a.py", "test_1"), ("tests/b.py", "test_2")])
|
||||
assert a == tg.group_key([("tests/b.py", "test_2"), ("tests/a.py", "test_1")])
|
||||
|
||||
Reference in New Issue
Block a user