API Contract Until Match
FeaturedOn demandAbout API Contract Until Match
This loop keeps an API implementation aligned with its published contract. Each round runs the contract tests, uses the failures to change the implementation, then re-tests in the next round until the suite passes or the round limit is reached.
Key features
- 01Judged by the exit code of the contract test suite
- 02Manual trigger, so the user decides when to start
- 03Capped at 10 rounds to avoid endless retries
- 04Supports Cursor
Use cases
- 01Confirming an API still follows its contract after an endpoint change
- 02Updating an existing implementation to a new contract version
- 03Checking that contract tests pass before merging
- Goal
- The API implementation matches the published contract and npm run test:contract passes.
- Exit when
- Stop when the contract test suite exits 0, or after 10 rounds if it still fails.
- Between iterations run
- npm run test:contract
Launch prompt
Paste into Cursor. The agent repeats the steps below until the exit condition is met.
Start the "API Contract Until Match" loop. Goal: The API implementation matches the published contract and npm run test:contract passes. Max iterations: 10. Step 1: Run contract tests — Execute npm run test:contract and note the exit code and any failing cases. An exit code of 0 means the goal is met. `npm run test:contract` Step 2: Diagnose failures — Read the failure output against the published contract to see whether the response shape, status code or parameter handling differs. Step 3: Fix the implementation — Change only the code that deviates from the contract, leaving the contract itself untouched, then start the next round with another test run. Between iterations run: `npm run test:contract` Exit when: Stop when the contract test suite exits 0, or after 10 rounds if it still fails.
Steps
Each round runs in order; if the exit condition isn’t met, another round starts, up to 10.
Execute npm run test:contract and note the exit code and any failing cases. An exit code of 0 means the goal is met.
npm run test:contractRead the failure output against the published contract to see whether the response shape, status code or parameter handling differs.
Change only the code that deviates from the contract, leaving the contract itself untouched, then start the next round with another test run.
Supported agents
Coding agents that can run this loop directly.