feat(run)!: video modes on the config, targets, the CLI, and tests, with provider recordings

Merged
OK
2mo ago
+2610-411

What and why

Video had one run-wide switch (artifacts.kinds: ['video'] or --video) and a retain flag. This PR makes it a first-class, engine-agnostic option, adds retry-aware modes, and lets hosted services supply the recording.

How other tools do it (the research that shaped the API)

ToolWhere it is setModesPer-test
Playwrightconfig, project, test.use per file or describeoff, on, retain-on-failure, on-first-retry, plus 3 added in 1.61describe only, because the video fixture is worker-scoped
Cypressconfigon/off, delete in after:specnone
Detoxconfig, --record-videosnone, failing, allnone
Maestro, Appiumin-flow start/stopexplicityes
BrowserStack, Sauce, LambdaTest, Browserbasesession capabilityon, or videoUploadOnPassper session; a URL after the session ends
Kernel, Limrun, Anchormid-session start/stop APIexplicitper session; bytes or a URL

Other runners bind recording to context or session creation, so a per-test switch would cost them a new worker or session. e2e starts and stops recording per attempt through the engine hooks, so a per-test override costs nothing here.

The API

export default {
  video: 'retain-on-failure',                    // config default
  targets: [
    { name: 'web', engine: web({ url }) },
    { name: 'kernel', engine: web({ url, browser: kernel() }), video: 'on-first-retry' },
  ],
} satisfies E2EConfig;

test('checkout', { video: 'on' }, async ({ app, screen }) => { /* ... */ }); // innermost wins
  • Modes: off, on, retain-on-failure, on-first-retry. They are Playwright's first four, and they cover the two patterns every tool converges on: record everything and keep failures, or record only the retry.
  • Precedence, lowest to highest: the config's video, the target's, --video [mode], then a test or describe. Inside a serial group the group decides, as it does for retries.
  • Breaking: artifacts.kinds: ['video'] and artifacts.video are removed, and using them is INVALID_CONFIG with the new spelling in the message.
  • Preflight: UNSUPPORTED_ARTIFACT is raised only when a test that runs would actually record on an engine that cannot.
  • Step captions were prototyped here and taken out to be designed properly in #636 (the prototype is on oskar/video-captions-prototype).
  • Local screencast: web({ video: { size, quality } }).

Provider recordings, engine-agnostic

flowchart LR
  A[attempt starts video] --> B{provider has record?}
  B -- yes --> C[provider.record lease -> ProviderRecording]
  B -- no --> D[engine capture: Playwright screencast / agent-device]
  C --> E[stopProviderRecording: file in video/ or http link]
  D --> F[VideoSegment files]
  E --> G[report: path or url]
  F --> G
  • e2e/engine exports ProviderRecording, ProviderRecordContext, isProviderRecording, and stopProviderRecording. VideoSegment becomes VideoFile | VideoLink.
  • BrowserProvider.record and DeviceProvider.record use the same seam. On mobile the worker now learns its lease id, so a provider can recover its lease.
  • Kernel replays are the first provider that records, saved as video/replay.mp4. Headless browsers and replay: false fall back to the screencast.
  • Schema: report-1 artifacts gain an optional url (http(s) only), with both fixtures updated. The run page links a hosted video to its own URL.

Verified

Ran it locally: yes

  • /tmp/video-smoke, a fresh project using the packed tarballs, a local app, and retries: 1. Each target has places an order (passes), fails on purpose (fails on both attempts), and keeps quiet (video: 'off'):
Targetpassesfails (2 attempts)video: 'off'
video: 'on'keptboth keptnothing
web({ video: { size: 640x360 } })kept, 640x360both keptnothing
retain-on-failuredroppedboth keptnothing
on-first-retrynothingattempt 1 onlynothing
  • Real Kernel: an agent test with video: 'on' produced video/replay.mp4, the Kernel replay of the whole browser window.

  • e2e mcp on Kernel: start_recording / stop_recording saved a 1920x1080 Kernel replay to .e2e/videos/<session>/1-todo-demo.mp4. On a local browser the same tools saved the page screencast as .webm.

  • After taking captions out, the /tmp/video-smoke run again kept every video under on and only the failed ones under retain-on-failure, with no .vtt written and no captions field.

  • A fresh-context review found 8 issues and all are fixed (the eighth was about captions, which are now out):

    • Provider URLs and timestamps normalized to the schema's shapes.
    • --video no longer hides an invalid target mode.
    • video rejected on a describe nested in a serial group.
    • One list of modes.
    • One shared recording check for web and mobile.
    • A mobile lease's own leaseId.
    • The changeset note for stores.
  • Follow-ups, not in this PR:

    • expiresAt on links, because signed URLs expire.
    • Handing the attempt's verdict to a provider's stop, so retain-on-failure can delete the remote recording.
    • More Playwright modes if someone asks for them.

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). Removed without a deprecation window, by decision.
  • 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.

https://github.com/user-attachments/assets/819fe714-79ad-4d17-b9ac-a8a0061e79d2


Devin Review