> ## Documentation Index
> Fetch the complete documentation index at: https://docs.testsprite.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rerun & Auto-Heal

> Re-run a saved test, batch-rerun a whole suite, and let AI repair UI drift automatically — all from the CLI.

## What rerun does

**Rerun** re-executes an existing test with no new plan generation. It is the main iteration loop: fix code, rerun, read the verdict, repeat.

| Test type | What rerun executes |
| :- | :- |
| <kbd>Frontend</kbd> | Auto-heal is on by default: the agent re-runs the test against the live app and, if the app changed, repairs it and saves the repaired version. With `--no-auto-heal`, the saved Playwright script is replayed verbatim. |
| <kbd>Backend</kbd> | The full dependency closure in wave order: producers, the named test, then teardown. |

A fresh `test run` instead replays the saved script when it has current saved code, and otherwise lets the agent run the test. A `--local` run always uses the agent.

## Rerunning a test

```bash theme={null}
testsprite test rerun test_3a9f21c7 --wait --timeout 300
```

This uses the Default environment; add `--env <name>` for another (an unknown name fails, never falls back). Saved scripts can contain hard-coded URLs that an environment URL change does not rewrite; see [Environments](https://docs.testsprite.com/cli/core/environments.md). A loopback environment opens a tunnel automatically (`rerun` has no `--local` flag; see [Environments](https://docs.testsprite.com/cli/core/local-apps.md)).

Without `--wait` the command returns once the rerun is accepted; with it, it blocks until a terminal status, using the same exit codes as `test run --wait`.

## Rerunning many

```bash theme={null}
testsprite test rerun --all --project proj_8f0f6 --status failed --filter "checkout" --wait
```

| Flag | Description |
| :- | :- |
| `--skip-terminal` | Skip tests already <kbd>passed</kbd>, <kbd>failed</kbd>, <kbd>blocked</kbd>, or <kbd>cancelled</kbd> |
| `--status <list>` | Only tests with these statuses (comma-separated) |
| `--filter <substr>` | Case-insensitive name filter |
| `--max-concurrency <n>` | Max simultaneous reruns (1–100, default 50) |

## Backend dependency closure

A backend rerun expands to the **producers** (tests whose `--produces` variable the test `--needs`), the test itself, and **teardown** tests (`--category teardown` in the project), so it never runs against stale upstream state. To rerun only the named test:

```bash theme={null}
testsprite test rerun test_3a9f21c7 --skip-dependencies --wait
```

> [!WARNING]
>
> `--skip-dependencies` can make a backend test fail if it relies on data a producer creates. Use it only when the fixtures are already in place.

## Auto-heal

When the UI has shifted since the test was written (a button renamed, a form gained a field), the verbatim script fails even though the feature works. Auto-heal detects the drift and repairs the script so the test passes; if the feature itself is broken, the test stays <kbd>failed</kbd>. When a step is repaired, the new version replaces the saved one.

It is on by default for every frontend CLI rerun on every plan, and ignored for backend tests, whose failures are almost always real assertion or fixture issues. Opt out to replay the saved script exactly:

```bash theme={null}
testsprite test rerun test_3a9f21c7 --wait --no-auto-heal
```

For a deterministic regression gate, use `--no-auto-heal` or `test flaky` (which always replays without healing). A strict replay of a test with no saved code can be refused instead of started.

> [accordion] When auto-heal helps
>
> Minor UI refactors that moved or renamed things: a relabeled button, a sidebar collapsed into a menu, a custom dropdown replaced by a design-system component. The saved script refers to stale selectors or text, and auto-heal re-binds the test to the new UI.

> [accordion] When auto-heal doesn't help
>
> A real product bug: the form rejects valid input, an API returns 500, the redirect lands on the wrong page. Recovery fails and the test stays <kbd>failed</kbd>. Pull the failure bundle (`testsprite test failure get <test-id>`) to see what broke.

## Credits

A rerun is billed the same as a fresh run, whether or not auto-heal repairs a step; there is no discounted replay tier. Check current costs with `testsprite usage`. With insufficient credits the command exits `12`; top up under <kbd>Workspace Settings → Billing → Usage</kbd> in the Portal. See [Exit Codes](https://docs.testsprite.com/cli/reference/exit-codes.md).

## Where to Go Next

> [card] [Running Tests](https://docs.testsprite.com/cli/core/running-tests.md)
>
> Fresh runs, `--target-url`, and exit codes

> [card] [Reading Results](https://docs.testsprite.com/cli/core/reading-results.md)
>
> Failure bundles, step logs, and run history after a rerun

> [card] [Exit Codes](https://docs.testsprite.com/cli/reference/exit-codes.md)
>
> Exit 12 and everything else the CLI can emit

> [card] [Agent Integration](https://docs.testsprite.com/cli/core/agent-integration.md)
>
> Wire the rerun loop into your coding agent's verify-fix cycle


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.