mirror of
https://github.com/tester-army/e2e.git
synced 2026-11-26 02:27:16 +08:00
* feat!: browser fixture, getByRole name arg, toMatchSchema, top-level hooks, separate credential namespace API review feedback before launch: - web fixture renamed browser (Web -> Browser, WebExpectation -> BrowserExpectation); requires: ['browser']; destructuring web hints the new name. web() factory and other Web* types unchanged. - getByRole(role, name, options?) beside the object form; MCP locate writes the short form. - expect(value).toMatchSchema(standardSchema): sync, returns the typed output; poll resolves to it, soft returns undefined after a kept failure. - describe, beforeEach, afterEach, beforeAll, afterAll exported from e2e; web and mobile export typed beforeEach/afterEach. - credentials and secrets are separate namespaces: a password handle is <name>.password, secrets.get() never returns it. Committed recordings migrated offline (old key hash verified, then recomputed). - runtime test.skip keeps Playwright semantics; docs say it throws. * docs(web): browser acts on one active tab; cookies, routes, dialogs cover the whole browser * fix(secrets): judge a fill's purpose by the config, not the handle; no old-name hints A config-time secrets.get() handle reads its purpose from the run's registry again, and authorizeSecretFill checks the registered purpose, so a handle claiming generic-secret cannot put a password into a plain field. Drop the web fixture migration hint. Changesets name the on-screen marker change for replay entries. * docs(skill): browser fixture, getByRole name arg, toMatchSchema, top-level hooks, credential namespace on the rewritten skill * fix(expect): negated toMatchSchema returns nothing, as its type says * fix(expect,docs): soft double negation stays soft, null ~standard is INVALID_ARGUMENT, Playwright samples keep Playwright's getByRole Also documents SoftExpectCall, SoftValueExpectation, and NegatedPollExpectation on the expect reference, requires: ['browser'] in the skill's options table, and tightens the poll and secret-purpose tests. * docs(babysit): triage pattern for scripted renames that rewrite another library's code * docs: engine options take a secrets entry, web package hook exports, vault example imports * refactor(secrets)!: credentials hold their password, allSecrets feeds fills; engines export describe and every hook; BrowserRoute, BrowserResponse From the maintainability review: - ResolvedConfig.secrets is the config.secrets entries only; a credential carries its password; allSecrets is the one map fills, the ledger, and redaction read. The per-consumer purpose filters and the .password suffix parsing are gone, and e2e mcp builds handles from config. - The config load and a running test name the credential a missing secrets.get() most likely meant. - @e2e-dev/web and @e2e-dev/mobile export describe and all four hooks beside test, so a test file registers from one import. - WebRoute and WebResponse are BrowserRoute and BrowserResponse. - getByRole normalizes its arguments once; isTextMatch is the one string-or-RegExp check; poll reuses ValueMatcherName. * revert(web): keep WebRoute and WebResponse; Browser names the fixture, Web the network and option types
294 lines
12 KiB
Plaintext
294 lines
12 KiB
Plaintext
---
|
|
title: Caching agent steps
|
|
description: Replay verified agent actions without model calls, and let the agent take over when the app changes.
|
|
---
|
|
|
|
The replay cache records the actions in an `agent.act()` step after a later
|
|
check verifies the result. On the next run, the runner replays those actions
|
|
without calling the model. If a control or the expected end state no longer
|
|
matches, the agent takes over from the current screen.
|
|
|
|
`agent.assert`, `agent.waitFor`, and `agent.extract` always run live.
|
|
|
|
The run summary reports the outcomes:
|
|
|
|
```text
|
|
AI 4.1k tokens · 2 model calls · anthropic/claude-sonnet-4.5
|
|
Cache 4 replayed · 1 handed off · 1 missed
|
|
```
|
|
|
|
| Run summary | `step.cache.mode` | Meaning |
|
|
| --- | --- | --- |
|
|
| `replayed` | `self-finalized` | The recording completed without a model call. |
|
|
| `handed off` | `agent-concluded` | Replay started, then the agent took over. |
|
|
| `missed` | `missed` | The agent ran the step from the beginning. |
|
|
|
|
Misses and hand-offs also include `step.cache.reason`. `agent.act()` returns
|
|
the same cache object as `result.cache`. The cache object is absent when
|
|
caching is off for the step.
|
|
|
|
To rule the cache out of a failure, run once without it:
|
|
|
|
<CodeGroup>
|
|
```bash npm
|
|
npx e2e run --no-cache
|
|
```
|
|
|
|
```bash pnpm
|
|
pnpm exec e2e run --no-cache
|
|
```
|
|
|
|
```bash bun
|
|
bunx e2e run --no-cache
|
|
```
|
|
</CodeGroup>
|
|
|
|
## How a replay works
|
|
|
|
1. Check the starting screen: the same route, whatever the record id, the
|
|
query, or the fragment. Retries always run live.
|
|
2. Find each recorded control and repeat its action. The runner matches
|
|
controls by their role, name, test id, and surrounding context. It waits
|
|
for missing controls and stops if a match is ambiguous. A control with no
|
|
name is found by its place among the unnamed controls of its kind.
|
|
3. Check the final path and controls that appeared during the original step.
|
|
Text that changes with the data, a count, a date, an id, is not used.
|
|
4. Finish without a model call, or let the agent continue with a record of
|
|
what ran and why replay stopped.
|
|
|
|
Typed values replay as recorded, even when an earlier run left the same
|
|
value on screen. Secret fills resolve the current value by name and run
|
|
through authorization again.
|
|
|
|
## What must match
|
|
|
|
A cache entry belongs to a specific test, target, instruction, and set of
|
|
params. Renaming the test or target, changing the instruction or an ordinary
|
|
param, or upgrading the engine's major or minor version causes a miss.
|
|
Changing the model does not.
|
|
|
|
A timestamp or a fresh email address would cause a miss on every run. Wrap
|
|
values like these in `unique()` so the runner substitutes the current value
|
|
when replaying:
|
|
|
|
```ts
|
|
import { unique } from 'e2e';
|
|
|
|
const name = `E2E ${Date.now()} Company`;
|
|
await agent.act('create a company named {name}', { params: { name: unique(name) } });
|
|
await expect(screen.getByRole('heading', { name })).toBeVisible();
|
|
```
|
|
|
|
Use `unique()` for data the flow enters or checks. Keep choices that change
|
|
the flow, such as a plan name, as ordinary params. The substitution covers
|
|
the value as a URL spells it too, `%20` in a path or `+` in a search query.
|
|
|
|
When a `unique()` value equals another param's value or appears inside one,
|
|
the step passes but is not recorded, and `step.cache.notRecorded` reads
|
|
`param-collision`. The next run, with a fresh value, records it.
|
|
|
|
For preview URLs that change on each deploy, set
|
|
[`app.identity`](/reference/config#the-app-under-test) to keep the same cache
|
|
identity. On devices, replay uses the
|
|
[screen title](/reference/mobile#replay-cache-on-a-device) as the path.
|
|
|
|
## When a recording is written
|
|
|
|
In `read-write` mode, the runner saves a recording at the end of the
|
|
attempt when a later verification step passed. A step that took no action
|
|
records nothing.
|
|
|
|
| Counts as verification | Does not count |
|
|
| --- | --- |
|
|
| `expect(locator).toHaveText(...)` and other locator matchers | `expect(value).toBe(...)` on a plain value |
|
|
| `expect(browser).toHaveURL(...)` and other engine assertions | `expect.poll(...)` |
|
|
| `locator.waitFor()`, `browser.waitForURL()` | `locator.textContent()` and other reads |
|
|
| `agent.assert(...)`, `agent.waitFor(...)` | `agent.extract(...)`, another `act`, the attempt passing |
|
|
|
|
Follow each `act` with a check of its outcome:
|
|
|
|
```ts title="tests/cart.e2e.ts"
|
|
import { expect, test } from 'e2e';
|
|
|
|
test('adds an item', async ({ app, agent, screen }) => {
|
|
await app.open('/cart');
|
|
await agent.act('add one item to the cart');
|
|
await expect(screen.getByRole('status')).toHaveText('1 item');
|
|
});
|
|
```
|
|
|
|
A failing attempt can still save steps verified before the failure. It
|
|
deletes unverified entries and replays implicated in the failure, including
|
|
an `end-mismatch`. Custom stores need a `delete` method for this cleanup.
|
|
Cancelling a run leaves the cache unchanged.
|
|
|
|
## Why a step was not replayed
|
|
|
|
`step.cache.reason` in the report says why:
|
|
|
|
| Reason | What happened | What to do |
|
|
| --- | --- | --- |
|
|
| `no-entry` | No recording matches this step and its params. | The next verified pass records it. |
|
|
| `retry` | Retries never replay. | Nothing. |
|
|
| `invalid-entry` | The file is unreadable, over 1 MiB, or from another schema version. | `npx e2e cache clear`. |
|
|
| `truncated` | The recording hit a limit, see [below](#limits-and-gaps). | Split the step, or pass the secret as a `Secret`. |
|
|
| `wrong-context` | The app was on another screen than when the step was recorded: a different route, not a different record, query, or fragment. | Open the same screen before the step. |
|
|
| `target-not-found` | A recorded control did not appear within 15 seconds. | The UI changed. The next passing run re-records. |
|
|
| `target-ambiguous` | The number of matching controls changed. | Give repeated controls distinct names or use unique test data. |
|
|
| `gap` | An action cannot be replayed, see [below](#limits-and-gaps). | The agent continues this part live. Put stable values in `params`. |
|
|
| `action-failed` | The app rejected a replayed action. | Check the app. |
|
|
| `action-uncertain` | A replayed action failed with an unknown commit state. The agent is told to check before acting again. | Check the app. |
|
|
| `viewport-changed` | A bare-point tap or hover was recorded on a viewport of another size. | Keep the viewport fixed. |
|
|
| `end-mismatch` | Every action ran, but the recorded path or a control that should have appeared did not come back. | Leftover data from an earlier run, a banner that comes and goes, or a regression. |
|
|
|
|
A stop before any action ran is a miss. After replay starts, it is a
|
|
hand-off. Unique test data and cleanup in `afterEach` help avoid stale
|
|
state between runs.
|
|
|
|
### Limits and gaps
|
|
|
|
A recording is `truncated` when the step took more than 50 actions (only
|
|
possible with `maxSteps` raised above 50), typed a value or URL over 4,096
|
|
characters or one holding a registered secret, or acted on a control with no
|
|
usable description.
|
|
|
|
A `gap` is an action the cache cannot repeat: a mutating
|
|
[project tool](/tools), or a value the agent read off the screen, typed after
|
|
seeing a screenshot, or worked out from the date. `step.cache.derived` names
|
|
the rule: `whole-node` (a control's whole name or text), `minted-token` (a
|
|
code or id the app showed as its own word), `date`, or `pixels`. Values from
|
|
the instruction or `params`, or ones the agent composed itself, replay.
|
|
|
|
## What a recording holds
|
|
|
|
Each entry is a JSON file under `.e2e/cache/`, named by a hash of its key.
|
|
It contains actions, target descriptions, typed text, a step summary, and
|
|
checks for the final state. Those checks include the path and up to eight
|
|
controls that appeared during the step.
|
|
|
|
Entries contain no prompts, conversations, screenshots, observed trees, or
|
|
secret values. A secret fill stores only the secret's name. Other typed
|
|
values are stored verbatim, so review recordings before sharing them; see
|
|
[cache trust](/security#cache-trust).
|
|
|
|
## Modes
|
|
|
|
| Mode | Replays | Records | Default |
|
|
| --- | --- | --- | --- |
|
|
| `'read-write'` | yes | yes | locally |
|
|
| `'read-only'` | yes | no | in CI when `cache` is unset |
|
|
| `'off'` | no | no | `--no-cache` for one run |
|
|
|
|
```ts title="e2e.config.ts fragment"
|
|
cache: 'off',
|
|
// or
|
|
cache: { mode: 'read-write', dir: '.e2e/cache' },
|
|
```
|
|
|
|
`--no-cache` overrides the config. To let CI update recordings, explicitly
|
|
set `cache: 'read-write'`. In `read-only` mode, stale entries remain until
|
|
a read-write run replaces them.
|
|
|
|
A custom `cache.store` replaces the file store and does not default to
|
|
read-only in CI. `e2e explore` and `e2e mcp` do not use the cache. See the
|
|
[config reference](/reference/config#cache).
|
|
|
|
## Commit the replay cache
|
|
|
|
<span id="commit-your-traces" />
|
|
|
|
`e2e init` adds `.e2e/cache/` to `.gitignore`, so every machine records its
|
|
own and CI starts with none. To share replays, remove that line and commit
|
|
the directory. CI stays `read-only` unless you set `cache: 'read-write'`.
|
|
Treat committed entries as test data and review them in the pull request
|
|
that re-recorded them.
|
|
|
|
Local runs leave a committed directory clean unless something changed. A
|
|
replayed step never rewrites its entry, and a live re-recording with the same
|
|
actions, paths, and anchors is not written: the summary, the measured end
|
|
wait, and the rule that flagged a typed run-time value differ between two
|
|
live runs of the same flow and do not count. A file changes when:
|
|
|
|
- a step records for the first time,
|
|
- the agent finishes a step after a hand-off, re-recording what it saw,
|
|
- a step fails after replaying, or ends in an `end-mismatch` the agent had
|
|
to repair, which deletes the entry,
|
|
- no verification step confirmed the entry by the end of the attempt, which
|
|
deletes it.
|
|
|
|
A replay that still finds every control refreshes nothing, so an entry for a
|
|
drifting UI is repaired only once a control can no longer be found.
|
|
|
|
## Fail on a stale recording
|
|
|
|
A committed recording that stops replaying is quiet by default: the agent
|
|
takes the step over, the test passes, and every CI run pays for the model
|
|
calls until someone re-records. `--strict-cache` (or `cache: { strict: true }`)
|
|
makes it loud. A step whose recording exists but no longer replays fails
|
|
with `REPLAY_STALE` and makes no model call:
|
|
|
|
<CodeGroup>
|
|
```bash npm
|
|
CI=1 npx e2e run --strict-cache
|
|
```
|
|
|
|
```bash pnpm
|
|
CI=1 pnpm exec e2e run --strict-cache
|
|
```
|
|
|
|
```bash bun
|
|
CI=1 bunx e2e run --strict-cache
|
|
```
|
|
</CodeGroup>
|
|
|
|
The reasons that fail are the ones that mean the app or the entry changed:
|
|
`invalid-entry`, `wrong-context`, `target-not-found`, `target-ambiguous`,
|
|
`viewport-changed`, `action-failed`, `action-uncertain`, and `end-mismatch`.
|
|
A step with no recording (`no-entry`), a retry, a `gap`, and a `truncated`
|
|
recording still run live. `REPLAY_STALE` exits 2 and is not retried, since a
|
|
retry never replays and would pass live. The entry stays where it is, even
|
|
in `read-write` mode, so every strict run fails on it until it is re-recorded:
|
|
run the test in `read-write` mode without the flag, and with `cache.strict`
|
|
off when the config set it, then commit the changed entry; a custom
|
|
`cache.store` receives the new entry from that run instead. The message
|
|
names the knob that turned strict on and where the entry lives: the cache
|
|
directory, or the configured `cache.store`. A store whose read fails is not
|
|
a stale recording; the step runs live.
|
|
|
|
## Inspect the cache
|
|
|
|
<CodeGroup>
|
|
```bash npm
|
|
npx e2e cache ls # one row per entry: test, target, instruction digest, age, actions
|
|
npx e2e cache stats # entry count and size
|
|
npx e2e cache clear # delete every entry
|
|
```
|
|
|
|
```bash pnpm
|
|
pnpm exec e2e cache ls # one row per entry: test, target, instruction digest, age, actions
|
|
pnpm exec e2e cache stats # entry count and size
|
|
pnpm exec e2e cache clear # delete every entry
|
|
```
|
|
|
|
```bash bun
|
|
bunx e2e cache ls # one row per entry: test, target, instruction digest, age, actions
|
|
bunx e2e cache stats # entry count and size
|
|
bunx e2e cache clear # delete every entry
|
|
```
|
|
</CodeGroup>
|
|
|
|
<Note>
|
|
The `cached` percentage in AI usage is the provider's prompt cache. It
|
|
reduces the cost of a model call. The replay cache described here skips the
|
|
call entirely.
|
|
</Note>
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Config reference" icon="sliders" href="/reference/config#cache">
|
|
`mode`, `store`, `dir`.
|
|
</Card>
|
|
<Card title="CLI reference" icon="terminal" href="/reference/cli#e2e-cache">
|
|
`e2e cache ls`, `stats`, `clear`.
|
|
</Card>
|
|
</CardGroup>
|