Skip to content

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

TypeScript

ci: a changed interaction spec runs in both interaction lanes (#10015)

Cindy Zhangcf62942d9314
diff --git a/.github/scripts/ci-interaction-webkit.test.mjs b/.github/scripts/ci-interaction-webkit.test.mjs
index c3abb33b42..25f2e513ee 100644
--- a/.github/scripts/ci-interaction-webkit.test.mjs
+++ b/.github/scripts/ci-interaction-webkit.test.mjs
@@ -14,7 +14,9 @@
* context. The scope step's own behavior is in test-scope-action.test.mjs.
*/
+import {execFileSync} from 'node:child_process';
import fs from 'node:fs';
+import os from 'node:os';
import path from 'node:path';
import {build} from 'esbuild';
@@ -178,20 +180,117 @@ describe('WebKit interaction proof routing', () => {
// SideNav) stay with the Chromium proofs.
expect(run).not.toContain('animatedLayoutAdopters');
expect(run).not.toMatch(/motion\/ /);
- // Carousel paging renders its Storybook story, so it stays there too, and
- // its files start no WebKit run.
+ // 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');
- for (const file of [
- 'packages/core/src/Carousel/useCarouselPaging.ts',
- 'packages/core/src/Carousel/__tests__/CarouselPaging.interaction.browser.spec.ts',
- ]) {
- expect(inScope(file), file).toBe(false);
- }
+ expect(inScope('packages/core/src/Carousel/useCarouselPaging.ts')).toBe(
+ false,
+ );
for (const component of ['DateInput', 'TabList', 'TreeList', 'SideNav']) {
expect(run).not.toContain(component);
}
});
+ // A pull request that changes an interaction spec, outside a Lab-only pull
+ // request (which runs no interaction proofs, spec:AST-030 FR26), runs that
+ // spec in both lanes, wherever it lives: the Chromium legs plan every spec,
+ // and the WebKit plan adds the changed ones to its paths.
+ describe('a changed interaction spec', () => {
+ const spec =
+ 'packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts';
+
+ it('starts both lanes', () => {
+ expect(inScope(spec)).toBe(true);
+ expect(new RegExp(decide(chromium).with.paths).test(spec)).toBe(true);
+ expect(
+ inScope(
+ '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,
+ );
+ });
+
+ 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 }}');
+ // 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) {
+ 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(''));
+ const bin = path.join(dir, 'bin');
+ fs.mkdirSync(bin);
+ fs.writeFileSync(
+ path.join(bin, 'node'),
+ '#!/usr/bin/env bash\nprintf "%s\\n" "$@"\n',
+ {mode: 0o755},
+ );
+ const script = step(webkit, "Plan this leg's WebKit interaction proofs")
+ .run.replaceAll('${{ matrix.leg }}', '1')
+ .replaceAll('${{ strategy.job-total }}', '2');
+ const out = execFileSync('bash', ['-e', '-c', script], {
+ cwd: dir,
+ encoding: 'utf8',
+ env: {
+ ...process.env,
+ PATH: `${bin}:${process.env.PATH}`,
+ RUNNER_TEMP: dir,
+ CHANGED_FILES: list,
+ },
+ });
+ return out.trim().split('\n');
+ } finally {
+ fs.rmSync(dir, {recursive: true, force: true});
+ }
+ }
+
+ it("adds the changed spec to the WebKit plan's paths", () => {
+ const args = planArgs(
+ [spec, 'packages/core/src/List/ListRow.tsx'],
+ [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');
+ });
+
+ 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], []);
+ 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::',
+ );
+ });
+ });
+
// Every source file the WebKit specs bundle into their pages is in scope,
// so a change that reaches the run always runs it.
async function expectBundleInScope(entry) {
diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjs
index 1c862a2112..89bb3ce3c1 100644
--- a/.github/scripts/ci-test-routing.test.mjs
+++ b/.github/scripts/ci-test-routing.test.mjs
@@ -481,6 +481,7 @@ describe('ci.yml RTL package sharding', () => {
'pr-a11y-guards',
'pr-a11y-specs',
'pr-component-a11y-contracts',
+ 'pr-interaction-webkit',
'pr-rtl',
'pr-rtl-merge',
'pr-rtl-shard',
diff --git a/.github/scripts/playwright-legs.test.mjs b/.github/scripts/playwright-legs.test.mjs
index 51e9246e10..a00c35bab3 100644
--- a/.github/scripts/playwright-legs.test.mjs
+++ b/.github/scripts/playwright-legs.test.mjs
@@ -246,6 +246,8 @@ describe('the interaction proof legs in ci.yml', () => {
'packages/core/src/motion/__tests__/animator.interaction',
'packages/core/src/hooks/__tests__/usePager.interaction',
'internal/interaction-harness/',
+ // Plus the interaction specs this pull request changes.
+ '"${CHANGED_SPECS[@]}"',
]);
});
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d6bc66bda6..62dfb4b889 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2509,7 +2509,7 @@ jobs:
id: scope
uses: ./.test-scope/.github/actions/test-scope
with:
- 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/(playwright-legs|a11y-pr-contracts)\.mjs$|scripts/lib/duration-split\.mjs$|\.github/playwright-leg-durations\.json$|\.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/(playwright-legs|a11y-pr-contracts)\.mjs$|scripts/lib/duration-split\.mjs$|\.github/playwright-leg-durations\.json$|\.github/actions/test-scope/|.*\.interaction\.browser\.spec\.ts$)'
outside-pull-request: skip
requires-head-file: playwright.interaction.config.ts
@@ -2669,9 +2669,11 @@ 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)|packages/core/src/privateAttributes/(hapticSwitch|reducedMotion)\.stylex\.ts$|packages/core/src/Layer/inputHold\.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)\.mjs$|scripts/lib/duration-split\.mjs$|\.github/playwright-leg-durations\.json$|\.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|scrollView)|packages/core/src/privateAttributes/(hapticSwitch|reducedMotion)\.stylex\.ts$|packages/core/src/Layer/inputHold\.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)\.mjs$|scripts/lib/duration-split\.mjs$|\.github/playwright-leg-durations\.json$|\.github/actions/test-scope/|.*\.interaction\.browser\.spec\.ts$)'
outside-pull-request: skip
requires-head-file: playwright.interaction.config.ts
+ # Lists the changed files, so the planner adds a changed spec.
+ component-audit: 'true'
- name: Require this pull request's Storybook build
if: steps.scope.outputs.applies == 'true' && needs.build-storybook.result != 'success'
@@ -2681,7 +2683,7 @@ jobs:
- name: Skip the WebKit proofs outside their scope
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)."
+ run: echo "No WebKit interaction proofs for this change (it touches no gesture, motion, touch or press code, no interaction spec, 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
@@ -2749,11 +2751,24 @@ jobs:
# 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.
+ # the scope checkout, as for the Chromium legs. An interaction spec the
+ # pull request changes runs here too, wherever it lives.
- name: Plan this leg's WebKit interaction proofs
id: plan
if: steps.scope.outputs.applies == 'true'
+ env:
+ CHANGED_FILES: ${{ steps.scope.outputs.changed_files_path }}
run: |
+ 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."
+ fi
node "$RUNNER_TEMP/interaction-legs/.github/scripts/playwright-legs.mjs" plan \
--key interaction-webkit --config playwright.interaction.config.ts --project webkit \
--leg ${{ matrix.leg }} --of ${{ strategy.job-total }} \
@@ -2763,7 +2778,8 @@ jobs:
packages/core/src/motion/__tests__/animatedLayout.interaction \
packages/core/src/motion/__tests__/animator.interaction \
packages/core/src/hooks/__tests__/usePager.interaction \
- internal/interaction-harness/
+ internal/interaction-harness/ \
+ "${CHANGED_SPECS[@]}"
# 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