From b87a9bbb81c4209a04be3f562e051cce17169f24 Mon Sep 17 00:00:00 2001 From: Will Gosnold Date: Tue, 27 Oct 2026 19:13:01 +0100 Subject: [PATCH 1/2] ci: shard the root test job The root job ran the whole suite from source and then the whole e2e suite against the binary, in one job, and took about 17 minutes. The required check waited on it, so every PR did too. Make the user a matrix axis of the test job, so root runs the same three shards as the runner user and the shard list stays in one place. Root stays on Ubuntu. The rest shard runs the unit files and the e2e describes that need the source. The test-root job is gone. Part of #382 Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/ci.yml | 63 ++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc64df6f..faf5d3bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: test: - name: test (${{ matrix.os }}, ${{ matrix.shard.name }}) + name: test (${{ matrix.os }}, ${{ matrix.user }}, ${{ matrix.shard.name }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -24,6 +24,9 @@ jobs: # requests test on Ubuntu only. Pushes to main (and manual runs, for # checking a branch on macOS before merging) test on both. os: ${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest"]' || '["ubuntu-latest", "macos-latest"]') }} + # The tests run once as the runner user and once as root. Root stays + # on Ubuntu, where sudo needs no password. + user: [runner, root] # The end-to-end tests are nearly all the run time, so they are split # by top-level describe block across parallel jobs. The three patterns # cover every test exactly once; a new top-level describe block lands @@ -32,6 +35,8 @@ jobs: - { name: fork, pattern: "^ForkTest " } - { name: vendor, pattern: "^VendorTest " } - { name: rest, pattern: "^(?!ForkTest |VendorTest )" } + exclude: + - { os: macos-latest, user: root } steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -41,51 +46,39 @@ jobs: bun-version: 1.4.3 - run: bun install --frozen-lockfile - run: bun run typecheck - # Every test file except e2e, which runs below against the compiled - # binary that ships. Each file gets a fresh module registry: - # units.test.ts needs settings.ts loaded under its own sandbox. - - name: Unit tests - if: matrix.shard.name == 'rest' - run: bun test --isolate $(ls test/*.test.ts | grep -v '/e2e\.test\.ts$') - run: bun run build - name: The compiled binary carries no crash-injection code run: bun test/crash-build.ts check dist/patchbook - - name: End-to-end tests against the compiled binary - run: bun test test/e2e.test.ts --test-name-pattern "$PATTERN" + # Root ignores file permissions, so a test that needs a refused write must be skipped by permissionTest. One that is not fails the root jobs. + # The "rest" shard also runs from source what skips under PATCHBOOK_CMD: + # every test file but e2e, then the e2e describes that need the source. + # Each unit file gets a fresh module registry: units.test.ts needs + # settings.ts loaded under its own sandbox. + - name: Tests as ${{ matrix.user }} + run: | + as=() + if [ "$USER_KIND" = root ]; then as=(sudo env "PATH=$PATH" HOME=/root); fi + "${as[@]}" bash -euxo pipefail -c ' + [ "$([ "$(id -u)" = 0 ] && echo root || echo runner)" = "$1" ] + if [ "$2" = rest ]; then + bun test --isolate $(ls test/*.test.ts | grep -v "/e2e\.test\.ts$") + bun test test/e2e.test.ts --test-name-pattern "so only from source" + fi + PATCHBOOK_CMD="$PWD/dist/patchbook" bun test test/e2e.test.ts --test-name-pattern "$3" + ' bash "$USER_KIND" "$SHARD" "$PATTERN" env: - PATCHBOOK_CMD: ${{ github.workspace }}/dist/patchbook + USER_KIND: ${{ matrix.user }} + SHARD: ${{ matrix.shard.name }} PATTERN: ${{ matrix.shard.pattern }} - test-root: - name: test (root) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 - with: - bun-version: 1.4.3 - - run: bun install --frozen-lockfile - - run: bun run build - # Root ignores file permissions, so a test that needs a refused write must be skipped by permissionTest. One that is not fails here. - - name: Tests as root, from source and against the compiled binary - run: | - sudo env "PATH=$PATH" HOME=/root bash -euxo pipefail -c ' - [ "$(id -u)" = 0 ] - bun test --isolate - PATCHBOOK_CMD="$PWD/dist/patchbook" bun test test/e2e.test.ts - ' - # main's ruleset requires a check named "test (ubuntu-latest)". This job - # gives that name one result for the whole matrix above and the root job. + # gives that name one result for the whole matrix above. required: name: test (ubuntu-latest) if: always() - needs: [test, test-root] + needs: test runs-on: ubuntu-latest steps: - - run: test "$RESULT" = success && test "$ROOT" = success + - run: test "$RESULT" = success env: RESULT: ${{ needs.test.result }} - ROOT: ${{ needs.test-root.result }} From 29d397c9d9a9188a126c0b985aa548cb2b738e8c Mon Sep 17 00:00:00 2001 From: Will Gosnold Date: Tue, 27 Oct 2026 19:33:58 +0100 Subject: [PATCH 2/2] ci: correct two comments in the test job Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index faf5d3bc..d33ad442 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,8 +24,8 @@ jobs: # requests test on Ubuntu only. Pushes to main (and manual runs, for # checking a branch on macOS before merging) test on both. os: ${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest"]' || '["ubuntu-latest", "macos-latest"]') }} - # The tests run once as the runner user and once as root. Root stays - # on Ubuntu, where sudo needs no password. + # The tests run once as the runner user and once as root. Root runs + # on Ubuntu only, for the same reason. user: [runner, root] # The end-to-end tests are nearly all the run time, so they are split # by top-level describe block across parallel jobs. The three patterns @@ -50,10 +50,10 @@ jobs: - name: The compiled binary carries no crash-injection code run: bun test/crash-build.ts check dist/patchbook # Root ignores file permissions, so a test that needs a refused write must be skipped by permissionTest. One that is not fails the root jobs. - # The "rest" shard also runs from source what skips under PATCHBOOK_CMD: - # every test file but e2e, then the e2e describes that need the source. - # Each unit file gets a fresh module registry: units.test.ts needs - # settings.ts loaded under its own sandbox. + # The "rest" shard also runs every test file but e2e from source, then + # the e2e describes that skip under PATCHBOOK_CMD. Each unit file gets a + # fresh module registry: units.test.ts needs settings.ts loaded under + # its own sandbox. - name: Tests as ${{ matrix.user }} run: | as=()