Flows
Flows are end-to-end tests written as user goals in plain language. A model drives a real browser to reach each goal, exact assertions check the result, and every step that passes is recorded so CI replays it deterministically, with no model call.
A flow
Section titled “A flow”Flow files are named *.flow.ts:
import { flow } from "@bareci/flows";
flow("a buyer checks out with a saved card", async ({ page, ai, expect }) => { await page.goto("/cart"); await ai.do("pay with the saved Visa and confirm the order"); await ai.check("an order confirmation number is shown"); await expect(page.getByRole("heading", { name: /thank you/i })).toBeVisible();});pageis a Playwright page whose relativegotopaths resolve against the base URL.expectis Playwright’s.ai.do(instruction)reaches a goal. The model reads the page’s accessibility tree and answers with concrete actions, turn by turn, up to 8 turns. A screenshot is sent only when the model asks for one or the tree is nearly empty.ai.check(instruction)decides whether a condition holds, without acting. A passing check must come with exact assertions, which run at once and are what replay uses.
The flow’s name names its recording, so names are unique.
| Mode | Recorded step | Unrecorded step | Writes |
|---|---|---|---|
auto (default) |
Replayed; on drift the model heals it | Model | A new recording directly; a change as a patch |
strict |
Replayed; drift fails the flow with a diff | Fails (not_recorded) |
Nothing; never calls a model |
record |
Model | Model | Overwrites the recording |
Use strict in CI.
Recordings
Section titled “Recordings”Recordings are committed JSON in .bareci/flows/<slug>.json:
{ "version": 1, "flow": "a buyer pays for the order", "steps": [ { "kind": "do", "instruction": "pay for the order", "actions": [{ "type": "click", "target": { "by": "role", "value": "button", "name": "Pay now" } }] } ]}An action is { type, target?, value? }: goto, click, fill, press, select, check, uncheck, expectVisible, expectText or expectUrl. A target is found by role (with its accessible name), label, text, placeholder, testId or css. On replay a target must match exactly one element: none is drift, several is ambiguous.
Healing is a proposal
Section titled “Healing is a proposal”Healing never edits a committed recording. The new version is written to .bareci/flows/<slug>.json.patch, a unified diff that git apply accepts, and the report names it. Strict CI keeps failing until the patch is accepted.
bareci-flows propose --pr <number> puts the last run’s patches on the pull request. It only ever changes .bareci/flows/<slug>.json files. When the changed lines are inside the PR’s own diff, they become GitHub suggestions in one review, and “Commit suggestion” accepts them. GitHub allows no suggestion outside the diff, which is the usual case (the app changed, the recording did not), so then the new recording is a commit on bareci/flows-heal/pr-<number>, on top of the PR’s head, with a comment that says how to cherry-pick it. The token comes from BARECI_FLOWS_GITHUB_TOKEN, then GITHUB_TOKEN.
Running flows
Section titled “Running flows”bareci flows run --strict --base-url https://my-preview.example| Flag | What it does |
|---|---|
--strict, --record |
The mode (default auto) |
--base-url URL |
Where the app runs; in the lifecycle, the pull request’s preview |
--out DIR |
Evidence and reports (default .bareci/out/flows/) |
--model ID |
The model for AI steps |
--max-tokens N |
Model tokens the whole run may use (default 200 000) |
--video WHEN |
on (default), on-failure or off |
--trace WHEN |
on-failure (default), on or off |
--headed |
Show the browser |
--json |
Print the report as JSON |
Exit 0 when every flow passes, 1 when one fails, 2 on a usage or setup error.
Evidence
Section titled “Evidence”Each run writes a screenshot after each AI step, report.json with every step, its source (replay, model or heal), the Playwright lines that repeat it, durations and token counts, and junit.xml for Tests.
Each flow also gets a video, <slug>/video.webm at 960×540, and on failure a Playwright trace, <slug>/trace.zip (open it with npx playwright show-trace). Evidence has caps so it never runs up storage:
| Evidence | Cap |
|---|---|
| Video, one flow | 8 MiB |
| Trace, one flow | 16 MiB |
| Videos and traces, one run | 64 MiB |
A file over a cap is dropped, and the report says which and why (evidenceDropped). Screenshots are always kept.
A trace holds every action and its arguments, DOM snapshots, console output and network traffic. Before it is kept, credential headers (Authorization, Cookie, Set-Cookie and the like) and cookies are removed, and every secret is replaced with [redacted]: values the flow marks with secret(), values passed with --secret-env NAME, and whatever was in a password field. The report and junit.xml are masked the same way. Video and screenshots show what the page showed.
flow("a member signs in", async ({ page, secret }) => { await page.getByLabel("API key").fill(secret(process.env.TEST_API_KEY ?? ""));});On a BareCI run, the machine collects .bareci/out/flows/ whenever the command wrote a report there, with no --collect (at most 200 files and 256 MiB), and its junit.xml goes to Tests. The dashboard shows each flow with its video, steps, screenshots and trace. Artifacts are kept 7 days.
Models and keys
Section titled “Models and keys”Claude is the default model. On a BareCI machine, Flows uses BareCI’s key through BareCI’s model proxy: the key never reaches the machine, and BareCI meters each call’s tokens from the model’s own answer. Any repository can bring its own key with BARECI_FLOWS_ANTHROPIC_API_KEY (or ANTHROPIC_API_KEY), which BareCI does not limit. Replay-only runs need no key. Model calls are counted per step.
A run stops calling the model after 200 000 tokens; change it with --max-tokens. On BareCI’s key a call may use Claude Haiku, Sonnet or Opus 5.5 with max_tokens up to 16 000, without tools; an organisation has at most 2 calls in flight (8 on a paid plan) and uses at most 2 million tokens a month.
Writing flows with an agent
Section titled “Writing flows with an agent”Over MCP an agent gets a live browser: browser_start, then browser_act with an instruction or an exact action. Each answer has the page after it and the flow line that repeats the step, so the agent writes the flow as it goes. These tools run in the local MCP server, bareci mcp. See the Flows API.
A live browser closes itself after 10 minutes with no call, so one an agent forgets costs little; a call in progress is never cut off, and a plain-language step gives up after 3 minutes (actTimeoutMs). Pass idleTimeoutMs to startSession, or set BARECI_FLOWS_SESSION_IDLE_MS, for another limit. A call to a closed session says it was closed for being idle, and stopSession still returns its token count.
Flows run in Chromium, Firefox or WebKit (--browser); BareCI’s own CI tests Chromium only. Mobile apps on simulators are planned.