diff --git a/.github/workflows/agent.yml b/.github/workflows/agent.yml new file mode 100644 index 0000000..e454986 --- /dev/null +++ b/.github/workflows/agent.yml @@ -0,0 +1,44 @@ +name: Agent checks + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + agent: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + # Read-only workflow: downstream steps do not push + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - uses: pnpm/action-setup@v4 + with: + version: 10.13.1 + + - uses: actions/setup-node@v4 + with: + node-version: "22" + cache: pnpm + + - name: Check agent CI configuration + run: node --test scripts/agent-ci.test.mjs + + - name: Install JS dependencies + run: pnpm install --frozen-lockfile --ignore-scripts + + - name: Test agent + run: pnpm agent:test + + - name: Typecheck agent + run: pnpm agent:typecheck diff --git a/docs/CI.md b/docs/CI.md index 3d5cf30..d1806c3 100644 --- a/docs/CI.md +++ b/docs/CI.md @@ -24,6 +24,15 @@ dependencies without lifecycle scripts, then runs `pnpm web:test`, locally to check `apps/web`; `node --test scripts/web-ci.test.mjs` verifies the CI job configuration. +## Agent checks + +The `Agent checks` workflow (`.github/workflows/agent.yml`) runs on pushes to +`main` and on pull requests. Its single blocking job installs locked JS +dependencies without lifecycle scripts, then runs `pnpm agent:test` and +`pnpm agent:typecheck` in order. Run the same two commands locally to check +`services/agent`; `node --test scripts/agent-ci.test.mjs` verifies the CI job +configuration. + ## Keeper checks The `Keeper checks` workflow (`.github/workflows/keeper.yml`) runs on pushes to diff --git a/scripts/agent-ci.test.mjs b/scripts/agent-ci.test.mjs new file mode 100644 index 0000000..7755f92 --- /dev/null +++ b/scripts/agent-ci.test.mjs @@ -0,0 +1,32 @@ +// Copyright (c) 2026 Sub Rosa contributors +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { test } from "node:test"; + +const workflow = readFileSync( + new URL("../.github/workflows/agent.yml", import.meta.url), + "utf8", +); +const scripts = JSON.parse( + readFileSync(new URL("../package.json", import.meta.url), "utf8"), +).scripts; + +test("agent CI runs agent:test and agent:typecheck as blocking steps in one job on every PR", () => { + assert.match(workflow, /^ push:\n branches: \[main\]$/m); + assert.match(workflow, /^ pull_request:$/m); + assert.match(workflow, /^permissions:\n contents: read$/m); + + const job = workflow.match(/^ agent:\n([\s\S]*)$/m)?.[1]; + assert.ok(job, "agent job must exist"); + assert.doesNotMatch(job, /^ [a-z][\w-]*:/m, "checks must stay in the agent job"); + assert.doesNotMatch(job, /\bcontinue-on-error\s*:/, "checks must block on failure"); + assert.match(job, /^ run: pnpm install --frozen-lockfile --ignore-scripts$/m); + + let previousStep = -1; + for (const script of ["agent:test", "agent:typecheck"]) { + assert.ok(scripts[script], `root script ${script} must exist`); + const step = job.indexOf(` run: pnpm ${script}\n`); + assert.ok(step > previousStep, `${script} must run after the preceding check`); + previousStep = step; + } +});