diff --git a/alembic/versions/0140_test_guards.py b/alembic/versions/0140_test_guards.py
new file mode 100644
index 00000000..1d0b6ba8
--- /dev/null
+++ b/alembic/versions/0140_test_guards.py
@@ -0,0 +1,63 @@
+"""code_shape_guards, code_shape_guard_reviews, and the removal verdicts
+
+Revision ID: 0140
+Revises: 0139
+Create Date: 2026-12-01
+
+What each test guards, read by the coverage sync from the repo archive, so
+the ledger can show tests that guard the same thing from different files:
+- code_shape_guards: test shape -> guarded shape, or -> a repo path.
+ Mechanical, rebuilt by every sync, not backed up.
+- code_shape_guard_reviews: a group judged to be distinct behaviours.
+- code_shapes.covered_by_id: the shape a `redundant` row is covered by.
+- code_shapes.test_signals: a test's weak-test signals from the last sync.
+The statuses `redundant` and `unused` need no schema change: status is a
+plain text column.
+"""
+import sqlalchemy as sa
+from alembic import op
+
+revision = "0140"
+down_revision = "0139"
+branch_labels = None
+depends_on = None
+
+
+def upgrade() -> None:
+ op.add_column("code_shapes", sa.Column(
+ "covered_by_id", sa.Integer(),
+ sa.ForeignKey("code_shapes.id", ondelete="SET NULL"), nullable=True,
+ ))
+ op.add_column("code_shapes", sa.Column(
+ "test_signals", sa.Text(), nullable=False, server_default="",
+ ))
+ op.create_table(
+ "code_shape_guards",
+ sa.Column("id", sa.Integer(), primary_key=True),
+ sa.Column("test_id", sa.Integer(), sa.ForeignKey("code_shapes.id", ondelete="CASCADE"), nullable=False),
+ sa.Column("guarded_id", sa.Integer(), sa.ForeignKey("code_shapes.id", ondelete="CASCADE"), nullable=True),
+ sa.Column("path", sa.Text(), nullable=True),
+ sa.Column("basis", sa.Text(), nullable=False, server_default="static"),
+ )
+ op.create_index("ix_code_shape_guards_test", "code_shape_guards", ["test_id"])
+ op.create_index("ix_code_shape_guards_guarded", "code_shape_guards", ["guarded_id"])
+ op.create_table(
+ "code_shape_guard_reviews",
+ sa.Column("id", sa.Integer(), primary_key=True),
+ sa.Column("project_id", sa.Integer(), sa.ForeignKey("projects.id", ondelete="CASCADE"), nullable=False),
+ sa.Column("group_key", sa.Text(), nullable=False),
+ sa.Column("verdict", sa.Text(), nullable=False, server_default="distinct"),
+ sa.Column("reason", sa.Text(), nullable=False, server_default=""),
+ sa.Column("reviewed_by", sa.Text(), nullable=False),
+ sa.Column("reviewed_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
+ sa.UniqueConstraint("project_id", "group_key", name="uq_code_shape_guard_reviews_group"),
+ )
+
+
+def downgrade() -> None:
+ op.drop_table("code_shape_guard_reviews")
+ op.drop_index("ix_code_shape_guards_guarded", table_name="code_shape_guards")
+ op.drop_index("ix_code_shape_guards_test", table_name="code_shape_guards")
+ op.drop_table("code_shape_guards")
+ op.drop_column("code_shapes", "test_signals")
+ op.drop_column("code_shapes", "covered_by_id")
diff --git a/frontend/src/components/TestGuardReview.vue b/frontend/src/components/TestGuardReview.vue
new file mode 100644
index 00000000..4fc96e9f
--- /dev/null
+++ b/frontend/src/components/TestGuardReview.vue
@@ -0,0 +1,242 @@
+
+
+
+
+ Tests in different files that exercise exactly the same code. Read them:
+ if one checks nothing the other doesn't, mark it redundant and delete it;
+ if each checks something of its own, keep them all and say what.
+ Loading… {{ error }}
+ No tests guard the same thing from different files.
+
+ Showing {{ groups.length }} of {{ count }}, largest first.
+
+
+ {{ s.symbol }}
+
+
+
+
+ {{ label(t) }}
+ {{ sig }}
+
+
Not measured yet — Refresh reads the bound repo's definitions into diff --git a/plugin/.claude-plugin/plugin.json b/plugin/.claude-plugin/plugin.json index d3486fef..75ce7a61 100644 --- a/plugin/.claude-plugin/plugin.json +++ b/plugin/.claude-plugin/plugin.json @@ -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), and syncs your saved Grimoire Processes as skills (/grimoire:sync).", - "version": "2026.11.28.2315", + "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", "author": { "name": "Bryan Van Deusen" }, diff --git a/plugin/README.md b/plugin/README.md index 41a652a6..b4e2ba9f 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -17,7 +17,8 @@ instance into a first-class Claude Code extension: any client's package would ship: using-grimoire, writing-plans, reporting-back (reply to the operator in a shape that says where the work stands), systematic-debugging, verification, brainstorming, reusing-code (record and - recall reusable code as snippets), shape-accounting and family-canon. + recall reusable code as snippets), shape-accounting, family-canon and + reviewing-tests (give every test one verdict and prove the survivors fail). Replaces superpowers. - **Your Grimoire Processes as skills** — saved Processes are synced into local `~/.claude/skills/grimoire-proc-*` stubs that auto-surface by relevance; the diff --git a/plugin/hooks/grimoire_static_context.md b/plugin/hooks/grimoire_static_context.md index 0f1b8fd9..6b7439cc 100644 --- a/plugin/hooks/grimoire_static_context.md +++ b/plugin/hooks/grimoire_static_context.md @@ -6,7 +6,7 @@ once, in the **`using-grimoire`** skill: reach for it at the start of the sessio and whenever you are unsure what Grimoire expects. Each tool's contract is in its description, and the process skills (writing-plans, reporting-back, reusing-code, systematic-debugging, verification, brainstorming, -shape-accounting, family-canon) carry their arcs. +shape-accounting, family-canon, reviewing-tests) carry their arcs. What only Claude Code needs said: diff --git a/plugin/skills/reviewing-tests/SKILL.md b/plugin/skills/reviewing-tests/SKILL.md new file mode 100644 index 00000000..88d1b74e --- /dev/null +++ b/plugin/skills/reviewing-tests/SKILL.md @@ -0,0 +1,91 @@ +--- +name: reviewing-tests +description: Use when a test suite needs reviewing rather than growing — the operator asks to review, prune or tighten tests, CI is slow and the suite only ever grows, the coverage line counts test groups guarding the same thing or tests guarding nothing found, or a project's test standard asks for a review. Triggers on "review the tests", "prune the suite", "too many tests", "redundant tests", "CI is slow", "test standard". Gives each test one verdict, proves the survivors still fail, and lists every removal with its reason. +metadata: + moments: work.verify +--- + +# Reviewing a test suite + +Every change adds tests and nothing removes them, so a suite left alone only +grows: each test costs every CI run, forever, whether or not it still +protects anything. A review is the subtraction pass. It gives every test one +verdict, keeps the ones that earn their place, and leaves a record good +enough that any removal can be argued back. + +## The standard comes from the project, not from this skill + +Look for the project's own test standard first: a family idea it has +adopted (`enter_project` lists ideas under `family`; `get_family_adoption` +reads the project's answer), a rule, or a note — `search` for "test +standard" in the project. Review against it, and use the test levels it +names (unit, database, web, …) for "move" below. With no standard recorded, +the verdicts below are the floor; agree the project's levels with the +operator before moving any test, and offer to record them so the next review +starts from them. + +## Before: the numbers you will compare against + +Write these into the review's task before touching anything: + +- tests **collected**, from a real run's summary (not files, not a grep: a + file that fails to collect reads exactly like a pass); +- lines of test code; +- CI time, from the last few green runs on the main working branch; +- the coverage line's test figures: linked, guarding nothing found, + redundant, and the number of groups guarding the same thing. + +## Area by area + +Take one area at a time, the project's Systems or its test directories, and +finish it before starting the next. In each area: + +1. **Read what the ledger already knows.** `list_shapes(path=)` lists + the test cases; a `test` status means the refresh linked it to something + it guards, `unclassified` means it is linked to nothing. `test_guard_groups` + lists tests in different files that guard exactly the same thing, each + 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. +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; + - **merge** — it checks one case of a behaviour other tests also check: + fold them into one table of cases; + - **rewrite** — the subject is right and the check is weak: it pins a + name, a signature or a mock call where it should pin an outcome; + - **move** — it sits at a level the project's standard puts elsewhere; + - **remove** — another test checks everything it checks + (`redundant`, naming that test), or what it protects no longer matters + to anyone (`unused`). +3. **Record the verdicts where they are kept.** Removals go in the ledger: + `classify_shapes` with `status="redundant"` and `covered_by` {path, + symbol} for a test another covers, `status="unused"` for one nothing + needs, a reason on each. A group judged to be distinct behaviours goes to + `review_test_group` with what each test checks that the others don't. A + test linked to nothing and kept says what it guards in an `exempt` reason. +4. **Break what the survivors claim to protect.** Choose three to five + behaviours the kept tests guard, break each one deliberately in the + product code, and confirm the tests go red; then revert. Run them where + the project's own rules say tests run. A test that stays green while its + behaviour is broken protects nothing, whatever its name says: rewrite it + or remove it. +5. **Land the area as one change** that does nothing but this review, so it + can be reverted alone. Behaviour changes found on the way are their own + issues, never folded in. + +## After + +- Rerun the same numbers and put them beside the baseline in the review's + task. +- List every removed test with its verdict and reason, in that task's log. + The list is what lets someone argue one back. +- A test is never removed to make a red build green. A failing test is a + finding about the code until a reading says otherwise. + +## Report + +Lead with the numbers (tests, lines, CI time, before and after), then the +removals by area with their reasons, then what the deliberate breaks proved +and anything they caught. A test found guarding a real bug's absence that +nobody knew about is the most valuable line in the report; say so plainly. diff --git a/plugin/skills/shape-accounting/SKILL.md b/plugin/skills/shape-accounting/SKILL.md index 640b5f4a..c6c0c23e 100644 --- a/plugin/skills/shape-accounting/SKILL.md +++ b/plugin/skills/shape-accounting/SKILL.md @@ -24,6 +24,10 @@ row carries a status: unreachable from any other file). Accounted for without a judgment; still proposed against, grouped and flagged; any judgment you make overrides it. Not the todo. +- `redundant` — should be removed: `covered_by` names the shape that already + does its job. **Reason required.** Delete the code; the next sync retires + the row. +- `unused` — should be removed: nothing needs it. **Reason required.** - `unclassified` — nobody has judged it yet. **This is the todo list.** ## The loop @@ -181,6 +185,17 @@ Three questions the ledger answers mechanically: one and record the verdict with `classify_shapes` — `instance` if it is, otherwise what it actually is. +## Tests that guard the same thing + +Every refresh links each test to the shapes its body exercises (mocks +excluded), and the coverage line's "N test groups guarding the same thing — +test_guard_groups" counts tests in different files that guard exactly the +same set. A group is a candidate: read the tests, then mark one `redundant` +with the test that covers it, or `review_test_group` with what each checks +that the others don't. Each test's `signals` (signature, mock-only, +source-text) are evidence for that reading, never a verdict. +A whole-suite pass is its own procedure: the reviewing-tests skill. + ## What this buys Divergence becomes mechanical: when button B appears where button A is canon, diff --git a/src/grimoire/mcp/server.py b/src/grimoire/mcp/server.py index f327eccb..c2359d41 100644 --- a/src/grimoire/mcp/server.py +++ b/src/grimoire/mcp/server.py @@ -108,7 +108,7 @@ _READ_ONLY_TOOLS = frozenset({ "list_repo_bindings", # The shape ledger's todo query. Reads only — classify_shapes is # the write, and it is deliberately NOT here. - "list_shapes", "shape_history", "stamps_to_review", + "list_shapes", "shape_history", "stamps_to_review", "test_guard_groups", # The retrieval telemetry readout. Aggregates two log tables and # writes nothing. Listed explicitly because its name carries no read # prefix, so the completeness test below cannot derive it — the same @@ -196,7 +196,7 @@ _WRITE_TOOLS = frozenset({ "merge_snippets", "unmerge_snippet", "create_process", "update_process", "delete_process", "classify_shapes", "classify_shapes_by_rule", "confirm_shape_proposals", - "refresh_pattern_coverage", "move_path", + "refresh_pattern_coverage", "move_path", "review_test_group", # design systems "create_design_system", "update_design_system", "delete_design_system", "create_design_token", "update_design_token", "delete_design_token", diff --git a/src/grimoire/mcp/tools/shapes.py b/src/grimoire/mcp/tools/shapes.py index dcc77f10..1dae61aa 100644 --- a/src/grimoire/mcp/tools/shapes.py +++ b/src/grimoire/mcp/tools/shapes.py @@ -26,6 +26,11 @@ async def classify_shapes( - `variant` of snippet N — a deliberate, named departure. `reason` (the why) is REQUIRED; it is the record. - `exempt` — judged genuinely one-off. `reason` REQUIRED. + - `redundant` — should be removed: another shape already does its + job. `covered_by` {path, symbol} names that shape and `reason` says + why it covers this one — for a test, what the covering test checks + that this one also checked. test_guard_groups lists the candidates. + - `unused` — should be removed: nothing needs it. `reason` REQUIRED. - `canonical` of snippet N — this row IS the snippet's reference (rarely set by hand; the coverage sync stamps these mechanically). - `unclassified` — withdraw a judgment; the shape rejoins the todo. @@ -38,7 +43,7 @@ async def classify_shapes( Args: project_id: The project whose ledger is being judged. classifications: Objects of {path, symbol, status, kind?, snippet_id?, - idea_id?, reason?, reason_code?}. path+symbol name the shape exactly as + idea_id?, reason?, reason_code?, covered_by?}. path+symbol name the shape exactly as list_shapes shows it; kind ("sym"/"css") narrows when one file defines both. snippet_id is required for canonical/instance/ variant — or idea_id, a family idea: the shape is then judged @@ -46,7 +51,7 @@ async def classify_shapes( language, or its first reference when none is in that language (an idea is shared across languages: a Python shape can be an instance of an idea whose reference is Go). reason is required - for variant/exempt. reason_code is + for variant/exempt/redundant/unused. reason_code is an OPTIONAL index beside the prose (one of: scoped-css, one-off-handler, test-helper, convention-plumbing, pure-helper, generated, script, typed-record) so the ledger can be filtered @@ -106,7 +111,11 @@ async def list_shapes( (fed by the coverage refresh). Filters compose: Args: - status: canonical | instance | variant | exempt | scoped | unclassified. + status: canonical | instance | variant | exempt | redundant | unused | + scoped | test | unclassified. `test` is the sync's stamp on a + test case linked to what it guards; a test case linked to + nothing stays `unclassified`. `redundant`/`unused` are the removal + verdicts: the row stays until the code goes. `scoped` is the sync's mechanical stamp on one-offs by construction (a Vue component's scoped