diff --git a/.agents/scripts/merge-pr.sh b/.agents/scripts/merge-pr.sh index be36fafaa..3f97614ce 100755 --- a/.agents/scripts/merge-pr.sh +++ b/.agents/scripts/merge-pr.sh @@ -55,8 +55,14 @@ red_checks() { rerunnable_runs() { flaky=$(gh issue list --label flaky-test --state open --limit 100 --json title,body \ -q '.[] | .title, .body' | grep -oE '(e2e|src|ui)/[A-Za-z0-9_./-]+\.(test|spec)\.tsx?' || true) - gh pr checks "$pr" --json bucket,link -q '.[] | select(.bucket == "fail" or .bucket == "cancel") | "\(.bucket) \(.link)"' | - while read -r bucket link; do + red=$(gh pr checks "$pr" --json bucket,link,name -q '.[] | select(.bucket == "fail" or .bucket == "cancel") | "\(.bucket) \(.link) \(.name)"') + others=$(echo "$red" | awk '$3 != "Quality"') + echo "$red" | grep . | + while read -r bucket link name; do + # why: Quality only sums up the CI jobs it needs and fails when one was cancelled, so + # next to a red job, judging it would call that job's cancel this PR's to fix. Red + # alone, Quality was cancelled itself and is re-run like any job. + [ "$name" != Quality ] || [ -z "$others" ] || continue run=$(echo "$link" | sed -n 's#.*/actions/runs/\([0-9][0-9]*\).*#\1#p') [ -n "$run" ] || { echo none; continue; } if [ "$bucket" = fail ]; then diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c14babba8..9daaa17b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,8 +16,10 @@ concurrency: cancel-in-progress: true jobs: - quality: - name: Quality + # why: `pnpm check` runs these one after another in ~5 min; split, the slowest part (one e2e + # shard) sets the wall time. Keep the steps below in step with `pnpm check`. + static: + name: Static checks runs-on: ubuntu-24.04 permissions: contents: read @@ -26,7 +28,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - # The comment lint in `pnpm check` diffs against origin/main. + # why: the comment lint diffs against origin/main. fetch-depth: 0 - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: @@ -37,8 +39,88 @@ jobs: corepack prepare pnpm@11.22.0+sha512.1ff870c4c6133dfd88fb2afc46dd13d47f09c9794b438c6fdb47ca98caf3bc16381ee0be93a091b8e3824cf01f889f46d7d9e20910fb0be1ab0fb5baa80dd621 --activate - name: Install dependencies run: pnpm install --frozen-lockfile --ignore-scripts - - name: Quality checks - run: pnpm check + - name: Typecheck + run: pnpm run typecheck && pnpm run typecheck:e2e + - name: Lint + run: pnpm run lint && pnpm run lint:comments + - name: Format + run: pnpm run format:check + + unit: + name: Unit tests + runs-on: ubuntu-24.04 + permissions: + contents: read + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: 22 + - name: Enable Corepack + run: | + corepack enable + corepack prepare pnpm@11.22.0+sha512.1ff870c4c6133dfd88fb2afc46dd13d47f09c9794b438c6fdb47ca98caf3bc16381ee0be93a091b8e3824cf01f889f46d7d9e20910fb0be1ab0fb5baa80dd621 --activate + - name: Install dependencies + run: pnpm install --frozen-lockfile --ignore-scripts + - name: Unit tests + run: pnpm run test:unit + + e2e: + name: E2E (${{ matrix.shard }}/3) + runs-on: ubuntu-24.04 + permissions: + contents: read + timeout-minutes: 10 + strategy: + # why: one red shard must not cancel the others, or their failures go unreported. + fail-fast: false + matrix: + shard: [1, 2, 3] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: 22 + - name: Enable Corepack + run: | + corepack enable + corepack prepare pnpm@11.22.0+sha512.1ff870c4c6133dfd88fb2afc46dd13d47f09c9794b438c6fdb47ca98caf3bc16381ee0be93a091b8e3824cf01f889f46d7d9e20910fb0be1ab0fb5baa80dd621 --activate + - name: Install dependencies + run: pnpm install --frozen-lockfile --ignore-scripts + - name: Build + run: pnpm run build && pnpm run build:e2e + - name: E2E tests + env: + SHARD: ${{ matrix.shard }} + run: pnpm exec vitest run --project e2e --tags-filter='!slow' --shard="$SHARD/3" + + # why: branch protection requires the check named Quality, so this job stands for all of the + # above. `always()` makes it report a failure when a job it needs fails, where a job skipped + # by a failed need would count as passed. + quality: + name: Quality + needs: [static, unit, e2e] + if: always() + runs-on: ubuntu-24.04 + permissions: {} + timeout-minutes: 5 + steps: + - name: Every job passed + env: + RESULTS: ${{ join(needs.*.result, ' ') }} + run: | + echo "results: $RESULTS" + for result in $RESULTS; do + case $result in + success | skipped) ;; + *) echo "a job Quality needs ended $result" >&2; exit 1 ;; + esac + done # Decides whether the Console job has work to do. A workflow-level `paths` filter would leave # the required Console check pending forever on a PR it skips; a job skipped by `if` reports diff --git a/docs/internal/DELIVERY.md b/docs/internal/DELIVERY.md index d28c2a814..abc98bfa0 100644 --- a/docs/internal/DELIVERY.md +++ b/docs/internal/DELIVERY.md @@ -339,7 +339,8 @@ coming back for the same reason is a missing rule or a missing spec line; `main` takes changes only through a pull request whose Quality, Fallow and Console checks passed. That is a ruleset on GitHub, not a convention: agents push with a maintainer's account, so anything that binds them binds you too, -and nobody bypasses it. On a pull request the Console job is skipped when the +and nobody bypasses it. Quality is one job that passes only when the static +checks, the unit tests and every e2e shard passed. On a pull request the Console job is skipped when the PR changes no source, UI, console spec or build file (a skipped job counts as passed), and runs in Chromium only unless the PR changes `ui/` or the console specs. Every push to `main` runs it in every browser. Releases therefore run in the Release workflow diff --git a/docs/internal/agent-rules/toolchain.md b/docs/internal/agent-rules/toolchain.md index 73015f815..27ffabfed 100644 --- a/docs/internal/agent-rules/toolchain.md +++ b/docs/internal/agent-rules/toolchain.md @@ -29,7 +29,10 @@ e2e suite, the console lane in every browser (`pnpm test:console`), `tsc`, lint, the comment lint (architecture rule 17) and typecheck. Errors show in its output. - **Push hook:** Fallow, then the e2e typecheck. -- **CI:** `pnpm check` and Fallow on every push. The console lane runs on +- **CI:** what `pnpm check` runs, and Fallow, on every push. The `pnpm + check` steps run as parallel jobs (static checks, unit tests, the e2e + lane in three shards); the Quality check passes only when all of them + do. The console lane runs on every push to `main`, and on a pull request when it changes a source, UI, console spec or build file: in every browser when it changes `ui/` or the console specs, else in Chromium only. diff --git a/src/merge-pr.test.ts b/src/merge-pr.test.ts index f18aca77b..3f8864adb 100644 --- a/src/merge-pr.test.ts +++ b/src/merge-pr.test.ts @@ -24,17 +24,15 @@ interface Fleet { /** Whether the check passes after a re-run. */ readonly passesOnRerun: boolean; readonly body?: string; + readonly qualityAlone?: boolean; } const VALID_BODY = "## Review\n\nSpec review: skipped. Code review: skipped. Claims review: skipped.\n" + "Rounds: 0. Tokens: n/a.\n\n*Written by an agent.*\n"; -/** - * Runs the gate on PR 7 against a fake `gh` whose one CI check, Quality (Actions run 77), is - * red until `gh run rerun` is called. Returns the gate's exit code and output, how many times it - * re-ran the job, and whether it merged. - */ +// why: CI's red job comes with a red Quality check that needs it, as on GitHub, so a gate that +// judged Quality instead of the job would show here. function gate(fleet: Fleet) { const dir = mkdtempSync(join(tmpdir(), "merge-pr-")); const write = (name: string, text: string) => writeFileSync(join(dir, name), text); @@ -49,6 +47,7 @@ function gate(fleet: Fleet) { `#!/bin/sh d=${JSON.stringify(dir)} state() { if [ -f "$d/reran" ]; then echo ${after}; else echo ${fleet.bucket}; fi; } +quality() { if [ "$(state)" = pass ]; then echo pass; else echo fail; fi; } case "$*" in "pr view 7 --json state"*) echo OPEN ;; "pr view 7 --json isDraft"*) echo false ;; @@ -56,9 +55,18 @@ case "$*" in "pr view 7 --json body"*) cat "$d/body" ;; "pr view 7 --json headRefName"*) echo chore/x ;; "pr view 7 --json mergeable"*) echo MERGEABLE ;; - "pr checks 7 --json name,bucket"*) echo "$(state) Quality" ;; +${ + fleet.qualityAlone === true + ? ` "pr checks 7 --json name,bucket"*) echo "pass E2E (2/3)"; echo "$(state) Quality" ;; "pr checks 7 --json bucket,link"*) - b=$(state); [ "$b" = pass ] || echo "$b https://github.com/o/r/actions/runs/77/job/5" ;; + b=$(state); [ "$b" = pass ] || echo "$b https://github.com/o/r/actions/runs/77/job/6 Quality" ;;` + : ` "pr checks 7 --json name,bucket"*) echo "$(state) E2E (2/3)"; echo "$(quality) Quality" ;; + "pr checks 7 --json bucket,link"*) + b=$(state); [ "$b" = pass ] || { + echo "$b https://github.com/o/r/actions/runs/77/job/5 E2E (2/3)" + echo "fail https://github.com/o/r/actions/runs/77/job/6 Quality" + } ;;` +} "issue list --label flaky-test"*) cat "$d/flaky" ;; "run view 77 --log-failed") cat "$d/log" ;; "run rerun 77 --failed") echo rerun >>"$d/reran" ;; @@ -92,8 +100,8 @@ esac } const FLAKY_LOG = - "Quality\tQuality checks\t2026-10-06T10:00:00Z FAIL e2e/gateway-fast-fail.test.ts > a gateway fails fast\n" + - "Quality\tQuality checks\t2026-10-06T10:00:00Z ✓ e2e/lease-lifecycle.test.ts (12 tests)\n"; + "E2E (2/3)\tE2E tests\t2026-10-06T10:00:00Z FAIL e2e/gateway-fast-fail.test.ts > a gateway fails fast\n" + + "E2E (2/3)\tE2E tests\t2026-10-06T10:00:00Z ✓ e2e/lease-lifecycle.test.ts (12 tests)\n"; const FLAKY_ISSUE = "Fails under load on main.\nTest: `e2e/gateway-fast-fail.test.ts` > a gateway fails fast\n"; @@ -127,12 +135,24 @@ describe("merge-pr.sh re-run of red CI", () => { expect(result.status).toBe(0); }); - it("re-runs a job GitHub cancelled, and merges when the re-run passes", () => { + it("re-runs a job GitHub cancelled, though the Quality check that needs it failed, and merges when the re-run passes", () => { const result = gate({ bucket: "cancel", log: "", flakyIssues: "", passesOnRerun: true }); expect(result.reruns).toBe(1); expect(result.merged).toBe(true); }); + it("re-runs a Quality check GitHub cancelled while every job it needs passed, and merges when the re-run passes", () => { + const result = gate({ + bucket: "cancel", + log: "", + flakyIssues: "", + passesOnRerun: true, + qualityAlone: true, + }); + expect(result.reruns).toBe(1); + expect(result.merged).toBe(true); + }); + it("does not re-run a job that failed in a test no open flaky-test issue names, and does not merge", () => { const log = FLAKY_LOG.replace("e2e/gateway-fast-fail.test.ts", "e2e/doctor-drift.test.ts"); const result = gate({ bucket: "fail", log, flakyIssues: FLAKY_ISSUE, passesOnRerun: true }); @@ -144,7 +164,7 @@ describe("merge-pr.sh re-run of red CI", () => { it("does not re-run a failed job whose log names no failed test, and does not merge", () => { const log = - "Quality\tQuality checks\t2026-10-06T10:00:00Z error TS2322: Type 'string' is not assignable\n"; + "E2E (2/3)\tE2E tests\t2026-10-06T10:00:00Z error TS2322: Type 'string' is not assignable\n"; const result = gate({ bucket: "fail", log, flakyIssues: FLAKY_ISSUE, passesOnRerun: true }); expect(result.reruns).toBe(0); expect(result.merged).toBe(false);