An open source design system that's fully customizable and agent ready
TypeScript
ci: run the interaction proofs in legs split by recorded time (#9800)
Cindy Zhangda689f9893d3
diff --git a/.github/interaction-durations.json b/.github/interaction-durations.jsonnew file mode 100644index 0000000000..df7172816b--- /dev/null+++ b/.github/interaction-durations.json@@ -0,0 +1,40 @@+{+ "chromium": {+ "internal/interaction-harness/src/harness.interaction.browser.spec.ts": 118.3,+ "internal/interaction-harness/src/storybook.interaction.browser.spec.ts": 1.6,+ "packages/core/src/AlertDialog/__tests__/AlertDialog.interaction.browser.spec.ts": 20.3,+ "packages/core/src/AppShell/__tests__/AppShellLayoutRoot.interaction.browser.spec.ts": 4.6,+ "packages/core/src/ButtonGroup/__tests__/ButtonGroupCorners.interaction.browser.spec.ts": 0.9,+ "packages/core/src/Chat/__tests__/ChatMessageAvatar.interaction.browser.spec.ts": 1.2,+ "packages/core/src/DateInput/__tests__/DateInputFocusLeave.interaction.browser.spec.ts": 2.6,+ "packages/core/src/DateInput/__tests__/MonthScroller.interaction.browser.spec.ts": 5.1,+ "packages/core/src/DateInput/__tests__/MonthScrollerSteps.interaction.browser.spec.ts": 7.8,+ "packages/core/src/DateRangeInput/__tests__/DateRangeInputReflow.interaction.browser.spec.ts": 3.5,+ "packages/core/src/Field/__tests__/SearchKeyboard.interaction.browser.spec.ts": 5.6,+ "packages/core/src/SegmentedControl/__tests__/SegmentedControl.interaction.browser.spec.ts": 85.9,+ "packages/core/src/SideNav/__tests__/SideNavRailMotion.interaction.browser.spec.ts": 16.1,+ "packages/core/src/Slider/__tests__/SliderFinePointer.interaction.browser.spec.ts": 5.6,+ "packages/core/src/Slider/__tests__/SliderTouch.interaction.browser.spec.ts": 50.4,+ "packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts": 98.1,+ "packages/core/src/Switch/__tests__/SwitchPointer.interaction.browser.spec.ts": 18.3,+ "packages/core/src/TabList/__tests__/TabListOverflow.interaction.browser.spec.ts": 1.6,+ "packages/core/src/TabList/__tests__/TabPressPointer.interaction.browser.spec.ts": 2.7,+ "packages/core/src/TreeList/__tests__/TreeListGuideAlignment.interaction.browser.spec.ts": 2.9,+ "packages/core/src/animator/__tests__/createAnimator.interaction.browser.spec.ts": 6.8,+ "packages/core/src/gestures/__tests__/browser/gestures.interaction.browser.spec.ts": 41.7,+ "packages/core/src/gestures/__tests__/browser/presentedHitTesting.interaction.browser.spec.ts": 4.5,+ "packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts": 38.5,+ "packages/core/src/motion/__tests__/animatedLayout.interaction.browser.spec.ts": 24.4,+ "packages/core/src/motion/__tests__/animatedLayoutAdopters.interaction.browser.spec.ts": 24.5,+ "packages/core/src/motion/__tests__/animator.interaction.browser.spec.ts": 16.6+ },+ "webkit": {+ "internal/interaction-harness/src/harness.interaction.browser.spec.ts": 168.8,+ "internal/interaction-harness/src/storybook.interaction.browser.spec.ts": 8.8,+ "packages/core/src/gestures/__tests__/browser/gestures.interaction.browser.spec.ts": 51.6,+ "packages/core/src/gestures/__tests__/browser/presentedHitTesting.interaction.browser.spec.ts": 6.6,+ "packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts": 35.5,+ "packages/core/src/motion/__tests__/animatedLayout.interaction.browser.spec.ts": 41.8,+ "packages/core/src/motion/__tests__/animator.interaction.browser.spec.ts": 24.5+ }+}diff --git a/.github/scripts/ci-head-checkout-scripts.test.mjs b/.github/scripts/ci-head-checkout-scripts.test.mjsindex 6068a562a2..add1c105d0 100644--- a/.github/scripts/ci-head-checkout-scripts.test.mjs+++ b/.github/scripts/ci-head-checkout-scripts.test.mjs@@ -16,7 +16,9 @@* guarded: the step's condition requires `hashFiles('<script>') != ''`, the* job's scope step names it as `requires-head-file` and the step reads* `head_file_present`, the step loads it from the workflow's own commit- * (`git show "$WORKFLOW_SHA:<script>"`), or the step checks for it itself+ * (`git show "$WORKFLOW_SHA:<script>"`, or from the job's `.test-scope`+ * checkout, whose sparse directories hold it, directly or through a copy an+ * earlier step made in `$RUNNER_TEMP`), or the step checks for it itself* (`[ ! -f ... ]`). A job that does not measure the head takes the default* merge checkout instead, and this test does not apply to it.*@@ -102,6 +104,58 @@ export function skipsWhenMissing(run, script) {);}+/**+ * Whether the job's scope checkout (`path: .test-scope`, the workflow's own+ * commit) holds the script: a sparse-checkout directory contains it.+ */+export function scopeHolds(job, script) {+ const scope = (job.steps ?? []).find(+ step =>+ String(step.uses ?? '').startsWith('actions/checkout@') &&+ step.with?.path === '.test-scope' &&+ step.with?.ref == null,+ );+ const dirs = String(scope?.with?.['sparse-checkout'] ?? '')+ .split('\n')+ .map(line => line.trim().replace(/\/$/, ''))+ .filter(Boolean);+ return dirs.some(dir => script.startsWith(`${dir}/`));+}++/**+ * Whether the step runs `$RUNNER_TEMP/<dir>/<script>` that an earlier step of+ * the job copied there from the scope checkout:+ * `cp .test-scope/<script> "$RUNNER_TEMP/<dir>/<script's directory>/"`.+ */+export function copiedFromScope(job, step, script) {+ const escaped = script.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const used = new RegExp(`\\$RUNNER_TEMP/([\\w.-]+)/${escaped}`).exec(+ String(step.run ?? ''),+ );+ if (!used || !scopeHolds(job, script)) return false;+ const copy = `cp .test-scope/${script} "$RUNNER_TEMP/${used[1]}/${script.slice(0, script.lastIndexOf('/') + 1)}"`;+ const steps = job.steps ?? [];+ return steps+ .slice(0, steps.indexOf(step))+ .some(+ earlier =>+ String(earlier.run ?? '').includes(copy) &&+ beforeHeadCheckout(job, earlier),+ );+}++/** Whether the step runs before the job's head checkout replaces the workspace. */+export function beforeHeadCheckout(job, step) {+ const steps = job.steps ?? [];+ const head = steps.findIndex(+ each =>+ String(each.uses ?? '').startsWith('actions/checkout@') &&+ String(each.with?.ref ?? '').includes('pull_request.head.sha') &&+ !each.with?.path,+ );+ return head === -1 || steps.indexOf(step) < head;+}+export function unguardedScripts(job) {const scope = (job.steps ?? []).find(step =>String(step.uses ?? '').includes('test-scope'),@@ -116,6 +170,16 @@ export function unguardedScripts(job) {if (condition.includes(`hashFiles('${script}') != ''`)) continue;// Loaded from the workflow's own commit, not the head.if (run.includes(`$WORKFLOW_SHA:${script}`)) continue;+ // Read from the job's scope checkout, also the workflow's own commit,+ // before the head checkout replaces the workspace.+ if (+ run.includes(`.test-scope/${script}`) &&+ scopeHolds(job, script) &&+ beforeHeadCheckout(job, step)+ )+ continue;+ // Run from a copy an earlier step took from that scope checkout.+ if (copiedFromScope(job, step, script)) continue;// The step skips a head without this script on its own.if (skipsWhenMissing(run, script)) continue;if (diff --git a/.github/scripts/ci-interaction-webkit.test.mjs b/.github/scripts/ci-interaction-webkit.test.mjsindex 168c129da4..b57f44ce37 100644--- a/.github/scripts/ci-interaction-webkit.test.mjs+++ b/.github/scripts/ci-interaction-webkit.test.mjs@@ -73,7 +73,8 @@ describe('WebKit interaction proof routing', () => {});it('decides its own scope first, skips visibly, and gates every later step on it', () => {- expect(webkit.steps[0].with['sparse-checkout']).toBe(+ // The scope action first; the leg planner shares the checkout.+ expect(webkit.steps[0].with['sparse-checkout'].trim().split('\n')[0]).toBe('.github/actions/test-scope',);expect(decide(webkit).uses).toBe(@@ -96,9 +97,10 @@ describe('WebKit interaction proof routing', () => {]);for (const candidate of webkit.steps.slice(2)) {if (guards.has(candidate.name)) continue;+ // A leg whose plan holds no spec file runs no proofs.expect(candidate.if, candidate.name ?? candidate.uses).toMatch(new RegExp(- `^(always\\(\\) && )?${applies.replace(/[.()|]/g, '\\$&')}$`,+ `^(always\\(\\) && )?${applies.replace(/[.()|]/g, '\\$&')}( && steps\\.plan\\.outputs\\.files != '0')?$`,),);}@@ -158,7 +160,8 @@ describe('WebKit interaction proof routing', () => {});it('runs only the specs whose code its scope covers', () => {- const run = step(webkit, 'Run WebKit interaction proofs').run;+ // Each leg plans its share from these paths and runs only that share.+ const run = step(webkit, "Plan this leg's WebKit interaction proofs").run;const targets = ['packages/core/src/gestures/','packages/core/src/motion/__tests__/animatedLayout.interaction',diff --git a/.github/scripts/ci-interaction.test.mjs b/.github/scripts/ci-interaction.test.mjsindex bc8b5df6ca..e8219ee5d8 100644--- a/.github/scripts/ci-interaction.test.mjs+++ b/.github/scripts/ci-interaction.test.mjs@@ -59,7 +59,8 @@ describe('interaction proof routing', () => {});it('decides its own scope first, and gates every later step on it', () => {- expect(proofs.steps[0].with['sparse-checkout']).toBe(+ // The scope action first; the leg planner shares the checkout.+ expect(proofs.steps[0].with['sparse-checkout'].trim().split('\n')[0]).toBe('.github/actions/test-scope',);expect(decide().uses).toBe('./.test-scope/.github/actions/test-scope');@@ -70,9 +71,10 @@ describe('interaction proof routing', () => {]);for (const candidate of proofs.steps.slice(2)) {if (guards.has(candidate.name)) continue;+ // A leg whose plan holds no spec file runs no proofs.expect(candidate.if, candidate.name ?? candidate.uses).toMatch(new RegExp(- `^(always\\(\\) && )?${applies.replace(/[.()|]/g, '\\$&')}$`,+ `^(always\\(\\) && )?${applies.replace(/[.()|]/g, '\\$&')}( && steps\\.plan\\.outputs\\.files != '0')?$`,),);}diff --git a/.github/scripts/interaction-legs.mjs b/.github/scripts/interaction-legs.mjsnew file mode 100644index 0000000000..ce8d7f38c6--- /dev/null+++ b/.github/scripts/interaction-legs.mjs@@ -0,0 +1,210 @@+#!/usr/bin/env node+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file interaction-legs.mjs+ * @description Splits the interaction proofs of one Playwright project into+ * legs of about equal running time, by spec file, from the per-file times a+ * CI run recorded (spec:AST-030 FR13).+ * @input `plan`: the project, this leg and the leg count, and any Playwright+ * path filters; `.github/interaction-durations.json`. `record`: CI job logs+ * of the list reporter.+ * @output `plan`: this leg's spec files, one per line, for Playwright's+ * `--test-list`, and `files=<count>` for `$GITHUB_OUTPUT`. `record`: the+ * durations file, rewritten for the project.+ * @position The pr-interaction and pr-interaction-webkit legs in ci.yml.+ */++import {execFileSync} from 'node:child_process';+import fs from 'node:fs';+import path from 'node:path';+import {fileURLToPath} from 'node:url';++import {costOf, splitByDuration} from '../../scripts/lib/duration-split.mjs';+import {listedFiles} from './a11y-pr-contracts.mjs';++// CI runs this file from the workflow's own commit, outside the checkout, in+// the checkout's root.+const ROOT = process.cwd();+export const DURATIONS = path.join(ROOT, '.github/interaction-durations.json');+const CONFIG = 'playwright.interaction.config.ts';++/**+ * Splits `files` into `legs` lists of about equal estimated time, with the+ * shared duration splitter: slowest first, each onto the leg with the least+ * time so far. A file with no recorded time counts the median recorded time.+ * Every file lands in exactly one leg.+ */+export function planLegs(files, durations, legs) {+ if (!Number.isInteger(legs) || legs < 1)+ throw new Error(`legs must be a positive integer, got ${legs}`);+ const unique = [...new Set(files)];+ const cost = costOf(unique, durations ?? {});+ return splitByDuration(unique, legs, cost).map(leg => ({+ files: leg,+ seconds: leg.reduce((sum, file) => sum + cost(file), 0),+ }));+}++const TEST_LINE = /^(\S+Z)\s+\S+\s+\d+\s+\[([\w-]+)\] › ([^:]+):\d+:\d+ › /;+const RUNNING = /Running \d+ tests? using/;++/** Milliseconds of a log line's timestamp; GitHub writes seven fraction digits. */+function stamp(line) {+ return Date.parse(line.split(/\s/, 1)[0].replace(/(\.\d{3})\d*Z$/, '$1Z'));+}++/**+ * Seconds per spec file from a CI job log of the list reporter: each test's+ * time is the gap from the line before it, so a file's time includes its setup.+ */+export function recordLog(text, project) {+ const seconds = {};+ let previous = null;+ for (const line of text.split('\n')) {+ const at = stamp(line);+ if (previous == null && RUNNING.test(line) && Number.isFinite(at)) {+ previous = at;+ continue;+ }+ const match = TEST_LINE.exec(line);+ if (!match || previous == null || match[2] !== project) continue;+ const time = stamp(match[1]);+ seconds[match[3]] = (seconds[match[3]] ?? 0) + (time - previous) / 1000;+ previous = time;+ }+ return seconds;+}++function readDurations(file = DURATIONS) {+ return fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};+}++function option(args, name) {+ const index = args.indexOf(name);+ return index === -1 ? undefined : args[index + 1];+}++/** The spec files Playwright lists for a project with these extra arguments. */+function list(project, out, extra) {+ // The report goes to a file: a spec's own logging can share stdout.+ const reportFile = `${out}.list.json`;+ execFileSync(+ 'pnpm',+ [+ 'exec',+ 'playwright',+ 'test',+ '--config',+ CONFIG,+ '--project',+ project,+ '--list',+ '--reporter=json',+ ...extra,+ ],+ {+ cwd: ROOT,+ env: {+ ...process.env,+ PLAYWRIGHT_JSON_OUTPUT_FILE: path.resolve(reportFile),+ },+ stdio: ['ignore', 'ignore', 'inherit'],+ },+ );+ const report = JSON.parse(fs.readFileSync(reportFile, 'utf8'));+ fs.rmSync(reportFile, {force: true});+ return listedFiles(report);+}++function plan(args) {+ const split = args.indexOf('--');+ const own = split === -1 ? args : args.slice(0, split);+ const filters = split === -1 ? [] : args.slice(split + 1);+ const project = option(own, '--project');+ const leg = Number(option(own, '--leg'));+ const legs = Number(option(own, '--of'));+ const out = option(own, '--out');+ const durations = option(own, '--durations') ?? DURATIONS;+ if (!project || !out || !Number.isInteger(leg) || leg < 1 || leg > legs) {+ throw new Error(+ 'usage: plan --project <name> --leg <i> --of <n> --out <file> [--durations <file>] [-- <filters...>]',+ );+ }+ const files = list(project, out, filters);+ if (files.length === 0)+ throw new Error(`Playwright listed no ${project} interaction spec files`);+ const legsPlan = planLegs(+ files,+ readDurations(durations)[project] ?? {},+ legs,+ );+ const mine = legsPlan[leg - 1];+ fs.writeFileSync(out, mine.files.map(file => `${file}\n`).join(''));+ // Playwright runs nothing, and passes, for a test list that matches no+ // spec, so the leg checks that its list selects exactly its files.+ if (mine.files.length > 0) {+ const selected = list(project, out, ['--test-list', out]);+ if (selected.join('\n') !== mine.files.join('\n'))+ throw new Error(+ `The ${project} leg's test list selects ${selected.length} spec files, not its ${mine.files.length}`,+ );+ }+ console.log(+ `${project} leg ${leg}/${legs}: ${mine.files.length} of ${files.length} spec files, about ${Math.round(mine.seconds)} s`,+ );+ for (const [i, each] of legsPlan.entries())+ console.log(+ ` leg ${i + 1}: about ${Math.round(each.seconds)} s, ${each.files.length} files`,+ );+ for (const file of mine.files) console.log(` ${file}`);+ if (process.env.GITHUB_OUTPUT)+ fs.appendFileSync(+ process.env.GITHUB_OUTPUT,+ `files=${mine.files.length}\n`,+ );+}++function record(args) {+ const project = option(args, '--project');+ const logs = args.filter(+ (arg, i) => !arg.startsWith('--') && args[i - 1] !== '--project',+ );+ if (!project || logs.length === 0)+ throw new Error('usage: record --project <name> <job log...>');+ const seconds = {};+ for (const log of logs) {+ for (const [file, value] of Object.entries(+ recordLog(fs.readFileSync(log, 'utf8'), project),+ )) {+ seconds[file] = (seconds[file] ?? 0) + value;+ }+ }+ if (Object.keys(seconds).length === 0)+ throw new Error(`no ${project} test lines in the logs`);+ const durations = readDurations();+ durations[project] = Object.fromEntries(+ Object.entries(seconds)+ .sort(([a], [b]) => (a < b ? -1 : 1))+ .map(([file, value]) => [file, Math.round(value * 10) / 10]),+ );+ fs.writeFileSync(DURATIONS, `${JSON.stringify(durations, null, 2)}\n`);+ console.log(+ `${project}: ${Object.keys(seconds).length} spec files recorded into ${path.relative(ROOT, DURATIONS)}`,+ );+}++if (+ process.argv[1] &&+ path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)+) {+ const [command, ...args] = process.argv.slice(2);+ try {+ if (command === 'plan') plan(args);+ else if (command === 'record') record(args);+ else throw new Error('usage: interaction-legs.mjs plan|record ...');+ } catch (error) {+ console.error(error.message);+ process.exitCode = 1;+ }+}diff --git a/.github/scripts/interaction-legs.test.mjs b/.github/scripts/interaction-legs.test.mjsnew file mode 100644index 0000000000..f7d9a4e433--- /dev/null+++ b/.github/scripts/interaction-legs.test.mjs@@ -0,0 +1,415 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {execFileSync, spawnSync} from 'node:child_process';+import fs from 'node:fs';+import path from 'node:path';+import {fileURLToPath} from 'node:url';++import {describe, expect, it} from 'vitest';+import yaml from 'yaml';++import {planLegs, recordLog} from './interaction-legs.mjs';++const root = path.resolve(+ path.dirname(fileURLToPath(import.meta.url)),+ '../..',+);+const ci = yaml.parse(+ fs.readFileSync(path.join(root, '.github/workflows/ci.yml'), 'utf8'),+);+const durations = JSON.parse(+ fs.readFileSync(+ path.join(root, '.github/interaction-durations.json'),+ 'utf8',+ ),+);+const step = (job, name) => job.steps.find(each => each.name === name);++describe('planLegs', () => {+ const times = {a: 120, b: 100, c: 80, d: 50, e: 40, f: 30, g: 20, h: 10};+ const files = Object.keys(times);++ it('puts every spec file in exactly one leg', () => {+ for (const legs of [1, 2, 3, 5, 8, 11]) {+ const plan = planLegs(files, times, legs);+ expect(plan).toHaveLength(legs);+ expect(plan.flatMap(leg => leg.files).sort()).toEqual([...files].sort());+ }+ });++ it('balances the legs by recorded time, the longest file first', () => {+ const plan = planLegs(files, times, 3);+ const seconds = plan.map(leg => leg.seconds);+ // No leg is longer than the shortest by more than its longest file.+ expect(Math.max(...seconds) - Math.min(...seconds)).toBeLessThanOrEqual(+ 120,+ );+ expect(seconds.reduce((sum, value) => sum + value, 0)).toBe(450);+ expect(plan.map(leg => leg.files)).toEqual([+ ['a', 'f'],+ ['b', 'e', 'h'],+ ['c', 'd', 'g'],+ ]);+ });++ it('gives the same split for the same files in any order', () => {+ const shuffled = ['h', 'c', 'a', 'f', 'b', 'g', 'd', 'e', 'a'];+ expect(planLegs(shuffled, times, 3)).toEqual(planLegs(files, times, 3));+ });++ it('counts a spec file with no recorded time as the median recorded time', () => {+ const plan = planLegs([...files, 'new.spec.ts'], times, 2);+ const leg = plan.find(each => each.files.includes('new.spec.ts'));+ const others = leg.files.filter(file => file !== 'new.spec.ts');+ expect(+ leg.seconds - others.reduce((sum, file) => sum + times[file], 0),+ ).toBe(50);+ expect(planLegs(['x', 'y'], {}, 2).map(each => each.seconds)).toEqual([+ 1, 1,+ ]);+ });++ it('refuses a leg count that is not a positive integer', () => {+ expect(() => planLegs(files, times, 0)).toThrow(/positive integer/);+ expect(() => planLegs(files, times, 1.5)).toThrow(/positive integer/);+ });+});++describe('the list reader and recordLog', () => {+ it('reads the list report with the reader the accessibility contracts use', () => {+ const source = fs.readFileSync(+ path.join(root, '.github/scripts/interaction-legs.mjs'),+ 'utf8',+ );+ expect(source).toContain(+ "import {listedFiles} from './a11y-pr-contracts.mjs';",+ );+ expect(source).not.toMatch(/function listedFiles/);+ });++ it("records each test's gap from the line before it, under its spec file and project", () => {+ const log = [+ '2026-11-03T17:05:40.000Z Running 3 tests using 1 worker',+ '2026-11-03T17:05:43.000Z ✓ 1 [chromium] › a.spec.ts:10:3 › first (2.9s)',+ '2026-11-03T17:05:44.500Z ✓ 2 [chromium] › a.spec.ts:20:3 › second (1.4s)',+ '2026-11-03T17:05:49.500Z - 3 [chromium] › b.spec.ts:5:3 › skipped',+ '2026-11-03T17:05:59.000Z ✓ 1 [webkit] › c.spec.ts:5:3 › another project',+ ].join('\n');+ expect(recordLog(log, 'chromium')).toEqual({+ 'a.spec.ts': 4.5,+ 'b.spec.ts': 5,+ });+ expect(recordLog('no run here', 'chromium')).toEqual({});+ });+});++describe('the interaction proof legs in ci.yml', () => {+ const lanes = [+ {+ id: 'pr-interaction',+ project: 'chromium',+ legs: [1, 2],+ run: 'Run interaction proofs',+ plan: "Plan this leg's interaction proofs",+ evidence: 'interaction-evidence-${{ matrix.leg }}',+ },+ {+ id: 'pr-interaction-webkit',+ project: 'webkit',+ legs: [1, 2],+ run: 'Run WebKit interaction proofs',+ plan: "Plan this leg's WebKit interaction proofs",+ evidence: 'interaction-evidence-webkit-${{ matrix.leg }}',+ },+ ];++ for (const lane of lanes) {+ it(`${lane.id} runs as ${lane.legs.length} legs that each plan their share and run only it`, () => {+ const job = ci.jobs[lane.id];+ expect(job.strategy).toEqual({+ 'fail-fast': false,+ matrix: {leg: lane.legs},+ });+ expect(job.name).toBe(+ `${lane.id} (\${{ matrix.leg }}/\${{ strategy.job-total }})`,+ );+ const plan = step(job, lane.plan);+ expect(plan.id).toBe('plan');+ expect(plan.if).toBe("steps.scope.outputs.applies == 'true'");+ // A head cut before the legs has neither the planner nor the times,+ // so both come from the scope checkout: the workflow's own commit.+ const scope = job.steps[0];+ expect(scope.name).toBe('Check out the scope action');+ expect(scope.with.ref).toBeUndefined();+ expect(scope.with.path).toBe('.test-scope');+ expect(scope.with['sparse-checkout'].trim().split('\n')).toEqual([+ '.github/actions/test-scope',+ '.github/scripts',+ 'scripts/lib',+ ]);+ // The head checkout replaces the workspace, so a step before it keeps+ // the three files in the runner's temporary directory.+ const keep = step(job, "Keep the leg planner from the workflow's commit");+ const checkout = job.steps.findIndex(+ each =>+ each.name === 'Checkout' &&+ String(each.with?.ref).includes('pull_request.head.sha'),+ );+ expect(job.steps.indexOf(keep)).toBeGreaterThan(1);+ expect(job.steps.indexOf(keep)).toBeLessThan(checkout);+ expect(keep.if).toBe("steps.scope.outputs.applies == 'true'");+ for (const [file, dir] of [+ ['.github/scripts/interaction-legs.mjs', '.github/scripts/'],+ ['.github/scripts/a11y-pr-contracts.mjs', '.github/scripts/'],+ ['scripts/lib/duration-split.mjs', 'scripts/lib/'],+ ['.github/interaction-durations.json', '.github/'],+ ])+ expect(keep.run).toContain(+ `cp .test-scope/${file} "$RUNNER_TEMP/interaction-legs/${dir}"`,+ );+ expect(plan.run).toContain(+ `node "$RUNNER_TEMP/interaction-legs/.github/scripts/interaction-legs.mjs" plan --project ${lane.project}`,+ );+ expect(plan.run).toContain(+ '--durations "$RUNNER_TEMP/interaction-legs/.github/interaction-durations.json"',+ );+ expect(plan.run).not.toMatch(/git (fetch|show)/);+ expect(plan.run).toContain(+ '--leg ${{ matrix.leg }} --of ${{ strategy.job-total }}',+ );+ expect(plan.run).toContain('--out "$RUNNER_TEMP/interaction-leg.txt"');+ const run = step(job, lane.run);+ expect(job.steps.indexOf(plan)).toBeLessThan(job.steps.indexOf(run));+ expect(run.if).toBe(+ "steps.scope.outputs.applies == 'true' && steps.plan.outputs.files != '0'",+ );+ expect(run.run).toContain(+ '--test-list "$RUNNER_TEMP/interaction-leg.txt"',+ );+ expect(run.run).toContain(`--project ${lane.project}`);+ // One worker per runner: the proofs measure frame timing.+ expect(run.run).not.toMatch(/--workers|INTERACTION_WORKERS|--shard/);+ expect(+ job.steps.find(each =>+ each.uses?.startsWith('actions/upload-artifact@'),+ ).with.name,+ ).toBe(lane.evidence);+ });+ }++ it('a change to the planner, its modules or the recorded times runs both lanes', () => {+ for (const id of ['pr-interaction', 'pr-interaction-webkit']) {+ const scope = ci.jobs[id].steps.find(each => each.id === 'scope');+ const pattern = new RegExp(scope.with.paths);+ for (const file of [+ '.github/scripts/interaction-legs.mjs',+ '.github/scripts/a11y-pr-contracts.mjs',+ 'scripts/lib/duration-split.mjs',+ '.github/interaction-durations.json',+ ])+ expect(pattern.test(file), `${id} ${file}`).toBe(true);+ }+ });++ it('the WebKit legs plan only the paths the WebKit lane covers', () => {+ const plan = step(+ ci.jobs['pr-interaction-webkit'],+ "Plan this leg's WebKit interaction proofs",+ ).run;+ const filters = plan+ .slice(plan.indexOf(' -- ') + 4)+ .replaceAll('\\', '')+ .trim()+ .split(/\s+/);+ expect(filters).toEqual([+ 'packages/core/src/gestures/',+ 'packages/core/src/motion/__tests__/animatedLayout.interaction',+ 'packages/core/src/motion/__tests__/animator.interaction',+ 'packages/core/src/hooks/__tests__/usePager.interaction',+ 'internal/interaction-harness/',+ ]);+ });++ it("the test join reads each lane's whole result, so a failed, cancelled or skipped leg fails it", () => {+ const test = ci.jobs.test;+ expect(test.needs).toEqual(+ expect.arrayContaining(['pr-interaction', 'pr-interaction-webkit']),+ );+ const join = test.steps.find(each =>+ String(each.run ?? '').includes('ci-test-join.mjs'),+ );+ expect(join.env.PR_INTERACTION_RESULT).toBe(+ '${{ needs.pr-interaction.result }}',+ );+ expect(join.env.PR_INTERACTION_WEBKIT_RESULT).toBe(+ '${{ needs.pr-interaction-webkit.result }}',+ );+ const passing = {+ TEST_UI_RESULT: 'success',+ TEST_NODE_RESULT: 'success',+ TEST_BUILD_RESULT: 'success',+ TEST_NATIVE_SWIFT_RESULT: 'success',+ PR_INTERACTION_RESULT: 'success',+ PR_INTERACTION_WEBKIT_RESULT: 'success',+ RELEASE_BUMP: 'false',+ RELEASE_BUMP_RESULT: 'skipped',+ DOCSITE_ONLY: 'false',+ SPEC_ONLY: 'false',+ TOOLING_ONLY: 'false',+ LAB_ONLY: 'false',+ };+ const joinExit = env =>+ spawnSync(+ process.execPath,+ [path.join(root, '.github/scripts/ci-test-join.mjs')],+ {env: {PATH: process.env.PATH, ...env}},+ ).status;+ expect(joinExit(passing)).toBe(0);+ // GitHub reports a matrix job's result as success only when every leg+ // succeeded; any other aggregate fails the join.+ for (const lane of [+ 'PR_INTERACTION_RESULT',+ 'PR_INTERACTION_WEBKIT_RESULT',+ ]) {+ for (const result of ['failure', 'cancelled', 'skipped', '']) {+ expect(+ joinExit({...passing, [lane]: result}),+ `${lane}=${result}`,+ ).toBe(1);+ }+ }+ });++ it('records a time for each project the legs plan, each under the legs\u2019 per-runner budget', () => {+ for (const lane of lanes) {+ const times = durations[lane.project];+ expect(Object.keys(times).length, lane.project).toBeGreaterThan(0);+ const plan = planLegs(Object.keys(times), times, lane.legs.length);+ // About six minutes a leg under load; the recorded run was a loaded one.+ for (const leg of plan)+ expect(leg.seconds, lane.project).toBeLessThanOrEqual(6 * 60);+ }+ });++ it('plans from a copy outside the checkout, run in its root, with the times it is given', () => {+ const out = path.join(+ fs.mkdtempSync(path.join(root, 'node_modules/.cache-interaction-legs-')),+ 'leg.txt',+ );+ try {+ const fake = path.join(path.dirname(out), 'pnpm');+ // A stand-in pnpm that writes a list report for two spec files.+ fs.writeFileSync(+ fake,+ // With a test list it lists only the files the list names, unless+ // the list names z.spec.ts, which matches nothing.+ [+ `#!${process.execPath}`,+ "const fs = require('node:fs');",+ "const at = process.argv.indexOf('--test-list');",+ "let files = (process.env.FAKE_FILES || 'x.spec.ts,y.spec.ts').split(',');",+ "if (at !== -1) files = fs.readFileSync(process.argv[at + 1], 'utf8').split('\\n').filter(f => f && f !== 'z.spec.ts');",+ 'fs.writeFileSync(process.env.PLAYWRIGHT_JSON_OUTPUT_FILE, JSON.stringify({suites: files.map(file => ({specs: [{file}]}))}));',+ '',+ ].join('\n'),+ {mode: 0o755},+ );+ const output = path.join(path.dirname(out), 'github-output');+ // CI runs the workflow commit's copies of the planner and the splitter+ // it imports, laid out as in the tree, outside the checkout.+ const copies = path.join(path.dirname(out), 'legs');+ for (const file of [+ '.github/scripts/interaction-legs.mjs',+ '.github/scripts/a11y-pr-contracts.mjs',+ 'scripts/lib/duration-split.mjs',+ ]) {+ fs.mkdirSync(path.dirname(path.join(copies, file)), {recursive: true});+ fs.copyFileSync(path.join(root, file), path.join(copies, file));+ }+ const copy = path.join(copies, '.github/scripts/interaction-legs.mjs');+ const times = path.join(path.dirname(out), 'durations.json');+ fs.writeFileSync(+ times,+ JSON.stringify({chromium: {'x.spec.ts': 1, 'y.spec.ts': 100}}),+ );+ execFileSync(+ process.execPath,+ [+ copy,+ 'plan',+ '--project',+ 'chromium',+ '--leg',+ '2',+ '--of',+ '2',+ '--durations',+ times,+ '--out',+ out,+ ],+ {+ cwd: root,+ env: {+ ...process.env,+ PATH: `${path.dirname(fake)}:${process.env.PATH}`,+ GITHUB_OUTPUT: output,+ },+ encoding: 'utf8',+ },+ );+ // y is the long file, so it takes leg 1 and x is leg 2's.+ expect(fs.readFileSync(out, 'utf8')).toBe('x.spec.ts\n');+ expect(fs.readFileSync(output, 'utf8')).toBe('files=1\n');+ // A leg whose test list matches none of its files fails the plan.+ expect(() =>+ execFileSync(+ process.execPath,+ [+ copy,+ 'plan',+ '--project',+ 'chromium',+ '--leg',+ '1',+ '--of',+ '1',+ '--durations',+ times,+ '--out',+ out,+ ],+ {+ cwd: root,+ env: {+ ...process.env,+ PATH: `${path.dirname(fake)}:${process.env.PATH}`,+ FAKE_FILES: 'z.spec.ts',+ },+ stdio: 'pipe',+ },+ ),+ ).toThrow(/selects 0 spec files, not its 1/);+ expect(() =>+ execFileSync(+ process.execPath,+ [+ path.join(root, '.github/scripts/interaction-legs.mjs'),+ 'plan',+ '--project',+ 'chromium',+ '--leg',+ '3',+ '--of',+ '2',+ '--out',+ out,+ ],+ {stdio: 'pipe'},+ ),+ ).toThrow();+ } finally {+ fs.rmSync(path.dirname(out), {recursive: true, force: true});+ }+ });+});diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 524713ae4b..c082e251f2 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -2287,9 +2287,20 @@ jobs:delete-merged: truepr-interaction:+ name: pr-interaction (${{ matrix.leg }}/${{ strategy.job-total }})needs: [room, admission, heavy-ci, build-storybook]if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft && (github.event.pull_request.head.repo.full_name == github.repository || contains(github.event.pull_request.labels.*.name, 'ci:run'))) && (!cancelled() && needs.heavy-ci.outputs.deferred != 'true' && (github.event_name != 'workflow_dispatch' && always() && !cancelled() && needs.room.outputs.full != 'true' && needs.admission.outputs.full != 'true')) }}# Frame evidence measures timing: four cores, one Playwright worker.+ # One runner ran every proof in about ten minutes and passed the job's+ # fifteen once its checkout was slow. Two legs share the spec files by+ # their recorded times (interaction-legs.mjs), so each runs in about five+ # minutes, and a leg with the slowest checkout seen still ends with about+ # four minutes to spare. `test` reads the job's result, which is success+ # only when every leg passed.+ strategy:+ fail-fast: false+ matrix:+ leg: [1, 2]runs-on: ubuntu-latesttimeout-minutes: 15permissions:@@ -2301,10 +2312,16 @@ jobs:# This job decides its own scope (no separate scope job): the step# reads the PR's file list and the base's trusted classifier, and# everything is in scope when it cannot decide.+ # The workflow's own commit: the scope action, and the leg planner with+ # the shared splitter it imports and the recorded times (in .github, a+ # parent of the action, so the checkout's cone holds it).- name: Check out the scope actionuses: actions/checkout@v7with:- sparse-checkout: .github/actions/test-scope+ sparse-checkout: |+ .github/actions/test-scope+ .github/scripts+ scripts/libpath: .test-scopepersist-credentials: false@@ -2312,7 +2329,7 @@ jobs:id: scopeuses: ./.test-scope/.github/actions/test-scopewith:- paths: '^(internal/interaction-harness/|internal/a11y-spec/|playwright\.interaction\.config\.ts$|packages/[^/]+/src/|packages/themes/[^/]+/src/|apps/storybook/|\.github/workflows/ci\.yml$|package\.json$|pnpm-lock\.yaml$|\.github/actions/test-scope/)'+ paths: '^(internal/interaction-harness/|internal/a11y-spec/|playwright\.interaction\.config\.ts$|packages/[^/]+/src/|packages/themes/[^/]+/src/|apps/storybook/|\.github/workflows/ci\.yml$|package\.json$|pnpm-lock\.yaml$|\.github/scripts/(interaction-legs|a11y-pr-contracts)\.mjs$|scripts/lib/duration-split\.mjs$|\.github/interaction-durations\.json$|\.github/actions/test-scope/)'outside-pull-request: skiprequires-head-file: playwright.interaction.config.ts@@ -2326,6 +2343,19 @@ jobs:if: steps.scope.outputs.applies != 'true'run: echo "No interaction proofs for this change."+ # The head checkout below replaces the workspace, scope checkout+ # included, so the leg planner, the modules it imports (the shared+ # splitter and the Playwright list reader) and the recorded times move+ # to the runner's temporary directory first.+ - name: Keep the leg planner from the workflow's commit+ if: steps.scope.outputs.applies == 'true'+ run: |+ mkdir -p "$RUNNER_TEMP/interaction-legs/.github/scripts" "$RUNNER_TEMP/interaction-legs/scripts/lib"+ cp .test-scope/.github/scripts/interaction-legs.mjs "$RUNNER_TEMP/interaction-legs/.github/scripts/"+ cp .test-scope/scripts/lib/duration-split.mjs "$RUNNER_TEMP/interaction-legs/scripts/lib/"+ cp .test-scope/.github/scripts/a11y-pr-contracts.mjs "$RUNNER_TEMP/interaction-legs/.github/scripts/"+ cp .test-scope/.github/interaction-durations.json "$RUNNER_TEMP/interaction-legs/.github/"+# The caps step comes from the merge commit, not the pull request's# head: a head that predates the step does not have it. The head# checkout below replaces this directory.@@ -2375,10 +2405,25 @@ jobs:if: steps.scope.outputs.applies == 'true'run: pnpm install --frozen-lockfile && npx playwright install chromium- - name: Run interaction proofs+ # This leg's share of the spec files, by their recorded times. Every+ # spec file is in exactly one leg; one with no recorded time counts the+ # median. The planner, the shared splitter it imports and the times come+ # from the scope checkout, the workflow's own commit (kept above): a+ # head cut before them has none.+ - name: Plan this leg's interaction proofs+ id: planif: steps.scope.outputs.applies == 'true'+ run: |+ node "$RUNNER_TEMP/interaction-legs/.github/scripts/interaction-legs.mjs" plan --project chromium \+ --leg ${{ matrix.leg }} --of ${{ strategy.job-total }} \+ --durations "$RUNNER_TEMP/interaction-legs/.github/interaction-durations.json" \+ --out "$RUNNER_TEMP/interaction-leg.txt"++ - name: Run interaction proofs+ if: steps.scope.outputs.applies == 'true' && steps.plan.outputs.files != '0'run: |pnpm exec playwright test \+ --test-list "$RUNNER_TEMP/interaction-leg.txt" \--config playwright.interaction.config.ts \--project chromium \--output interaction-proof-output@@ -2388,7 +2433,7 @@ jobs:if: always() && steps.scope.outputs.applies == 'true'uses: actions/upload-artifact@v7with:- name: interaction-evidence+ name: interaction-evidence-${{ matrix.leg }}path: test-results/interaction-evidenceif-no-files-found: ignoreretention-days: 7@@ -2405,9 +2450,16 @@ jobs:# required context. Specs that need Chromium-only evidence skip themselves# in WebKit.pr-interaction-webkit:+ name: pr-interaction-webkit (${{ matrix.leg }}/${{ strategy.job-total }})needs: [room, admission, heavy-ci, build-storybook]if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft && (github.event.pull_request.head.repo.full_name == github.repository || contains(github.event.pull_request.labels.*.name, 'ci:run'))) && (!cancelled() && needs.heavy-ci.outputs.deferred != 'true' && (github.event_name != 'workflow_dispatch' && always() && !cancelled() && needs.room.outputs.full != 'true' && needs.admission.outputs.full != 'true')) }}# Frame evidence measures timing: four cores, one Playwright worker.+ # Two legs share the spec files by their recorded times, as the Chromium+ # proofs' two do; the harness spec alone fills one.+ strategy:+ fail-fast: false+ matrix:+ leg: [1, 2]runs-on: ubuntu-latesttimeout-minutes: 15permissions:@@ -2419,10 +2471,16 @@ jobs:# This job decides its own scope (no separate scope job): the step# reads the PR's file list and the base's trusted classifier, and# everything is in scope when it cannot decide.+ # The workflow's own commit: the scope action, and the leg planner with+ # the shared splitter it imports and the recorded times (in .github, a+ # parent of the action, so the checkout's cone holds it).- name: Check out the scope actionuses: actions/checkout@v7with:- sparse-checkout: .github/actions/test-scope+ sparse-checkout: |+ .github/actions/test-scope+ .github/scripts+ scripts/libpath: .test-scopepersist-credentials: false@@ -2430,7 +2488,7 @@ jobs:id: scopeuses: ./.test-scope/.github/actions/test-scopewith:- paths: '^(packages/core/src/gestures/|packages/core/src/motion/|packages/core/src/internal/touch|packages/core/src/utils/(press|touch|primaryClick|isApplePlatform|flatTree|inputStream|clickGuard|selectionLock|coarsePointer|sharedResizeObserver)|packages/core/src/privateAttributes/(hapticSwitch|reducedMotion)\.stylex\.ts$|packages/core/src/hooks/(useMenuPress|menuPress|useLongPress|usePressFeedback|isRtlElement|useIsomorphicLayoutEffect|useAttachment|usePager|__tests__/(usePager|pagerBundle))|internal/interaction-harness/|internal/a11y-spec/|playwright\.interaction\.config\.ts$|packages/themes/[^/]+/src/|apps/storybook/|\.github/workflows/ci\.yml$|package\.json$|pnpm-lock\.yaml$|\.github/actions/test-scope/)'+ paths: '^(packages/core/src/gestures/|packages/core/src/motion/|packages/core/src/internal/touch|packages/core/src/utils/(press|touch|primaryClick|isApplePlatform|flatTree|inputStream|clickGuard|selectionLock|coarsePointer|sharedResizeObserver)|packages/core/src/privateAttributes/(hapticSwitch|reducedMotion)\.stylex\.ts$|packages/core/src/hooks/(useMenuPress|menuPress|useLongPress|usePressFeedback|isRtlElement|useIsomorphicLayoutEffect|useAttachment|usePager|__tests__/(usePager|pagerBundle))|internal/interaction-harness/|internal/a11y-spec/|playwright\.interaction\.config\.ts$|packages/themes/[^/]+/src/|apps/storybook/|\.github/workflows/ci\.yml$|package\.json$|pnpm-lock\.yaml$|\.github/scripts/(interaction-legs|a11y-pr-contracts)\.mjs$|scripts/lib/duration-split\.mjs$|\.github/interaction-durations\.json$|\.github/actions/test-scope/)'outside-pull-request: skiprequires-head-file: playwright.interaction.config.ts@@ -2444,6 +2502,19 @@ jobs:if: steps.scope.outputs.applies != 'true'run: echo "No WebKit interaction proofs for this change (it touches no gesture, motion, touch or press code, and none of their shared setup)."+ # The head checkout below replaces the workspace, scope checkout+ # included, so the leg planner, the modules it imports (the shared+ # splitter and the Playwright list reader) and the recorded times move+ # to the runner's temporary directory first.+ - name: Keep the leg planner from the workflow's commit+ if: steps.scope.outputs.applies == 'true'+ run: |+ mkdir -p "$RUNNER_TEMP/interaction-legs/.github/scripts" "$RUNNER_TEMP/interaction-legs/scripts/lib"+ cp .test-scope/.github/scripts/interaction-legs.mjs "$RUNNER_TEMP/interaction-legs/.github/scripts/"+ cp .test-scope/scripts/lib/duration-split.mjs "$RUNNER_TEMP/interaction-legs/scripts/lib/"+ cp .test-scope/.github/scripts/a11y-pr-contracts.mjs "$RUNNER_TEMP/interaction-legs/.github/scripts/"+ cp .test-scope/.github/interaction-durations.json "$RUNNER_TEMP/interaction-legs/.github/"+# The caps step comes from the merge commit, not the pull request's# head: a head that predates the step does not have it. The head# checkout below replaces this directory.@@ -2495,6 +2566,23 @@ jobs:if: steps.scope.outputs.applies == 'true'run: pnpm install --frozen-lockfile && npx playwright install --with-deps webkit+ # This leg's share of the WebKit spec files, from the paths the lane+ # covers, by their recorded times. The planner and the times come from+ # the scope checkout, as for the Chromium legs.+ - name: Plan this leg's WebKit interaction proofs+ id: plan+ if: steps.scope.outputs.applies == 'true'+ run: |+ node "$RUNNER_TEMP/interaction-legs/.github/scripts/interaction-legs.mjs" plan --project webkit \+ --leg ${{ matrix.leg }} --of ${{ strategy.job-total }} \+ --durations "$RUNNER_TEMP/interaction-legs/.github/interaction-durations.json" \+ --out "$RUNNER_TEMP/interaction-leg.txt" -- \+ packages/core/src/gestures/ \+ packages/core/src/motion/__tests__/animatedLayout.interaction \+ packages/core/src/motion/__tests__/animator.interaction \+ packages/core/src/hooks/__tests__/usePager.interaction \+ internal/interaction-harness/+# WebKit renders through Mesa's llvmpipe, which sizes its thread pool# from the CPUs the process may run on. A container's CPU quota is not# that mask, so a runner that shows the host's CPUs oversubscribes the@@ -2502,7 +2590,7 @@ jobs:# set (the job's share, rounded up); without a quota the count stays# nproc, llvmpipe's own default.- name: Run WebKit interaction proofs- if: steps.scope.outputs.applies == 'true'+ if: steps.scope.outputs.applies == 'true' && steps.plan.outputs.files != '0'run: |LP_NUM_THREADS="$(nproc)"if [ -r /sys/fs/cgroup/cpu.max ]; then@@ -2517,11 +2605,7 @@ jobs:export LP_NUM_THREADSecho "llvmpipe threads: $LP_NUM_THREADS"pnpm exec playwright test \- packages/core/src/gestures/ \- packages/core/src/motion/__tests__/animatedLayout.interaction \- packages/core/src/motion/__tests__/animator.interaction \- packages/core/src/hooks/__tests__/usePager.interaction \- internal/interaction-harness/ \+ --test-list "$RUNNER_TEMP/interaction-leg.txt" \--config playwright.interaction.config.ts \--project webkit \--output interaction-proof-output-webkit@@ -2530,7 +2614,7 @@ jobs:if: always() && steps.scope.outputs.applies == 'true'uses: actions/upload-artifact@v7with:- name: interaction-evidence-webkit+ name: interaction-evidence-webkit-${{ matrix.leg }}path: test-results/interaction-evidenceif-no-files-found: ignoreretention-days: 7diff --git a/scripts/lib/duration-split.test.mjs b/scripts/lib/duration-split.test.mjsindex ebbffcde81..eda95817c1 100644--- a/scripts/lib/duration-split.test.mjs+++ b/scripts/lib/duration-split.test.mjs@@ -69,9 +69,13 @@ describe('splitting test files by recorded time', () => {expect(read('.github/scripts/a11y-contract-shard.mjs')).toMatch(/import \{medianOf\} from '\.\.\/\.\.\/scripts\/lib\/duration-split\.mjs'/,);+ expect(read('.github/scripts/interaction-legs.mjs')).toMatch(+ /import \{costOf, splitByDuration\} from '\.\.\/\.\.\/scripts\/lib\/duration-split\.mjs'/,+ );for (const file of ['scripts/vitest-shard-sequencer.mjs','.github/scripts/a11y-contract-shard.mjs',+ '.github/scripts/interaction-legs.mjs',])expect(read(file), file).not.toMatch(/known\[Math\.floor/);});