From f2387a4335a68ba9c59f2b5614f532c18a61ffc4 Mon Sep 17 00:00:00 2001 From: Scott Lovegrove Date: Thu, 3 Dec 2026 16:04:18 +0000 Subject: [PATCH 1/3] chore(agents): run the agent tooling tests apart from the package tests Publishing runs npm test through prepublishOnly, and npm test also ran the agent tooling's tests in .agents/scripts. A slow agent-tooling test timing out there broke outline-cli's 3.2.0 publish, and the same setup is here. npm test now covers only the package's tests. The tooling's tests run with npm run test:agents (vitest.agents.config.ts), which CI runs on every pull request and verify runs when something those tests read changed since main. --- .agents/scripts/lib/steps.test.ts | 11 ++++++++- .agents/scripts/lib/steps.ts | 27 ++++++++++++++++++++++ .agents/scripts/lib/verify.test.ts | 37 ++++++++++++++++++++++++++++++ .agents/scripts/lib/verify.ts | 28 +++++++++++++++++++--- .github/workflows/test.yml | 3 +++ AGENTS.md | 5 ++-- CODEBASE.md | 9 +++++--- docs/agents.md | 7 +++--- package.json | 1 + vitest.agents.config.ts | 9 ++++++++ vitest.config.ts | 3 +-- 11 files changed, 126 insertions(+), 14 deletions(-) create mode 100644 vitest.agents.config.ts diff --git a/.agents/scripts/lib/steps.test.ts b/.agents/scripts/lib/steps.test.ts index 254572b..f220050 100644 --- a/.agents/scripts/lib/steps.test.ts +++ b/.agents/scripts/lib/steps.test.ts @@ -1,4 +1,4 @@ -import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs' +import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import { basename, join } from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' @@ -130,6 +130,15 @@ describe('verify covers CI', () => { } }) + it('watches only paths that exist, so a rename cannot stop a step running locally', () => { + const missing = VERIFY_STEPS.flatMap((step) => + (step.onlyWhenChanged ?? []) + .filter((path) => !existsSync(join(REPO_ROOT, path))) + .map((path) => `${step.name}: ${path}`), + ) + expect(missing).toEqual([]) + }) + it('names only steps that exist', () => { const names = VERIFY_STEPS.map((step) => step.name) for (const entry of CI_EQUIVALENTS) { diff --git a/.agents/scripts/lib/steps.ts b/.agents/scripts/lib/steps.ts index 97e0a00..7dcd23c 100644 --- a/.agents/scripts/lib/steps.ts +++ b/.agents/scripts/lib/steps.ts @@ -1,6 +1,7 @@ import { existsSync } from 'node:fs' import { join } from 'node:path' import { readJson } from './state.ts' +import { AGENT_DOCS } from './tree.ts' import type { Step } from './verify.ts' const bin = (tool: string) => `node_modules/.bin/${tool}` @@ -16,6 +17,31 @@ export const VERIFY_STEPS: Step[] = [ { name: 'types', command: bin('tsc'), args: ['--noEmit'] }, { name: 'types:tools', command: bin('tsc'), args: ['--noEmit', '-p', '.agents/scripts'] }, { name: 'tests', command: bin('vitest'), args: ['run'], env: CI_ENV }, + { + name: 'tests:agents', + command: bin('vitest'), + args: ['run', '--config', 'vitest.agents.config.ts'], + env: CI_ENV, + // Everything the tests in .agents/scripts read from the checkout. + onlyWhenChanged: [ + '.agents/', + 'vitest.agents.config.ts', + // Its scripts (instructions, steps) and what it packs (package-contents). + 'package.json', + // The tools the tests run: lefthook, npm and @todoist/cli-core/testing. + 'package-lock.json', + '.github/workflows/', + 'lefthook.yml', + // The hook configs (hook-wiring) and the skill links (instructions). + '.claude/', + '.codex/', + '.pi/', + ...AGENT_DOCS, + // The test helpers the write-tests skill names (instructions). + 'src/lib/__fixtures__/', + 'src/lib/global-args.ts', + ], + }, { name: 'build', command: 'npm', args: ['run', '--silent', 'build'], env: CI_ENV }, { name: 'skill-sync', @@ -37,6 +63,7 @@ export const CI_EQUIVALENTS: { run: string; steps: string[]; why?: string }[] = { run: 'npm run lint:check', steps: ['lint', 'format'] }, { run: 'npm run build', steps: ['build'] }, { run: 'npm test', steps: ['tests'] }, + { run: 'npm run test:agents', steps: ['tests:agents'] }, { run: 'npm run check:skill-sync', steps: ['skill-sync'] }, { run: 'gh skill publish --dry-run', diff --git a/.agents/scripts/lib/verify.test.ts b/.agents/scripts/lib/verify.test.ts index 7087129..a360cc3 100644 --- a/.agents/scripts/lib/verify.test.ts +++ b/.agents/scripts/lib/verify.test.ts @@ -283,3 +283,40 @@ describe('what counts as a change', () => { expect(lines[0]).toBe('No changes since main; checking the tree anyway.') }) }) + +describe('a step that runs only when what it reads changed', () => { + const SKIPPED = + '- agents skipped: nothing it reads changed since main; CI runs it on every pull request' + // Fails if it runs, so a pass proves it was skipped. + const agents = { ...fail('agents'), onlyWhenChanged: ['.agents/', 'vitest.agents.config.ts'] } + + it('is skipped, and says so, when nothing it reads changed', async () => { + repo.write('src/a.ts', 'export const a = 2\n') + expect(await verify([pass('lint'), agents])).toEqual({ ok: true, recorded: true }) + expect(lines).toContain(SKIPPED) + }) + + it('runs when a path it reads changed', async () => { + repo.write('vitest.agents.config.ts', 'export default {}\n') + expect(await verify([pass('lint'), agents])).toEqual({ ok: false, recorded: false }) + expect(lines.some((line) => line.startsWith('✗ agents (exit 3'))).toBe(true) + }) + + it('counts as passed, so the steps that wait on or follow it still run', async () => { + repo.write('src/a.ts', 'export const a = 2\n') + const result = await verify([ + agents, + pass('tests', { waitFor: ['agents'] }), + pass('report', { after: 'agents' }), + ]) + expect(result).toEqual({ ok: true, recorded: true }) + expect(lines.some((line) => line.startsWith('✓ tests'))).toBe(true) + expect(lines.some((line) => line.startsWith('✓ report'))).toBe(true) + }) + + it('runs without a default branch, since there is nothing to compare with', async () => { + const result = await verify([agents], { base: null }) + expect(result).toEqual({ ok: false, recorded: false }) + expect(lines.some((line) => line.startsWith('✗ agents (exit 3'))).toBe(true) + }) +}) diff --git a/.agents/scripts/lib/verify.ts b/.agents/scripts/lib/verify.ts index 1bd72bb..55645e2 100644 --- a/.agents/scripts/lib/verify.ts +++ b/.agents/scripts/lib/verify.ts @@ -23,6 +23,11 @@ export type Step = { /** Starts only after these steps have finished, passed or not: they share files on disk. */ waitFor?: string[] env?: Record + /** + * Runs only when a path changed since the base starts with one of these. CI runs the step on + * every pull request regardless. + */ + onlyWhenChanged?: string[] } export type VerifyOptions = { @@ -41,10 +46,10 @@ const LOG_TAIL_LINES = 30 export async function runVerify(options: VerifyOptions): Promise { const { root, steps, base, baseName = 'main', out = console.log } = options - if (base === undefined) { + const changes = base === undefined ? undefined : changedSince(root, base) + if (changes === undefined) { out(`No ${baseName} branch found, so checking the whole tree.`) } else { - const changes = changedSince(root, base) const kinds = new Set( changes.map((path) => (needsChecks(root, path) ? 'code' : classify(path))), ) @@ -71,7 +76,7 @@ export async function runVerify(options: VerifyOptions): Promise { const logDir = join(stateDir(root), 'logs') mkdirSync(logDir, { recursive: true }) - const passed = await runSteps(root, steps, logDir, out) + const passed = await runSteps(root, steps, logDir, out, { changes, baseName }) if (!passed) return { ok: false, recorded: false } const after = snapshot(root) @@ -95,16 +100,33 @@ export async function runVerify(options: VerifyOptions): Promise { return { ok: true, recorded: true } } +/** Whether a step has to run: always, unless it names what it reads and none of that changed. */ +function needed(step: Step, changes: string[] | undefined): boolean { + const prefixes = step.onlyWhenChanged + if (prefixes === undefined || changes === undefined) return true + return changes.some((path) => prefixes.some((prefix) => path.startsWith(prefix))) +} + async function runSteps( root: string, steps: Step[], logDir: string, out: (line: string) => void, + since: { changes: string[] | undefined; baseName: string }, ): Promise { const results = new Map>() const start = (step: Step): Promise => { const existing = results.get(step.name) if (existing) return existing + // A skipped step counts as passed, so the steps after it still run. + if (!needed(step, since.changes)) { + out( + `- ${step.name} skipped: nothing it reads changed since ${since.baseName}; CI runs it on every pull request`, + ) + const skipped = Promise.resolve(true) + results.set(step.name, skipped) + return skipped + } const find = (name: string) => { const found = steps.find((s) => s.name === name) if (!found) throw new Error(`step ${step.name} runs after unknown ${name}`) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f02fb52..0c70b40 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,3 +33,6 @@ jobs: - name: Run tests run: npm test + + - name: Run agent tooling tests + run: npm run test:agents diff --git a/AGENTS.md b/AGENTS.md index 189019f..3c73bb1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,12 +38,13 @@ Reviewers, Doistbot included, apply these to every change: ```bash npm run build # Compile TypeScript to dist/ (uses tsconfig.build.json, excludes tests) npm run dev # Watch mode compilation (uses tsconfig.build.json, excludes tests) -npm test # Run all tests (vitest) +npm test # Run the package's tests (vitest); publishing runs these npm run test:watch # Run tests in watch mode +npm run test:agents # Run the agent tooling's tests (.agents/scripts), for changes to the agent tooling npm run type-check # Type check src + tests (tsconfig.json) and the agent tooling (.agents/scripts) npm run lint # Fix lint issues (oxlint) + format (oxfmt) npm run lint:check # Check lint + formatting (for CI) -npm run verify # Every check CI runs (lint, format, types, tests, build, skill sync) +npm run verify # Every check CI runs (lint, format, types, tests, build, skill sync, agent tooling tests) ``` The project uses two tsconfig files: `tsconfig.json` includes test files for type-checking, while `tsconfig.build.json` extends it and excludes colocated `*.test.ts` and `*.spec.ts` files (plus `src/__mocks__`) so test-only code is not compiled into `dist/`. diff --git a/CODEBASE.md b/CODEBASE.md index b4c9ebb..e6f307f 100644 --- a/CODEBASE.md +++ b/CODEBASE.md @@ -48,6 +48,7 @@ come from `@todoist/cli-core`. ├─ tsconfig.json # Includes src + tests (type-check, IDE) ├─ tsconfig.build.json # Excludes *.test.ts/.spec.ts, __mocks__, __fixtures__ ├─ vitest.config.ts # { globals, root: 'src', inlines @todoist/cli-core } +├─ vitest.agents.config.ts # The agent tooling's tests (.agents/scripts/) ├─ .oxlintrc.json / .oxfmtrc.json ├─ lefthook.yml # Git hooks: branch guard; pre-commit lint, format, types; │ # pre-push tests @@ -264,9 +265,11 @@ see a per-command `--user`). ## Testing -- **Runner:** vitest. `npm test` (one-shot, including the agent tooling's tests - in `.agents/scripts/`), `npm run test:watch`. Single file: - `npx vitest run src/lib/refs.test.ts`. +- **Runner:** vitest. `npm test` (one-shot, the package's tests; `prepublishOnly` + runs it), `npm run test:watch`. Single file: + `npx vitest run src/lib/refs.test.ts`. The agent tooling's tests in + `.agents/scripts/` run apart, with `npm run test:agents` + (`vitest.agents.config.ts`); see `docs/agents.md`. - **Location:** colocated `*.test.ts` next to the module under test. - **Fixtures:** `src/lib/__fixtures__/accounts.ts` (`ACCOUNT_ALAN` / `ACCOUNT_ELLIE`) — don't hand-build account objects. Manual npm-package mocks diff --git a/docs/agents.md b/docs/agents.md index 162261f..e4b43bd 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -49,11 +49,12 @@ The release workflow commits and pushes to `main` from GitHub Actions, and `npm ## `npm run verify` -One command, every check the pull-request workflows run (`lint.yml`, `test.yml`, `check-skill-sync.yml`): lint, format, both type checks, all tests, the build and the skill sync check. It takes about fifteen seconds, so it always checks the whole tree. Picking only the affected tests would save a few seconds and add a way to miss something. +One command, every check the pull-request workflows run (`lint.yml`, `test.yml`, `check-skill-sync.yml`): lint, format, both type checks, the tests, the build and the skill sync check, plus the agent tooling's tests when the tooling changed. It takes about fifteen seconds, so it always checks the whole tree. Picking only the affected tests would save a few seconds and add a way to miss something. - **Before the checks** it stops if Node is older than `package.json` requires, or if `node_modules` does not match the lockfile, transitive dependencies included (npm's own record of what it installed, `node_modules/.package-lock.json`, against `package-lock.json`). Both make checks fail, or pass, for reasons unrelated to your change. - **Only docs changed** since the branch left `main`: it says there is nothing to check. The agent instructions (`AGENTS.md`, `CODEBASE.md`, `docs/agents.md`, `.agents/`) count as code, since a test checks every reference in them, and so does the generated `skills/comms-cli/SKILL.md`, which `npm run check:skill-sync` reads. Deleting or renaming a doc counts as code too, since the agent docs may name it; adding one after a pass means running verify again. - **Only CI files changed** (Renovate, `.github/` config other than workflows): it says no local check reads them. Every workflow counts as code, since a local test compares verify with the three above and checks no other workflow runs commands on pull requests. +- **The agent tooling's tests** (`npm run test:agents`) run only when something they read changed since `main`: `.agents/`, their config, `package.json`, the lockfile, the workflows, `lefthook.yml`, the hook configs, the agent docs, and the test helpers the `write-tests` skill names. The list is the step's `onlyWhenChanged` in `.agents/scripts/lib/steps.ts`. Otherwise verify says it skipped them, and counts them as passed; CI runs them on every pull request. Without a `main` to compare with, they run. - **Order:** every check starts together, except the skill sync check, which imports from `dist/` and so waits for the build. - **`CI=true`** is set for the build, the tests and the skill sync check, as GitHub Actions sets it. Variables that change what the CLI does (`COMMS_API_TOKEN`, `COMMS_AS_URL`, `COMMS_BASE_URL`, `COMMS_INCLUDE_PRIVATE_CHANNELS`, `TWIST_AUTH_TOKEN`, `TWIST_BASE_URL`, `TDC_ACCESSIBLE`, `TDC_SPINNER`, `FORCE_COLOR`) are removed, with a note, since CI never sets them. A real token or server never reaches the tests. - **Output:** one line per step. A failing step prints the last 30 lines of its log and the log's path under `.tmp/agents/logs/`. @@ -152,11 +153,11 @@ Your part: answer the decision questions, and read the evidence report, especial - `.agents/scripts/` holds scripts and their tests, next to the skills and review checks. It is not under `scripts/` because `scripts/` ships in the npm package. - Skills live in `.agents/skills/`, where Codex reads them. Claude Code reads them through the symlinks in `.claude/skills/`; a test keeps the two in step. - The tooling runs straight from TypeScript with Node's type stripping, so it only uses erasable syntax (`.agents/scripts/tsconfig.json` enforces this). `npm run type-check` covers it, and `npm run lint:check` lints it. -- Tests run in `npm test` and CI. They copy the tools into throwaway git repositories and never touch your checkout. A test helper clears the variables git exports to hooks, since `npm test` itself runs inside `pre-push`. +- Their tests run apart from the package's. `npm test` (`vitest.config.ts`) covers only what ships, and it is what `prepublishOnly` runs before a publish, so a slow or broken tooling test can't stop a release. `npm run test:agents` (`vitest.agents.config.ts`) runs the tooling's tests: CI runs it on every pull request, and `npm run verify` when something they read changed. They copy the tools into throwaway git repositories and never touch your checkout. A test helper clears the variables git exports to hooks, in case they run from one. ## Releases -semantic-release publishes from `main` on every merge, and a pre-release from `next`. The squash-merged PR title decides whether anything ships: `feat:`, `fix:`, `perf:` and any breaking change (`!`) release; `chore:`, `ci:`, `docs:`, `test:` and `refactor:` do not. Changes to the agent tooling use `chore:` or `ci:`, so they never publish a new version. No path filter is needed. +semantic-release publishes from `main` on every merge, and a pre-release from `next`. The squash-merged PR title decides whether anything ships: `feat:`, `fix:`, `perf:` and any breaking change (`!`) release; `chore:`, `ci:`, `docs:`, `test:` and `refactor:` do not. Changes to the agent tooling use `chore:` or `ci:`, so they never publish a new version. No path filter is needed. Publishing runs `npm test` first, which leaves out the agent tooling's tests. ## What fails open diff --git a/package.json b/package.json index 3514f9f..2b00bb3 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "sync:skill": "npm run build && node scripts/sync-skill.js", "test": "vitest run", "test:watch": "vitest", + "test:agents": "vitest run --config vitest.agents.config.ts", "verify": "node .agents/scripts/verify.ts", "review:worktree": "node .agents/scripts/review-worktree.ts", "prepublishOnly": "npm run build && npm test", diff --git a/vitest.agents.config.ts b/vitest.agents.config.ts new file mode 100644 index 0000000..d3b4c9a --- /dev/null +++ b/vitest.agents.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'vitest/config' + +// The agent tooling's tests: `npm run test:agents`. They check the tooling in `.agents/`, not the +// package, so `npm test` (and the publish that runs it) leaves them out. +export default defineConfig({ + test: { + include: ['.agents/scripts/**/*.test.ts'], + }, +}) diff --git a/vitest.config.ts b/vitest.config.ts index 8fff175..4b891df 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,8 +4,7 @@ export default defineConfig({ test: { globals: true, root: 'src', - // The agent tooling's tests live outside `root`, next to the tooling. - include: ['**/*.{test,spec}.{js,ts}', '../.agents/scripts/**/*.test.ts'], + include: ['**/*.{test,spec}.{js,ts}'], exclude: ['dist/**/*', 'node_modules/**/*'], // Inline @todoist/cli-core so vitest's module mocks (e.g. vi.doMock for // 'node:fs/promises' or vi.mock('@todoist/cli-core', …)) reach its From 83f15a70b5e6b7fd69600e4c9e4f12c0d9bf4246 Mon Sep 17 00:00:00 2001 From: Scott Lovegrove Date: Thu, 3 Dec 2026 16:13:16 +0000 Subject: [PATCH 2/3] chore(agents): run the agent tooling tests when a Cursor hooks file appears hook-wiring.test.ts checks that .cursor/hooks.json stays absent, so adding one is a change the agent tooling tests read. --- .agents/scripts/lib/steps.test.ts | 3 ++- .agents/scripts/lib/steps.ts | 2 ++ docs/agents.md | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.agents/scripts/lib/steps.test.ts b/.agents/scripts/lib/steps.test.ts index f220050..0c35e49 100644 --- a/.agents/scripts/lib/steps.test.ts +++ b/.agents/scripts/lib/steps.test.ts @@ -133,7 +133,8 @@ describe('verify covers CI', () => { it('watches only paths that exist, so a rename cannot stop a step running locally', () => { const missing = VERIFY_STEPS.flatMap((step) => (step.onlyWhenChanged ?? []) - .filter((path) => !existsSync(join(REPO_ROOT, path))) + // hook-wiring.test.ts checks .cursor/ holds no hooks file, so adding one runs the tests. + .filter((path) => path !== '.cursor/' && !existsSync(join(REPO_ROOT, path))) .map((path) => `${step.name}: ${path}`), ) expect(missing).toEqual([]) diff --git a/.agents/scripts/lib/steps.ts b/.agents/scripts/lib/steps.ts index 7dcd23c..eaddf83 100644 --- a/.agents/scripts/lib/steps.ts +++ b/.agents/scripts/lib/steps.ts @@ -36,6 +36,8 @@ export const VERIFY_STEPS: Step[] = [ '.claude/', '.codex/', '.pi/', + // hook-wiring.test.ts checks that no Cursor hooks file appears. + '.cursor/', ...AGENT_DOCS, // The test helpers the write-tests skill names (instructions). 'src/lib/__fixtures__/', diff --git a/docs/agents.md b/docs/agents.md index e4b43bd..2b4cbaa 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -54,7 +54,7 @@ One command, every check the pull-request workflows run (`lint.yml`, `test.yml`, - **Before the checks** it stops if Node is older than `package.json` requires, or if `node_modules` does not match the lockfile, transitive dependencies included (npm's own record of what it installed, `node_modules/.package-lock.json`, against `package-lock.json`). Both make checks fail, or pass, for reasons unrelated to your change. - **Only docs changed** since the branch left `main`: it says there is nothing to check. The agent instructions (`AGENTS.md`, `CODEBASE.md`, `docs/agents.md`, `.agents/`) count as code, since a test checks every reference in them, and so does the generated `skills/comms-cli/SKILL.md`, which `npm run check:skill-sync` reads. Deleting or renaming a doc counts as code too, since the agent docs may name it; adding one after a pass means running verify again. - **Only CI files changed** (Renovate, `.github/` config other than workflows): it says no local check reads them. Every workflow counts as code, since a local test compares verify with the three above and checks no other workflow runs commands on pull requests. -- **The agent tooling's tests** (`npm run test:agents`) run only when something they read changed since `main`: `.agents/`, their config, `package.json`, the lockfile, the workflows, `lefthook.yml`, the hook configs, the agent docs, and the test helpers the `write-tests` skill names. The list is the step's `onlyWhenChanged` in `.agents/scripts/lib/steps.ts`. Otherwise verify says it skipped them, and counts them as passed; CI runs them on every pull request. Without a `main` to compare with, they run. +- **The agent tooling's tests** (`npm run test:agents`) run only when something they read changed since `main`: `.agents/`, their config, `package.json`, the lockfile, the workflows, `lefthook.yml`, the hook configs (and any Cursor hooks file, which a test forbids), the agent docs, and the test helpers the `write-tests` skill names. The list is the step's `onlyWhenChanged` in `.agents/scripts/lib/steps.ts`. Otherwise verify says it skipped them, and counts them as passed; CI runs them on every pull request. Without a `main` to compare with, they run. - **Order:** every check starts together, except the skill sync check, which imports from `dist/` and so waits for the build. - **`CI=true`** is set for the build, the tests and the skill sync check, as GitHub Actions sets it. Variables that change what the CLI does (`COMMS_API_TOKEN`, `COMMS_AS_URL`, `COMMS_BASE_URL`, `COMMS_INCLUDE_PRIVATE_CHANNELS`, `TWIST_AUTH_TOKEN`, `TWIST_BASE_URL`, `TDC_ACCESSIBLE`, `TDC_SPINNER`, `FORCE_COLOR`) are removed, with a note, since CI never sets them. A real token or server never reaches the tests. - **Output:** one line per step. A failing step prints the last 30 lines of its log and the log's path under `.tmp/agents/logs/`. From e992e51a628338d229bf48915b36c65ca5b0ee32 Mon Sep 17 00:00:00 2001 From: Scott Lovegrove Date: Thu, 3 Dec 2026 16:18:30 +0000 Subject: [PATCH 3/3] chore(agents): run the agent tooling tests on deletions, merges and an unchanged tree verify now runs a step with onlyWhenChanged when nothing changed since the base, as it runs every other step then, and when a changed file was deleted or renamed, since the agent docs may name it. test.yml also runs on pushes to main and next, so both suites run on every merge without the release depending on them. In verify the agent tooling tests wait for the package tests, so two vitest pools don't slow each other into timeouts. The helper sources instructions.test.ts reads come from one constant in tree.ts, shared with the step. The tooling tsconfig drops vitest/globals, since vitest.agents.config.ts doesn't enable them. The docs say pre-push runs only the package's tests. --- .agents/scripts/instructions.test.ts | 12 ++++++------ .agents/scripts/lib/steps.test.ts | 5 +++++ .agents/scripts/lib/steps.ts | 8 +++++--- .agents/scripts/lib/tree.ts | 3 +++ .agents/scripts/lib/verify.test.ts | 15 +++++++++++++++ .agents/scripts/lib/verify.ts | 20 +++++++++++++------- .agents/scripts/tsconfig.json | 2 +- .github/workflows/test.yml | 2 ++ AGENTS.md | 2 +- CODEBASE.md | 5 +++-- CONTRIBUTING.md | 5 +++-- docs/agents.md | 10 +++++----- 12 files changed, 62 insertions(+), 27 deletions(-) diff --git a/.agents/scripts/instructions.test.ts b/.agents/scripts/instructions.test.ts index c6dca21..39774ba 100644 --- a/.agents/scripts/instructions.test.ts +++ b/.agents/scripts/instructions.test.ts @@ -6,7 +6,7 @@ import { basename, dirname, join, relative, resolve } from 'node:path' import { describe, expect, it } from 'vitest' import { git } from './lib/git.ts' import { REPO_ROOT } from './lib/test-repo.ts' -import { AGENT_DOCS } from './lib/tree.ts' +import { AGENT_DOCS, TEST_HELPER_PATHS } from './lib/tree.ts' const SKILLS_DIR = join(REPO_ROOT, '.agents/skills') const skills = readdirSync(SKILLS_DIR).filter((name) => !name.startsWith('.')) @@ -149,11 +149,11 @@ it('names only test helpers that the fixtures, global-args or @todoist/cli-core/ const skill = readFileSync(join(SKILLS_DIR, 'write-tests/SKILL.md'), 'utf8') const section = skill.split('## Helpers')[1]?.split('\n## ')[0] ?? '' const named = [...section.matchAll(/`(\w+)`/g)].map((match) => match[1] ?? '') - const fixtures = join(REPO_ROOT, 'src/lib/__fixtures__') - const sources = [ - ...readdirSync(fixtures).map((file) => join(fixtures, file)), - join(REPO_ROOT, 'src/lib/global-args.ts'), - ] + // A path ending in `/` is a folder of helper files. + const sources = TEST_HELPER_PATHS.flatMap((path) => { + const full = join(REPO_ROOT, path) + return path.endsWith('/') ? readdirSync(full).map((file) => join(full, file)) : [full] + }) const local = sources.flatMap((file) => [ ...readFileSync(file, 'utf8').matchAll( diff --git a/.agents/scripts/lib/steps.test.ts b/.agents/scripts/lib/steps.test.ts index 0c35e49..390033a 100644 --- a/.agents/scripts/lib/steps.test.ts +++ b/.agents/scripts/lib/steps.test.ts @@ -140,6 +140,11 @@ describe('verify covers CI', () => { expect(missing).toEqual([]) }) + it('starts the agent tooling tests after the package tests, so their pools never compete', () => { + const agents = VERIFY_STEPS.find((step) => step.name === 'tests:agents') + expect(agents?.waitFor).toEqual(['tests']) + }) + it('names only steps that exist', () => { const names = VERIFY_STEPS.map((step) => step.name) for (const entry of CI_EQUIVALENTS) { diff --git a/.agents/scripts/lib/steps.ts b/.agents/scripts/lib/steps.ts index eaddf83..9633236 100644 --- a/.agents/scripts/lib/steps.ts +++ b/.agents/scripts/lib/steps.ts @@ -1,7 +1,7 @@ import { existsSync } from 'node:fs' import { join } from 'node:path' import { readJson } from './state.ts' -import { AGENT_DOCS } from './tree.ts' +import { AGENT_DOCS, TEST_HELPER_PATHS } from './tree.ts' import type { Step } from './verify.ts' const bin = (tool: string) => `node_modules/.bin/${tool}` @@ -22,6 +22,9 @@ export const VERIFY_STEPS: Step[] = [ command: bin('vitest'), args: ['run', '--config', 'vitest.agents.config.ts'], env: CI_ENV, + // After the package tests, so two vitest pools don't share the CPU and slow each other into + // timeouts. + waitFor: ['tests'], // Everything the tests in .agents/scripts read from the checkout. onlyWhenChanged: [ '.agents/', @@ -40,8 +43,7 @@ export const VERIFY_STEPS: Step[] = [ '.cursor/', ...AGENT_DOCS, // The test helpers the write-tests skill names (instructions). - 'src/lib/__fixtures__/', - 'src/lib/global-args.ts', + ...TEST_HELPER_PATHS, ], }, { name: 'build', command: 'npm', args: ['run', '--silent', 'build'], env: CI_ENV }, diff --git a/.agents/scripts/lib/tree.ts b/.agents/scripts/lib/tree.ts index 0c15843..5f6cbce 100644 --- a/.agents/scripts/lib/tree.ts +++ b/.agents/scripts/lib/tree.ts @@ -83,6 +83,9 @@ export const CHECKED_WORKFLOWS = [ /** Agent instructions outside .agents/. instructions.test.ts checks every reference in them. */ export const AGENT_DOCS = new Set(['AGENTS.md', 'CODEBASE.md', 'docs/agents.md']) +/** Where the test helpers the write-tests skill names live; instructions.test.ts reads them. */ +export const TEST_HELPER_PATHS = ['src/lib/__fixtures__/', 'src/lib/global-args.ts'] + /** The kind of file, as far as local checks are concerned. */ export type FileKind = 'docs' | 'unchecked' | 'code' diff --git a/.agents/scripts/lib/verify.test.ts b/.agents/scripts/lib/verify.test.ts index a360cc3..9c2dfb9 100644 --- a/.agents/scripts/lib/verify.test.ts +++ b/.agents/scripts/lib/verify.test.ts @@ -314,6 +314,21 @@ describe('a step that runs only when what it reads changed', () => { expect(lines.some((line) => line.startsWith('✓ report'))).toBe(true) }) + it('runs when nothing changed, since verify then checks the whole tree', async () => { + expect(await verify([pass('lint'), agents])).toEqual({ ok: false, recorded: false }) + expect(lines[0]).toBe('No changes since main; checking the tree anyway.') + expect(lines.some((line) => line.startsWith('✗ agents (exit 3'))).toBe(true) + }) + + it.each([ + ['deleted', () => rmSync(join(repo.dir, 'README.md'))], + ['renamed', () => repo.git(['mv', 'src/a.ts', 'src/b.ts'])], + ])('runs when a file was %s, since the agent docs may name it', async (_kind, change) => { + change() + expect(await verify([pass('lint'), agents])).toEqual({ ok: false, recorded: false }) + expect(lines.some((line) => line.startsWith('✗ agents (exit 3'))).toBe(true) + }) + it('runs without a default branch, since there is nothing to compare with', async () => { const result = await verify([agents], { base: null }) expect(result).toEqual({ ok: false, recorded: false }) diff --git a/.agents/scripts/lib/verify.ts b/.agents/scripts/lib/verify.ts index 55645e2..2ecd70c 100644 --- a/.agents/scripts/lib/verify.ts +++ b/.agents/scripts/lib/verify.ts @@ -1,5 +1,5 @@ import { spawn } from 'node:child_process' -import { createWriteStream, mkdirSync, readFileSync } from 'node:fs' +import { createWriteStream, existsSync, mkdirSync, readFileSync } from 'node:fs' import { join, relative } from 'node:path' import { cleanGitEnv, resolveCommit } from './git.ts' import { forgetPassedChanges, recordPassedPatch } from './patches.ts' @@ -24,8 +24,9 @@ export type Step = { waitFor?: string[] env?: Record /** - * Runs only when a path changed since the base starts with one of these. CI runs the step on - * every pull request regardless. + * Runs only when a path changed since the base starts with one of these, or a file was deleted + * or renamed (the agent docs may name it). With nothing changed it runs, as every step does. CI + * runs the step on every pull request regardless. */ onlyWhenChanged?: string[] } @@ -101,10 +102,15 @@ export async function runVerify(options: VerifyOptions): Promise { } /** Whether a step has to run: always, unless it names what it reads and none of that changed. */ -function needed(step: Step, changes: string[] | undefined): boolean { +function needed(root: string, step: Step, changes: string[] | undefined): boolean { const prefixes = step.onlyWhenChanged - if (prefixes === undefined || changes === undefined) return true - return changes.some((path) => prefixes.some((prefix) => path.startsWith(prefix))) + // No base, or nothing changed: verify checks the whole tree, so every step runs. + if (prefixes === undefined || changes === undefined || changes.length === 0) return true + return changes.some( + (path) => + // A deleted or renamed file may be one the agent docs name. + !existsSync(join(root, path)) || prefixes.some((prefix) => path.startsWith(prefix)), + ) } async function runSteps( @@ -119,7 +125,7 @@ async function runSteps( const existing = results.get(step.name) if (existing) return existing // A skipped step counts as passed, so the steps after it still run. - if (!needed(step, since.changes)) { + if (!needed(root, step, since.changes)) { out( `- ${step.name} skipped: nothing it reads changed since ${since.baseName}; CI runs it on every pull request`, ) diff --git a/.agents/scripts/tsconfig.json b/.agents/scripts/tsconfig.json index 492e870..9aa3e9e 100644 --- a/.agents/scripts/tsconfig.json +++ b/.agents/scripts/tsconfig.json @@ -11,7 +11,7 @@ "allowImportingTsExtensions": true, "erasableSyntaxOnly": true, "lib": ["es2023"], - "types": ["node", "vitest/globals"] + "types": ["node"] }, "include": [".", "../../.pi/**/*"] } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0c70b40..939899c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,8 @@ name: Test on: + push: + branches: [main, next] pull_request: permissions: diff --git a/AGENTS.md b/AGENTS.md index 3c73bb1..0415486 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -109,7 +109,7 @@ throw new CliError('ERROR_CODE', 'User-facing message', ['Optional hint']) ## Git hooks and agent tooling -- Lefthook refuses commits and pushes to `main`, runs oxlint, oxfmt and the type check on pre-commit, and the tests on pre-push. Work on a branch. +- Lefthook refuses commits and pushes to `main`, runs oxlint, oxfmt and the type check on pre-commit, and `npm test` (the package's tests only) on pre-push. The agent tooling's tests run in CI, and in `npm run verify` when something they read changed. Work on a branch. - Your `git push` and `gh pr create` are stopped until `npm run verify` has passed on exactly the commit being pushed (Claude Code, Codex and Cursor hooks, and a Pi extension), or on the same changes before a rebase that only moved `main` under them. Verify, then commit exactly what it saw, or commit first and verify the clean tree. If something must be pushed unverified, ask the person you're working with to push it. - Agent tooling lives in `.agents/scripts/`, never in `scripts/` (which ships in the npm package). - How it all fits together: [`docs/agents.md`](docs/agents.md). diff --git a/CODEBASE.md b/CODEBASE.md index e6f307f..9c089d3 100644 --- a/CODEBASE.md +++ b/CODEBASE.md @@ -51,7 +51,7 @@ come from `@todoist/cli-core`. ├─ vitest.agents.config.ts # The agent tooling's tests (.agents/scripts/) ├─ .oxlintrc.json / .oxfmtrc.json ├─ lefthook.yml # Git hooks: branch guard; pre-commit lint, format, types; -│ # pre-push tests +│ # pre-push npm test ├─ renovate.json # Dependency automation └─ release.config.js # semantic-release config ``` @@ -294,7 +294,8 @@ see a per-command `--user`). `prepare` script. `pre-commit` refuses commits on `main`, then lints and formats staged files and runs the type check; `commit-msg` repeats the branch rule for empty commits; `pre-push` refuses pushes to `main`, then - runs the tests. See `docs/agents.md`. + runs `npm test`, the package's tests only (the agent tooling's tests run in + CI, and in verify when something they read changed). See `docs/agents.md`. - **Release:** semantic-release on merge to `main`; Conventional Commits required (enforced by `check-semantic-pull-request.yml`). `update-comms-sdk.yml` keeps `@todoist/comms-sdk` current. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eab768a..2fd61e0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,10 +26,11 @@ After cloning the repository and installing dependencies with `npm install`, sev - `npm run dev`: Runs in development mode - `npm run lint`: Auto-fixes lint and formatting issues - `npm run lint:check`: Validates code quality and formatting -- `npm test`: Runs all tests +- `npm test`: Runs the package's tests (publishing runs these) +- `npm run test:agents`: Runs the agent tooling's tests in `.agents/scripts/`, for changes to the agent tooling - `npm run test:watch`: Runs tests in watch mode - `npm run type-check`: Type checks without emitting -- `npm run verify`: Runs every check CI runs (lint, format, types, tests, build, skill sync) in about fifteen seconds +- `npm run verify`: Runs every check CI runs (lint, format, types, tests, build, skill sync, agent tooling tests) in about fifteen seconds ## Sending a Pull Request diff --git a/docs/agents.md b/docs/agents.md index 2b4cbaa..3111995 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -41,7 +41,7 @@ This repository is set up so coding agents prove their work before they call it - **`pre-commit`** refuses a commit on `main`, then lints and formats the staged files (re-staging what the tools fix) and runs the type check. Unstaged changes in a partly staged file are left alone. - **`commit-msg`** refuses a commit on `main` again. Lefthook runs no pre-commit job when nothing is staged, so without it an empty commit would get past. -- **`pre-push`** refuses a push to `main`, then runs the tests. It checks `git push --dry-run` too. +- **`pre-push`** refuses a push to `main`, then runs `npm test`, the package's tests only; the agent tooling's tests run in CI, and in verify when something they read changed. It checks `git push --dry-run` too. - If node is not on `PATH` (some GUI git clients), both hooks still apply the branch rule, skip the checks, and say so. CI runs the same checks. - The default branch is read from `origin/HEAD`, falling back to `main`. Pushes to `next`, the pre-release branch, are allowed: syncing it with `main` is a direct push (see `CONTRIBUTING.md`). @@ -54,8 +54,8 @@ One command, every check the pull-request workflows run (`lint.yml`, `test.yml`, - **Before the checks** it stops if Node is older than `package.json` requires, or if `node_modules` does not match the lockfile, transitive dependencies included (npm's own record of what it installed, `node_modules/.package-lock.json`, against `package-lock.json`). Both make checks fail, or pass, for reasons unrelated to your change. - **Only docs changed** since the branch left `main`: it says there is nothing to check. The agent instructions (`AGENTS.md`, `CODEBASE.md`, `docs/agents.md`, `.agents/`) count as code, since a test checks every reference in them, and so does the generated `skills/comms-cli/SKILL.md`, which `npm run check:skill-sync` reads. Deleting or renaming a doc counts as code too, since the agent docs may name it; adding one after a pass means running verify again. - **Only CI files changed** (Renovate, `.github/` config other than workflows): it says no local check reads them. Every workflow counts as code, since a local test compares verify with the three above and checks no other workflow runs commands on pull requests. -- **The agent tooling's tests** (`npm run test:agents`) run only when something they read changed since `main`: `.agents/`, their config, `package.json`, the lockfile, the workflows, `lefthook.yml`, the hook configs (and any Cursor hooks file, which a test forbids), the agent docs, and the test helpers the `write-tests` skill names. The list is the step's `onlyWhenChanged` in `.agents/scripts/lib/steps.ts`. Otherwise verify says it skipped them, and counts them as passed; CI runs them on every pull request. Without a `main` to compare with, they run. -- **Order:** every check starts together, except the skill sync check, which imports from `dist/` and so waits for the build. +- **The agent tooling's tests** (`npm run test:agents`) run only when something they read changed since `main`: `.agents/`, their config, `package.json`, the lockfile, the workflows, `lefthook.yml`, the hook configs (and any Cursor hooks file, which a test forbids), the agent docs, and the test helpers the `write-tests` skill names. The list is the step's `onlyWhenChanged` in `.agents/scripts/lib/steps.ts`. They also run when a file was deleted or renamed, since the agent docs may name it, and when nothing changed, since verify then checks the whole tree. Otherwise verify says it skipped them, and counts them as passed; CI runs them on every pull request. Without a `main` to compare with, they run. +- **Order:** every check starts together, except the skill sync check, which imports from `dist/` and so waits for the build, and the agent tooling's tests, which wait for the package tests so two vitest pools don't slow each other into timeouts. - **`CI=true`** is set for the build, the tests and the skill sync check, as GitHub Actions sets it. Variables that change what the CLI does (`COMMS_API_TOKEN`, `COMMS_AS_URL`, `COMMS_BASE_URL`, `COMMS_INCLUDE_PRIVATE_CHANNELS`, `TWIST_AUTH_TOKEN`, `TWIST_BASE_URL`, `TDC_ACCESSIBLE`, `TDC_SPINNER`, `FORCE_COLOR`) are removed, with a note, since CI never sets them. A real token or server never reaches the tests. - **Output:** one line per step. A failing step prints the last 30 lines of its log and the log's path under `.tmp/agents/logs/`. - **The record:** after a full pass it writes a content hash of every file local checks read (not docs, not CI-only files) to `.tmp/agents/verified.json`. A run that fails, or sees files change while it runs, deletes it. The push check reads it. When the tree verify passed is exactly the last commit, it also records that commit's changes since `main` by patch, in `.tmp/agents/verified-patches.json`, for the push check's rebase exemption. @@ -153,11 +153,11 @@ Your part: answer the decision questions, and read the evidence report, especial - `.agents/scripts/` holds scripts and their tests, next to the skills and review checks. It is not under `scripts/` because `scripts/` ships in the npm package. - Skills live in `.agents/skills/`, where Codex reads them. Claude Code reads them through the symlinks in `.claude/skills/`; a test keeps the two in step. - The tooling runs straight from TypeScript with Node's type stripping, so it only uses erasable syntax (`.agents/scripts/tsconfig.json` enforces this). `npm run type-check` covers it, and `npm run lint:check` lints it. -- Their tests run apart from the package's. `npm test` (`vitest.config.ts`) covers only what ships, and it is what `prepublishOnly` runs before a publish, so a slow or broken tooling test can't stop a release. `npm run test:agents` (`vitest.agents.config.ts`) runs the tooling's tests: CI runs it on every pull request, and `npm run verify` when something they read changed. They copy the tools into throwaway git repositories and never touch your checkout. A test helper clears the variables git exports to hooks, in case they run from one. +- Their tests run apart from the package's. `npm test` (`vitest.config.ts`) covers only what ships, and it is what `prepublishOnly` runs before a publish, so a slow or broken tooling test can't stop a release. `npm run test:agents` (`vitest.agents.config.ts`) runs the tooling's tests: CI runs it on every pull request and every merge to `main` and `next`, and `npm run verify` when something they read changed. They copy the tools into throwaway git repositories and never touch your checkout. A test helper clears the variables git exports to hooks, in case they run from one. ## Releases -semantic-release publishes from `main` on every merge, and a pre-release from `next`. The squash-merged PR title decides whether anything ships: `feat:`, `fix:`, `perf:` and any breaking change (`!`) release; `chore:`, `ci:`, `docs:`, `test:` and `refactor:` do not. Changes to the agent tooling use `chore:` or `ci:`, so they never publish a new version. No path filter is needed. Publishing runs `npm test` first, which leaves out the agent tooling's tests. +semantic-release publishes from `main` on every merge, and a pre-release from `next`. The squash-merged PR title decides whether anything ships: `feat:`, `fix:`, `perf:` and any breaking change (`!`) release; `chore:`, `ci:`, `docs:`, `test:` and `refactor:` do not. Changes to the agent tooling use `chore:` or `ci:`, so they never publish a new version. No path filter is needed. Publishing runs `npm test` first, which leaves out the agent tooling's tests. `test.yml` runs both suites on every pull request and again on every push to `main` and `next`, so a merge is tested without the release depending on it. ## What fails open