feat(skill): prefer agent.act when configured, tighten test structure and migration guidance

Merged
MI
4d ago
+1456-1118

What

The e2e skills, the MCP server's test_lines tool, and the test-writing docs pages change in five ways:

  • Trim skills/e2e/SKILL.md to 146 lines (9.1 KB, down 49% from 17.8 KB on main) as a progressive-disclosure router that directs coding agents to load only the matching reference topic and jump via ## Contents, moving Rerunning a test while you fix it and Feedback into references/debugging.md.
  • Default UI user flows to agent.act (with data in params, one goal per test) whenever e2e.config.ts configures a model or custom executor on agents.default or a selected agents.<name>, reserving screen.* actions for low-level mechanics under test, test.setup sign-in, or model-less configs.
  • Steer coding agents to reuse existing tests/, fixtures, helpers, and page objects; test one behavior per test with every expect and agent.assert at the end (no mid-test assertions, no stashed one-shot locator reads, no undone actions or unchecked screens); name repeated locators; own server data and cleanup in test.extend fixtures (try/finally); and in list mutations, add two items, act on the second item shown, never the first, and check the first is unchanged.
  • Harden skills/migrate-to-e2e/SKILL.md to preserve every source assertion at its original observation point, route same-platform targets with { tags } and --target instead of beforeEach viewport or timezone skips, classify stays per test (keeping tried-and-failed ports as blocked), and keep the resume headers in MIGRATION.md.
  • Update test_lines in e2e mcp to adapt its guidance across fresh drafts, resumed tests opened with open_session { test }, and held tests attached with open_session { attach }, including agent.act advice in fresh drafts only when the session's agent has a model or custom executor configured.

Why

Three failure modes showed up in real agent runs and migration evaluations:

  1. SKILL.md loaded 17.8 KB upfront on every invocation, and agents following the old skill wrote multi-behavior tests with mid-test assertions, test-body cleanup, repeated locators, and list mutations targeting row 1 (which pass broken apps that always edit or delete the first row).
  2. When a project configured an agent model alongside an existing deterministic login test, smaller coding agents kept writing screen.* action chains instead of agent.act (0 of 17 tests on Claude Haiku 5.5 on main).
  3. On a real Playwright migration (HomeKeeper, 33 tests across 15 files), strict numeric assertion floors clashed with the no-mid-test-assertions rule, causing moved pre-reload checks, stashed one-shot reads, runtime beforeEach target skips that ran fixture teardowns on skipped attempts, and blanket file-level stays labels.

How it works

  1. skills/e2e/SKILL.md (146 lines, 9,113 bytes, down from 312 lines, 17,825 bytes on main) keeps the compact frontmatter description, the 8-topic routing table, a 6-step workflow with an explicit pre-run audit (SKILL.md:69: agent.act default when configured, one behavior with no undone actions or unchecked screens, second item shown at SKILL.md:82, no mid-test assertions, every test passes alone), and compact core rules (SKILL.md:101). Rerunning a test while you fix it and Feedback (keeping its "Never file the issue yourself" and search-first guardrails) live in skills/e2e/references/debugging.md. The duplicated docs/examples/skill/e2e.config.ts is removed because docs/examples/skill/e2e.setup.config.ts compiles the same config in setup.md.
  2. skills/e2e/references/writing-tests.md opens ## Contents by directing agents to read "A complete file" and "Structure" first and load later API sections only when needed. ## Structure (writing-tests.md:78) breaks Assert into sub-bullets covering mid-way .waitFor() narrowing, zero-match vs. multi-match locator exceptions, and banning pre-reload assertion moves or stashed one-shot reads (isVisible(), isEnabled(), count(), inputValue(), textContent(), getAttribute(), browser.evaluate()). It adds "Prove the change on the changed record" (writing-tests.md:129), "Act on the second item shown, never the first" (writing-tests.md:136), "Each test owns its starting state and passes alone" (writing-tests.md:174, noting simulator-only app.clearState() on iOS and device.installApp on physical iPhones), "Name and reuse what the tests repeat" (writing-tests.md:194), and "Prefer agent.act when a model is configured" (writing-tests.md:202), and warns under Fixtures that test.extend teardowns still run after beforeEach calls test.skip(...).
  3. projectTest (writing-tests.md:740 and docs/examples/skill/project-settings.e2e.ts) uses request, browser.cookies(url), randomUUID(), and agent.act, captures any returned project ID from a 2xx response before asserting HTTP 201, wraps creation and use() in try/finally, and checks delete status against [200, 204, 404]. writing-tests.md:732 keeps the web-only qualifier for named session (devices have no named sessions), and setup.md notes setting workers: 1 only for shared state no test can own.
  4. skills/migrate-to-e2e/SKILL.md updates Step 5 (migrate-to-e2e/SKILL.md:225, :255, :267), Step 6, and Step 8 to preserve each source assertion at its original observation point without stashed one-shot reads or duplicate expect padding, route same-platform targets with { tags } and --target, classify stays per test (separating blocked from stays), and keep the resume header fields in MIGRATION.md.
  5. test_lines (packages/e2e/src/session-tools/test-lines.ts:204 and :222): tool() and draft() distinguish fresh recordings (testRan === undefined && attached !== true), resumed tests (testRan !== undefined), and held-test attachments (attached === true), wired through packages/e2e/src/session-tools/catalog.ts:81 from packages/e2e/src/mcp/session.ts:476 (hasAgent: config.agent.model !== undefined || config.agent.executor !== undefined) and packages/e2e/src/run/worker/held-test-tools.ts:462 (attached: true). Fresh drafts include agent.act guidance only when hasAgent is true. tests/unit/mcp-test-lines.test.ts, tests/integration/mcp-test-run.test.ts, and tests/integration/mcp-step-attachment.test.ts cover all three modes and both halves of hasAgent.
  6. The agent, bug-bash, debugging, and mcp references and the docs pages agentic-vs-deterministic, agent-steps, ci, coding-agents, core-concepts, core, mcp-server, quickstart, reference/expect, reference/mcp, and reference/screen follow the same rules. docs/coding-agents.mdx's shop filter example waits for an over-$20 item in arrange and checks both the status text and visible Products items; docs/core.mdx's chat example passes app.baseUrl to launch(web(), ...). Four standalone examples (docs/examples/skill/todos.e2e.ts, docs/examples/skill/project-settings.e2e.ts, docs/examples/skill/shop.e2e.ts, and docs/examples/core/chat.e2e.ts) are registered in scripts/check-docs-examples.ts.
  7. plugins/e2e/skills/ is regenerated by pnpm plugins:sync; .changeset/skill-test-names-and-mix.md records a patch for e2e.

Verified

Ran it locally: yes, on head d9a3d64e4.

pnpm check                     -> exit 0 (55 verbatim docs examples compiled, 23 plugin files synced, 379 MDX pages)
e2e focused unit + MCP suites  -> Test Files 9 passed (9), Tests 315 passed (315)
pnpm --filter @e2e-dev/testbed test (87f316cae, same runtime) -> Test Files 49 passed (49), Tests 619 passed | 1 skipped (620)
docs_impact.py (origin/main..87f316cae) -> 0 FAIL, 0 WARN, 0 INFO
mutant.sh (f290b8577, same src logic)   -> 7 mutants, 7 killed, 0 survived, 0 unconfirmed, 0 did not build
  • Mutation testing ran in a detached worktree at f290b8577 (identical branching logic in test-lines.ts, catalog.ts, session.ts, and held-test-tools.ts; d9a3d64e4 only updated comments in test-lines.ts and docs/skill text) against mcp-test-lines.test.ts, mcp-test-run.test.ts, and mcp-step-attachment.test.ts, killing 7 of 7 mutants by AssertionError.

Agentic default and reuse A/B eval (web bookshop with agents.default.model + seeded support/shop.ts and deterministic login.e2e.ts)

Fresh delegated writers (Claude Haiku 5.5 and GPT-6 Luna, n=2 per arm) wrote cart, checkout, account, and auth suites under an identical neutral prompt, verified with tsc --noEmit and e2e list:

ModelArmtsc & e2e listNew tests using agent.actagent.act calls with paramsscreen.* action callsReused support/shop.tsMid-test expect
Haiku 5.5main (1642ef238)pass0 / 17 (0%)0 / 03910 / 101
Haiku 5.5PR #2157pass18 / 18 (100%)25 / 32 (78%)010 / 100
GPT-6 Lunamain (1642ef238)pass13 / 16 (81%)2 / 22 (9%)158 / 8 (0/2 BOOKS)0
GPT-6 LunaPR #2157pass16 / 16 (100%)25 / 31 (81%)08 / 8 (2/2 BOOKS)0

Deterministic mutation evals (15-mutant web bookshop, no model configured)

Fresh delegated writers on the model-less bookshop (M3 = Remove deletes the first row; 3x clean, 15 mutants, every test run alone):

Modelmain (5acb82235, 17.8 KB)Compressed PR (432c350ab, n=3)Post-agent.act-default spot-check (n=1)
Haiku 5.513.3/15, M3 0 of 314.67/15 (15, 15, 14), M3 3/3, alone 58/5814/15, M3 YES, alone 19/19, 0 agent.*
GPT-6 Luna12.7/15, M3 0 of 314.00/15 (15, 14, 13), M3 3/3, alone 46/4610/15, M3 YES, alone 12/12, 0 agent.*

Playwright migration eval on HomeKeeper (live local Supabase + Vite + Chromium/WebKit, 33 source tests across 15 files)

Fresh gpt-6-luna (high) migrations before and after the writing-tests.md and migrate-to-e2e/SKILL.md parity, target-routing, and per-test stays fixes, independently run live and audited by three stronger read-only advisors (Claude Fable 5.2, GPT-6.2 Astra, Gemini 4 Neon):

MetricRound 1 (before migration fixes)Round 2 (after migration fixes)
Playwright tests ported11 / 33 (33%) across 5 files -> 14 e2e tests26 / 33 (79%) across 13 files -> 45 e2e tests
Runtime beforeEach skips28 skipped attempts (25.1 s of 46.6 s run)0 skipped attempts (disjoint target runs)
stays tests22 / 33 (blanket whole-file stays)7 / 33 (per-test classification)
Independent live run17 passed, 28 skipped, 0 failed45 / 45 passed, 0 skipped, 0 failed (Playwright untouched: 33/15)

Round 2's three-advisor audit caught one remaining wording loophole (narrow isEnabled()/browser.evaluate() wording allowed stashing .isVisible()/.count()/.textContent()/.inputValue() one-shot reads); 87f316cae closed that loophole across the full read family, and d9a3d64e4 addresses all review comments from kdy1.

  • Limits: No live LLM API key was configured locally, so the Bookshelf agentic A/B eval proved authoring, tsc --noEmit, and e2e list, not live agent.act execution. Docs pages are verified by pnpm check (docs:check, 55 compiled verbatim examples, 379 MDX pages), not rendered screenshots.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.