Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci: the WebKit lane runs a component folder's interaction specs when its code changes (#10225)

Cindy Zhang9782deaebb1f
diff --git a/.github/scripts/ci-interaction-webkit.test.mjs b/.github/scripts/ci-interaction-webkit.test.mjs
index 87dc7af02d..23e32a1dd3 100644
--- a/.github/scripts/ci-interaction-webkit.test.mjs
+++ b/.github/scripts/ci-interaction-webkit.test.mjs
@@ -6,12 +6,14 @@
* pr-interaction runs the touch interaction proofs in Chromium only, so a
* WebKit- or iOS-only correction (a tap on content that moved under the
* finger, Safari's own pointer events) had no CI guard. pr-interaction-webkit
- * runs the same proofs in WebKit, but only for the code where the engines
- * differ on touch: the gesture host and recognizers, the motion runtime, the
- * touch helpers, press feedback and the menu press model, plus the harness and
- * config that drive them. Out of that scope it skips visibly and reports
- * success, and the existing `test` join requires it, so it adds no required
- * context. The scope step's own behavior is in test-scope-action.test.mjs.
+ * runs the proofs in WebKit for what a change reaches: its own paths for the
+ * code where the engines differ on touch (the gesture host and recognizers,
+ * the motion runtime, the touch helpers, press feedback and the menu press
+ * model, plus the harness and config that drive them), each interaction spec
+ * the change edits, and every interaction spec in a component folder whose
+ * code it changes. With nothing to run it skips visibly and reports success,
+ * and the existing `test` join requires it, so it adds no required context.
+ * The scope step's own behavior is in test-scope-action.test.mjs.
*/
import {execFileSync} from 'node:child_process';
@@ -24,6 +26,7 @@ import {describe, expect, it} from 'vitest';
import yaml from 'yaml';
import {ungated} from './ci-pr-gate.mjs';
+import {isInteractionSpec, selectProofs} from './playwright-legs.mjs';
const root = path.resolve(import.meta.dirname, '../..');
const ci = yaml.parse(
@@ -36,7 +39,33 @@ const step = (job, name) =>
const decide = job => job.steps.find(candidate => candidate.id === 'scope');
const applies = "steps.scope.outputs.applies == 'true'";
const inScope = touched => new RegExp(decide(webkit).with.paths).test(touched);
-const runs = files => files.some(inScope);
+// Every interaction spec in the repository, as the legs step lists them.
+function specsUnder(dir) {
+ const out = [];
+ for (const entry of fs.readdirSync(path.join(root, dir), {
+ withFileTypes: true,
+ })) {
+ const file = `${dir}/${entry.name}`;
+ if (entry.isDirectory()) {
+ if (entry.name !== 'node_modules' && entry.name !== 'dist')
+ out.push(...specsUnder(file));
+ } else if (isInteractionSpec(file)) out.push(file);
+ }
+ return out;
+}
+const listedSpecs = [...specsUnder('packages'), ...specsUnder('internal')];
+// What the WebKit legs run for a change: nothing outside the scope step's
+// paths, else what the legs step selects.
+const proofs = files =>
+ files.some(inScope)
+ ? selectProofs({
+ listed: listedSpecs,
+ changed: files,
+ shared: new RegExp(webkit.env.WEBKIT_SHARED_PATHS),
+ filters: webkit.env.WEBKIT_SPEC_PATHS.trim().split(/\s+/),
+ })
+ : [];
+const runs = files => proofs(files).length > 0;
describe('WebKit interaction proof routing', () => {
it('is joined by test, adding no required context of its own', () => {
@@ -235,9 +264,9 @@ describe('WebKit interaction proof routing', () => {
it('runs only the specs whose code its scope covers', () => {
// Each leg plans its share from these paths and runs only that share.
const run = webkit.env.WEBKIT_SPEC_PATHS;
- expect(
- step(webkit, "Plan this leg's WebKit interaction proofs").run,
- ).toContain('"${SPEC_PATHS[@]}"');
+ const count = step(webkit, "Count this run's WebKit legs").run;
+ expect(count).toContain('--shared "$WEBKIT_SHARED_PATHS"');
+ expect(count).toContain('-- "${SPEC_PATHS[@]}" > "$selected"');
const targets = [
'packages/core/src/gestures/',
'packages/core/src/motion/__tests__/animatedLayout.interaction',
@@ -251,14 +280,16 @@ describe('WebKit interaction proof routing', () => {
}
// The adopters spec renders Storybook components (Collapsible, TreeList,
// ScrollableArea), and component specs (DateInput, TabList, TreeList,
- // SideNav) stay with the Chromium proofs.
+ // SideNav) run for a change to their own folder, not for shared code.
expect(run).not.toContain('animatedLayoutAdopters');
expect(run).not.toMatch(/motion\/ /);
- // Carousel paging renders its Storybook story, so it stays there too: its
- // code starts no WebKit run. A change to its spec does (see below).
expect(run).not.toContain('CarouselPaging');
- expect(inScope('packages/core/src/Carousel/useCarouselPaging.ts')).toBe(
- false,
+ // A component's own code runs that folder's interaction specs, and no
+ // shared proof.
+ expect(proofs(['packages/core/src/Carousel/useCarouselPaging.ts'])).toEqual(
+ [
+ 'packages/core/src/Carousel/__tests__/Carousel.interaction.browser.spec.ts',
+ ],
);
for (const component of ['DateInput', 'TabList', 'TreeList', 'SideNav']) {
expect(run).not.toContain(component);
@@ -281,46 +312,65 @@ describe('WebKit interaction proof routing', () => {
'packages/core/src/Carousel/__tests__/CarouselPaging.interaction.browser.spec.ts',
),
).toBe(true);
- // Only spec files: the component's code still starts no WebKit run.
- expect(inScope('packages/core/src/List/ListRow.tsx')).toBe(false);
- expect(inScope('packages/core/src/List/__tests__/ListRow.test.tsx')).toBe(
- false,
- );
+ // The component's code runs its folder's specs; a unit test runs none.
+ const listCode = proofs(['packages/core/src/List/ListRow.tsx']);
+ expect(listCode.length).toBeGreaterThan(0);
+ expect(
+ listCode.every(file => file.startsWith('packages/core/src/List/')),
+ ).toBe(true);
+ expect(
+ proofs(['packages/core/src/List/__tests__/ListRow.test.tsx']),
+ ).toEqual([]);
});
it('lists the changed files for the WebKit plan', () => {
expect(decide(webkit).with['component-audit']).toBe('true');
- expect(
- step(webkit, "Plan this leg's WebKit interaction proofs").env
- .CHANGED_FILES,
- ).toBe('${{ steps.scope.outputs.changed_files_path }}');
+ const count = step(webkit, "Count this run's WebKit legs");
+ expect(count.env.CHANGED_FILES).toBe(
+ '${{ steps.scope.outputs.changed_files_path }}',
+ );
+ expect(count.run).toContain('--changed "${CHANGED_FILES:-}"');
// The Chromium legs plan every spec file, with no path filter.
expect(
step(chromium, "Plan this leg's interaction proofs").run,
).not.toContain(' -- ');
});
- // Runs the plan step with a stub `node` that prints its arguments.
- function planArgs(changed, present) {
+ // Runs a step's script with a stub `node` that prints its arguments, over
+ // the legs step's selection, and returns them with the step's outputs.
+ function runStep(name, selected, present) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'webkit-plan-'));
try {
for (const file of present) {
fs.mkdirSync(path.join(dir, path.dirname(file)), {recursive: true});
fs.writeFileSync(path.join(dir, file), '');
}
- const list = changed == null ? '' : path.join(dir, 'changed.txt');
- if (list)
- fs.writeFileSync(list, changed.map(file => `${file}\n`).join(''));
+ fs.mkdirSync(path.join(dir, 'interaction-legs'));
+ fs.writeFileSync(
+ path.join(dir, 'interaction-legs/selected.txt'),
+ selected.map(file => `${file}\n`).join(''),
+ );
const bin = path.join(dir, 'bin');
fs.mkdirSync(bin);
fs.writeFileSync(
path.join(bin, 'node'),
- '#!/usr/bin/env bash\nprintf "%s\\n" "$@"\n',
+ // `select` prints the selection it was handed; the rest print args.
+ '#!/usr/bin/env bash\nif [ "$2" = select ]; then cat "$RUNNER_TEMP/interaction-legs/selected.txt"; else printf "%s\\n" "$@"; fi\n',
{mode: 0o755},
);
- const script = step(webkit, "Plan this leg's WebKit interaction proofs")
+ const output = path.join(dir, 'output.txt');
+ fs.writeFileSync(output, '');
+ // The scope checkout the legs step lists the tree from.
+ fs.writeFileSync(
+ path.join(bin, 'git'),
+ '#!/usr/bin/env bash\nexit 0\n',
+ {mode: 0o755},
+ );
+ const script = step(webkit, name)
.run.replaceAll('${{ steps.legs.outputs.leg }}', '1')
- .replaceAll('${{ steps.legs.outputs.count }}', '2');
+ .replaceAll('${{ steps.legs.outputs.count }}', '2')
+ .replaceAll('${{ matrix.leg }}', '1')
+ .replaceAll('${{ strategy.job-total }}', '2');
const out = execFileSync('bash', ['-e', '-c', script], {
cwd: dir,
encoding: 'utf8',
@@ -328,41 +378,49 @@ describe('WebKit interaction proof routing', () => {
...process.env,
PATH: `${bin}:${process.env.PATH}`,
RUNNER_TEMP: dir,
- CHANGED_FILES: list,
+ GITHUB_OUTPUT: output,
+ CHANGED_FILES: '',
WEBKIT_SPEC_PATHS: webkit.env.WEBKIT_SPEC_PATHS,
+ WEBKIT_SHARED_PATHS: webkit.env.WEBKIT_SHARED_PATHS,
},
});
- return out.trim().split('\n');
+ return {
+ args: out.trim().split('\n'),
+ outputs: fs.readFileSync(output, 'utf8'),
+ };
} finally {
fs.rmSync(dir, {recursive: true, force: true});
}
}
+ const plan = (selected, present) =>
+ runStep("Plan this leg's WebKit interaction proofs", selected, present);
- it("adds the changed spec to the WebKit plan's paths", () => {
- const args = planArgs(
- [spec, 'packages/core/src/List/ListRow.tsx'],
- [spec],
- );
+ it("plans the selected specs the head has, and the lane's own paths", () => {
+ const {args} = plan(['packages/core/src/gestures/', spec], [spec]);
const paths = args.slice(args.indexOf('--') + 1);
- expect(paths).toContain(spec);
- expect(paths).toContain('packages/core/src/gestures/');
- expect(paths).not.toContain('packages/core/src/List/ListRow.tsx');
+ expect(paths).toEqual(['packages/core/src/gestures/', spec]);
});
it('leaves out a spec the pull request deletes', () => {
const deleted =
'packages/core/src/List/__tests__/Old.interaction.browser.spec.ts';
- const args = planArgs([deleted], []);
+ const {args} = plan([deleted, 'internal/interaction-harness/'], []);
expect(args).not.toContain(deleted);
expect(args.at(-1)).toBe('internal/interaction-harness/');
});
- it('plans only its own paths, and warns, when the scope step lists no files', () => {
- const args = planArgs(null, []);
- expect(args.at(-1)).toBe('internal/interaction-harness/');
- expect(args.join('\n')).toContain(
- '::warning title=Changed specs not planned::',
- );
+ it('plans no file, and never every spec, when the head has none of the selected specs', () => {
+ const deleted =
+ 'packages/core/src/List/__tests__/Old.interaction.browser.spec.ts';
+ const {args, outputs} = plan([deleted], []);
+ expect(outputs).toContain('files=0');
+ expect(args.join('\n')).not.toContain(' plan');
+ });
+
+ it('runs no leg when the selection is empty', () => {
+ const {outputs} = runStep("Count this run's WebKit legs", [], []);
+ expect(outputs).toContain('count=0');
+ expect(outputs).toContain('runs=false');
});
});
@@ -457,23 +515,38 @@ describe('WebKit interaction proof routing', () => {
'.github/actions/test-scope/action.yml',
]) {
expect(inScope(touched), touched).toBe(true);
+ expect(runs([touched]), touched).toBe(true);
+ }
+ });
+
+ it('runs every interaction spec of a component folder whose code changes, in every package', () => {
+ const folderOf = file =>
+ /^(packages\/[^/]+\/src\/[A-Z][^/]*)\//.exec(file)?.[1];
+ const folders = [...new Set(listedSpecs.map(folderOf).filter(Boolean))];
+ // Lab's own proofs too, not only Core's. A pull request that changes
+ // only Lab takes the Lab-only lane, which runs no interaction proofs
+ // (spec:AST-030 FR26), so Lab's folders run beside a change outside Lab.
+ expect(folders).toContain('packages/lab/src/RefreshControl');
+ for (const folder of folders) {
+ const change = `${folder}/Changed.tsx`;
+ expect(inScope(change), change).toBe(true);
+ const own = listedSpecs.filter(file => folderOf(file) === folder);
+ expect(proofs([change]), folder).toEqual(expect.arrayContaining(own));
}
});
- it('skips for everything else, including components the Chromium proofs cover', () => {
+ it('runs nothing for everything else, including components with no interaction spec', () => {
for (const untouched of [
- 'packages/core/src/Toast/Toast.tsx',
'packages/core/src/Selector/useSelectorPresentation.ts',
'packages/core/src/utils/focusReturn.ts',
'packages/core/src/internal/focus.ts',
- 'packages/core/src/DateInput/DateInput.tsx',
'packages/core/locales/en.json',
'packages/core/package.json',
'packages/themes/neutral/package.json',
'docs/specs/AST-030/spec.md',
'.github/workflows/release.yml',
]) {
- expect(inScope(untouched), untouched).toBe(false);
+ expect(runs([untouched]), untouched).toBe(false);
}
});
@@ -498,14 +571,19 @@ describe('WebKit interaction proof routing', () => {
'packages/core/src/utils/pressFeedback.ts',
]),
).toBe(true);
- // #9016 (Toast timer), #9025 (TextArea counter), #9048 (CI cache).
+ // #9016 (Toast timer) runs Toast's own proofs, and only those.
+ const toast = proofs([
+ '.changeset/toast-pause-sources.md',
+ 'packages/core/src/Toast/Toast.tsx',
+ 'packages/core/src/Toast/ToastViewport.test.tsx',
+ 'docs/specs/components/Toast/Toast.spec.md',
+ ]);
+ expect(toast.length).toBeGreaterThan(0);
+ expect(
+ toast.every(file => file.startsWith('packages/core/src/Toast/')),
+ ).toBe(true);
+ // #9025 (TextArea counter), #9048 (CI cache).
for (const files of [
- [
- '.changeset/toast-pause-sources.md',
- 'packages/core/src/Toast/Toast.tsx',
- 'packages/core/src/Toast/ToastViewport.test.tsx',
- 'docs/specs/components/Toast/Toast.spec.md',
- ],
[
'.changeset/textarea-counter-i18n.md',
'packages/core/locales/en.json',
diff --git a/.github/scripts/playwright-legs.mjs b/.github/scripts/playwright-legs.mjs
index 6ce37c0dd1..162035be6b 100644
--- a/.github/scripts/playwright-legs.mjs
+++ b/.github/scripts/playwright-legs.mjs
@@ -6,12 +6,14 @@
* @description Splits the spec files of one Playwright suite into legs of
* about equal running time, from the per-file times a CI run recorded
* (spec:AST-030 FR13).
- * @input `legs`: the suite's times key, its path filters, the changed files,
- * a leg's setup time and time limit. `plan`: the suite's times key, its
+ * @input `select`: the listed spec files, the changed files, the shared-code
+ * pattern and the suite's own path filters. `legs`: the suite's times key,
+ * its path filters, the changed files, a leg's setup time and time limit. `plan`: the suite's times key, its
* config and project, this leg and the leg count, and any Playwright path
* filters; `.github/playwright-leg-durations.json`. `record`: CI job logs
* of the list reporter.
- * @output `legs`: `count=<legs>`, `runs=<true|false>` and the `leg=<i>` this
+ * @output `select`: the path filters and spec files a WebKit run covers, one
+ * per line. `legs`: `count=<legs>`, `runs=<true|false>` and the `leg=<i>` this
* leg plans, for `$GITHUB_OUTPUT`.
* `plan`: this leg's spec files, one per line, for Playwright's
* `--test-list`, and `files=<count>` for `$GITHUB_OUTPUT`. `record`: the
@@ -30,7 +32,11 @@ import {
medianOf,
splitByDuration,
} from '../../scripts/lib/duration-split.mjs';
-import {listedFiles} from './a11y-pr-contracts.mjs';
+import {
+ isComponentPath,
+ listedFiles,
+ specOwners,
+} from './a11y-pr-contracts.mjs';
// CI may run this file from the workflow's own commit, outside the checkout,
// in the checkout's root.
@@ -202,6 +208,58 @@ export function isInteractionSpec(file) {
);
}
+// The component folder a path is in: `packages/<package>/src/<Component>`.
+// Shared folders (`motion`, `hooks`, `utils`) are not component folders: the
+// lane's shared-code pattern decides what their changes run.
+// Files that put no code on a proof's page: tests, stories, docs, notes.
+const NOT_RENDERED = /(?:^|\/)__tests__\/|\.(?:test|stories|doc)\.[^/]+$|\.md$/;
+
+/**
+ * The interaction specs in each component folder whose code a change
+ * reaches: a changed file in `packages/<package>/src/<Component>/` that puts
+ * code on a page selects every listed interaction spec under that folder.
+ * @param {string[]} listed every file of the tree
+ * @param {string[]} changed the changed files
+ */
+export function folderSpecs(listed, changed) {
+ // A component folder as the accessibility contracts read it.
+ const folderOf = file => specOwners(file).prefixes;
+ const folders = new Set(
+ changed
+ .filter(
+ file =>
+ isComponentPath(file) &&
+ !NOT_RENDERED.test(file) &&
+ !isInteractionSpec(file),
+ )
+ .flatMap(folderOf),
+ );
+ return listed
+ .filter(
+ file =>
+ isInteractionSpec(file) &&
+ folderOf(file).some(folder => folders.has(folder)),
+ )
+ .sort();
+}
+
+/**
+ * What a WebKit run covers for a change. The suite's own path filters run
+ * when the change touches shared code (`shared`); every interaction spec the
+ * change edits runs; and so does every spec in a folder whose code it changes.
+ * An unknown change (no file list) runs the suite's own filters only.
+ * @param {{listed: string[], changed: string[] | null, shared: RegExp, filters: string[]}} options
+ */
+export function selectProofs({listed, changed, shared, filters}) {
+ if (changed == null) return [...filters];
+ const out = new Set();
+ if (changed.some(file => shared.test(file)))
+ for (const filter of filters) out.add(filter);
+ for (const file of changed) if (isInteractionSpec(file)) out.add(file);
+ for (const file of folderSpecs(listed, changed)) out.add(file);
+ return [...out];
+}
+
// A suite with one unnamed project prints no `[project]`.
const TEST_LINE =
/^(\S+Z)\s+\S+\s+\d+\s+(?:\[([\w-]+)\] › )?([^:\s]+):\d+:\d+ › /;
@@ -425,6 +483,37 @@ function legs(args) {
);
}
+function select(args) {
+ const split = args.indexOf('--');
+ const own = split === -1 ? args : args.slice(0, split);
+ const filters = split === -1 ? [] : args.slice(split + 1);
+ const listedFile = option(own, '--listed');
+ const pattern = option(own, '--shared');
+ if (!listedFile || !pattern || filters.length === 0)
+ throw new Error(
+ 'usage: select --listed <file> --shared <pattern> [--changed <file>] -- <filters...>',
+ );
+ const lines = file =>
+ fs.readFileSync(file, 'utf8').split('\n').filter(Boolean);
+ const changedFile = option(own, '--changed');
+ const changed =
+ changedFile && fs.existsSync(changedFile) ? lines(changedFile) : null;
+ // Without `--changed` every listed path is planned on purpose (the release
+ // interaction check); only a list that was meant to be there and is not
+ // gets a warning.
+ if (own.includes('--changed') && changed == null)
+ console.error(
+ "::warning title=Changed specs not planned::The scope step could not list the changed files, so only this lane's own paths run here.",
+ );
+ const selected = selectProofs({
+ listed: lines(listedFile),
+ changed,
+ shared: new RegExp(pattern),
+ filters,
+ });
+ for (const line of selected) console.log(line);
+}
+
function record(args) {
const key = option(args, '--key');
const project = option(args, '--project');
@@ -471,10 +560,12 @@ if (
) {
const [command, ...args] = process.argv.slice(2);
try {
- if (command === 'legs') legs(args);
+ if (command === 'select') select(args);
+ else if (command === 'legs') legs(args);
else if (command === 'plan') plan(args);
else if (command === 'record') record(args);
- else throw new Error('usage: playwright-legs.mjs legs|plan|record ...');
+ else
+ throw new Error('usage: playwright-legs.mjs select|legs|plan|record ...');
} catch (error) {
console.error(error.message);
process.exitCode = 1;
diff --git a/.github/scripts/playwright-legs.test.mjs b/.github/scripts/playwright-legs.test.mjs
index 2f7ffd07f0..b800d44c8b 100644
--- a/.github/scripts/playwright-legs.test.mjs
+++ b/.github/scripts/playwright-legs.test.mjs
@@ -13,10 +13,12 @@ import {
costsFor,
countTests,
estimateSeconds,
+ folderSpecs,
isInteractionSpec,
legCount,
planLegs,
recordLog,
+ selectProofs,
testsReader,
} from './playwright-legs.mjs';
@@ -221,15 +223,17 @@ describe('estimateSeconds and legCount', () => {
});
describe('the list reader and recordLog', () => {
- it('reads the list report with the reader the accessibility contracts use', () => {
+ it("reads the list report and the component folder with the accessibility contracts' own helpers", () => {
const source = fs.readFileSync(
path.join(root, '.github/scripts/playwright-legs.mjs'),
'utf8',
);
- expect(source).toContain(
- "import {listedFiles} from './a11y-pr-contracts.mjs';",
+ expect(source).toMatch(
+ /import \{[^}]*\bisComponentPath\b[^}]*\blistedFiles\b[^}]*\bspecOwners\b[^}]*\} from '\.\/a11y-pr-contracts\.mjs';/,
);
expect(source).not.toMatch(/function listedFiles/);
+ // No folder rule of its own.
+ expect(source).not.toMatch(/const FOLDER =/);
});
it("records each test's gap from the line before it, under its spec file and project", () => {
@@ -409,10 +413,12 @@ describe('the interaction proof legs in ci.yml', () => {
});
// Runs the count step with the real planner on these recorded times.
+ // A shared-code change: the lane's own paths count.
+ const gestureChange = ['packages/core/src/gestures/GestureHost.ts'];
function countFor(
leg,
webkitTimes,
- changed = [],
+ changed = gestureChange,
unrecorded = [],
{deleted = [], sources = {}, perTest, env = {}} = {},
) {
@@ -494,6 +500,7 @@ describe('the interaction proof legs in ci.yml', () => {
CHANGED_FILES: list,
GITHUB_OUTPUT: output,
WEBKIT_SPEC_PATHS: job.env.WEBKIT_SPEC_PATHS,
+ WEBKIT_SHARED_PATHS: job.env.WEBKIT_SHARED_PATHS,
...env,
},
},
@@ -568,9 +575,10 @@ describe('the interaction proof legs in ci.yml', () => {
expect(
countFor(1, times, [], [], {env: {WEBKIT_ALL_SPECS: 'true'}}),
).toEqual({count: '2', runs: 'true', leg: '1'});
+ // Without it, a change that touches nothing WebKit covers plans none.
expect(
countFor(1, times, [], [], {env: {WEBKIT_ALL_SPECS: 'false'}}),
- ).toEqual({count: '1', runs: 'true', leg: '1'});
+ ).toEqual({count: '0', runs: 'false', leg: '1'});
});
it('writes the test counts it read for the plan, and skips a deleted spec', () => {
@@ -609,14 +617,9 @@ describe('the interaction proof legs in ci.yml', () => {
expect(countFor(2, near)).toEqual({count: '1', runs: 'false', leg: '2'});
// So does a planned spec with no recorded time: here the median, 500 s.
expect(
- countFor(
- 2,
- near,
- [],
- [
- 'internal/interaction-harness/src/pointer.interaction.browser.spec.ts',
- ],
- ),
+ countFor(2, near, gestureChange, [
+ 'internal/interaction-harness/src/pointer.interaction.browser.spec.ts',
+ ]),
).toEqual({count: '2', runs: 'true', leg: '2'});
expect(
countFor(2, near, [
@@ -672,26 +675,26 @@ describe('the interaction proof legs in ci.yml', () => {
'packages/core/src/hooks/__tests__/usePager.interaction',
'internal/interaction-harness/',
]);
- // The leg count and the plan read the same paths; the plan adds the
- // interaction specs this pull request changes.
- for (const name of [
- "Count this run's WebKit legs",
- "Plan this leg's WebKit interaction proofs",
- ]) {
- const {run} = step(job, name);
- expect(run, name).toContain(
- 'if [ "${WEBKIT_ALL_SPECS:-}" = true ]; then SPEC_PATHS=(packages/ internal/); else read -ra SPEC_PATHS <<< "$WEBKIT_SPEC_PATHS"; fi',
- );
- expect(run, name).toContain('"${SPEC_PATHS[@]}"');
- }
+ // The leg count selects from the lane's paths once, and the count and
+ // the plan both read that selection, so the two legs agree. The release
+ // interaction check selects every spec.
+ const count = step(job, "Count this run's WebKit legs").run;
+ expect(count).toContain(
+ 'if [ "${WEBKIT_ALL_SPECS:-}" = true ]; then SPEC_PATHS=(packages/ internal/); else read -ra SPEC_PATHS <<< "$WEBKIT_SPEC_PATHS"; fi',
+ );
+ expect(count).toContain('-- "${SPEC_PATHS[@]}" > "$selected"');
+ expect(count).toContain('-- "${SELECTED[@]}"');
const plan = step(job, "Plan this leg's WebKit interaction proofs").run;
+ expect(plan).toContain(
+ 'done < "$RUNNER_TEMP/interaction-legs/selected.txt"',
+ );
expect(
plan
.slice(plan.indexOf(' -- ') + 4)
.replaceAll('\\', '')
.trim()
.split(/\s+/),
- ).toEqual(['"${SPEC_PATHS[@]}"', '"${CHANGED_SPECS[@]}"']);
+ ).toEqual(['"${PLANNED[@]}"']);
});
it("the test join reads each lane's whole result, so a failed, cancelled or skipped leg fails it", () => {
@@ -1037,3 +1040,77 @@ describe('the interaction proof legs in ci.yml', () => {
}
});
});
+
+describe('what a WebKit run covers for a change', () => {
+ const listed = [
+ 'packages/core/src/DateInput/DateInput.tsx',
+ 'packages/core/src/DateInput/__tests__/DateInputWheel.interaction.browser.spec.ts',
+ 'packages/core/src/DateInput/__tests__/DateInputTouch.interaction.browser.spec.ts',
+ 'packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts',
+ 'packages/lab/src/RefreshControl/__tests__/RefreshControl.interaction.browser.spec.ts',
+ 'packages/core/src/utils/__tests__/press.interaction.browser.spec.ts',
+ 'packages/core/src/gestures/__tests__/browser/gestures.interaction.browser.spec.ts',
+ ];
+ const shared =
+ /^(packages\/core\/src\/gestures\/|\.github\/workflows\/ci\.yml$)/;
+ const filters = ['packages/core/src/gestures/'];
+ const select = changed => selectProofs({listed, changed, shared, filters});
+
+ it('runs every interaction spec in a component folder whose code changes, in any package', () => {
+ expect(select(['packages/core/src/DateInput/DateInput.tsx'])).toEqual([
+ 'packages/core/src/DateInput/__tests__/DateInputTouch.interaction.browser.spec.ts',
+ 'packages/core/src/DateInput/__tests__/DateInputWheel.interaction.browser.spec.ts',
+ ]);
+ expect(
+ select(['packages/lab/src/RefreshControl/useRefreshControl.ts']),
+ ).toEqual([
+ 'packages/lab/src/RefreshControl/__tests__/RefreshControl.interaction.browser.spec.ts',
+ ]);
+ });
+
+ it('runs nothing for files that put no code on a page, or a folder without specs', () => {
+ for (const file of [
+ 'packages/core/src/DateInput/DateInput.test.tsx',
+ 'packages/core/src/DateInput/__tests__/DateInput.calendar.test.tsx',
+ 'packages/core/src/DateInput/DateInput.doc.mjs',
+ 'packages/core/src/DateInput/DateInput.stories.tsx',
+ 'packages/core/src/DateInput/README.md',
+ 'packages/core/src/Selector/Selector.tsx',
+ // A shared folder is the shared-code pattern's to decide.
+ 'packages/core/src/utils/focusReturn.ts',
+ ]) {
+ expect(select([file]), file).toEqual([]);
+ }
+ });
+
+ it("runs the lane's own paths for shared code, and each spec a change edits", () => {
+ expect(select(['packages/core/src/gestures/GestureHost.ts'])).toEqual(
+ filters,
+ );
+ const edited =
+ 'packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts';
+ expect(select([edited])).toEqual([edited]);
+ expect(
+ select([
+ '.github/workflows/ci.yml',
+ 'packages/core/src/DateInput/DateInput.tsx',
+ ]),
+ ).toEqual([
+ ...filters,
+ 'packages/core/src/DateInput/__tests__/DateInputTouch.interaction.browser.spec.ts',
+ 'packages/core/src/DateInput/__tests__/DateInputWheel.interaction.browser.spec.ts',
+ ]);
+ });
+
+ it("runs only the lane's own paths when the changed files are unknown", () => {
+ expect(selectProofs({listed, changed: null, shared, filters})).toEqual(
+ filters,
+ );
+ });
+
+ it('lists only interaction specs of the folder', () => {
+ expect(
+ folderSpecs(listed, ['packages/core/src/DateInput/DateInput.tsx']),
+ ).not.toContain('packages/core/src/DateInput/DateInput.tsx');
+ });
+});
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 241d01acfb..97f9b22de4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2738,6 +2738,9 @@ jobs:
run:
shell: bash
env:
+ # The code where WebKit and Chromium differ on touch, and the lane's
+ # shared setup. A change to it runs WEBKIT_SPEC_PATHS.
+ WEBKIT_SHARED_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|scrollView|nodeType|inputAge)|packages/core/src/privateAttributes/(hapticSwitch|reducedMotion)\.stylex\.ts$|packages/core/src/theme/tokenReferences\.ts$|packages/core/src/Layer/(inputHold|modalOutlet)\.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/(playwright-legs|a11y-pr-contracts|lane-environment)\.mjs$|\.github/scripts/(stale-head-hint|merge-base)\.sh$|scripts/lib/duration-split\.mjs$|\.github/(playwright-leg-durations|lane-environments)\.json$|\.github/actions/test-scope/|.*\.interaction\.browser\.spec\.ts$)'
# The release interaction check's throwaway pull request runs every
# interaction spec in WebKit: the release receipt needs the whole suite,
# which the leg count spreads over the matrix. Only the release tooling
@@ -2745,8 +2748,9 @@ jobs:
# the account the tooling uses. Any other pull request keeps the paths
# below.
WEBKIT_ALL_SPECS: ${{ startsWith(github.head_ref, 'interaction-check/') && github.event.pull_request.user.login == 'cixzhang' && github.event.pull_request.head.repo.full_name == github.repository }}
- # The specs the WebKit legs run otherwise, besides each interaction spec
- # the pull request changes.
+ # The specs a shared-code change runs. Besides them, a change runs each
+ # interaction spec it edits, and every interaction spec in a component
+ # folder whose code it changes (`playwright-legs.mjs select`).
WEBKIT_SPEC_PATHS: >-
packages/core/src/gestures/
packages/core/src/motion/__tests__/animatedLayout.interaction
@@ -2779,7 +2783,7 @@ jobs:
id: scope
uses: ./.test-scope/.github/actions/test-scope
with:
- 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|scrollView|nodeType|inputAge)|packages/core/src/privateAttributes/(hapticSwitch|reducedMotion)\.stylex\.ts$|packages/core/src/theme/tokenReferences\.ts$|packages/core/src/Layer/(inputHold|modalOutlet)\.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/(playwright-legs|a11y-pr-contracts|lane-environment)\.mjs$|\.github/scripts/(stale-head-hint|merge-base)\.sh$|scripts/lib/duration-split\.mjs$|\.github/(playwright-leg-durations|lane-environments)\.json$|\.github/actions/test-scope/|.*\.interaction\.browser\.spec\.ts$)'
+ paths: '^(packages/[^/]+/src/[^/]+/|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/(playwright-legs|a11y-pr-contracts|lane-environment)\.mjs$|scripts/lib/duration-split\.mjs$|\.github/(playwright-leg-durations|lane-environments)\.json$|\.github/actions/test-scope/|.*\.interaction\.browser\.spec\.ts$|\.github/scripts/(stale-head-hint|merge-base)\.sh$)'
outside-pull-request: skip
requires-head-file: playwright.interaction.config.ts
# Lists the changed files, so the planner adds a changed spec.
@@ -2831,6 +2835,19 @@ jobs:
CHANGED=(--changed "${CHANGED_FILES:-}")
if [ "${WEBKIT_ALL_SPECS:-}" = true ]; then CHANGED=(); fi
git -C .test-scope ls-tree -r --name-only HEAD > "$RUNNER_TEMP/interaction-legs/listed.txt"
+ selected="$RUNNER_TEMP/interaction-legs/selected.txt"
+ node "$RUNNER_TEMP/interaction-legs/.github/scripts/playwright-legs.mjs" select \
+ --listed "$RUNNER_TEMP/interaction-legs/listed.txt" \
+ "${CHANGED[@]}" \
+ --shared "$WEBKIT_SHARED_PATHS" \
+ -- "${SPEC_PATHS[@]}" > "$selected"
+ if [ ! -s "$selected" ]; then
+ echo "No WebKit interaction proof covers this change: it touches no shared touch code, no interaction spec, and no component folder that holds one."
+ printf 'count=0\nruns=false\nleg=%s\n' "${{ matrix.leg }}" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+ echo "WebKit proofs for this change:"; sed 's/^/ /' "$selected"
+ mapfile -t SELECTED < "$selected"
node "$RUNNER_TEMP/interaction-legs/.github/scripts/playwright-legs.mjs" legs \
--listed "$RUNNER_TEMP/interaction-legs/listed.txt" --source .test-scope \
--tests-out "$RUNNER_TEMP/interaction-legs/tests.json" \
@@ -2839,11 +2856,11 @@ jobs:
"${CHANGED[@]}" \
--setup-seconds 90 --max-seconds 600 \
--leg ${{ matrix.leg }} --max-legs ${{ strategy.job-total }} \
- -- "${SPEC_PATHS[@]}"
+ -- "${SELECTED[@]}"
- name: Leave the proofs to the other legs
if: steps.scope.outputs.applies == 'true' && steps.legs.outputs.runs != 'true'
- run: echo "This run's WebKit proofs fit ${{ steps.legs.outputs.count }} legs, so this leg runs none."
+ run: echo "This leg runs no WebKit proofs (${{ steps.legs.outputs.count }} leg(s) planned for this change)."
# 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
@@ -2912,26 +2929,25 @@ jobs:
if: steps.scope.outputs.applies == 'true' && steps.legs.outputs.runs == 'true'
run: pnpm install --frozen-lockfile && npx playwright install webkit chromium-headless-shell
- # 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. An interaction spec the
- # pull request changes runs here too, wherever it lives.
+ # This leg's share of the WebKit spec files the legs step selected, by
+ # their recorded times. The planner and the times come from the scope
+ # checkout, as for the Chromium legs. A selected spec file that the head
+ # does not have (one the pull request deletes) is left out.
- name: Plan this leg's WebKit interaction proofs
id: plan
if: steps.scope.outputs.applies == 'true' && steps.legs.outputs.runs == 'true'
- env:
- CHANGED_FILES: ${{ steps.scope.outputs.changed_files_path }}
run: |
- if [ "${WEBKIT_ALL_SPECS:-}" = true ]; then SPEC_PATHS=(packages/ internal/); else read -ra SPEC_PATHS <<< "$WEBKIT_SPEC_PATHS"; fi
- CHANGED_SPECS=()
- if [ -n "${CHANGED_FILES:-}" ] && [ -s "$CHANGED_FILES" ]; then
- while IFS= read -r file; do
- case "$file" in
- *.interaction.browser.spec.ts) [ -f "$file" ] && CHANGED_SPECS+=("$file") ;;
- esac
- done < "$CHANGED_FILES"
- else
- echo "::warning title=Changed specs not planned::The scope step could not list the changed files, so a changed interaction spec outside this lane's paths does not run here."
+ PLANNED=()
+ while IFS= read -r entry; do
+ case "$entry" in
+ *.spec.ts) [ -f "$entry" ] && PLANNED+=("$entry") ;;
+ *) PLANNED+=("$entry") ;;
+ esac
+ done < "$RUNNER_TEMP/interaction-legs/selected.txt"
+ if [ "${#PLANNED[@]}" -eq 0 ]; then
+ echo "The head has none of the selected WebKit spec files."
+ echo "files=0" >> "$GITHUB_OUTPUT"
+ exit 0
fi
node "$RUNNER_TEMP/interaction-legs/.github/scripts/playwright-legs.mjs" plan \
--key interaction-webkit --fallback-key interaction-chromium --tests "$RUNNER_TEMP/interaction-legs/tests.json" \
@@ -2939,8 +2955,7 @@ jobs:
--leg ${{ steps.legs.outputs.leg }} --of ${{ steps.legs.outputs.count }} \
--durations "$RUNNER_TEMP/interaction-legs/.github/playwright-leg-durations.json" \
--out "$RUNNER_TEMP/interaction-leg.txt" -- \
- "${SPEC_PATHS[@]}" \
- "${CHANGED_SPECS[@]}"
+ "${PLANNED[@]}"
# 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