An open source design system that's fully customizable and agent ready
TypeScript
ci: run the interaction proofs in WebKit for gesture, motion and touch changes (#9138)
Cindy Zhang26143a4a7cf1
diff --git a/.github/scripts/ci-interaction-webkit.test.mjs b/.github/scripts/ci-interaction-webkit.test.mjsnew file mode 100644index 0000000000..20982174e6--- /dev/null+++ b/.github/scripts/ci-interaction-webkit.test.mjs@@ -0,0 +1,264 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Routing contract for the WebKit interaction proofs.+ *+ * 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.+ */++import fs from 'node:fs';+import path from 'node:path';++import {build} from 'esbuild';+import {describe, expect, it} from 'vitest';+import yaml from 'yaml';++import {ungated} from './ci-pr-gate.mjs';++const root = path.resolve(import.meta.dirname, '../..');+const ci = yaml.parse(+ fs.readFileSync(path.join(root, '.github/workflows/ci.yml'), 'utf8'),+);+const webkit = ci.jobs['pr-interaction-webkit'];+const chromium = ci.jobs['pr-interaction'];+const step = (job, name) =>+ job.steps.find(candidate => candidate.name === 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);++describe('WebKit interaction proof routing', () => {+ it('is joined by test, adding no required context of its own', () => {+ expect(ci.jobs.test.needs).toContain('pr-interaction-webkit');+ expect(+ step(ci.jobs.test, 'Require expected test-owner outcomes').env,+ ).toMatchObject({+ PR_INTERACTION_WEBKIT_RESULT: '${{ needs.pr-interaction-webkit.result }}',+ });+ const join = fs.readFileSync(+ path.join(root, '.github/scripts/ci-test-join.mjs'),+ 'utf8',+ );+ expect(join).toContain(+ "['pr-interaction-webkit', process.env.PR_INTERACTION_WEBKIT_RESULT]",+ );+ });++ it('always reports, behind the same pull-request gate as the Chromium proofs', () => {+ expect(webkit.if).toBe(chromium.if);+ expect(ungated(webkit.if)).toBe(+ "github.event_name != 'workflow_dispatch' && always() && !cancelled()",+ );+ expect(webkit.needs).toEqual(['build-storybook']);+ });++ it('stays on a standard runner within the 15-minute budget', () => {+ expect(webkit['runs-on']).toBe('ubuntu-latest');+ expect(webkit['timeout-minutes']).toBeLessThanOrEqual(15);+ });++ it('decides its own scope first, skips visibly, and gates every later step on it', () => {+ expect(webkit.steps[0].with['sparse-checkout']).toBe(+ '.github/actions/test-scope',+ );+ expect(decide(webkit).uses).toBe(+ './.test-scope/.github/actions/test-scope',+ );+ expect(webkit.steps.indexOf(decide(webkit))).toBe(1);+ expect(decide(webkit).with).toMatchObject({+ 'outside-pull-request': 'skip',+ 'requires-head-file': 'playwright.interaction.config.ts',+ });+ expect(step(webkit, 'Skip the WebKit proofs outside their scope').if).toBe(+ "steps.scope.outputs.applies != 'true'",+ );+ expect(step(webkit, "Require this pull request's Storybook build").if).toBe(+ `${applies} && needs.build-storybook.result != 'success'`,+ );+ const guards = new Set([+ "Require this pull request's Storybook build",+ 'Skip the WebKit proofs outside their scope',+ ]);+ for (const candidate of webkit.steps.slice(2)) {+ if (guards.has(candidate.name)) continue;+ expect(candidate.if, candidate.name ?? candidate.uses).toMatch(+ new RegExp(+ `^(always\\(\\) && )?${applies.replace(/[.()|]/g, '\\$&')}$`,+ ),+ );+ }+ });++ it('runs the interaction config in WebKit against the exact PR head', () => {+ const checkout = webkit.steps.find(+ candidate =>+ candidate.uses?.startsWith('actions/checkout@') &&+ candidate.with?.path === undefined,+ );+ expect(checkout?.with?.ref).toBe(+ '${{ github.event.pull_request.head.sha }}',+ );+ expect(step(webkit, 'Install Playwright WebKit').run).toContain(+ 'npx playwright install --with-deps webkit',+ );+ const run = step(webkit, 'Run WebKit interaction proofs').run;+ expect(run).toContain('--config playwright.interaction.config.ts');+ expect(run).toContain('--project webkit');+ expect(run).not.toContain('--project chromium');+ });++ it('runs only the specs whose code its scope covers', () => {+ const run = step(webkit, 'Run WebKit interaction proofs').run;+ const targets = [+ 'packages/core/src/gestures/',+ 'packages/core/src/motion/__tests__/animatedLayout.interaction',+ 'packages/core/src/motion/__tests__/animator.interaction',+ 'internal/interaction-harness/',+ ];+ for (const target of targets) {+ expect(run).toContain(target);+ expect(inScope(target), target).toBe(true);+ }+ // The adopters spec renders Storybook components (Collapsible, TreeList,+ // ScrollableArea), and component specs (DateInput, TabList, TreeList,+ // SideNav) stay with the Chromium proofs.+ expect(run).not.toContain('animatedLayoutAdopters');+ expect(run).not.toMatch(/motion\/ /);+ for (const component of ['DateInput', 'TabList', 'TreeList', 'SideNav']) {+ expect(run).not.toContain(component);+ }+ });++ // Every source file the WebKit specs bundle into their pages is in scope,+ // so a change that reaches the run always runs it.+ it.each([+ 'packages/core/src/gestures/__tests__/browser/fixture.ts',+ 'packages/core/src/motion/__tests__/animatedLayoutBundle.ts',+ 'packages/core/src/motion/__tests__/motionBundle.ts',+ ])('keeps everything %s bundles in scope', async entry => {+ const {metafile} = await build({+ absWorkingDir: root,+ entryPoints: [entry],+ bundle: true,+ write: false,+ metafile: true,+ format: 'iife',+ platform: 'browser',+ logLevel: 'silent',+ });+ const sources = Object.keys(metafile.inputs).filter(+ input =>+ !input.includes('node_modules') &&+ !input.includes('/__tests__/') &&+ (input.startsWith('packages/') || input.startsWith('internal/')),+ );+ expect(sources.length).toBeGreaterThan(0);+ for (const source of sources) {+ expect(inScope(source), source).toBe(true);+ }+ });++ it('runs for gesture, motion, touch, press-feedback and menu-press code, and their harness', () => {+ for (const touched of [+ 'packages/core/src/gestures/GestureHost.ts',+ 'packages/core/src/gestures/__tests__/browser/presentedHitTesting.interaction.browser.spec.ts',+ 'packages/core/src/motion/animator.ts',+ 'packages/core/src/motion/uikit/longPress.ts',+ 'packages/core/src/internal/touch.ts',+ 'packages/core/src/utils/pressFeedback.ts',+ 'packages/core/src/utils/pressFeedbackImports.test.ts',+ 'packages/core/src/utils/pressGesture.ts',+ 'packages/core/src/utils/touchPresentation.ts',+ 'packages/core/src/utils/primaryClick.ts',+ 'packages/core/src/utils/isApplePlatform.ts',+ 'packages/core/src/hooks/useMenuPress.ts',+ 'packages/core/src/hooks/menuPressGesture.ts',+ 'packages/core/src/hooks/useLongPress.ts',+ 'packages/core/src/hooks/usePressFeedback.ts',+ 'internal/interaction-harness/src/webInput.ts',+ 'playwright.interaction.config.ts',+ // Shared setup, as pr-interaction keeps (spec:AST-030 FR13): a+ // Playwright upgrade, Storybook config, theme sources, the a11y spec+ // helpers.+ 'package.json',+ 'pnpm-lock.yaml',+ 'apps/storybook/.storybook/preview.tsx',+ 'packages/themes/neutral/src/neutralTheme.ts',+ 'internal/a11y-spec/src/storybook.ts',+ // Its own definition, so a change to this lane runs it.+ '.github/workflows/ci.yml',+ '.github/actions/test-scope/action.yml',+ ]) {+ expect(inScope(touched), touched).toBe(true);+ }+ });++ it('skips for everything else, including components the Chromium proofs cover', () => {+ for (const untouched of [+ 'packages/core/src/Toast/Toast.tsx',+ 'packages/core/src/Selector/useSelectorPresentation.ts',+ 'packages/core/src/utils/clickGuard.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);+ }+ });++ // Replay of real pull requests (their file lists, abridged to the paths+ // that decide the route).+ it('replays: the gesture pull requests run it, unrelated ones skip it', () => {+ // #8666: wheel and pen input drivers in the interaction harness.+ expect(+ runs([+ 'internal/interaction-harness/README.md',+ 'internal/interaction-harness/src/touch.ts',+ 'internal/interaction-harness/src/webInput.ts',+ ]),+ ).toBe(true);+ // #8360: one click guard for the menu press model and the gesture host.+ expect(+ runs([+ '.changeset/click-guard.md',+ 'packages/core/src/gestures/GestureHost.ts',+ 'packages/core/src/hooks/useMenuPress.ts',+ 'packages/core/src/utils/clickGuard.ts',+ 'packages/core/src/utils/pressFeedback.ts',+ ]),+ ).toBe(true);+ // #9016 (Toast timer), #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',+ 'packages/core/src/Toast/Toast.spec.md',+ ],+ [+ '.changeset/textarea-counter-i18n.md',+ 'packages/core/locales/en.json',+ 'packages/core/src/TextArea/TextArea.tsx',+ ],+ [+ '.github/actions/setup/action.yml',+ '.github/scripts/ci-no-dependency-cache.test.mjs',+ ],+ ]) {+ expect(runs(files), files.join(', ')).toBe(false);+ }+ });+});diff --git a/.github/scripts/ci-test-join.mjs b/.github/scripts/ci-test-join.mjsindex dc0c4300b7..7f81bea208 100644--- a/.github/scripts/ci-test-join.mjs+++ b/.github/scripts/ci-test-join.mjs@@ -19,6 +19,7 @@ const requiredSuccess = [['test-build', process.env.TEST_BUILD_RESULT],['test-native-swift', process.env.TEST_NATIVE_SWIFT_RESULT],['pr-interaction', process.env.PR_INTERACTION_RESULT],+ ['pr-interaction-webkit', process.env.PR_INTERACTION_WEBKIT_RESULT],];function fail(message) {diff --git a/.github/scripts/ci-test-join.test.mjs b/.github/scripts/ci-test-join.test.mjsindex ab37a40040..1ed04e4a84 100644--- a/.github/scripts/ci-test-join.test.mjs+++ b/.github/scripts/ci-test-join.test.mjs@@ -19,6 +19,7 @@ const broad = {TEST_BUILD_RESULT: 'success',TEST_NATIVE_SWIFT_RESULT: 'success',PR_INTERACTION_RESULT: 'success',+ PR_INTERACTION_WEBKIT_RESULT: 'success',};// An override of `null` removes the variable, as a missing `needs` result would.@@ -55,6 +56,10 @@ describe('pull-request test join', () => {['PR_INTERACTION_RESULT', 'skipped'],['PR_INTERACTION_RESULT', 'cancelled'],['PR_INTERACTION_RESULT', null],+ ['PR_INTERACTION_WEBKIT_RESULT', 'failure'],+ ['PR_INTERACTION_WEBKIT_RESULT', 'skipped'],+ ['PR_INTERACTION_WEBKIT_RESULT', 'cancelled'],+ ['PR_INTERACTION_WEBKIT_RESULT', null],]) {expect(run({[name]: value}), name).toMatchObject({status: 1});}diff --git a/.github/scripts/ci-tooling-routing.test.mjs b/.github/scripts/ci-tooling-routing.test.mjsindex 95673a78e0..69ef628cc2 100644--- a/.github/scripts/ci-tooling-routing.test.mjs+++ b/.github/scripts/ci-tooling-routing.test.mjs@@ -197,6 +197,7 @@ describe('Node-tooling CI routing', () => {'test-build','test-native-swift','pr-interaction',+ 'pr-interaction-webkit',]);expect(ci.jobs.build.needs).toEqual(['build-storybook', 'typecheck']);const testJoin = step(ci.jobs.test, 'Require expected test-owner outcomes');@@ -221,6 +222,7 @@ describe('Node-tooling CI routing', () => {TEST_BUILD_RESULT: '${{ needs.test-build.result }}',TEST_NATIVE_SWIFT_RESULT: '${{ needs.test-native-swift.result }}',PR_INTERACTION_RESULT: '${{ needs.pr-interaction.result }}',+ PR_INTERACTION_WEBKIT_RESULT: '${{ needs.pr-interaction-webkit.result }}',});const buildJoin = step(ci.jobs.build,diff --git a/.github/scripts/heavy-caps-action.test.mjs b/.github/scripts/heavy-caps-action.test.mjsindex 113240edf7..bbe72f54d4 100644--- a/.github/scripts/heavy-caps-action.test.mjs+++ b/.github/scripts/heavy-caps-action.test.mjs@@ -402,6 +402,7 @@ describe('per-author caps on heavy suites (spec:AST-030 FR16)', () => {);expect(heavyJobs.map(([id]) => id).sort()).toEqual(['pr-interaction',+ 'pr-interaction-webkit','test-build',]);for (const [id, job] of heavyJobs) {diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 4503097173..5e9d912a1b 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -810,9 +810,9 @@ jobs:run: node internal/shadcn-registry/verify-full-catalog.mjs# Historical required check name. The Vitest lanes, the Build test owner,- # native Swift and the interaction proofs always report (each skips its own- # work outside its scope), so this join projects their combined result- # without creating another surface lane.+ # native Swift and the interaction proofs (Chromium and WebKit) always+ # report (each skips its own work outside its scope), so this join projects+ # their combined result without creating another surface lane.test:needs:[@@ -822,6 +822,7 @@ jobs:test-build,test-native-swift,pr-interaction,+ pr-interaction-webkit,]if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (github.event_name != 'workflow_dispatch' && always() && !cancelled()) }}runs-on: ubuntu-slim@@ -866,6 +867,7 @@ jobs:TEST_BUILD_RESULT: ${{ needs.test-build.result }}TEST_NATIVE_SWIFT_RESULT: ${{ needs.test-native-swift.result }}PR_INTERACTION_RESULT: ${{ needs.pr-interaction.result }}+ PR_INTERACTION_WEBKIT_RESULT: ${{ needs.pr-interaction-webkit.result }}run: node .github/scripts/ci-test-join.mjs# Build the packages and Storybook, and analyze components (parallel with@@ -1861,6 +1863,129 @@ jobs:if-no-files-found: ignoreretention-days: 7+ # The gesture, motion and harness interaction proofs in WebKit, the engine+ # of every iOS browser, for the code where WebKit and Chromium differ on+ # touch: the gesture host and recognizers, the motion runtime, the touch and+ # press helpers and the menu press model, plus the harness and the shared+ # setup that runs them (spec:AST-030 FR13). The run is limited to the specs+ # whose bundles reach only that same code, so a WebKit break elsewhere never+ # turns an unrelated pull request red; the motion adopters spec renders+ # Storybook components and stays with the Chromium proofs. Out of scope every step after the scope step skips and+ # the job reports success, so the `test` join reads it without a new+ # required context. Specs that need Chromium-only evidence skip themselves+ # in WebKit.+ pr-interaction-webkit:+ needs: [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'))) && (github.event_name != 'workflow_dispatch' && always() && !cancelled()) }}+ # Frame evidence measures timing: four cores, one Playwright worker.+ runs-on: ubuntu-latest+ timeout-minutes: 15+ permissions:+ # The heavy-suite caps read the author's pull requests and runs.+ actions: read+ contents: read+ pull-requests: read+ steps:+ # 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.+ - name: Check out the scope action+ uses: actions/checkout@v7+ with:+ sparse-checkout: .github/actions/test-scope+ path: .test-scope+ persist-credentials: false++ - name: Decide this job's scope+ 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)|packages/core/src/hooks/(useMenuPress|menuPress|useLongPress|usePressFeedback)|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/)'+ outside-pull-request: skip+ requires-head-file: playwright.interaction.config.ts++ - name: Require this pull request's Storybook build+ if: steps.scope.outputs.applies == 'true' && needs.build-storybook.result != 'success'+ run: |+ echo "The proofs read this pull request's Storybook build, which did not succeed."+ exit 1++ - 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)."++ # 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.+ - name: Check out the heavy-suite caps+ if: steps.scope.outputs.applies == 'true'+ uses: actions/checkout@v7+ with:+ path: .heavy-caps+ sparse-checkout: .github/actions/heavy-caps+ persist-credentials: false++ - name: Per-author heavy-suite caps+ if: steps.scope.outputs.applies == 'true'+ uses: ./.heavy-caps/.github/actions/heavy-caps++ # The daily heavy-run cap counts this step (spec:AST-030 FR16).+ - name: Heavy suite runs+ if: steps.scope.outputs.applies == 'true'+ run: 'true'++ - name: Checkout+ if: steps.scope.outputs.applies == 'true'+ uses: actions/checkout@v7+ with:+ ref: ${{ github.event.pull_request.head.sha }}++ - name: Verify evidence checkout+ if: steps.scope.outputs.applies == 'true'+ env:+ EXPECTED_HEAD_SHA: ${{ github.event.pull_request.head.sha }}+ run: test "$(git rev-parse HEAD)" = "$EXPECTED_HEAD_SHA"++ - name: Setup Node and pnpm+ if: steps.scope.outputs.applies == 'true'+ uses: ./.github/actions/setup+ with:+ install: 'false'++ - name: Download Storybook artifact+ if: steps.scope.outputs.applies == 'true'+ uses: actions/download-artifact@v8+ with:+ name: storybook-${{ needs.build-storybook.outputs.short_hash }}+ path: apps/storybook/dist++ # WebKit needs system libraries the runner image lacks; --with-deps+ # installs them.+ - name: Install Playwright WebKit+ if: steps.scope.outputs.applies == 'true'+ run: pnpm install --frozen-lockfile && npx playwright install --with-deps webkit++ - name: Run WebKit interaction proofs+ if: steps.scope.outputs.applies == 'true'+ run: |+ pnpm exec playwright test \+ packages/core/src/gestures/ \+ packages/core/src/motion/__tests__/animatedLayout.interaction \+ packages/core/src/motion/__tests__/animator.interaction \+ internal/interaction-harness/ \+ --config playwright.interaction.config.ts \+ --project webkit \+ --output interaction-proof-output-webkit++ - name: Upload WebKit interaction evidence+ if: always() && steps.scope.outputs.applies == 'true'+ uses: actions/upload-artifact@v7+ with:+ name: interaction-evidence-webkit+ path: test-results/interaction-evidence+ if-no-files-found: ignore+ retention-days: 7+# Build package test owner. The plugin's production CSS partition is a Build# integration contract: source inspection cannot prove which declaration# paints after Vite emits the final bundle. The `test-build` name makes that