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 @@ + + + + + diff --git a/frontend/src/views/ProjectView.vue b/frontend/src/views/ProjectView.vue index e55db8f8..ee6c114d 100644 --- a/frontend/src/views/ProjectView.vue +++ b/frontend/src/views/ProjectView.vue @@ -18,6 +18,7 @@ import { canWriteRecord } from "@/utils/permission"; import ProjectRulesTab from "@/components/rules/ProjectRulesTab.vue"; import SystemsSection from "@/components/SystemsSection.vue"; import InceptionCard from "@/components/InceptionCard.vue"; +import TestGuardReview from "@/components/TestGuardReview.vue"; import { fmtDate } from "@/utils/dateFormat"; import type { InceptionDecision, InceptionRecord } from "@/api/inception"; import { @@ -498,6 +499,8 @@ interface Coverage { divergent?: number; divergence?: Divergence[]; recheck?: number; + // Same-guard test groups awaiting a verdict (TestGuardReview). + test_groups?: number; } interface Divergence { path: string; @@ -834,7 +837,7 @@ async function confirmDelete() {
@@ -888,6 +891,12 @@ async function confirmDelete() { {{ coverage.recheck }} to recheck
+

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..9bdf5795 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", + "version": "2026.12.01.0217", "author": { "name": "Bryan Van Deusen" }, diff --git a/plugin/skills/shape-accounting/SKILL.md b/plugin/skills/shape-accounting/SKILL.md index 640b5f4a..3baae236 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,16 @@ 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. + ## 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..720a901f 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,9 @@ 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 | 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