Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
CI: typecheck and build run beside the shards, not ahead of them
milind-soni724017fc5aad
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 39836ca7b4..d5de9fbcc4 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -54,7 +54,7 @@ jobs:&& github.actor == github.repository_owner && github.triggering_actor == github.repository_owner&& (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository&& github.event.pull_request.user.login == github.repository_owner)- && 'typecheck + lint + Linux tests (Boat)' || 'typecheck + lint' }}+ && 'preflight + Linux tests (Boat)' || 'preflight' }}runs-on: >-${{ vars.BOAT_CI == 'on' && contains(fromJSON('["push", "pull_request", "merge_group"]'), github.event_name)&& github.actor == github.repository_owner && github.triggering_actor == github.repository_owner@@ -101,15 +101,6 @@ jobs:- name: Validate locale catalogsrun: pnpm i18n:check- run: pnpm lint- # A pull request that changes only docs, tests under scripts/ or the- # control plane cannot change what these three check.- - if: steps.scope.outputs.build == 'true'- run: pnpm typecheck- - if: steps.scope.outputs.build == 'true'- run: pnpm check:electron- - name: production UI build- if: steps.scope.outputs.build == 'true'- run: pnpm exec vite build# The rest runs only on a Boat VM, where ci-scope moved the Linux jobs' work into this job.- name: Remove what Boat installs and GitHub's runners lackif: steps.scope.outputs.linux_lanes@@ -147,6 +138,30 @@ jobs:if-no-files-found: warnretention-days: 7+ build:+ needs: static+ if: contains(needs.static.outputs.jobs, '"build"')+ # The slow checks, about three minutes, beside the shards rather than ahead+ # of them. A pull request that changes only docs, tests under scripts/ or+ # the control plane cannot change what they check.+ name: typecheck + build+ runs-on: ubuntu-latest+ timeout-minutes: 15+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ persist-credentials: false+ - uses: pnpm/action-setup@ff378ebe6b225b0680b81c1ad4498ae0d1d3a5e3 # v6.0.10+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0+ with:+ node-version: 24+ cache: pnpm+ - run: pnpm install --frozen-lockfile+ - run: pnpm typecheck+ - run: pnpm check:electron+ - name: production UI build+ run: pnpm exec vite build+vitest:# Admit the expensive runner fan-out only after the quick checks pass.# A failing preflight still fails the required gates; nothing is waived.@@ -346,7 +361,7 @@ jobs:gate:# One aggregation, not three queued runners doing the same check.name: CI- needs: [static, vitest, behavior-evals, packaged-server, windows-cua, electron-smokes]+ needs: [static, build, vitest, behavior-evals, packaged-server, windows-cua, electron-smokes]# Still report failed/skipped dependencies, but don't keep a superseded# workflow alive just to schedule its summary jobs.if: ${{ !cancelled() }}diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 268161a50d..b5af765726 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -268,7 +268,8 @@ select the remaining checks; see [CI job selection](docs/ci.md). Documentation-oPRs run the docs tests, while translation-only PRs run the locale subset. Runtimechanges select broader tests and smokes.-- **typecheck + lint** — the static job always runs the checks above, and adds typecheck, Electron syntax checks, and a production UI build when selected. It runs before the dependent jobs.+- **preflight** — the static job always runs the checks above, in under a minute, before the dependent jobs.+- **typecheck + build** — when selected, typecheck, Electron syntax checks and a production UI build, beside the shards.- **vitest (os, part)** — full platform suites use eight Linux or Windows shards and four macOS shards; subset jobs have their own file lists and shard counts. Windows jobs run on PRs whose changes can affect Windows or carry the `windows` label. macOS Vitest shards run in the nightly/manual full lane. Files run serially within each shard, balanced by recorded platform time. Use the [reproduction steps](docs/ci.md#vitest-shards) for the failing job.- **packaged server smoke (os)** — when selected, the server bundle is copied out of the repo and started with no `node_modules` in reach.- **Windows CUA host smoke**, **macOS smokes (packaged server + Electron)** — when selected, real Electron utility processes run against disposable homes; never the live app.diff --git a/docs/ci.md b/docs/ci.mdindex d25cdd1824..79ec39727f 100644--- a/docs/ci.md+++ b/docs/ci.md@@ -20,8 +20,9 @@ too) into areas, and runs only the jobs some area can affect:| control plane | `cloudflare/control-plane/` | the control-plane job || everything | anything else: `.github/` workflows, `package.json`, the lockfile and workspace, tsconfig, vite and vitest config, `third_party/`, `scripts/` code, unknown paths | every job |-The build is static's typecheck, Electron syntax check and UI build. Several-areas run the union of their jobs. Why the mapping is what it is:+The build is the `build` job: typecheck, Electron syntax check and UI build,+about three minutes, beside the shards rather than ahead of them. Several areas+run the union of their jobs. Why the mapping is what it is:- The server imports a few renderer files (`SRC_OUTSIDE_RENDERER`), and therenderer imports Electron modules, so a server or desktop change can affect@@ -50,7 +51,7 @@ sets (`laneOf` in `scripts/ci-scope.mjs`):| Event | Lane | What runs || --- | --- | --- || `pull_request` | its areas | the table above, with Linux shards, and Windows jobs only for a change that can break Windows (Windows below) |-| `push` to main, `merge_group` | main | static (typecheck, lint, the build), the eight Linux and eight Windows shards with the Electron node tests, the macOS smokes job, behavior evals, the Linux and Windows packaged server smokes, the open-source edition, the control plane, the renderer smoke and Linux and Windows browser identity |+| `push` to main, `merge_group` | main | static (lint and the CI checks), the build, the eight Linux and eight Windows shards with the Electron node tests, the macOS smokes job, behavior evals, the Linux and Windows packaged server smokes, the open-source edition, the control plane, the renderer smoke and Linux and Windows browser identity || `schedule` (nightly, 21:17 UTC), `workflow_dispatch` (manual runs, the release branch's CI that `prepare-release.yml` starts, and the release lane) | full | every job on every platform: also the Windows and macOS shards, the Windows packaged server and Windows CUA smokes, Windows and macOS browser identity, the browser driver on all three, the Linux package and the Linux ARM64 installer |The main lane runs Linux, Windows and one macOS job. The macOS shards, the@@ -77,8 +78,8 @@ lane, which only an emergency `ship_without_ci` release skips.main lane; a pull request whose diff cannot be read falls back to every jobon every platform.-The single `CI` gate keeps the existing required dependencies. `static`-outputs the selected job ids; the gate wants each required job to have passed+The single `CI` gate keeps the existing required dependencies, and adds+`build`. `static` outputs the selected job ids; the gate wants each required job to have passedwhen it was selected and to have been skipped when it was not. Failures,cancellations, a missing or malformed selection and unexpected runs or skipsfail the gate. Advisory jobs remain advisory. A new push to a PR cancels that@@ -370,7 +371,7 @@ instead (Settings → Secrets and variables → Actions → Variables; anythinglist and to the condition in `ci.yml`'s `static` job. To run Windows on a PRas well, label it `windows` (Windows above).- **What changes.** `static` runs on `boat-xlarge` (16 vCPU, 32 GB) and is- named "typecheck + lint + Linux tests (Boat)". After its usual checks it+ named "preflight + Linux tests (Boat)". After its usual checks itruns the Linux vitest shards, behavior evals and the Linux packaged serversmoke side by side as lanes of that VM (`scripts/ci-linux-lanes.mjs`, thesame commands as their GitHub jobs), and prints each lane's log in a groupdiff --git a/scripts/ci-scope.mjs b/scripts/ci-scope.mjsindex a9996c56d9..cd69a9ccf8 100644--- a/scripts/ci-scope.mjs+++ b/scripts/ci-scope.mjs@@ -5,11 +5,10 @@ import { fileURLToPath } from "node:url";// The ci.yml jobs a pull request runs only when its change can affect them;// `static` and the `CI` gate always run. Besides these job ids a scope's checks-// name "build" (static's typecheck, Electron syntax check and UI build) and the-// vitest job's parts: "linux-tests", "host-tests" (Windows, and macOS where the-// event runs it), and the subsets in VITEST_SUBSETS.+// name the vitest job's parts: "linux-tests", "host-tests" (Windows, and macOS+// where the event runs it), and the subsets in VITEST_SUBSETS.export const SELECTABLE_JOBS = [- "vitest", "behavior-evals", "packaged-server", "windows-cua", "electron-smokes", "cloudflared-linux-arm64",+ "build", "vitest", "behavior-evals", "packaged-server", "windows-cua", "electron-smokes", "cloudflared-linux-arm64","foss", "control-plane", "ui-smoke", "browser-identity", "package-linux", "browser-driver",];@@ -225,7 +224,7 @@ export function vitestMatrix(oses) {}/** What ci.yml runs for a scope on an event whose suite covers `oses`: the- * selected job ids, whether `static` builds, and the vitest matrix. */+ * selected job ids and the vitest matrix. */export function ciOutputs({ checks }, oses) {const platforms = oses.filter((os) => checks.includes(os === "ubuntu-latest" ? "linux-tests" : "host-tests"));const { include } = vitestMatrix(platforms);@@ -241,7 +240,6 @@ export function ciOutputs({ checks }, oses) {const jobs = SELECTABLE_JOBS.filter((job) => (job === "vitest" ? include.length > 0: job === "windows-cua" ? checks.includes(job) && oses.includes("windows-latest") : checks.includes(job)));return {- build: checks.includes("build"),jobs,vitest_os: oses,// macOS's packaged server smoke runs in the macOS smokes job.diff --git a/scripts/ci-scope.test.ts b/scripts/ci-scope.test.tsindex 59cfba1342..3da75e98f6 100644--- a/scripts/ci-scope.test.ts+++ b/scripts/ci-scope.test.ts@@ -20,7 +20,7 @@ const ALL = ["macos-latest", "ubuntu-latest", "windows-latest"];const PR = ["ubuntu-latest", "windows-latest"];const LINUX = ["ubuntu-latest"];const MAIN = ["ubuntu-latest", "windows-latest"];-const SERVER_JOBS = ["vitest", "behavior-evals", "packaged-server", "electron-smokes", "foss", "ui-smoke", "browser-identity", "package-linux", "browser-driver"];+const SERVER_JOBS = ["build", "vitest", "behavior-evals", "packaged-server", "electron-smokes", "foss", "ui-smoke", "browser-identity", "package-linux", "browser-driver"];const temporaryDirectories: string[] = [];afterEach(() => {for (const directory of temporaryDirectories.splice(0)) rmSync(directory, { recursive: true, force: true });@@ -66,11 +66,11 @@ function outputs(text: string) {}const packaged = (oses: string[]) => oses.filter((os) => os !== "macos-latest");-const everything = (oses: string[]) => ({ build: true, jobs: SELECTABLE_JOBS, vitest_os: oses, packaged_server_os: packaged(oses), vitest_matrix: vitestMatrix(oses) });-const staticOnly = (oses: string[], build: boolean) => ({ build, jobs: [], vitest_os: oses, packaged_server_os: packaged(oses), vitest_matrix: vitestMatrix(oses) });+const everything = (oses: string[]) => ({ jobs: SELECTABLE_JOBS, vitest_os: oses, packaged_server_os: packaged(oses), vitest_matrix: vitestMatrix(oses) });+const staticOnly = (oses: string[], build: boolean) => ({ jobs: build ? ["build"] : [], vitest_os: oses, packaged_server_os: packaged(oses), vitest_matrix: vitestMatrix(oses) });/** What a push to main and a merge group run: Linux's and Windows' shards, the macOS smokes and the short Linux checks. */-const MAIN_JOBS = ["vitest", "behavior-evals", "packaged-server", "electron-smokes", "foss", "control-plane", "ui-smoke", "browser-identity"];-const mainLane = () => ({ build: true, jobs: MAIN_JOBS, vitest_os: MAIN, packaged_server_os: MAIN, vitest_matrix: vitestMatrix(MAIN) });+const MAIN_JOBS = ["build", "vitest", "behavior-evals", "packaged-server", "electron-smokes", "foss", "control-plane", "ui-smoke", "browser-identity"];+const mainLane = () => ({ jobs: MAIN_JOBS, vitest_os: MAIN, packaged_server_os: MAIN, vitest_matrix: vitestMatrix(MAIN) });describe("vitest matrix", () => {it("gives Linux and Windows eight shards each and macOS four, and only Linux every e2e file", () => {@@ -166,16 +166,16 @@ describe("CI path scope", () => {describe("CI outputs", () => {it("runs a renderer change's tests on Linux only", () => {const out = ciOutputs(selectCiScope(["src/App.tsx"]), PR);- expect(out).toEqual({ build: true, jobs: ["vitest", "ui-smoke"], vitest_os: PR, packaged_server_os: PR, vitest_matrix: vitestMatrix(["ubuntu-latest"]) });+ expect(out).toEqual({ jobs: ["build", "vitest", "ui-smoke"], vitest_os: PR, packaged_server_os: PR, vitest_matrix: vitestMatrix(["ubuntu-latest"]) });});it("runs a server change's tests on Linux and Windows, and its other checks", () => {- expect(ciOutputs(selectCiScope(["server/index.ts"]), PR)).toEqual({ build: true, jobs: SERVER_JOBS, vitest_os: PR, packaged_server_os: PR, vitest_matrix: vitestMatrix(PR) });+ expect(ciOutputs(selectCiScope(["server/index.ts"]), PR)).toEqual({ jobs: SERVER_JOBS, vitest_os: PR, packaged_server_os: PR, vitest_matrix: vitestMatrix(PR) });});it("runs the locale tests in their own shards, with the Electron node tests, when no full Linux run covers them", () => {const out = ciOutputs(selectCiScope(["src/locales/de.json"]), PR);- expect(out.jobs).toEqual(["vitest"]);+ expect(out.jobs).toEqual(["build", "vitest"]);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,@@ -186,7 +186,7 @@ describe("CI outputs", () => {it("runs the docs tests in one job for docs, and skips the build", () => {const out = ciOutputs(selectCiScope(["docs/analytics.md"]), PR);- expect(out).toMatchObject({ build: false, jobs: ["vitest"] });+ expect(out).toMatchObject({ 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,}]);@@ -450,7 +450,7 @@ describe("CI scope CLI", () => {pull_request: { base: { sha: base }, head: { sha: git("rev-parse", "HEAD") } },});expect(output).toEqual(ciOutputs({ checks: ["docs-tests"] }, LINUX));- expect(output).toMatchObject({ build: false, jobs: ["vitest"] });+ expect(output).toMatchObject({ jobs: ["vitest"] });expect(stderr).toBe("");});@@ -467,7 +467,7 @@ describe("CI scope CLI", () => {pull_request: { base: { sha: base }, head: { sha: git("rev-parse", "HEAD") } },});expect(output).toEqual(ciOutputs({ checks: ["docs-tests"] }, LINUX));- expect(output).toMatchObject({ build: false, jobs: ["vitest"] });+ expect(output).toMatchObject({ jobs: ["vitest"] });expect(stderr).toBe("");});@@ -481,12 +481,12 @@ describe("CI scope CLI", () => {pull_request: { base: { sha: base }, head: { sha: git("rev-parse", "HEAD") } },});// A server change that cannot break Windows first: its Windows jobs wait for main.- expect(output).toEqual({ build: true, jobs: SERVER_JOBS, vitest_os: LINUX, packaged_server_os: LINUX, vitest_matrix: vitestMatrix(LINUX) });+ expect(output).toEqual({ jobs: SERVER_JOBS, vitest_os: LINUX, packaged_server_os: LINUX, vitest_matrix: vitestMatrix(LINUX) });expect(stderr).toBe("");});it("runs a renderer pull request's tests on Linux, and a translation pull request's locale tests", () => {- for (const [source, jobs, oses] of [["src/App.tsx", ["vitest", "ui-smoke"], ["ubuntu-latest"]], ["src/locales/de.json", ["vitest"], []]] as const) {+ for (const [source, jobs, oses] of [["src/App.tsx", ["build", "vitest", "ui-smoke"], ["ubuntu-latest"]], ["src/locales/de.json", ["build", "vitest"], []]] as const) {const { directory, git, base } = fixture(source);writeFileSync(join(directory, source), "changed\n");git("commit", "--quiet", "-am", "change");@@ -759,7 +759,7 @@ describe("CI scope CLI on a pull request's Windows jobs", () => {return { output: outputs(readFileSync(outputPath, "utf8")), stdout, stderr };}- const serverJobs = (oses: string[]) => ({ build: true, jobs: SERVER_JOBS, vitest_os: oses, packaged_server_os: oses, vitest_matrix: vitestMatrix(oses) });+ const serverJobs = (oses: string[]) => ({ jobs: SERVER_JOBS, vitest_os: oses, packaged_server_os: oses, vitest_matrix: vitestMatrix(oses) });it("runs the Windows jobs for a changed line that names Windows, and says why", async () => {const { directory, payload } = serverChange('if (process.platform === "win32") quote();\n');diff --git a/scripts/ci-workflow.test.ts b/scripts/ci-workflow.test.tsindex e774cf7c76..adb77bc783 100644--- a/scripts/ci-workflow.test.ts+++ b/scripts/ci-workflow.test.ts@@ -7,7 +7,7 @@ import { SELECTABLE_JOBS, vitestMatrix } from "./ci-scope.mjs";import { interpolate } from "./testing/github-expression.ts";const workflow = parse(readFileSync(new URL("../.github/workflows/ci.yml", import.meta.url), "utf8"));-const requiredRuntimeJobs = ["vitest", "behavior-evals", "packaged-server", "windows-cua", "electron-smokes"];+const requiredRuntimeJobs = ["build", "vitest", "behavior-evals", "packaged-server", "windows-cua", "electron-smokes"];function runGate(needs: Record<string, unknown>) {// Execute the actual gate, not a duplicate of its success/failure logic.@@ -237,13 +237,14 @@ describe("CI concurrency", () => {vitest_matrix: "${{ steps.scope.outputs.vitest_matrix }}",packaged_server_os: "${{ steps.scope.outputs.packaged_server_os }}",});- // Only these three static steps depend on the scope's build flag; the rest always run, or run only on Boat.- const built = (workflow.jobs.static.steps as { if?: string; run?: string }[]).filter((step) => step.if?.includes("outputs.build"));- expect(built.map((step) => [step.if, step.run])).toEqual([- ["steps.scope.outputs.build == 'true'", "pnpm typecheck"],- ["steps.scope.outputs.build == 'true'", "pnpm check:electron"],- ["steps.scope.outputs.build == 'true'", "pnpm exec vite build"],- ]);+ // The build job runs where the scope selects it, and static holds only what is quick and always runs.+ expect(workflow.jobs.build.if).toBe(`contains(needs.static.outputs.jobs, '"build"')`);+ expect((workflow.jobs.build.steps as { run?: string }[]).map((step) => step.run).filter(Boolean))+ .toEqual(["pnpm install --frozen-lockfile", "pnpm typecheck", "pnpm check:electron", "pnpm exec vite build"]);+ for (const run of ["pnpm typecheck", "pnpm check:electron", "pnpm exec vite build"]) {+ expect((workflow.jobs.static.steps as { run?: string }[]).some((step) => step.run === run), run).toBe(false);+ }+ expect((workflow.jobs.static.steps as { if?: string }[]).some((step) => step.if?.includes("outputs.build"))).toBe(false);expect(workflow.jobs.static.steps.some((step: { run?: string }) =>step.run === "pnpm exec vitest run scripts/ci-scope.test.ts scripts/ci-linux-lanes.test.ts scripts/ci-workflow.test.ts scripts/testing/verification-docs.test.ts",)).toBe(true);@@ -316,8 +317,8 @@ describe("CI on Boat", () => {name: interpolate(workflow.jobs.static.name, context),timeout: interpolate(String(workflow.jobs.static["timeout-minutes"]), context),});- const boat = { runsOn: "boat-xlarge", name: "typecheck + lint + Linux tests (Boat)", timeout: 45 };- const github = (timeout: number) => ({ runsOn: "ubuntu-latest", name: "typecheck + lint", timeout });+ const boat = { runsOn: "boat-xlarge", name: "preflight + Linux tests (Boat)", timeout: 45 };+ const github = (timeout: number) => ({ runsOn: "ubuntu-latest", name: "preflight", timeout });it.each([["the owner's pull request", {}],@@ -345,7 +346,7 @@ describe("CI on Boat", () => {it("does the Linux work in the static job only where ci-scope moved it there, without Boat's extra rights or desktop", () => {const steps = workflow.jobs.static.steps as Step[];- const boatOnly = steps.slice(steps.findIndex((step) => step.name === "production UI build") + 1);+ const boatOnly = steps.slice(steps.findIndex((step) => step.name === "Remove what Boat installs and GitHub's runners lack"));expect(boatOnly.map((step) => step.if)).toEqual(["steps.scope.outputs.linux_lanes", "steps.scope.outputs.linux_lanes", "steps.scope.outputs.linux_lanes","${{ !cancelled() && steps.scope.outputs.linux_lanes }}", "failure() && steps.scope.outputs.linux_lanes",