Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
CI: Linux shards run four test files at once
milind-soni368310d07dd6
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 2d7c0144ff..e52e3d3333 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -174,9 +174,10 @@ jobs:matrix: ${{ fromJSON(needs.static.outputs.vitest_matrix) }}runs-on: ${{ matrix.os }}# scripts/testing/duration-sequencer.ts splits each platform's files by- # their recorded seconds on that platform, about 17 minutes a Linux shard- # and 10 to 15 a Windows one. The cap catches a hang, not normal suite- # growth; Windows runners are about 1.45x slower and vary more.+ # their recorded seconds on that platform, about 6 minutes a Linux shard+ # (four files at once) and 10 to 15 a Windows one (one at a time). The cap+ # catches a hang, not normal suite growth; Windows runners are about 1.45x+ # slower and vary more.timeout-minutes: ${{ matrix.os == 'ubuntu-latest' && 25 || 30 }}steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1@@ -201,6 +202,7 @@ jobs:OMB_VITEST_RETRY_LOG: ${{ runner.temp }}/vitest-retries.jsonlOMB_VITEST_E2E: ${{ matrix.e2e }}OMB_VITEST_SUBSET: ${{ matrix.files }}+ OMB_VITEST_WORKERS: ${{ matrix.workers }}run: pnpm exec vitest run ${{ matrix.files }} --shard=${{ matrix.shard }}/${{ matrix.shards }} --reporter=default --reporter=github-actions- name: Report flaky tests that needed a retry# Known flakes (scripts/testing/ci-retry-list.json) get two retries indiff --git a/docs/ci.md b/docs/ci.mdindex 65d109d1c2..ffc5718969 100644--- a/docs/ci.md+++ b/docs/ci.md@@ -93,10 +93,18 @@ run in the Windows Vitest/Electron jobs.## Vitest shards-The suite runs one file at a time, so a shard takes as long as its files added-up, and the slowest shard sets how long a PR and a release wait. Linux and-Windows run eight shards each, macOS four (the full lane only);-`scripts/ci-scope.mjs` builds the matrix.+The slowest shard sets how long a PR and a release wait. Linux and Windows run+eight shards each, macOS four (the full lane only); `scripts/ci-scope.mjs`+builds the matrix.++**Files at once.** A Linux shard runs four files at a time (`VITEST_WORKERS`,+`OMB_VITEST_WORKERS` in `vite.config.ts`), one for each of the runner's vCPUs.+Most of a shard's time is waiting on real servers and fake engines: one file at+a time it took 16 minutes with the machine 70% idle, and four at a time 5.+Windows and macOS shards, and every local run, still run one file at a time. So+that files side by side never share a port, each worker picks from its own+(`server/testing/worker-port.ts`); a test that picks a port some other way can+meet another file's.**Which files run where.** Linux runs every file. Most e2e files driveOMB's own logic through a real server and fake engines, which is the same on@@ -138,8 +146,8 @@ To reproduce a failing Vitest job locally:2. Use the same OS. Shard weights are platform-specific, so Windows shard 3and Linux shard 3 do not contain the same files.3. Copy the expanded command from **Run tests**, including any file filters- and the complete `--shard=n/count` fraction. Copy its `OMB_VITEST_E2E`- and `OMB_VITEST_SUBSET` environment values too. On Boat, the static job+ and the complete `--shard=n/count` fraction. Copy its `OMB_VITEST_E2E`,+ `OMB_VITEST_SUBSET` and `OMB_VITEST_WORKERS` environment values too. On Boat, the static jobcontains each shard's output in a `vitest (ubuntu-latest, ...)` lane'slog group; the lane uses the same matrix values.@@ -154,7 +162,7 @@ pnpm exec vitest run --shard=3/8The full Linux shard 3/8 uses a POSIX shell:```sh-OMB_VITEST_E2E=all OMB_VITEST_SUBSET= pnpm exec vitest run --shard=3/8+OMB_VITEST_E2E=all OMB_VITEST_SUBSET= OMB_VITEST_WORKERS=4 pnpm exec vitest run --shard=3/8```Docs and locale jobs select smaller file lists and have their own sharddiff --git a/scripts/ci-linux-lanes.mjs b/scripts/ci-linux-lanes.mjsindex 18189775b1..641ebbd384 100644--- a/scripts/ci-linux-lanes.mjs+++ b/scripts/ci-linux-lanes.mjs@@ -11,7 +11,7 @@ import { fileURLToPath } from "node:url";export function vitestLane(entry, retryLog) {return {name: `vitest (ubuntu-latest, ${entry.part})`,- env: { OMB_VITEST_RETRY_LOG: retryLog, OMB_VITEST_E2E: entry.e2e, OMB_VITEST_SUBSET: entry.files },+ env: { OMB_VITEST_RETRY_LOG: retryLog, OMB_VITEST_E2E: entry.e2e, OMB_VITEST_SUBSET: entry.files, OMB_VITEST_WORKERS: entry.workers },commands: [`pnpm exec vitest run ${entry.files} --shard=${entry.shard}/${entry.shards} --reporter=default --reporter=github-actions`,...(entry.node_tests ? ["pnpm broker:test && pnpm test:electron"] : []),diff --git a/scripts/ci-linux-lanes.test.ts b/scripts/ci-linux-lanes.test.tsindex 6bab3d8255..a87cc7a258 100644--- a/scripts/ci-linux-lanes.test.ts+++ b/scripts/ci-linux-lanes.test.ts@@ -25,14 +25,14 @@ describe("Linux lanes", () => {]);expect(lanes[0]).toEqual({name: "vitest (ubuntu-latest, shard 1/8)",- env: { OMB_VITEST_RETRY_LOG: "/t/retries.jsonl", OMB_VITEST_E2E: "all", OMB_VITEST_SUBSET: "" },+ env: { OMB_VITEST_RETRY_LOG: "/t/retries.jsonl", OMB_VITEST_E2E: "all", OMB_VITEST_SUBSET: "", OMB_VITEST_WORKERS: 4 },commands: ["pnpm exec vitest run --shard=1/8 --reporter=default --reporter=github-actions", "pnpm broker:test && pnpm test:electron"],});expect(lanes.slice(1, 8).every((lane) => lane.commands.length === 1)).toBe(true);});it("runs a subset's files and leaves out what the plan leaves out", () => {- const entry = { os: "ubuntu-latest", part: "docs tests", shard: 1, shards: 1, files: "a.test.ts b.test.ts", e2e: "all", node_tests: false };+ const entry = { os: "ubuntu-latest", part: "docs tests", shard: 1, shards: 1, files: "a.test.ts b.test.ts", e2e: "all", node_tests: false, workers: 4 };expect(lanesFor({ vitest: [entry], evals: false, packaged_server: false }, "/r")).toEqual([vitestLane(entry, "/r")]);expect(vitestLane(entry, "/r").commands).toEqual(["pnpm exec vitest run a.test.ts b.test.ts --shard=1/1 --reporter=default --reporter=github-actions"]);expect(lanesFor({ vitest: [], evals: true, packaged_server: false }, "/r")).toEqual([EVALS_LANE]);diff --git a/scripts/ci-scope.mjs b/scripts/ci-scope.mjsindex 29c6b8c488..48a9c84b8d 100644--- a/scripts/ci-scope.mjs+++ b/scripts/ci-scope.mjs@@ -209,17 +209,20 @@ export function laneOf(event) {return "full";}-// A shard runs its files one at a time, so the slowest shard sets the run's length. Windows and macOS run only the e2e-// files that depend on their OS, so their shards stay as short as Linux's, and macOS keeps four: the account runs five-// macOS jobs at a time.+// The slowest shard sets the run's length. Windows and macOS run only the e2e files that depend on their OS, so their+// shards stay as short as Linux's, and macOS keeps four: the account runs five macOS jobs at a time.export const VITEST_SHARDS = { "macos-latest": 4, "ubuntu-latest": 8, "windows-latest": 8 };+// Test files at once on each platform's runner (OMB_VITEST_WORKERS, vite.config.ts). A Linux shard mostly waits on real+// servers and fake engines: its 4 vCPU sat 70% idle one file at a time, and four files take a third of the time.+export const VITEST_WORKERS = { "macos-latest": 1, "ubuntu-latest": 4, "windows-latest": 1 };+/** ci.yml's vitest matrix: every shard of every selected platform, and which e2e files that platform runs. */export function vitestMatrix(oses) {return {include: oses.flatMap((os) => Array.from({ length: VITEST_SHARDS[os] }, (_, i) => ({os, part: `shard ${i + 1}/${VITEST_SHARDS[os]}`, shard: i + 1, shards: VITEST_SHARDS[os], files: "",- e2e: os === "ubuntu-latest" ? "all" : "host", node_tests: i === 0,+ e2e: os === "ubuntu-latest" ? "all" : "host", node_tests: i === 0, workers: VITEST_WORKERS[os],}))),};}@@ -234,7 +237,7 @@ export function ciOutputs({ checks }, oses) {for (let shard = 1; shard <= shards; shard++) {include.push({os: "ubuntu-latest", part: shards > 1 ? `${part} ${shard}/${shards}` : part, shard, shards,- files: files.join(" "), e2e: "all", node_tests: nodeTests && shard === 1,+ files: files.join(" "), e2e: "all", node_tests: nodeTests && shard === 1, workers: VITEST_WORKERS["ubuntu-latest"],});}}diff --git a/scripts/ci-scope.test.ts b/scripts/ci-scope.test.tsindex 59cfba1342..a05dfaf0db 100644--- a/scripts/ci-scope.test.ts+++ b/scripts/ci-scope.test.ts@@ -78,7 +78,7 @@ describe("vitest matrix", () => {const count = (os: string) => include.filter((entry) => entry.os === os).length;expect([count("ubuntu-latest"), count("windows-latest"), count("macos-latest")]).toEqual([8, 8, 4]);expect(include.find((entry) => entry.os === "windows-latest" && entry.shard === 8))- .toEqual({ os: "windows-latest", part: "shard 8/8", shard: 8, shards: 8, files: "", e2e: "host", node_tests: false });+ .toEqual({ os: "windows-latest", part: "shard 8/8", shard: 8, shards: 8, files: "", e2e: "host", node_tests: false, workers: 1 });expect(include.filter((entry) => entry.node_tests).map((entry) => [entry.os, entry.shard])).toEqual([["macos-latest", 1], ["ubuntu-latest", 1], ["windows-latest", 1]]);expect(include.filter((entry) => entry.e2e === "all").every((entry) => entry.os === "ubuntu-latest")).toBe(true);@@ -179,7 +179,7 @@ describe("CI outputs", () => {expect(VITEST_SUBSETS["locale-tests"].files).toEqual(expect.arrayContaining(["src/", "scripts/generate-locale.test.mjs", "scripts/testing/key-readback.e2e.test.ts"]));expect(out.vitest_matrix.include).toEqual([1, 2].map((shard) => ({os: "ubuntu-latest", part: `locale tests ${shard}/2`, shard, shards: 2,- files: VITEST_SUBSETS["locale-tests"].files.join(" "), e2e: "all", node_tests: shard === 1,+ files: VITEST_SUBSETS["locale-tests"].files.join(" "), e2e: "all", node_tests: shard === 1, workers: 4,})));expect(ciOutputs(selectCiScope(["src/locales/de.json", "src/App.tsx"]), PR).vitest_matrix).toEqual(vitestMatrix(["ubuntu-latest"]));});@@ -188,7 +188,7 @@ describe("CI outputs", () => {const out = ciOutputs(selectCiScope(["docs/analytics.md"]), PR);expect(out).toMatchObject({ build: false, jobs: ["vitest"] });expect(out.vitest_matrix.include).toEqual([{- os: "ubuntu-latest", part: "docs tests", shard: 1, shards: 1, files: VITEST_SUBSETS["docs-tests"].files.join(" "), e2e: "all", node_tests: false,+ os: "ubuntu-latest", part: "docs tests", shard: 1, shards: 1, files: VITEST_SUBSETS["docs-tests"].files.join(" "), e2e: "all", node_tests: false, workers: 4,}]);expect(ciOutputs(selectCiScope(["docs/analytics.md", "src/locales/de.json"]), PR).vitest_matrix.include.map((entry: { part: string }) => entry.part)).toEqual(["locale tests 1/2", "locale tests 2/2", "docs tests"]);diff --git a/scripts/ci-workflow.test.ts b/scripts/ci-workflow.test.tsindex a0556091af..2a9afcfa67 100644--- a/scripts/ci-workflow.test.ts+++ b/scripts/ci-workflow.test.ts@@ -91,6 +91,7 @@ describe("CI concurrency", () => {expect(run.run).toContain("pnpm exec vitest run ${{ matrix.files }} --shard=${{ matrix.shard }}/${{ matrix.shards }} ");expect(run.env?.OMB_VITEST_E2E).toBe("${{ matrix.e2e }}");expect(run.env?.OMB_VITEST_SUBSET).toBe("${{ matrix.files }}");+ expect(run.env?.OMB_VITEST_WORKERS).toBe("${{ matrix.workers }}");const { include } = vitestMatrix(["macos-latest", "ubuntu-latest", "windows-latest"]);for (const os of ["macos-latest", "ubuntu-latest", "windows-latest"]) {const shards = include.filter((entry) => entry.os === os);diff --git a/vite.config.ts b/vite.config.tsindex fcf2f6ce78..7724f1635e 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -15,6 +15,7 @@ const { version } = JSON.parse() as { version: string };const root = fileURLToPath(new URL(".", import.meta.url));+const workers = Number(process.env.OMB_VITEST_WORKERS) || 1;const page = (file: string) => fileURLToPath(new URL(file, import.meta.url));/** The window's rail of places loads /rail: rail.html, its own small page, in development as from the server. */@@ -57,9 +58,10 @@ export default defineConfig({// OMB_VITEST_E2E=host (CI's Windows and macOS shards) leaves the e2e files that run on Linux only.exclude: [...configDefaults.exclude, ...(hostE2eOnly() ? portableE2eFiles(root, include) : [])],setupFiles: ["server/testing/setup.ts", "src/testing/all-locales.ts"],- // the suite spawns fake provider CLIs and a real harness server;- // parallel files introduce load-sensitive flakes for no win- fileParallelism: false,+ // One file at a time by default: the suite spawns fake provider CLIs and real+ // harness servers, which a laptop feels. CI sets its runner's count (scripts/ci-scope.mjs).+ fileParallelism: workers > 1,+ maxWorkers: workers,// --shard splits the files by recorded CI seconds, not countsequence: { sequencer: DurationSequencer },// Known flakes in scripts/testing/ci-retry-list.json get two retries in