<!-- KeepSnappy docs for keepsnappy CLI 0.1.0-alpha.35 -->

# keepsnappy.yml and run flags

> Every keepsnappy.yml setting that keepsnappy run reads, the flags of keepsnappy run that CI uses, and what its exit codes mean.

This page is the reference for `keepsnappy run` in CI: every `keepsnappy.yml` setting it reads, its flags and its exit codes. To add the job, see [Set up CI](https://keepsnappy.com/docs/ci.md).

## keepsnappy.yml

Put `keepsnappy.yml` in the repository root. This full file, with Maestro, sets every setting; the examples below cover other runners. Your own file needs only `app.bundle_id` and `flows`: leave out the rest, `project.ingest_url` included.

```yaml
project:
  key_env: KEEPSNAPPY_KEY
  ingest_url: https://keepsnappy-api-922918702810.europe-west1.run.app
app:
  bundle_id: com.example.app
  scheme: myapp://
  wait_for_activation: false
  framework: react-native
platform: ios-sim
device: booted
repetitions: 5
verdict_gate: advisory
retry:
  failed_runs: 0
flows:
  runner: maestro
  paths:
    - e2e/flows/*.yaml
  tags: [perf]
  exclude_tags: [flaky]
  maestro_version: '1.39.13'
steps:
  rename:
    open-chat: open-conversation
output:
  dir: keepsnappy-out
timeout_seconds: 600
```

| Setting | Default | Meaning |
|---|---|---|
| `app.bundle_id` | required | The bundle id of the app the tests drive. |
| `app.scheme` | none | The app's registered link scheme, with `://`. Required with `android-emulator` and `android-device`: the tool opens the SDK's [activation](https://keepsnappy.com/docs/glossary.md#activation) and [flush](https://keepsnappy.com/docs/glossary.md#flush) links with it. With `ios-sim`, `app.scheme` alone changes nothing: a `waitForActivation` build is activated only with `app.wait_for_activation: true`. |
| `app.wait_for_activation` | `false` | `true`: the build uses the SDK option `waitForActivation` (dormant until a run [activates](https://keepsnappy.com/docs/glossary.md#activation) it). With `ios-sim`, `app.scheme` is not required: the CLI stops the app and writes the SDK's activation record into the app's data folder on the simulator before every run, and your test command is the launch that applies it. No link is opened, so no "Open in …?" prompt can block it; it works with any simulator that `xcrun simctl` can reach. After the last run it switches measuring off again and stops the app, so the build is dormant for your other jobs. Your test command must not clear the app's data or reinstall it (Maestro `clearState`, Detox `delete: true`, `uninstallApp`): either deletes the activation and every run then has no data. Android uses the activation link and requires `app.scheme`; it always activates, so the key changes nothing there. A cabled iPhone (`ios-device`) cannot activate a dormant build: the key is refused there. |
| `app.framework` | `react-native` | `react-native` or `web`. New configs from `init` write this setting. It selects what `review`, `act` and `watch --auto-on-worse` check before asking the AI. With this CLI version, the bundle check has no build-flavour evidence, so the AI still runs. |
| `platform` | `ios-sim` | `ios-sim` for a simulator, `ios-device` for a cabled iPhone, `android-emulator` for a running Android emulator (see [Android](https://keepsnappy.com/docs/android.md#android-emulator)), `android-device` for a USB Android phone (see [Android](https://keepsnappy.com/docs/android.md#android-usb-phone)). |
| `device` | `booted` | The simulator's UDID, or `booted` for the booted simulator. Required with `ios-device`. |
| `ios.device_set` | none | An existing simulator-set directory, for a [custom simulator set](#a-custom-simulator-set). |
| `repetitions` | `5` | How many times each journey runs per session. |
| `verdict_gate` | `blocking` | `blocking` keeps exit 3 for a blocking Worse. `advisory` keeps the Worse result on the dashboard but passes CI (exit 0); infrastructure, configuration and timeout failures still exit 1, 2 and 4. New configs from `init` use `advisory`; an absent setting keeps `blocking`. |
| `retry.failed_runs` (under `retry`) | `0` (off) | `0` to `3`: with the Appium driver, `keepsnappy farm run` and `farm open` plan this many spare runs per journey, begun only to replace a run that broke or lost its [flush](https://keepsnappy.com/docs/glossary.md#flush) (`--spare N`; a `--spare` flag wins, also `--spare 0`). Anything else (4, text) is a configuration error, exit 2. With Maestro the value is ignored with a note. `retry.failed_sessions` is not supported yet and is refused. `keepsnappy config set retry.failed_runs 1 --config keepsnappy.yml` writes it; `init` writes nothing new. |
| `flows.runner` | `maestro` | `maestro` runs Maestro flows. `command` runs `flows.command`. |
| `flows.paths` | none | Maestro flow files, directories or globs. Each flow is one journey. |
| `flows.tags`, `flows.exclude_tags` | none | Run only flows with one of `tags` and none of `exclude_tags`. |
| `flows.command` | none | The test command for `runner: command`, as one line or a list of arguments. |
| `flows.e2e_report` | none | The e2e (e2e.com) `report.json` each run is checked against, when a package script runs the e2e tests for you. See [e2e](https://keepsnappy.com/docs/test-tools/e2e.md#settings-in-keepsnappyyml). |
| `flows.maestro_version` | none | The Maestro version you expect. The tool writes it to the log; it does not install or pick a version. |
| `steps.rename` | none | Renames measured steps in the results: a map from the old name to the new one. Use it to keep a step's results under one name after you rename it. |
| `project.key_env` | `KEEPSNAPPY_KEY` | The name of the environment variable that holds the CI key. Never the key itself. |
| `project.ingest_url` | `https://keepsnappy-api-922918702810.europe-west1.run.app` | The KeepSnappy API that `--upload` sends to. Leave it unset unless the KeepSnappy team gives you another address. |
| `output.dir` | `keepsnappy-out` | Where each run's logs and measurements are written. |
| `timeout_seconds` | none | Stops a test run that takes longer. |

[Journeys](https://keepsnappy.com/docs/journeys.md) explains how flows become journeys and how they are named. For a complete setup with your test tool, see the guides for [Maestro](https://keepsnappy.com/docs/test-tools/maestro.md), [Appium](https://keepsnappy.com/docs/test-tools/appium.md) and [e2e](https://keepsnappy.com/docs/test-tools/e2e.md).

To run an Appium suite or another test command instead of Maestro flows, replace `flows`:

```yaml
flows:
  runner: command
  command: npx wdio run wdio.conf.ts
```

When a package script runs your e2e tests, name the report they write:

```yaml
flows:
  runner: command
  command: npm run test:e2e
  e2e_report: .e2e/report.json
```

The tool checks the whole file before it runs anything. It prints every problem it finds and exits 2.

### Simulator and emulator identity

Within an organization, uploads from the same platform, model and OS version use one device. Fresh leases on the same OS version share device history. KeepSnappy records the reported UDID or emulator serial, runtime build, and any runner host ID on the run.

### A custom simulator set

Most setups use Xcode's default simulator set and leave this out. `run`, `measure` and the doctor measure group can use another set, a directory that already exists on the runner. For `run` and doctor, name it with the `--device-set` flag or with this section. The flag wins, then the section, then the `SIMULATOR_DEVICE_SET_PATH` environment variable. `measure` doesn't read this section, so give it the flag or the environment variable:

```yaml
ios:
  device_set: /absolute/path/to/simulator-set
```

The CLI never creates or boots a simulator in the set. A path that does not exist is a configuration error naming where it came from, with no fallback to another set. Relative paths start from the current directory, and `~` is not expanded in `keepsnappy.yml`. Doctor reports the set it uses and where it came from. BrowserStack and a cabled iPhone ignore the setting, and the `farm`, `extract` and `aa` commands ([CLI](https://keepsnappy.com/docs/reference/cli.md#aa)) don't take the flag.

The CLI's own `simctl` calls use the set, but your test command launches the app itself, so it must use the same set in any `simctl` call it makes. Maestro finds simulators only in the default set, so the CLI refuses a Maestro command with a custom set. A shell script that starts Maestro hides it from that check, and the custom set still doesn't work.

## Flags of keepsnappy run

| Flag | Meaning |
|---|---|
| `--upload` | Uploads the runs as a session. Needs the CI key in the variable `project.key_env` names. |
| `--wait` | Closes the session and waits for its result, so a blocking **Worse** fails the job unless `verdict_gate` is `advisory` ([why](https://keepsnappy.com/docs/ci.md#required-or-advisory-checks)). Needs `--upload` and the branch. See below. |
| `--wait-timeout` | How many minutes `--wait` waits for the result. Default: 10. Needs `--wait`. |
| `--commit` | Measured commit. Default: PR head from `GITHUB_EVENT_PATH`, otherwise `GITHUB_SHA`. A synthetic merge context without a discoverable head is refused; pass `--commit HEAD_SHA`. |
| `--branch` | The branch. Default on GitHub Actions: the pull request's branch, else `GITHUB_REF_NAME`. Android runs and `--wait` require a branch. On iOS, an upload without a branch or `--wait` stores runs without a session or result. |
| `--base-commit` | The commit on `main` to compare with. Default: where the branch left `main`, which needs the full history: set `fetch-depth` to `0` on checkout. |
| `--device` | A simulator UDID. Overrides `device`. |
| `--device-set` | Simulator-set directory. Overrides `ios.device_set` and the environment. |
| `--repeat` | A number. Overrides `repetitions`. |
| `--no-notify` | A [quiet session](https://keepsnappy.com/docs/glossary.md#quiet-session): its result is stored and shown on the dashboard, but nothing about it goes to Slack, not even a failed session. Also `KEEPSNAPPY_NOTIFY` set to `off`. |
| `--config` | A file to read instead of `keepsnappy.yml`. |
| `--out` | A directory. Overrides `output.dir`. |
| `--fail-on-worse` | No longer needed: it changes nothing and says so. Needs `--wait`. |

You can also give the test command after `--`. It then replaces `flows`, and runs as one journey:

```sh
npx @keepsnappy/agent run --upload --wait -- npx wdio run wdio.conf.ts
```

## Exit codes

| Code | Meaning |
|---|---|
| `0` | The runs were measured, and uploaded with `--upload`. With `--wait`: no journey is a **Worse** that blocks, or `verdict_gate` is `advisory`. |
| `1` | Something outside your tests failed: the upload, the API, or no run sent any data. |
| `2` | `keepsnappy.yml` or the command line is wrong. The log says what to fix. |
| `3` | With `--wait` and `verdict_gate: blocking` (or no `verdict_gate`): a journey on a pull request is **Worse** and blocks, also when other journeys are still waiting at the deadline. |
| `4` | With `--wait`: the result did not arrive within `--wait-timeout`. The log links the dashboard. A session on `main` exits `0` instead. |

`keepsnappy measure` exits `1` when no run is valid, including an empty collection, and says that the measurement produced nothing usable. It exits `0` when at least one run is valid, even if other runs are invalid.

Without `--wait`, the result never changes the exit code. The job ends after the upload, and KeepSnappy judges the session a few minutes later.

With `--wait`, the job waits until KeepSnappy has judged this session, up to `--wait-timeout` minutes. The log then prints the result, and one line per journey that changed, worst first.

| Result of the session | Exit |
|---|---|
| A **Worse** that blocks, on a pull request, with `verdict_gate: blocking` or no `verdict_gate` | `3` |
| A **Worse** that blocks, on a pull request, with `verdict_gate: advisory` | `0` |
| A Worse that does not block, Slightly worse, Can’t tell, or not judged | `0` |
| No result within `--wait-timeout`, on a pull request | `4` |
| No result within `--wait-timeout`, on `main` | `0` |
| Better or No change | `0` |
| A session on `main`: waited for like any other, but it never fails, since `main` blocks no merge | `0` |

Only a blocking Worse on a pull request fails the step with `3`, and only when `verdict_gate` is `blocking` or missing; a result that does not come in time ends it with `4` on a pull request, with either setting. A result that comes late still reaches the dashboard, and `keepsnappy-result.json` says `timed_out: true`.

Whether to make the KeepSnappy check required, and what `verdict_gate` does to it, is on [Set up CI](https://keepsnappy.com/docs/ci.md#required-or-advisory-checks).

All KeepSnappy docs for agents: https://keepsnappy.com/llms.txt
