Files
sim/scripts/desktop-e2e.ts
WaleedandClaude Opus 5.5 ca57a3b3ff improvement(desktop-e2e): one shared harness with a bounded quit, flake fixes, and a trimmed suite (#10390)
* improvement(desktop-e2e): shared launch fixture with a bounded, diagnosed quit

* improvement(desktop-e2e): shared fixture bundling and tool authorization

* improvement(desktop-e2e): split local-files onto the shared harness and fix live-sim consent handling

local-files: four tests (consent, Full file access, fs races, restart/sign-out) on the desktop
fixture with bounded restarts; a minimal fixture page replaces apps/sim's Settings component;
the shared-prompt step waits for a real join; fs patches restore in finally and assert they ran.

desktop-tools-live-sim: launches through the harness, approves only folder consent dialogs,
and merges the two awaiting-approval tests into one launch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* improvement(desktop-e2e): move source-connect, page dialogs, and sign-in prompts onto the shared harness

- Launch, servers, fixture bundling, tool authorization, focus, and panel bounds come from the
  harness; Chromium for source-connect is Playwright's own context fixture. Report files and
  check() wrappers give way to test.step.
- browser-page.ts shares the shell fixture server, browser-chrome actions, and exact-URL page
  reads and trusted input between the dialogs and sign-in specs.
- Typed input is awaited until it lands before the next action; page lookups match the exact URL.
- Sign-in links record clicks so "nothing happened" checks only run after a click landed; the
  sign-in retry loop and the two-outcome passkey Enter check are gone; the suite is split into
  two tests so it no longer needs a longer timeout.
- source-connect waits for observable effects before asserting a stale callback, a repeated
  Connect, and the retried inventory left state alone; page errors are asserted at the end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* improvement(desktop-e2e): background executor and terminal cancel on the shared harness

Launch through the desktop fixture (launchAgainst), so every app quits under a
deadline and every profile, ZDOTDIR and temp dir is removed. Replace fixed
sleeps with condition waits (journal state, inbox reads, a tmux attachment
probe, a control run for relaunch recovery), deliver user input before the
agent acts, make tmux required in CI, and drop or merge tests other suites
already cover.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* improvement(desktop-e2e): move shell, quick chat, autofill, session, updater and packaged specs onto the shared harness

Every spec launches through the desktop fixture with a bounded quit, binds
fixtures to loopback, and records checks as test.step. Merges duplicate
launches in smoke and continue-sign-in, folds the packaged launch-telemetry
check into the offline-page launch, replaces fixed sleeps and one-shot reads
with condition waits, and deletes the check-report file report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* improvement(desktop-e2e): drop dead env and report plumbing; share launch, quit and fixture styles

* improvement(desktop-e2e): move browser tools, chrome, focus, and page-parity specs onto the shared harness

Browser tools share one app across read-only tests with a disposed provisional scope per test;
window-state and sign-out tests launch their own. Fixes focus, fire-and-forget IPC, and
load races; drops unasserted screenshots, the duplicate confirm-dialog check, and the
fixture-decided terminal test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* improvement(desktop-e2e): browser tools and chrome use the shared launch, quit and bundling

* chore(knip): drop the deleted worker-restart fixture entry

* fix(desktop-e2e): renew panel bounds, keep the child process, one app per browser-tools test, quit before cleanup

* fix(desktop-e2e): correct three migrated waits and keep the real toast timer

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 16:22:58 -08:00

63 lines
2.7 KiB
TypeScript

import { spawnSync } from 'node:child_process'
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { partitionFiles } from '@scripts/duration-shards'
import { createLogger } from '@sim/logger'
import { escapeRegExp } from '@sim/utils/string'
interface DiscoveryReport {
config: { rootDir: string }
suites: { file: string }[]
errors: unknown[]
}
const logger = createLogger('DesktopE2E')
const match = /^(\d+)\/(\d+)$/.exec(process.argv[2] ?? '')
if (!match) throw new Error('Usage: bun run ../../scripts/desktop-e2e.ts <shard>/<total>')
const index = Number(match[1])
const count = Number(match[2])
if (!Number.isSafeInteger(index) || !Number.isSafeInteger(count) || index < 1 || index > count) {
throw new Error('Invalid desktop shard index or count')
}
mkdirSync('test-results', { recursive: true })
const discoveryPath = resolve('test-results/desktop-discovery.json')
const discovery = spawnSync('bunx', ['playwright', 'test', '--list', '--reporter=json'], {
stdio: 'inherit',
env: { ...process.env, PLAYWRIGHT_JSON_OUTPUT_FILE: discoveryPath },
})
if (discovery.error) throw discovery.error
if (discovery.status !== 0) process.exit(discovery.status ?? 1)
const discoveryJson = readFileSync(discoveryPath, 'utf8')
const report = JSON.parse(discoveryJson) as DiscoveryReport
if (report.errors.length > 0) throw new Error('Playwright discovery reported errors')
// A test factory can declare tests in a helper; the outer suite owns the discoverable test file.
const files = new Set(report.suites.map((suite) => suite.file))
if (count > files.size) throw new Error('More desktop shards than discovered test files')
const durations = JSON.parse(
readFileSync(new URL('../apps/desktop/e2e-durations.json', import.meta.url), 'utf8')
) as Record<string, number>
const shards = partitionFiles([...files], durations, count)
const selected = shards[index - 1]
if (selected.length === 0) throw new Error('Desktop shard selected no test files')
logger.info(`Running desktop shard ${index}/${count}: ${selected.join(', ')}`)
const run = spawnSync(
'bunx',
[
'playwright',
'test',
...selected.map((file) => `^${escapeRegExp(resolve(report.config.rootDir, file))}$`),
// `github` turns failures into annotations; an explicit --reporter replaces the config's.
process.env.CI ? '--reporter=github,line,json' : '--reporter=line,json',
],
{ stdio: 'inherit', env: process.env }
)
mkdirSync('test-results', { recursive: true })
writeFileSync(discoveryPath, discoveryJson)
writeFileSync(
'test-results/desktop-shard-plan.json',
`${JSON.stringify({ index, count, discoveredFiles: files.size, shards }, null, 2)}\n`
)
if (run.error) throw run.error
process.exit(run.status ?? 1)