# uip tm wait

> Syntax and options for `uip tm wait`, which polls a test execution until it reaches a terminal state, prints a summary, and exits non-zero when a test failed or the run was cancelled.

`uip tm wait` polls a test execution until it reaches a terminal state (`Finished` or `Cancelled`) and then prints a summary with the passed and failed counts. It turns the asynchronous `uip tm testsets run` into a blocking step in a CI pipeline, and the exit code carries the verdict: `0` when no test failed, `1` when a test failed or the run was cancelled.

`wait` is registered as a top-level verb under `tm`, not as a resource. Invoke it as `uip tm wait`, not `uip tm executions wait`.

## Synopsis

```text
uip tm wait --execution-id <uuid> (--project-key <key> | --project-id <id> | --test-set-key <key>)
            [--timeout <seconds>]
```

Honors the [global options](./global-options.md). See [Exit codes](#exit-codes) for the codes this command uses.

## uip tm wait

Block until the given execution reaches a terminal state, polling Test Manager every 60 seconds.

### Arguments

None.

### Options

- `--execution-id <uuid>` *(required)* — execution to wait on. Get it from `uip tm testsets run`.
- `--project-key <key>` — owning project key.
- `--project-id <id>` — owning project ID. Use instead of `--project-key`.

  Pass `--project-id`, `--project-key`, or `--test-set-key`. When you pass more than one, `--project-id` is used first, then `--project-key`, then the project prefix of `--test-set-key`.
- `--test-set-key <key>` — test set key (for example, `DEMO:42`); the project key is derived from the prefix.
- `--timeout <seconds>` — maximum time to wait, in seconds: a whole number from `0` to `604800` (one week). Defaults to `1800` (30 minutes). Pass `0` to wait indefinitely. Any other value is refused with exit code `3`.

:::note
There is no `--poll-interval` flag on this command. The poll interval is fixed at 60 seconds.
:::

:::warning
A manual run closed early with [`executions finish`](./uip-test-manager-executions.md#uip-tm-executions-finish) keeps `Status: "Running"`, so `wait` never sees a terminal state on it. `wait` blocks until `--timeout` and then exits `4`. Check such a run's `ExecutionFinished` timestamp with [`executions get-stats`](./uip-test-manager-executions.md#uip-tm-executions-get-stats) instead.
:::

### Example

```bash
# wait up to 15 minutes
uip tm wait \
  --execution-id a1b2c3d4-0000-0000-0000-000000000001 \
  --project-key DEMO \
  --timeout 900
```

### Data shape (finished with no failed test)

```json
{
  "Result": "Success",
  "Code": "WaitComplete",
  "Data": {
    "ExecutionId": "a1b2c3d4-0000-0000-0000-000000000001",
    "Status": "Finished",
    "EndTime": "2025-04-15T10:32:11Z",
    "Duration": "00:02:11",
    "Passed": 12,
    "Failed": 0,
    "None": 0
  }
}
```

`Passed`, `Failed`, and `None` count the tests that passed, failed, and have no result. Tests with no result do not fail the wait, because a manual run can finish with tests that nobody recorded.

### Data shape (a test failed or the run was cancelled)

```json
{
  "Result": "Failure",
  "Code": "ExecutionTestsFailed",
  "ErrorCode": "execution_failed",
  "Message": "2 of 12 tests failed in execution 'a1b2c3d4-0000-0000-0000-000000000001'.",
  "Instructions": "List the failed tests with 'uip tm executions testcaselogs list --execution-id a1b2c3d4-0000-0000-0000-000000000001 --project-id 11111111-2222-3333-4444-555555555555 --results Failed', or download a JUnit report with 'uip tm result download --execution-id a1b2c3d4-0000-0000-0000-000000000001 --project-id 11111111-2222-3333-4444-555555555555'.",
  "Retry": "RetryWillNotFix",
  "Data": {
    "ExecutionId": "a1b2c3d4-0000-0000-0000-000000000001",
    "Status": "Finished",
    "EndTime": "2025-04-15T10:32:11Z",
    "Duration": "00:02:11",
    "Passed": 10,
    "Failed": 2,
    "None": 0
  }
}
```

`Data` holds the same fields as on success. `Status` is the terminal state Test Manager reports: `Finished` or `Cancelled`. `Code` is `ExecutionTestsFailed` when a test failed and `ExecutionCancelled` when the run was cancelled. Both exit `1`.

### Data shape (timeout)

```json
{
  "Result": "TimeoutError",
  "ErrorCode": "timeout",
  "Message": "Timed out after 900s waiting for execution 'a1b2c3d4-0000-0000-0000-000000000001'. Last status: Running.",
  "Instructions": "The execution may still be running. Run 'uip tm wait --execution-id a1b2c3d4-0000-0000-0000-000000000001' again, or check it with 'uip tm executions get-stats --execution-id a1b2c3d4-0000-0000-0000-000000000001'."
}
```

## Exit codes

`wait` follows the standard [exit codes](./exit-codes.md):

| Exit code | Meaning |
|---|---|
| `0` | The execution finished and no test failed. |
| `1` | A test failed, the run was cancelled, the execution was not found, polling failed (three consecutive API errors or an interrupt), sign-in failed, or no project was given. See the `Code`, `ErrorCode`, and `Message` fields for detail. |
| `2` | The login has no permission to read the execution. |
| `3` | Validation error (bad flag value, missing required option). |
| `4` | Timed out. The timeout elapsed before the execution reached a terminal state. |

An error that waiting cannot fix, such as an unknown execution ID (`ErrorCode: "not_found"`), stops the wait on the first read instead of at `--timeout`. Other errors are retried up to three times in a row.

### Script pattern

```bash
uip tm wait \
  --execution-id "$id" \
  --project-key DEMO \
  --timeout 1800
case $? in
  0) ;;
  1) echo "tests failed, run cancelled, or wait failed" >&2; exit 1 ;;
  4) echo "timed out" >&2; exit 4 ;;
  *) echo "wait failed" >&2; exit 1 ;;
esac
```

## Related

- [testsets run](./uip-test-manager-testsets.md#uip-tm-testsets-run) — produces the `ExecutionId` to wait on.
- [report](./uip-test-manager-report.md) — summary of the counts and the failed test cases, to read once `wait` returns.
- [result](./uip-test-manager-result.md) — JUnit XML export.
- [executions retry](./uip-test-manager-executions.md#uip-tm-executions-retry) — re-run the failed cases of a finished execution.
- [executions cancel](./uip-test-manager-executions.md#uip-tm-executions-cancel) — stop a running automated execution; poll it to `Cancelled` with `wait`.
- [run](./uip-test-manager-run.md) — run every test in an uploaded package, wait, and write a report in one command.

## See also

- [Test Manager overview](./uip-test-manager.md)
- [Exit codes](./exit-codes.md) — shared contract.
- [Scripting patterns](./scripting-patterns.md) — the launch-wait-verify pipeline.
