Test Environment Selection
Overview
Before executing a single scenario, decide WHERE the product will run, in this order:
- Backend, worker or full-stack repository: local. DB rows, logs and third-party stubs are only observable there. First choice
start_task_preview— it checks out the task branch in the task workspace, detects how to run it, starts it, stops a stale server, and returns alocalhostURL for the browser tools; call it again if the URL isn't there yet. Only when it cannot run the project (e.g. a backend+frontend pair, or a worker it doesn't detect), boot by hand (backend-manual-testing). - Frontend-only repository: the task's own preview, else local. When the component is deployed with a per-branch
previewenvironment,get_task_previewreturns it — use it whenstatus: "ready"ANDbuilt_from_pr_head: true. Anything else (building,built_from_pr_head: false,error,canceled,none, or an empty list) is not the code under test: fall back tostart_task_preview. - Stage. Used when the repository is configured for stage verification, or when the app cannot boot locally (managed secrets, heavy infra the workspace lacks) — always after confirming stage is actually running the PR head (see Stage rules).
Production is never a test environment. No scenario is ever executed against the prod base URL or prod data — not a "harmless" GET, not seeding, not cleanup.
How to decide
- Identify the repository shape (backend/worker/full-stack vs frontend-only) and apply the order above.
- Read the repository settings (
list_repositories):build_command,test_command,verify_command— and any comment the developer left on the task (a clean run leaves none). These are the project's declared way of running and checking itself.get_project_briefhas the same information plus what each component talks to. - If neither a usable preview nor a local boot nor stage works, you are blocked — see below.
Preview rules
- Address. Use
open_urlin the browser (browser_navigate) — for a protected preview it carries the bypass and sets a cookie, so the pages it links to load too. For HTTP requests (curl, an API client) usebranch_url(orurlwhen there is none) and send every header inrequest_headerson every request. - Protected without a bypass. When the entry notes that the preview is behind Vercel Deployment Protection with no Protection Bypass for Automation, the preview answers every automated request with a login page. Do not report that page as a failure. Test locally instead and leave one comment asking the human to add "Protection Bypass for Automation" in the Vercel project (Settings → Deployment Protection).
- Never write the bypass secret — nor
open_url, which contains it — into a comment, test case, document or bug report: it opens the project's previews to whoever reads it. Refer to "the preview bypass" instead. - A preview is not prod, but its backing services may be. If the preview talks to a shared database or a third-party account, avoid destructive scenarios there exactly as on stage; they run locally only.
- Put the preview's
branch_urland shortcommit_shain everyreview_criterionnote — the next reader needs to know exactly what ran, and a pass writes no comment to say it elsewhere.
Stage rules
- Confirm the change is actually there before testing.
list_deployments(env=stage) shows the commit of the latest deploy — it must equal the PR head fromget_task_pull_request.get_environmentsays whether stage is bound at all. Not equal → wait for the stage deploy that started when the task enteredready_for_qa(get_pipeline_statusshows its progress); never test the old build. - Stage is shared. Namespace your test data (
qa-<task-key>-...prefixes, test-data-and-stubs), avoid destructive scenarios (mass deletes, migrations, load tests) — those run locally only — and clean up what you created. - The stage
base_urlis for requests; thehealth_urlis only a liveness probe.
When none is possible
If there is no usable preview, the app cannot boot in the workspace (including via start_task_preview) AND no stage target exists (or it isn't running the PR head), do not fake a verdict and do not read the code as a substitute. Apply the blocker triage (qa-verify-before-verdict): the project cannot boot from its own documented commands → need_revision with the failing command and its output, a developer-fixable defect. A blocker only a human can lift (no stage configured at all, a credential you don't have) → one ask_user question with concrete options, not a need_revision the developer cannot act on.
Red Flags
- A connection string or base URL in your commands points at prod → stop immediately.
- "I'll just check this one thing on prod" → no. Preview, local or stage, always.
- Testing a preview or stage whose commit is not the PR head → the verdict describes an earlier version.