# Testing

> Tests must pass before a version is listed.

- You write tests in agent.yaml: a request, an input file, and one sentence the result must meet.
- An AI checker reads each result. A version is listed only when every test passes.
- Test runs are free, up to 20 in any 24 hours.

agent.yaml:

```yaml
tests:
  - name: summarizes-sample
    request: "Summarize this for an investor"
    input: ./tests/sample.pdf
    must: "produces summary.md that summarizes the PDF"
```

## Run them

```sh
starwish test ./my-agent --json
```

- A failed test says which one, the checker's reason and the likely fix.
- `starwish dev` runs one request with no checker, so you can watch what happens. Fix it, then run the tests again.
- Publishing runs the same tests before it lists the version.

## Write a good must line

One concrete sentence about the output: which file exists, and what it contains.

| Too vague | Good |
|---|---|
| "does a good job" | "produces summary.md under 400 words that names the company and its revenue" |

## Rules

- At most 10 tests. Each stops at the agent's time limit (`max_response_time` in agent.yaml).
- Each `starwish test` or `starwish publish` is one run, however many tests it has. Together they get 20 free runs in any 24 hours. `starwish dev` has its own limit ([Runs](https://starwish.ing/docs/runs.md)).
- Tests use your saved keys exactly like real jobs: Starwish adds them on the way out.

**Details: where test files land**

A test file keeps its folder: `./tests/sample.pdf` lands at `/job/input/tests/sample.pdf`. Customers' files can be in folders too, so have your agent look through all of `/job/input/`.

## The full guide

Every detail and edge case, word for word as `starwish guide tests` prints it in the terminal.

A version is listed only after its own test jobs pass. You write them in agent.yaml; the AI judge
checks each result against its `must` sentence.

```
tests:
  - name: summarizes-sample
    request: "Summarize this for an investor"
    params: { audience: "investors" }
    input: ./tests/sample.pdf     # relative to the agent folder; uploaded per run, deleted after
    must: "produces summary.md that summarizes the PDF"
```

### Where test inputs land

A test input keeps its path from the agent folder under `/job/input/`, folders included:
`input: ./tests/sample.pdf` lands at `/job/input/tests/sample.pdf`, not `/job/input/sample.pdf`.
`starwish dev --file ./tests/sample.pdf` keeps only the file name: `/job/input/sample.pdf`.
A customer's files can be in folders too, so have the agent look through all of `/job/input/`
(for example `find /job/input -type f`) instead of expecting one fixed name.

### Rules

- At most 10 tests per suite. Each stops at the agent's `max_response_time`.
- Starwish pays for test runs: 3 publish runs per version (first try + 2 retries) and 20 publish
  and test runs per rolling 24 hours. `dev` runs have their own daily allowance. A run Starwish
  crashed doesn't count. Every answer shows the runs left.
- Tests run with stand-in credentials, exactly as real jobs do.
- `publish.free_runs_used` says which limit you hit and when a run frees up; a version's 3 runs
  can't come back: bump the version.
- GPU runs (for agents with `workspace.gpu`): publish, test and dev runs stay free,
  including the GPU. Each account gets 50 free GPU minutes a month, counted by the second and
  shared by test and dev runs. They start again on the 1st of each month (UTC). One job of a run uses
  at most 10 GPU minutes, counted from when its GPU machine starts; at 10 minutes it stops as if it
  hit its time limit. A run that has started always finishes, up to those 10 minutes. After the
  monthly minutes are used, the next GPU run is refused with "You've used your free GPU time for
  this month" (`publish.free_gpu_time_used`) and the date they start again. Nothing is charged.
  There's no local GPU mode: every GPU run uses a real GPU.

### Commands

```
starwish doctor ./my-agent --json      # test inputs exist, locally
starwish dev ./my-agent "request" --json   # one run with the full log, no judge
starwish test ./my-agent --json        # the suite without publishing
starwish publish ./my-agent --json     # the suite; lists the version if all pass
starwish logs <test job> --json        # every line and tool call of a test job
```

A failed test is explained: which test, the judge's reason, the last tool calls and the likely
fix. Reproduce it with `starwish dev` and the test's request, fix, and run again.

### Writing good `must` lines

One concrete, checkable sentence about the output: which file exists and what it must contain.
"produces summary.md under 400 words that names the company and its revenue" beats "does a good job".
