Docs › Automation
CI and the API
Rerun a test on every deploy, or every morning, and fail the build when it gets worse for the people who matter.
Set up once
- Run the test once from the app. Its mission then has a trend, and the trend has an id: open it from Trends, and the id is in the address, after
#s.(it starts withs).GET /api/v1/serieslists them too. - Make a token. In Settings › API tokens, give it a Name such as GitHub Actions and press Make a token. Copy it straight away: it is not shown again. Store it as a CI secret,
ANYVISITOR_TOKEN, and the trend's id as a variable,ANYVISITOR_SERIES. - Set targets, if you want them, on the trend's page (see Trends and targets). The job fails when a run misses one.
A token acts as the person who made it and spends the team's credits. Making one needs Make API tokens on the People page; owners always can. Revoke next to a token stops it working. Settings lists every token with who made it and when it was last used.
A GitHub Actions job
After a successful deploy it starts the run on the deployed address, waits for the report, and fails the build on a missed target, a result worse than last time beyond the noise between AI testers, or a new critical problem. It also runs on weekday mornings against the test's own address.
# .github/workflows/persona-test.yml name: Persona test on: deployment_status: schedule: - cron: "17 6 * * 1-5" workflow_dispatch: jobs: anyvisitor: if: github.event_name != 'deployment_status' || github.event.deployment_status.state == 'success' runs-on: ubuntu-latest timeout-minutes: 45 env: AV: https://anyvisitor.com/api/v1 AUTH: "Authorization: Bearer ${{ secrets.ANYVISITOR_TOKEN }}" SERIES: ${{ vars.ANYVISITOR_SERIES }} # The deployed address after a deploy; empty means the test's own address. URL: ${{ github.event.deployment_status.environment_url }} steps: - name: Start the run id: start run: | body=$(jq -n --arg s "$SERIES" --arg u "$URL" --arg v "$GITHUB_SHA" --arg n "$(git log -1 --pretty=%s 2>/dev/null || echo "$GITHUB_REF_NAME")" \ '{series: $s, change: {version: $v, note: $n}} + (if $u == "" then {} else {url: $u} end)') out=$(curl -fsS -X POST "$AV/runs" -H "$AUTH" -H 'Content-Type: application/json' -d "$body") echo "$out" echo "id=$(echo "$out" | jq -r .id)" >> "$GITHUB_OUTPUT" - name: Wait for the report run: | for i in $(seq 1 80); do r=$(curl -fsS "$AV/runs/${{ steps.start.outputs.id }}" -H "$AUTH") s=$(echo "$r" | jq -r .status) [ "$s" = done ] || [ "$s" = failed ] && break sleep 30 done echo "$r" > run.json - name: Check it run: | r=run.json echo "Report: $(jq -r .reportUrl $r)" [ "$(jq -r .status $r)" = done ] || { echo "Run did not finish: $(jq -r .error $r)"; exit 1; } [ "$(jq -r .targetsMet $r)" != false ] || { echo "Missed a target"; exit 1; } worse=$(jq -r '[.sinceLast.deltas // {} | to_entries[] | select(.value.verdict == "worse") | .key] | join(", ")' $r) [ -z "$worse" ] || { echo "Worse than last run: $worse"; exit 1; } crit=$(jq -r '[.findings.new[] | select(.sev == "critical") | .title] | join("; ")' $r) [ -z "$crit" ] || { echo "New critical problem: $crit"; exit 1; } echo "OK: $(jq -r .summary $r)"
The run's report link is printed in the log, pass or fail, and the commit's message becomes the change note on the trend. Any CI that can call an HTTP API works the same way.
The API
Every call takes Authorization: Bearer <token>.
| Call | Send / get back |
|---|---|
POST /api/v1/runs | { series, url?, env?, change? } runs a trend's test again, optionally on another address such as a preview deploy, in the same trend. env, such as "Preview", makes it an environment of its own, so its report compares it with the last preview rather than with Production. change is { note?, version?, url? }, shown on the trend. Answers 201 { id, price, reportUrl }, or 402 when the team is short of credits. |
GET /api/v1/runs/{id} | { status, progress, step, error, summary, kpi, sinceLast, targetsMet, findings: { new, still, regressed, resolved }, credits, reportUrl } |
GET /api/v1/series | { series: [{ id, name, host, task, targets, last, lastRunAt }] }: the team's trends, and those on sites shared with it. |
sinceLast.deltas.{success, direct, medianSec, misclicks, seq}.verdict is better, worse, same or noise, within the variation between AI testers.
A rerun keeps the people picked by name and draws census audiences afresh, as Run again does in the app. Signed-in missions need a saved test login, or a sign-in kept from an earlier run, since nobody is there to sign in (see Signed-in tests and saved logins).
What's next
- Running tests from Claude: test Staging and let your assistant fix what testers hit.
- Developer automation: the overview.