Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .agents/scripts/merge-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ rerunnable_runs() {
-q '.[] | select(.pull_request == null) | .title, .body // ""' |
grep -oE '(e2e|src|ui)/[A-Za-z0-9_./-]+\.(test|spec)\.tsx?' || true)
red=$(checks | grep -e '^fail ' -e '^cancel ' || true)
others=$(echo "$red" | awk '$3 != "Quality"')
others=$(echo "$red" | sed 's/^[^ ]* [^ ]* //' | grep -vxE 'Quality|Console' || true)
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
# why: Quality and Console only sum up the CI jobs they need and fail when one was
# cancelled, so next to a red job, judging them would call that job's cancel this PR's to
# fix. Red alone, they were cancelled themselves and are re-run like any job.
case $name in Quality | Console) [ -z "$others" ] || continue ;; esac
run=$(echo "$link" | sed -n 's#.*/actions/runs/\([0-9][0-9]*\).*#\1#p')
[ -n "$run" ] || { echo none; continue; }
if [ "$bucket" = fail ]; then
Expand Down
37 changes: 33 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,20 @@ jobs:
echo "browsers=chromium" >>"$GITHUB_OUTPUT"
fi

console:
name: Console
console-lane:
name: Console (${{ matrix.shard }}/4)
needs: changes
# Runs unless Changes said there is nothing to test, so a broken Changes job runs the lane.
if: ${{ !cancelled() && needs.changes.outputs.console != 'false' }}
runs-on: ubuntu-24.04
permissions:
contents: read
timeout-minutes: 15
strategy:
# why: one red shard must not cancel the others, or their failures go unreported.
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -223,13 +228,37 @@ jobs:
- name: Browser lane
env:
BROWSERS: ${{ needs.changes.outputs.browsers }}
SHARD: ${{ matrix.shard }}
run: |
if [ "$BROWSERS" = chromium ]; then
pnpm test:console --project=chromium
pnpm test:console --project=chromium --shard="$SHARD/4"
else
pnpm test:console
pnpm test:console --shard="$SHARD/4"
fi

# why: branch protection requires the check named Console, so this job stands for the sharded
# lane. `always()` makes it report a failure when a shard fails, where a job skipped by a failed
# need would count as passed; a lane skipped by Changes leaves it green.
console:
name: Console
needs: [changes, console-lane]
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 Console needs ended $result" >&2; exit 1 ;;
esac
done

fallow:
name: Fallow
runs-on: ubuntu-24.04
Expand Down
3 changes: 2 additions & 1 deletion docs/internal/agent-rules/toolchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ list and this one the same.
- **CI:** what `pnpm check` runs, and Fallow, on every push. The `pnpm
check` steps run as parallel jobs (static checks, unit tests, the timing
tests, the e2e lane in three shards); the Quality check passes only when all of them
do. The console lane runs on
do. The console lane runs in four shards
(the required Console check passes only when they all do) 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.
Expand Down
5 changes: 5 additions & 0 deletions src/merge-pr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ describe("merge-pr.sh re-run of red CI", { timeout: 20_000 }, () => {
runs: [run("cancelled", "E2E (2/3)"), run("failure")],
runsAfterRerun: [run("success", "E2E (2/3)"), run("success")],
},
{
name: "a console shard, though the Console check that needs it failed,",
runs: [run("cancelled", "Console (2/4)"), run("failure", "Console")],
runsAfterRerun: [run("success", "Console (2/4)"), run("success", "Console")],
},
{
name: "a Quality check, while every job it needs passed,",
runs: [run("success", "E2E (2/3)"), run("cancelled")],
Expand Down
58 changes: 58 additions & 0 deletions src/test-lanes.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spawnSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
Expand Down Expand Up @@ -150,3 +151,60 @@ describe("test lanes (package.json)", () => {
expect(quality).toMatch(/needs:\s*\[[^\]]*\btiming\b/);
});
});

/** why: a job's block is its two-space-indented key and every line up to the next one. */
function ciJobs(ci: string): ReadonlyMap<string, string> {
const body = /\njobs:\n([\s\S]*)$/.exec(ci)?.[1] ?? "";
const jobs = new Map<string, string>();
for (const block of body.split(/\n(?= {2}[a-z][\w-]*:\n)/)) {
const id = /^ {2}([a-z][\w-]*):\n/.exec(block)?.[1];
if (id !== undefined) jobs.set(id, block);
}
return jobs;
}

// why: main's console lane needs about 33 minutes of one runner's two workers (#852), so each
// of four shards runs about 8 inside the 15-minute job timeout.
const CONSOLE_SHARDS_AT_LEAST = 4;

describe("the console lane in CI (.github/workflows/ci.yml)", () => {
it("runs the console lane over a matrix of at least four shards, each passing its `--shard=<i>/<n>` in both browser modes, and the required `Console` check needs that job and fails when it does not pass", () => {
const ci = readFileSync(join(REPO_ROOT, ".github/workflows/ci.yml"), "utf8");
const jobs = [...ciJobs(ci)];
const lanes = jobs.filter(([, job]) => job.includes("pnpm test:console"));
const required = jobs.find(([, job]) => /\n {4}name: Console\n/.test(job));

expect(lanes.map(([id]) => id)).toHaveLength(1);
const [laneId, lane] = lanes[0] ?? ["", ""];
const shards = /\n {8}shard: \[([^\]]*)\]/.exec(lane)?.[1]?.split(",") ?? [];
expect(shards.length, "shards in the console lane's matrix").toBeGreaterThanOrEqual(
CONSOLE_SHARDS_AT_LEAST,
);
const runs = lane.match(/pnpm test:console[^\n]*/g) ?? [];
expect(runs, "the lane's chromium-only and every-browser commands").toHaveLength(2);
expect(lane, "the shard index comes from the matrix").toMatch(
/\n {10}SHARD: \$\{\{ matrix\.shard \}\}/,
);
for (const run of runs) {
expect(run, "index from the matrix, count from its length").toMatch(
new RegExp(`--shard="\\$SHARD/${shards.length}"`),
);
}

expect(required, "a job named Console").toBeDefined();
const [requiredId, requiredJob] = required ?? ["", ""];
expect(requiredId).not.toBe(laneId);
expect(requiredJob).toMatch(new RegExp(`\\n {4}needs: \\[[^\\]]*\\b${laneId}\\b`));
expect(requiredJob).toMatch(/\n {4}if: (\$\{\{ )?always\(\)/);
const body = /\n {8}run: \|\n((?: {10}[^\n]*\n?)+)/.exec(requiredJob)?.[1] ?? "";
expect(body, "the Console job's run script").not.toBe("");
const verdict = (results: string) =>
spawnSync("bash", ["-c", body.replace(/^ {10}/gm, "")], {
env: { PATH: process.env["PATH"] ?? "", RESULTS: results },
}).status;
expect(verdict("success skipped success"), "every need passed or was skipped").toBe(0);
for (const bad of ["success failure", "cancelled", "skipped failure skipped"]) {
expect(verdict(bad), `results ${bad}`).toBe(1);
}
});
});
Loading