From fe34822d578cb728a348a188351a06d950bf54ab Mon Sep 17 00:00:00 2001 From: Evan Whittaker Date: Fri, 23 Oct 2026 18:25:04 -0500 Subject: [PATCH] Browser tests run in Playwright's image, with nothing fetched from Ubuntu's mirror The phone app's WebKit e2e also fetched its system libraries with `playwright install --with-deps`, and a slow mirror ran that job out of time too. It now runs in Playwright's image through `docker run`, with the workspace mounted at its own path so the test finds the `luxe` the job built, after removing the runner's unused Android SDK to make room for the image. Both images take their tag from the suite's lockfile, read in `what changed`, so a Dependabot bump of Playwright moves its image with it. In the image, site-cross's dev server came up on localhost and refused every probe: the server and the client resolved localhost to different loopbacks. Both servers now bind 127.0.0.1 and everything dials it. site-cross also reports why a dev server never answered: what the last probe got and the server's last lines of output. --- .github/workflows/ci.yml | 52 +++++++++++++++++++--------------- scripts/site-cross.mjs | 60 +++++++++++++++++++++++++++++++--------- 2 files changed, 77 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c773eb0..dfbd693 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,8 @@ jobs: timeout-minutes: 5 outputs: code: ${{ steps.diff.outputs.code }} + web_playwright: ${{ steps.playwright.outputs.web }} + app_playwright: ${{ steps.playwright.outputs.app }} steps: # Full history: the diff is taken from a merge base - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -67,6 +69,17 @@ jobs: env: BASE: ${{ github.event.pull_request.base.sha || github.event.before }} + # The browser suites run in Playwright's image, whose browsers only work with the Playwright + # that matches its tag. Read from the lockfiles, so a Dependabot bump moves the image with it + - name: Playwright versions + id: playwright + run: | + for suite in web=web app=crates/luxe-remote/app-tests; do + version=$(jq -r '.packages["node_modules/playwright"].version // empty' "${suite#*=}/package-lock.json") + [ -n "$version" ] || { echo "::error::no playwright in ${suite#*=}/package-lock.json"; exit 1; } + echo "${suite%%=*}=$version" >> "$GITHUB_OUTPUT" + done + gate: name: build · test · clippy · fmt needs: changes @@ -165,18 +178,24 @@ jobs: # made `target/debug/luxe`: a job of its own would compile the workspace a second time, and # the binary is too large to hand between jobs cheaply. The app's types and unit tests need # no Rust, so they stay in `remote-app`. - - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 - with: - node-version: 24 - cache: npm - cache-dependency-path: crates/luxe-remote/app-tests/package-lock.json - + # + # In Playwright's image, which has WebKit and the Ubuntu libraries it loads, rather than + # fetching those from Ubuntu's mirror on every run, where a slow mirror ran the job out of + # time. The workspace is mounted at its own path, so the test finds `target/debug/luxe` + # where it expects it, and runs as the runner's user, so what it writes stays cleanable. + # + # The build and test binaries leave the disk all but full, too full for the image, and + # `target/` can't give any back because the cache step saves it after this. The Android SDK + # the runner image ships is about 10 GB that nothing here uses. - name: Phone app end to end (WebKit) - working-directory: crates/luxe-remote/app-tests run: | - npm ci - npx playwright install --with-deps webkit - npm run e2e + sudo rm -rf /usr/local/lib/android + df -h / | tail -1 + docker run --rm --ipc=host --user "$(id -u):$(id -g)" -e HOME=/tmp/home \ + -v "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" -w "$GITHUB_WORKSPACE/crates/luxe-remote/app-tests" \ + "mcr.microsoft.com/playwright:v$PLAYWRIGHT-noble" sh -c 'npm ci && npm run e2e' + env: + PLAYWRIGHT: ${{ needs.changes.outputs.app_playwright }} # Does it build and pass on the platforms nobody develops on? Linux above is the canonical gate — # `fmt` is an answer about the source, not about the OS, so running it three times would only @@ -353,9 +372,7 @@ jobs: if: needs.changes.outputs.code == 'true' runs-on: ubuntu-latest container: - # The tag has to be web/'s Playwright version exactly, or the browsers it looks for aren't - # the ones in the image; the first step below checks - image: mcr.microsoft.com/playwright:v1.63.0-noble + image: mcr.microsoft.com/playwright:v${{ needs.changes.outputs.web_playwright }}-noble # Firefox won't run as root in a home it doesn't own, and Actions' home is the runner user's options: --user 1001 timeout-minutes: 15 @@ -372,15 +389,6 @@ jobs: run: npm ci working-directory: web - - name: The image matches web/'s Playwright - run: | - want=$(node -p "require('playwright/package.json').version") - if [ "$want" != "1.63.0" ]; then - echo "::error::web/ uses Playwright $want: set the web cross-browser image to v$want-noble" - exit 1 - fi - working-directory: web - - name: Build run: npm run build working-directory: web diff --git a/scripts/site-cross.mjs b/scripts/site-cross.mjs index f993122..73a1932 100644 --- a/scripts/site-cross.mjs +++ b/scripts/site-cross.mjs @@ -100,6 +100,13 @@ const MIME = { ".wasm": "application/wasm", }; +/** + * Where both servers listen and every browser and probe connects: an address, not `localhost`. + * In a container `localhost` can name `::1` to the server binding it and `127.0.0.1` to the + * client dialing it, and in Playwright's image the dev server came up and refused every request. + */ +const LOOPBACK = "127.0.0.1"; + /** Serves `web/dist` the way a static host would, including the `.wasm` type the player needs. */ function serveBuilt(root) { return new Promise((resolve) => { @@ -123,7 +130,7 @@ function serveBuilt(root) { } response.writeHead(404).end("not found"); }); - server.listen(0, () => resolve({ server, port: server.address().port })); + server.listen(0, LOOPBACK, () => resolve({ server, port: server.address().port })); }); } @@ -144,10 +151,35 @@ async function serveDev(port) { // shell that launched this with it. Spawned directly, `child.kill()` is the server. const child = spawn( process.execPath, - [join(web, "node_modules/astro/bin/astro.mjs"), "dev", "--port", String(port)], - { cwd: web, stdio: "ignore" }, + [join(web, "node_modules/astro/bin/astro.mjs"), "dev", "--host", LOOPBACK, "--port", String(port)], + { cwd: web, stdio: ["ignore", "pipe", "pipe"] }, ); - return { child, port }; + return watchServer({ child, port, output: [], exit: null }); +} + +/** + * Keeps the last of what `target`'s server prints, and how it ended, so a server that never + * answers can say why. Read either way: a pipe nobody drains fills up and stalls its server. + */ +function watchServer(target) { + const keep = (chunk) => { + target.output.push(...String(chunk).split("\n").filter((line) => line.trim())); + target.output.splice(0, Math.max(0, target.output.length - 30)); + }; + target.child.stdout.on("data", keep); + target.child.stderr.on("data", keep); + target.child.on("exit", (code, signal) => { + target.exit = signal ?? `exit code ${code}`; + }); + return target; +} + +/** Why `target`'s server never answered, with the last of what it printed. */ +function reportSilentServer(name, target) { + const why = target.exit ? `it ended (${target.exit})` : "it was still running"; + console.log(`✗ ${name.padEnd(9)} the dev server never answered; ${why}`); + console.log(` the last ask got: ${target.lastAnswer ?? "nothing yet"}`); + for (const line of target.output) console.log(` ${line}`); } function shutdown(target) { @@ -157,13 +189,15 @@ function shutdown(target) { } } -async function waitForServer(port, seconds = 90) { - for (let attempt = 0; attempt < seconds * 2; attempt += 1) { +async function waitForServer(target, seconds = 90) { + for (let attempt = 0; attempt < seconds * 2 && !target.exit; attempt += 1) { try { - const response = await fetch(`http://localhost:${port}/`); + const response = await fetch(`http://${LOOPBACK}:${target.port}/`); if (response.ok) return true; - } catch { - /* not up yet */ + target.lastAnswer = `HTTP ${response.status}: ${(await response.text()).slice(0, 300)}`; + } catch (error) { + // Not up yet, usually; the cause is what tells a refused port from a wrong address + target.lastAnswer = `${error.message}${error.cause ? ` (${error.cause.code ?? error.cause.message})` : ""}`; } await new Promise((done) => setTimeout(done, 500)); } @@ -210,7 +244,7 @@ async function demosFit(browser, port, path) { const tab = await context.newPage(); const problems = []; try { - await tab.goto(`http://localhost:${port}${path}`, { waitUntil: "networkidle" }); + await tab.goto(`http://${LOOPBACK}:${port}${path}`, { waitUntil: "networkidle" }); await settleHero(tab); const demos = tab.locator(".demo"); const count = await demos.count(); @@ -279,7 +313,7 @@ async function checkEngine(engine, name, port) { noise.push(`request failed: ${request.url()} (${request.failure()?.errorText})`); }); - await tab.goto(`http://localhost:${port}${page.path}`, { waitUntil: "networkidle" }); + await tab.goto(`http://${LOOPBACK}:${port}${page.path}`, { waitUntil: "networkidle" }); await settleHero(tab); if (page.demos) { @@ -366,8 +400,8 @@ for (const [name, engine] of [ if (!built) { shutdown(current); current = await serveDev((port += 1)); - if (!(await waitForServer(current.port))) { - console.log(`✗ ${name.padEnd(9)} the dev server never answered`); + if (!(await waitForServer(current))) { + reportSilentServer(name, current); failed = true; continue; }