Skip to content

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

TypeScript

ci: run the WebKit interaction legs in Playwright's image, with no apt install (#10013)

Cindy Zhang67ca4f841cc7
diff --git a/.github/scripts/ci-interaction-webkit.test.mjs b/.github/scripts/ci-interaction-webkit.test.mjs
index 7b2600abda..978535946d 100644
--- a/.github/scripts/ci-interaction-webkit.test.mjs
+++ b/.github/scripts/ci-interaction-webkit.test.mjs
@@ -117,8 +117,9 @@ describe('WebKit interaction proof routing', () => {
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',
+ // The image already holds WebKit and its system libraries: no apt step.
+ expect(step(webkit, 'Install Playwright WebKit').run).toBe(
+ 'pnpm install --frozen-lockfile && npx playwright install webkit chromium-headless-shell',
);
const run = step(webkit, 'Run WebKit interaction proofs').run;
expect(run).toContain('--config playwright.interaction.config.ts');
@@ -126,6 +127,66 @@ describe('WebKit interaction proof routing', () => {
expect(run).not.toContain('--project chromium');
});
+ it("installs Chromium's headless shell when an interaction spec launches Chromium", () => {
+ // A changed interaction spec runs in the WebKit legs too, so a spec that
+ // launches Chromium (to decode a WebKit recording) needs the shell there.
+ const launchesChromium = source => /\bchromium\.launch\(/.test(source);
+ expect(launchesChromium('const decoder = await chromium.launch();')).toBe(
+ true,
+ );
+ expect(launchesChromium('await webkit.launch();')).toBe(false);
+ const specs = execFileSync(
+ 'git',
+ ['ls-files', '*.interaction.browser.spec.ts'],
+ {cwd: root, encoding: 'utf8'},
+ )
+ .split('\n')
+ .filter(Boolean);
+ const launchers = specs.filter(file =>
+ launchesChromium(fs.readFileSync(path.join(root, file), 'utf8')),
+ );
+ if (launchers.length > 0) {
+ expect(
+ step(webkit, 'Install Playwright WebKit').run.split(/\s+/),
+ launchers.join(', '),
+ ).toContain('chromium-headless-shell');
+ }
+ });
+
+ it("runs in Playwright's image for exactly the Playwright version the lockfile resolves", () => {
+ expect(webkit['runs-on']).toBe('ubuntu-latest');
+ expect(webkit.container).toEqual({
+ image: expect.stringMatching(
+ /^mcr\.microsoft\.com\/playwright:v\d+\.\d+\.\d+-noble$/,
+ ),
+ options: '--ipc=host',
+ });
+ // Steps keep the runner's bash, and git trusts the root-owned checkout
+ // before the head check reads it.
+ expect(webkit.defaults).toEqual({run: {shell: 'bash'}});
+ const trust = step(webkit, 'Trust the checkout in the container');
+ expect(trust.run).toBe(
+ 'git config --global --add safe.directory "$GITHUB_WORKSPACE"',
+ );
+ expect(webkit.steps.indexOf(trust)).toBe(
+ webkit.steps.indexOf(step(webkit, 'Verify evidence checkout')) - 1,
+ );
+ const tag = /:v(\d+\.\d+\.\d+)-/.exec(webkit.container.image)[1];
+ const lock = fs.readFileSync(path.join(root, 'pnpm-lock.yaml'), 'utf8');
+ // Every resolved copy of the three packages, so a bump of any one of them
+ // fails here until the image tag moves with it.
+ for (const name of ['@playwright/test', 'playwright', 'playwright-core']) {
+ const pattern = new RegExp(
+ `^ '?${name.replace(/[/.]/g, '\\$&')}@(\\d+\\.\\d+\\.\\d+)'?:`,
+ 'gm',
+ );
+ const versions = new Set(
+ [...lock.matchAll(pattern)].map(match => match[1]),
+ );
+ expect([...versions], name).toEqual([tag]);
+ }
+ });
+
it("caps llvmpipe's threads at the job's cgroup CPU quota before Playwright runs", async () => {
const run = step(webkit, 'Run WebKit interaction proofs').run;
const setup = run.slice(0, run.indexOf('pnpm exec playwright test'));
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9ce9e7dd29..8bdd06030a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2643,6 +2643,18 @@ jobs:
leg: [1, 2]
runs-on: ubuntu-latest
timeout-minutes: 15
+ # Playwright's own image for the version the lockfile resolves, with
+ # WebKit and its system libraries already installed. Installing those on
+ # the runner took up to fifteen minutes when the package mirror was slow,
+ # which cancelled the leg before a proof ran. A guard test keeps the tag
+ # equal to the lockfile's Playwright version.
+ container:
+ image: mcr.microsoft.com/playwright:v1.61.1-noble
+ options: --ipc=host
+ # A container's steps default to `sh`; keep the runner's bash.
+ defaults:
+ run:
+ shell: bash
permissions:
# The heavy-suite caps read the author's pull requests and runs.
actions: read
@@ -2724,6 +2736,12 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
+ # The container runs as root over a workspace the runner owns, and git
+ # refuses a repository another user owns unless it is marked safe.
+ - name: Trust the checkout in the container
+ if: steps.scope.outputs.applies == 'true'
+ run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
+
- name: Verify evidence checkout
if: steps.scope.outputs.applies == 'true'
env:
@@ -2743,11 +2761,12 @@ jobs:
name: storybook-${{ needs.build-storybook.outputs.short_hash }}
path: apps/storybook/dist
- # WebKit needs system libraries the runner image lacks; --with-deps
- # installs them.
+ # The image carries WebKit, Chromium's headless shell and their system
+ # libraries; `install` finds them in place and downloads nothing. A spec
+ # that decodes a WebKit recording does so in the headless shell.
- name: Install Playwright WebKit
if: steps.scope.outputs.applies == 'true'
- run: pnpm install --frozen-lockfile && npx playwright install --with-deps webkit
+ 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
@@ -2802,6 +2821,8 @@ jobs:
fi
export LP_NUM_THREADS
echo "llvmpipe threads: $LP_NUM_THREADS"
+ # Which Mesa software rasterizer the frames go through.
+ echo "Mesa DRI drivers: $(ls /usr/lib/x86_64-linux-gnu/dri 2>/dev/null | tr '\n' ' ')"
pnpm exec playwright test \
--test-list "$RUNNER_TEMP/interaction-leg.txt" \
--config playwright.interaction.config.ts \
diff --git a/internal/interaction-harness/scripts/webkit-container.mjs b/internal/interaction-harness/scripts/webkit-container.mjs
index 21cb7b4eb1..f307ea0bb7 100644
--- a/internal/interaction-harness/scripts/webkit-container.mjs
+++ b/internal/interaction-harness/scripts/webkit-container.mjs
@@ -112,6 +112,10 @@ const command = [
`${shaderCache}:${containerShaderCache}`,
'-e',
`MESA_SHADER_CACHE_DIR=${containerShaderCache}`,
+ // Only this script sets it: the harness self-test then requires the
+ // host-kept cache above.
+ '-e',
+ 'ASTRYX_WEBKIT_CONTAINER=1',
'-w',
root,
...env,
diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
index ff5e96565f..83c5b7e218 100644
--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts
+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
@@ -1324,11 +1324,12 @@ test.describe('frame evidence', () => {
test('in the WebKit container, compiled shaders outlive the run', async ({
browser,
}, testInfo) => {
- // The official Playwright image keeps its browsers here.
+ // Only webkit-container.mjs sets ASTRYX_WEBKIT_CONTAINER, and only it
+ // keeps the shader cache on the host.
test.skip(
testInfo.project.name !== 'webkit' ||
- process.env.PLAYWRIGHT_BROWSERS_PATH !== '/ms-playwright',
- 'runs inside webkit-container.mjs',
+ process.env.ASTRYX_WEBKIT_CONTAINER !== '1',
+ 'no host-kept shader cache: runs only under webkit-container.mjs',
);
// A cache inside the container dies with it: every run then compiled each
// shader again, 450–700 ms in the first frame of a blurred layer.