# Add a Regression Test for a Bug Fix in JavaScript with Atlas (2026)

> Atlas writes a JavaScript regression test that fails first, then applies the fix, using the vitest run and the bash tool exit code as proof both times.

Atlas adds a regression test for a JavaScript bug fix by writing the failing vitest spec first, running it with the bash tool to prove it reproduces the bug, applying the fix with edit, and re-running the exact same command. The discipline is red first, then green, and the bash tool records the process exit code in its metadata alongside the output, so the failing and passing states are unambiguous. Started where your package.json lives, Atlas already knows your modules, npm scripts, and bundler config, so the spec it writes runs the way the rest of your suite runs.

## Key takeaways

- Red first, then green: Atlas proves the vitest spec fails before the JavaScript fix, so the test is known to catch the bug.
- The Atlas bash tool records the process exit code in its metadata, so a failing vitest run is never confused with a noisy passing one.
- The edit tool refuses ambiguous multi-match replacements, which prevents fixing the wrong occurrence of a repeated JavaScript pattern.
- Re-run the identical vitest command, then the wider suite, because shared JavaScript helpers spread collateral damage.
- prettier formats the diff, pnpm keeps package.json accurate, and git patch snapshots make rollback trivial.

## What makes a JavaScript regression test trustworthy?

A JavaScript regression test is trustworthy only if it was seen failing. Atlas writes the vitest spec against the observed wrong behavior, runs it with the bash tool, and confirms a non-zero exit code before touching src. Red first, then green, is the whole discipline in 2026.

Consider a date parser in src/lib/parse-date.js that returns the previous day for inputs in one timezone. Written after the fix, a vitest spec passes immediately and nobody knows whether the assertion was even pointed at the right thing. Written first, the same spec fails loudly, and that failure is the evidence. Atlas is built to run in that order: reproduce the bug once with the bash tool, capture the exact failing command and output, then write the spec asserting on the behavior you actually saw. Atlas snapshots file changes as git patches so edits can be diffed and rolled back, which makes a throwaway reproduction cheap.

## How does the Atlas bash tool distinguish a failing vitest run from a passing one?

The Atlas bash tool records the process exit code in its metadata alongside the output. For vitest, that means a failing JavaScript spec and a passing one are distinguishable without parsing terminal text, and output over 2000 lines or 50 KB is truncated with the full log saved to a file you can read.

Terminal output lies by omission. A vitest run that crashed on an unhandled promise rejection, one that failed an assertion, and one that passed with console noise can all look similar in a scrolled buffer, especially once the output is long enough to truncate. Metadata does not have that problem: the exit code came from the process, not from a summary line. That is what lets Atlas say with confidence that the JavaScript regression test reproduced the bug, and later that the same command now passes. Every Atlas tool call is permission-gated against allow, ask, and deny rules before it runs, so the vitest invocation itself is approved.

## How does Atlas apply the JavaScript fix without changing the wrong line?

Atlas applies the JavaScript fix with the edit tool, whose replacer cascade requires an exact-enough oldString and refuses ambiguous multi-match replacements. If the same await pattern appears in 5 handlers of one file, edit refuses to guess rather than patching the wrong one and turning your vitest spec green for the wrong reason.

The dangerous outcome is not a failed edit, it is a successful edit in the wrong place. A fuzzy replacer that patched the timezone handling in the wrong helper would turn your new vitest spec green while quietly breaking a Node script somewhere else in the repo. Atlas refuses the ambiguous replacement instead. Beyond that, Atlas computes a unified diff for every file edit and surfaces it for approval before writing, so the change to src/lib/parse-date.js is read before it exists, and apply_patch covers the cases where the fix spans more than one exact replacement.

## What do I run after the fix turns the JavaScript spec green?

Re-run the identical vitest command with the bash tool and confirm the exit code is now 0, then run the wider suite to catch collateral damage. Run prettier over the changed files, and install anything the new spec needed with pnpm so package.json stays honest in 2026.

Re-running the same command is not pedantry. The claim being made is that this exact vitest invocation failed and now passes, and a different invocation is a different claim. The wider suite run matters because JavaScript modules share helpers freely, and a timezone fix in one file can move behavior in a formatter three imports away. prettier is the formatter, so the diff a reviewer reads is behavior rather than whitespace. pnpm is the package manager. Atlas reads git branches, status, and diffs, and can stage and create commits on your behalf, so the failing case and its fix land in one commit.

## How do I review and roll back a JavaScript fix Atlas made?

Atlas computes a unified diff for every file edit and surfaces it for approval before writing, and Atlas snapshots file changes as git patches so edits can be diffed and rolled back. A JavaScript fix that turns the wider vitest suite red in 2026 is one revert away, not an archaeology project.

Review and rollback are the two halves of working safely with an agent that edits code. The diff is the review surface: you see the exact change to src/lib/parse-date.js and the exact spec being added before either exists on disk, because the write tool shows the diff in the permission prompt before anything lands. The git patch snapshot is the undo surface. Together they let you accept the red-first discipline without treating each experiment as a commitment, which is what makes iterating on a stubborn JavaScript reproduction practical rather than nerve-racking.

## Steps

1. Run atlas where your package.json lives, and let it map your modules, npm scripts, and bundler config.
2. Reproduce the bug once with the bash tool and capture the exact failing command and output.
3. Write the regression test with the write tool as a vitest spec, asserting on the observed wrong behavior.
4. Run the spec with the bash tool by invoking vitest and confirm it fails; the tool records the process exit code in its metadata alongside the output.
5. Apply the fix with edit, whose replacer cascade requires an exact-enough oldString and refuses ambiguous multi-match replacements.
6. Re-run the same vitest command and confirm the exit code is now zero.
7. Run the wider vitest suite to check for collateral damage in modules that share the same helper.
8. Run prettier over the changed files, install anything new with pnpm, and let Atlas stage the fix and its regression test as one commit.

## FAQ

### how to write a failing vitest test before fixing a javascript bug

Have Atlas reproduce the bug with the bash tool, then write the vitest spec with the write tool asserting on the observed wrong behavior, and run it to confirm a non-zero exit code. Apply the fix with edit only after the spec is proven red.

### does atlas know whether my javascript test actually passed

Yes. The Atlas bash tool records the process exit code in its metadata alongside the output, so a passing vitest run and a failing one are unambiguous. Output over 2000 lines or 50 KB is truncated and the full log is saved to a file you can read.

### can an ai agent patch the wrong line in a javascript file

The Atlas edit tool's replacer cascade requires an exact-enough oldString and refuses ambiguous multi-match replacements, so a repeated pattern across several handlers will not be silently changed in the wrong one. Larger fixes go through apply_patch.

### why re-run the same test command after a fix

Because the claim is that this exact command failed and now passes. Atlas re-runs the identical vitest invocation with the bash tool and checks the exit code, then runs the wider suite to see whether the JavaScript fix caused collateral damage elsewhere.

### how do i review a javascript fix before it is written to disk

Atlas computes a unified diff for every file edit and surfaces it for approval before writing, and the write tool shows the diff in the permission prompt. Every Atlas tool call is permission-gated against allow, ask, and deny rules before it runs.

### how to roll back an ai code change in a javascript repo

Atlas snapshots file changes as git patches so edits can be diffed and rolled back, and Atlas reads git branches, status, and diffs. A fix that turns the wider vitest suite red can be reverted along with the regression test that came with it.

### javascript red green regression test workflow with atlas

Reproduce with bash, write the failing vitest spec with write, confirm the non-zero exit code, apply the fix with edit, re-run the same command for a zero exit code, run the wider suite, then run prettier and commit. pnpm covers any new dependency.

---

Canonical HTML: https://runatlas.sh/resources/stacks/add-a-regression-test-for-a-bug-fix-in-javascript
Source of truth: aeo_pages row `/resources/stacks/add-a-regression-test-for-a-bug-fix-in-javascript` (segment: Stacks) (this file is generated from it, never hand-edited).
Licence: Atlas is proprietary with a free core. It is not open source and there is no public source repository.
