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

# Catch and fix a local regression with RWX

> Break a calculation in the sample project, inspect its failed test in RWX, and validate the fix before pushing.

In this exercise, deliberately break one calculation in the sample project,
inspect the failure in RWX, then restore it—all before committing or pushing.
Use the public project and workflow from the
[quickstart](/quickstart).

## Before you start

Complete the quickstart, including its passing run. Open your terminal in the
`rwx-quickstart` clone and check the source file:

```sh theme={null}
git diff -- src/index.js
```

This command should print nothing. Use the original example source for this
exercise; preserve any changes you have already made before continuing.
Your untracked `.rwx/quickstart.yml` can stay as it is. You need no local Node.js
installation and no new repository access.

## 1. Make a change that fails a test

Open `src/index.js`. In `calculateTotal`, change:

```js theme={null}
total += item.price * item.quantity;
```

to:

```js theme={null}
total += item.price;
```

The calculation now adds each item's price once, regardless of its quantity.
Inspect the change:

```sh theme={null}
git diff -- src/index.js
```

The diff should contain:

```diff theme={null}
-    total += item.price * item.quantity;
+    total += item.price;
```

Keep the edit local. [The RWX CLI sends local changes with a new run](https://www.rwx.com/docs/cli-reference/rwx-run),
so you can check this change before committing or pushing it.

## 2. Run the test task

```sh theme={null}
rwx run .rwx/quickstart.yml --wait --title "Test a local change: failure" --target test
```

The `--target test` option includes the `test` task and its dependencies:
`code`, `node`, and `npm-install`. The separate `lint` task is outside this run.
The existing `filter` on `npm-install` lets RWX reuse dependency installation
when only this source file changes.

The CLI should report:

```text theme={null}
Run result status: failed
```

That is the expected checkpoint: a cloud test has caught the local regression.

## 3. Inspect the assertion

Open the run URL printed by the CLI. Select **Tests**, then expand **Output**
under **Index functions > calculateTotal > should calculate total for valid
items**.

Look for **1 Failed**, **19 Successful**, and this assertion:

```text theme={null}
Expected: 35
Received: 15
```

<img src="https://mintcdn.com/rwx/5R4hL8ab__WRzwOm/images/local-change-failure.jpg?fit=max&auto=format&n=5R4hL8ab__WRzwOm&q=85&s=ca60526d2b16d0e1368c9e235bc927b6" alt="Failed test showing the expected total of 35 and actual total of 15" width="1090" height="480" data-path="images/local-change-failure.jpg" />

The test uses two items: a price of 10 with quantity 2, and a price of 5 with
quantity 3. The correct total is `10 * 2 + 5 * 3 = 35`. The changed calculation
returns `10 + 5 = 15`.

## 4. Restore the calculation and start a new run

In `src/index.js`, restore the original line:

```js theme={null}
total += item.price * item.quantity;
```

Start a new run with the current local files:

```sh theme={null}
rwx run .rwx/quickstart.yml --wait --title "Test a local change: fixed" --target test
```

The CLI should report `Run result status: succeeded`. Open the new run's
**Tests** tab and confirm **20 Successful**.

<img src="https://mintcdn.com/rwx/5R4hL8ab__WRzwOm/images/local-change-fixed.jpg?fit=max&auto=format&n=5R4hL8ab__WRzwOm&q=85&s=e9c038816dc68b8a1f10f8d708f049e7" alt="Restored source producing 20 successful test results" width="1090" height="554" data-path="images/local-change-fixed.jpg" />

Restoring the exact source from the quickstart can also make the test task a
cache hit: RWX already has a successful result for those inputs. A new run
checks the current input state and can reuse that result.

Use `rwx run` after editing your files. Retrying the earlier failed run uses
that run's original inputs; it does not upload the local fix.

## 5. Check your local source

```sh theme={null}
git diff -- src/index.js
```

It should print nothing again. You have completed a local failure-and-fix loop
in cloud CI without a commit or push.

## If a step fails

| What you see | What to do |
| - | - |
| The first run succeeds | Check that you saved `total += item.price;` in `src/index.js` and ran from the example clone |
| A setup task fails before tests start | Open the failed task's output; confirm the quickstart still runs with its original configuration |
| The restored run still fails | Restore the quantity multiplication and start a new `rwx run`; check the new run URL |
| The restored test is Cached | Open Tests and confirm 20 Successful; the cache contains a successful result for the restored inputs |

Continue with [running commands in a cloud sandbox](/cloud-sandbox)
to reuse one environment across commands and bring cloud file edits back to
your machine.


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