Run one Vitest regression with an agent
Give a coding agent a one-shot Vitest regression command, prove the named case fails, then rerun the full test file.
You ask a coding agent to fix a cart calculation. It starts the test runner in watch mode, waits for it to exit, and gives you a patch before you see the failing test. Give the agent a command that runs once and shows the regression by name.
Start with one failing case
Suppose the cart applies a minimum spend before adding a discount. The requirement says a cart at the threshold qualifies. Add a case named applies discount at the minimum to src/cart.test.ts that checks the result at that boundary.
Run Vitest with a file filter and a test-name filter from the package that owns the cart code.
pnpm exec vitest run src/cart.test.ts -t 'applies discount at the minimum'run exits after the check. Before the fix, the named case should fail and show the actual and expected results. Vitest treats the name filter as a regular expression, so use a distinct name and check which case ran. Other cases may appear as skipped.
Give the agent the command, the boundary input, and the expected result. Ask it to run the case before editing the implementation and repeat the same command after the change. If the first run passes, ask it to inspect the test setup before modifying the cart. The input may already qualify for another reason, or the test may exercise a mock.
Widen the run after the fix
Once the boundary case passes, remove the test-name filter and run the whole file.
pnpm exec vitest run src/cart.test.tsThe report now includes the other cart cases. A test for a cart below the threshold can catch a fix that grants the discount too broadly.
Ask for the exact command and the failing assertion from the first run, plus the passing result from the final run. If a command reports no matching test, have the agent check the package directory, the file filter, and the test name. The file argument filters by path. The test-name filter applies to the names within the selected files.
Keep the short command in the task description for the next attempt. Use the repository's broader verification command before merging, since the cart tests do not exercise every caller of the calculation.