agentleFS
mthinesmthines/agent-skills/skills/quality/test-provenance-guard/SKILL.md

test-provenance-guard

Skill13 starsChanged 2 months agoMITView on GitHub

Detects tests that pass by construction — tests that define a private copy of the function under test instead of importing the production module — and self-heals by extracting the inline logic to an exported function, updating production callers, and rewriting the test to import the export. Two checks: (1) static — the test file must import the SUT and must not shadow its exported names; (2) mutation — blanking the production function body re-runs the test and expects failure. Runs autonomously inside autonomous-workflow Phase 4 and as a slash command for human-driven PR review. Use when adding new tests for existing or refactored code, when CI is green but you are unsure whether the tests actually exercise production, or when reviewing a PR for tests-by-construction. Triggers on "test provenance", "tests by construction", "verify tests cover real code", "tests duplicate logic", "mutation sanity check", "are these tests fake", "/test-provenance-guard".

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If no test files resolve from either --diff or positional args, exit cleanly with no test files in scope, skipping.

    line 84
  2. Distinctive:

    After every run, emit a structured report.

    line 154
  3. Very specific:

    When called from autonomous-workflow Phase 4, also append one line to .agent/{branch}/plan.md's Progress Log:

    line 175
  4. Distinctive:

    No test files? Exit 0. Test files in unsupported languages?

    line 196
  5. Distinctive:

    Test files in unsupported languages?

    line 197
  6. Very specific:

    Every sabotage step is paired with a restore — git restore <sut-file> when the file was clean, or moving the recorded backup over it when …

    line 207

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Test Provenance Guard

Catches the failure mode where a new test file re-implements the function it claims to test, then asserts against its own copy. The tests pass. The CI is green. The tests provide zero regression protection.

This skill detects that pattern and, when invoked autonomously, fixes it without user intervention.

This SKILL.md is a thin index. Detailed procedures live in rules/*.md and load on demand. The case-study post-mortem and failure-mode taxonomy live in references/*.md.


Contents

  • Inputs
  • Workflow
  • Quick Decision Flow
  • Required Reading by Phase
  • Output Contract
  • Core Principles
  • Anti-patterns
  • Definition of Done
  • Related Skills

Inputs

Parse $ARGUMENTS:

ArgumentDefaultMeaning
--diffoffDiscover changed test files via git diff --name-only <base>...HEAD.
--base <ref>mainBase ref for --diff.
<positional paths>—Explicit test files to check (overrides --diff).
--mode static|mutate|bothbothWhich checks to run.
--fixon when called from autonomous-workflow; off for slash invocationApply self-heal: extract logic, rewrite tests, re-verify. Gated by confidence(code) ≥ 90 % unless --no-confidence-gate is passed.
--report-onlyoffForce off --fix even when called from autonomous-workflow.
--no-confidence-gateoffManual override — skip the pre-heal confidence gate. Reserved for human-driven slash invocations; never set inside the autonomous loop.

The skill defaults to --fix in the autonomous loop, but autofix is gated by Skill("confidence", "code") ≥ 90 % before any file is mutated (see Self-Heal Step 3). Below the threshold, the heal is skipped, the finding is emitted as heal-skipped-low-confidence, and the autonomous-workflow's stuck-loop protocol takes over.

Manual slash invocation defaults to report-only so a human can review the proposed extraction first; pass --fix explicitly to apply. The confidence gate is recommended for manual invocations too, but a human can pass --no-confidence-gate to override.

If no test files resolve from either --diff or positional args, exit cleanly with no test files in scope, skipping.


Workflow

PhaseNameRule fileGate
1Static checkrules/static-check.mdEvery test file imports the SUT; no shadowed exports
2Mutation checkrules/mutation-check.mdSabotaged production code makes the test FAIL
3Self-heal (if --fix)rules/self-heal.mdconfidence(code) ≥ 90 % on the proposed extraction; extracted helper exists, test imports it, mutation check now passes

Phase 1 is mandatory. Phase 2 runs only when Phase 1 passes (a static-shadow finding already explains the failure — no need to mutate). Phase 3 runs only on detected findings and only when --fix is on and the pre-heal confidence gate clears (≥ 90 %).


Quick Decision Flow

for each test file in scope:
    finding = static_check(file)                 # rules/static-check.md
    if finding.kind == "shadowed-export":
        if --fix: gated_self_heal(finding)        # rules/self-heal.md
        else:    record(finding)
        continue

    if finding.kind == "no-sut-import":
        record(finding)                           # cannot mutate without an SUT
        continue

    if mode in {"mutate", "both"}:
        finding = mutation_check(file)            # rules/mutation-check.md
        if finding.kind == "test-survives-sabotage":
            if --fix: gated_self_heal(finding)
            else:    record(finding)

report(findings)
exit code = 0 if all healed or no findings, else 1


def gated_self_heal(finding):
    proposal = plan_extraction(finding)            # Step 1+2 of self-heal
    if not --no-confidence-gate:
        score = Skill("confidence", "code", proposal)
        if score < 90:
            record(finding, status="heal-skipped-low-confidence", score=score)
            return
    self_heal(finding, proposal)                    # Steps 4-6 of self-heal

Required Reading by Phase

Load on demand — do not preload.

PhaseFiles
1rules/static-check.md
2rules/mutation-check.md
3rules/self-heal.md
—references/failure-modes.md — taxonomy
—references/pr-12340-postmortem.md — origin case

Output Contract

After every run, emit a structured report. The autonomous-workflow Phase 4 logger consumes the JSON line; humans read the Markdown summary.

TEST PROVENANCE REPORT
======================
Files checked: <N>
Findings:
  - <test-file>:<line> — <kind> — <one-line evidence>
    Action: <healed | reported | skipped | skipped-low-confidence>
    Confidence (if gated): <N>%

Self-heal summary (if --fix):
  - Pre-heal confidence: <N>% (gate ≥ 90 %)
  - Extracted <symbol> from <prod-file>:<line> → <new-export-file>:<line>
  - Rewrote <test-file> to import <symbol>
  - Mutation check after heal: PASS

Exit: <0 | 1>

When called from autonomous-workflow Phase 4, also append one line to .agent/{branch}/plan.md's Progress Log:

- [<ISO-8601>] Phase 4: test-provenance-guard — <N> file(s) checked, <M> finding(s), <K> healed (confidence ≥ 90 %), <L> skipped-low-confidence

Core Principles

  1. A test that does not import the production module is not a test of that module. The static check is the cheapest, strongest signal.
  2. A test that survives sabotage of its claimed target is by-construction. Mutation is the second-line evidence — slow but conclusive.
  3. Self-heal is a refactor, not a rewrite. Extract the inline logic verbatim; do not redesign the function while moving it.
  4. Never silently change test assertions. Self-heal moves logic and rewrites imports; assertions are preserved unchanged.
  5. Report, then act. Even when --fix is on, the report is emitted before the heal so the audit trail survives.
  6. Skip cleanly when out of scope. No test files? Exit 0. Test files in unsupported languages? Skip them with a one-line note and continue.

Anti-patterns

  • Treating a passing test as proof the test is correct. A test can pass for the wrong reason — that is the entire raison d'être of this skill.
  • Mutating without restoring. Every sabotage step is paired with a restore — git restore <sut-file> when the file was clean, or moving the recorded backup over it when it was dirty — see rules/mutation-check.md.
  • Self-healing with a redesign. Moving logic and improving it in the same step is two refactors masquerading as one — split them.
  • Running mutation when static already failed. Wasted tokens. Skip Phase 2 when Phase 1 already produced a finding.
  • Asking the user during autonomous runs. This skill self-heals when --fix is on; if it cannot, it reports the finding and exits — the autonomous-workflow stuck-loop protocol takes over.

Definition of Done

  • Every test file in scope passed Phase 1 (or was healed).
  • Every test file in scope passed Phase 2 (or was healed).
  • Self-heal summary lists the extraction(s) with file paths and line numbers.
  • All originally passing tests still pass after self-heal (<TEST_CMD> re-run is green).
  • Report emitted in the structured format above.
  • When called from autonomous-workflow, the Progress Log line is appended.

Related Skills

  • autonomous-workflow — invokes this skill from Phase 4 Step 5.
  • tdd — Test-After Mode's "mutate to verify" rule is the conceptual ancestor of Phase 2 here.
  • code-quality — Pass 12 ("Testability") covers adjacent design issues; this skill targets the specific by-construction failure.
  • confidence — when self-heal cannot resolve a finding, the autonomous-workflow Phase 4 stuck-loop protocol calls confidence(analysis) next.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.