mcpField

Post-Edit Test Guard

FeaturedEvent-driven

About Post-Edit Test Guard

This event-triggered loop starts after each batch of file edits. Each round runs only the tests related to the edited files and uses the exit code to decide whether more fixing is needed.

Key features

  1. 01Triggered by edit events, no manual start
  2. 02Runs only tests related to the changed files
  3. 03Uses the test exit code as the pass signal
  4. 04Supports Cursor

Use cases

  1. 01Editing several files in a row in Cursor and wanting regressions caught early
  2. 02Confirming affected modules still pass after a refactor
  3. 03Having a coding agent self-check after every change
Goal
After each batch of file edits, all tests related to those files pass before work continues.
Exit when
Stop when the related-tests command exits with code 0.
Between iterations run
npm test -- --findRelatedTests <edited files>

Launch prompt

Paste into Cursor. The agent repeats the steps below until the exit condition is met.

prompt.md
Start the "Post-Edit Test Guard" loop.
Goal: After each batch of file edits, all tests related to those files pass before work continues.
Step 1: Run related tests — Execute npm test -- --findRelatedTests against the files edited in this batch. An exit code of 0 counts as a pass; otherwise read the failure output. `npm test -- --findRelatedTests`
Step 2: Diagnose failures — If tests fail, compare the output with the latest changes to decide whether the edit or the test is at fault, and pinpoint what to fix.
Step 3: Fix and recheck — Apply the fix, then return to the test step. Repeat until the related tests pass, then move on to the next batch of edits.
Between iterations run: `npm test -- --findRelatedTests <edited files>`
Exit when: Stop when the related-tests command exits with code 0.

Steps

Each round runs in order; if the exit condition isn’t met, another round starts, up to 1.

01
Run related tests

Execute npm test -- --findRelatedTests against the files edited in this batch. An exit code of 0 counts as a pass; otherwise read the failure output.

$npm test -- --findRelatedTests
02
Diagnose failures

If tests fail, compare the output with the latest changes to decide whether the edit or the test is at fault, and pinpoint what to fix.

03
Fix and recheck

Apply the fix, then return to the test step. Repeat until the related tests pass, then move on to the next batch of edits.

Not met → next roundExits when met

Supported agents

Coding agents that can run this loop directly.

Cursor
Claude Code

Comments

Markdown supported