# Runner — run-agent-verification.ts

Reference for `run-agent-verification.ts`, the orchestrator that executes agent
verification cases and enforces the status contract. `index.md` covers when and
how to author cases; this file covers running them.

## Scaffolded files

When a project adopts agent verification, copy these starters from this slice's
bundle (`references/create-agent-verification/assets/`) into the repo:

- `tests/agent/agent-test-template.md` — case authoring template
- `tests/agent/agent-test-suites.example.json` — manifest example
- `tests/agent/run-agent-verification.ts` — local runner/orchestrator
- `tests/agent/agent-verification-types.ts` — shared timing types the runner
  imports (required for typecheck)

Each project owns its real `tests/agent/agent-test-suites.json`, case files,
fixtures, secrets, session bootstrap, CI wiring, and mutation policy.

## Setup

```json
{ "scripts": { "agent:verify": "tsx tests/agent/run-agent-verification.ts" } }
```

```bash
cp tests/agent/agent-test-suites.example.json tests/agent/agent-test-suites.json
pnpm agent:verify --target local --suite smoke --project-name "<project name>"
pnpm agent:verify --target local --case tests/agent/example/smoke.md
```

In a Bun project (`../_shared/package-manager.md`), Bun runs the TypeScript
runner itself:

```json
{ "scripts": { "agent:verify": "bun tests/agent/run-agent-verification.ts" } }
```

```bash
cp tests/agent/agent-test-suites.example.json tests/agent/agent-test-suites.json
bun run agent:verify --target local --suite smoke --project-name "<project name>"
bun run agent:verify --target local --case tests/agent/example/smoke.md
```

The `claude` engine runs with `--mcp-config .github/agent-verification-mcp.json`
(a fixed path) and fails without it: create that file before its first run, with
the project's `shiplight` server entry from `.mcp.json` under `mcpServers`.

Before a hybrid case runs, the runner prepares its `ui/` project with the manager
that project resolves by the same rule: in a Bun project
`bun install --frozen-lockfile` (then `bun install` if that fails) and
`bun run --bun playwright install chromium` (the manager rule's browser-install
row); otherwise `npm ci` (then `npm install`) and
`npx playwright install chromium`, as before. It cannot ask: with several
lockfile kinds it says so and uses npm when `npm` is on `PATH`, else Bun; with no
signal it uses Bun when it runs on Bun or `npm` is not on `PATH`, and npm
otherwise.

## Configuration

Defaults: manifest `tests/agent/agent-test-suites.json`; reports
`agent-test-reports`; allowed targets `local,staging,production`; engine `codex`.

| Flag | Environment variable |
| --- | --- |
| `--target` | `AGENT_VERIFICATION_TARGET` |
| `--engine` | `AGENT_VERIFICATION_ENGINE` |
| `--manifest` | `AGENT_VERIFICATION_MANIFEST_PATH` |
| `--report-dir` | `AGENT_VERIFICATION_REPORT_DIR` |
| `--allowed-targets` | `AGENT_VERIFICATION_ALLOWED_TARGETS` |
| `--project-name` | `AGENT_VERIFICATION_PROJECT_NAME` |

For full, current flags and defaults, prefer the runner's own `--help` over this
table.

## Status contract

The runner accepts final statuses `PASS`, `FAIL`, `BLOCKED`, `ABORTED`, and the
final non-empty line of each report must be exactly one `Status:` line. See the
**canonical contract in `index.md`** for the semantics (this file does not
restate them). Required cases fail the runner unless they return `PASS`; `ABORTED`
is reserved for orchestration interruptions and is rerun, not treated as product
evidence.

## Evidence

The runner writes an attempt journal to the report directory and prints its path
before the first case. The summary's `attemptJournal` field points to the same file.
Each engine attempt gets a row before launch, starting at one within its case.
The runner atomically updates the row when it has a terminal result, retaining
retries and engine fallbacks. An interruption can leave `ABORTED` with a null
cost. `costUsd` is null whenever the engine's measured charge is unavailable.
A measured zero remains zero. The journal contains case IDs, engine names,
attempt numbers, statuses, and costs. If the journal cannot be written, the
runner exits with an error before launching another attempt. The last journal
successfully written on disk remains available.

UI evidence comes from the case's codified Shiplight YAML runs (their report,
trace, and screenshots) — the executing agent does not drive a browser to
collect it. Text-only UI claims are not sufficient: reports must reference the
YAML run artifacts alongside the backend evidence (queries, API responses,
logs). See `_shared/evidence-and-report.md`.
