Post-Edit Test Guard
FeaturedEvent-drivenAbout 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
- 01Triggered by edit events, no manual start
- 02Runs only tests related to the changed files
- 03Uses the test exit code as the pass signal
- 04Supports Cursor
Use cases
- 01Editing several files in a row in Cursor and wanting regressions caught early
- 02Confirming affected modules still pass after a refactor
- 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.
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.
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 -- --findRelatedTestsIf 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.
Apply the fix, then return to the test step. Repeat until the related tests pass, then move on to the next batch of edits.
Supported agents
Coding agents that can run this loop directly.