From 1c8582c10ab4d80d6d5d7664adcdfde29ec86957 Mon Sep 17 00:00:00 2001 From: Scott Lovegrove Date: Thu, 3 Dec 2026 16:05:51 +0000 Subject: [PATCH 1/4] 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, which test the hooks, the guard and verify, none of which ship. 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 runs the package's own tests, plus the packed-tarball check, which tests what ships. The tooling's tests move to `npm run test:agents` (vitest.agents.config.ts), which CI runs on every pull request. `npm run verify` runs them when something they read changed since main, through a new `onlyWhenChanged` on its steps, and says it skipped them otherwise. They start after the package tests: two vitest runs side by side made the hook tests time out. --- .agents/scripts/lib/steps.test.ts | 19 ++++++++++-- .agents/scripts/lib/steps.ts | 29 ++++++++++++++++++ .agents/scripts/lib/verify.test.ts | 48 +++++++++++++++++++++++++++++- .agents/scripts/lib/verify.ts | 28 +++++++++++++++-- .github/workflows/test.yml | 3 ++ AGENTS.md | 3 +- CODEBASE.md | 10 +++++-- docs/agents.md | 10 ++++--- package.json | 1 + vitest.agents.config.ts | 19 ++++++++++++ vitest.config.ts | 6 ++-- 11 files changed, 161 insertions(+), 15 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 69c3bbf..1428ef6 100644 --- a/.agents/scripts/lib/steps.test.ts +++ b/.agents/scripts/lib/steps.test.ts @@ -5,7 +5,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { writeJson } from './state.ts' import { CI_EQUIVALENTS, preflight, removeLocalOnlyEnv, VERIFY_STEPS } from './steps.ts' import { REPO_ROOT } from './test-repo.ts' -import { CHECKED_WORKFLOWS } from './tree.ts' +import { AGENT_DOCS, CHECKED_WORKFLOWS } from './tree.ts' const WORKFLOWS_DIR = join(REPO_ROOT, '.github/workflows') const readWorkflow = (name: string) => readFileSync(join(WORKFLOWS_DIR, name), 'utf8') @@ -141,7 +141,7 @@ describe('verify covers CI', () => { }) it('runs the build and the tests with CI=true, as GitHub Actions does', () => { - for (const name of ['build', 'tests']) { + for (const name of ['build', 'tests', 'tests:agents']) { const step = VERIFY_STEPS.find((candidate) => candidate.name === name) expect(step?.env, name).toEqual({ CI: 'true' }) } @@ -153,6 +153,21 @@ describe('verify covers CI', () => { expect(env).toEqual({ PATH: '/bin' }) }) + it('runs the agent tooling tests when their own files, config or the agent docs change', () => { + const step = VERIFY_STEPS.find((candidate) => candidate.name === 'tests:agents') + expect(step?.args).toEqual(['run', '--config', 'vitest.agents.config.ts']) + expect(step?.waitFor).toEqual(['tests']) + expect(step?.onlyWhenChanged).toEqual( + expect.arrayContaining([ + '.agents/', + 'vitest.agents.config.ts', + '.github/workflows/', + 'package.json', + ...AGENT_DOCS, + ]), + ) + }) + it('starts the tests only once the build has written dist/', () => { const tests = VERIFY_STEPS.find((candidate) => candidate.name === 'tests') expect(tests?.waitFor).toContain('build') diff --git a/.agents/scripts/lib/steps.ts b/.agents/scripts/lib/steps.ts index dfe8f4a..03f24db 100644 --- a/.agents/scripts/lib/steps.ts +++ b/.agents/scripts/lib/steps.ts @@ -2,6 +2,7 @@ import { existsSync } from 'node:fs' import { join } from 'node:path' import { readJson } from './state.ts' import { listSome } from './text.ts' +import { AGENT_DOCS } from './tree.ts' import type { Step } from './verify.ts' const bin = (tool: string) => `node_modules/.bin/${tool}` @@ -26,6 +27,33 @@ export const VERIFY_STEPS: Step[] = [ env: CI_ENV, waitFor: ['build'], }, + // The agent tooling's tests, for changes to the tooling and to what it reads: its own files and + // config, the hook configs, the agent docs and the test helpers they name, the workflows and + // package.json scripts verify mirrors, and the lefthook the hook tests install from the lockfile. + // They start once the package's tests have finished: run side by side, the two vitest pools + // slow each other down enough for the hook tests to time out. + { + name: 'tests:agents', + command: bin('vitest'), + args: ['run', '--config', 'vitest.agents.config.ts'], + env: CI_ENV, + waitFor: ['tests'], + onlyWhenChanged: [ + '.agents/', + 'vitest.agents.config.ts', + ...AGENT_DOCS, + '.claude/', + '.codex/', + // hook-wiring.test.ts checks that no Cursor hooks file appears. + '.cursor/', + 'lefthook.yml', + '.github/workflows/', + 'package.json', + 'package-lock.json', + 'src/testing/', + 'src/test-support/', + ], + }, ] /** @@ -39,6 +67,7 @@ export const CI_EQUIVALENTS: { run: string; steps: string[]; why?: string }[] = { run: 'npm run check', steps: ['lint', 'format'] }, { run: 'npm run build', steps: ['build'] }, { run: 'npm test', steps: ['tests'] }, + { run: 'npm run test:agents', steps: ['tests:agents'] }, ] /** diff --git a/.agents/scripts/lib/verify.test.ts b/.agents/scripts/lib/verify.test.ts index 6cc857c..2fbc6df 100644 --- a/.agents/scripts/lib/verify.test.ts +++ b/.agents/scripts/lib/verify.test.ts @@ -18,10 +18,11 @@ const pass = (name: string, extra: Partial = {}): Step => ({ args: ['-c', `echo ${name} ok`], ...extra, }) -const fail = (name: string): Step => ({ +const fail = (name: string, extra: Partial = {}): Step => ({ name, command: 'sh', args: ['-c', 'i=1; while [ $i -le 40 ]; do echo "line $i"; i=$((i + 1)); done; exit 3'], + ...extra, }) const verify = (steps: Step[], options: { base?: string | null } = {}) => @@ -167,6 +168,51 @@ describe('a code change', () => { }) }) +describe('a step that runs only when what it reads changed', () => { + const tools = (extra: Partial = {}) => + fail('tools', { onlyWhenChanged: ['.agents/', 'tools.config.ts'], ...extra }) + + it('is skipped, and counts as passed, when nothing it reads changed', async () => { + repo.write('src/a.ts', 'export const a = 2\n') + expect(await verify([pass('lint'), tools()])).toEqual({ ok: true, recorded: true }) + expect(lines).toContain( + '- tools skipped: nothing it reads changed since main; CI runs it on every pull request', + ) + expect(lines.some((line) => line.startsWith('✗ tools'))).toBe(false) + }) + + it('runs when a path it reads changed', async () => { + repo.write('src/a.ts', 'export const a = 2\n') + repo.write('.agents/scripts/tool.ts', 'export const tool = 1\n') + expect(await verify([pass('lint'), tools()])).toEqual({ ok: false, recorded: false }) + expect(lines.some((line) => line.startsWith('✗ tools (exit 3'))).toBe(true) + }) + + it('runs when a file it reads by name changed', async () => { + repo.write('tools.config.ts', 'export default {}\n') + expect(await verify([tools()])).toEqual({ ok: false, recorded: false }) + expect(lines.some((line) => line.startsWith('✗ tools (exit 3'))).toBe(true) + }) + + it('still runs the steps that wait for it or run after it', async () => { + repo.write('src/a.ts', 'export const a = 2\n') + const steps = [ + tools(), + pass('after-tools', { after: 'tools' }), + pass('waits-for-tools', { waitFor: ['tools'] }), + ] + expect(await verify(steps)).toEqual({ ok: true, recorded: true }) + expect(lines.some((line) => line.startsWith('✓ after-tools'))).toBe(true) + expect(lines.some((line) => line.startsWith('✓ waits-for-tools'))).toBe(true) + }) + + it('runs without a default branch, when there is nothing to compare with', async () => { + repo.write('src/a.ts', 'export const a = 2\n') + expect(await verify([tools()], { base: null })).toEqual({ ok: false, recorded: false }) + expect(lines.some((line) => line.startsWith('✗ tools (exit 3'))).toBe(true) + }) +}) + describe('what counts as a change', () => { it('sees an untracked file as a change', async () => { repo.write('src/new.ts', 'new\n') diff --git a/.agents/scripts/lib/verify.ts b/.agents/scripts/lib/verify.ts index 8de3b4d..d7598fd 100644 --- a/.agents/scripts/lib/verify.ts +++ b/.agents/scripts/lib/verify.ts @@ -20,6 +20,11 @@ export type Step = { after?: string /** Starts only after these steps have finished, passed or not: they share files on disk. */ waitFor?: string[] + /** + * 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[] env?: Record } @@ -39,10 +44,12 @@ const LOG_TAIL_LINES = 30 export async function runVerify(options: VerifyOptions): Promise { const { root, steps, base, baseName = 'main', out = console.log } = options + // Undefined without a base: with nothing to compare against, every step runs. + let changes: string[] | undefined if (base === undefined) { out(`No ${baseName} branch found, so checking the whole tree.`) } else { - const changes = changedSince(root, base) + changes = changedSince(root, base) const kinds = new Set( changes.map((path) => (needsChecks(root, path) ? 'code' : classify(path))), ) @@ -76,7 +83,7 @@ export async function runVerify(options: VerifyOptions): Promise { clearVerified(root) const before = snapshot(root) - const passed = await runSteps(root, steps, logDirFor(root), out) + const passed = await runSteps(root, steps, { changes, baseName }, logDirFor(root), out) if (!passed) return { ok: false, recorded: false } const after = snapshot(root) @@ -103,9 +110,17 @@ function logDirFor(root: string): string { return dir } +/** Whether a step with `onlyWhenChanged` has nothing to read in these changes. */ +function nothingToRead(step: Step, changes: string[] | undefined): boolean { + const prefixes = step.onlyWhenChanged + if (!prefixes || changes === undefined) return false + return !changes.some((path) => prefixes.some((prefix) => path.startsWith(prefix))) +} + async function runSteps( root: string, steps: Step[], + since: { changes: string[] | undefined; baseName: string }, logDir: string, out: (line: string) => void, ): Promise { @@ -113,6 +128,15 @@ async function runSteps( 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 (nothingToRead(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 fcb534c..6c2bae5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,3 +32,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 240595e..c0b9b89 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,7 +40,8 @@ npm run dev # watch mode npm run type-check # tsc --noEmit for src/ and the agent tooling (.agents/scripts) npm run check # oxlint + oxfmt --check npm run fix # oxlint --fix + oxfmt -npm test # vitest run +npm test # vitest run: the package's own tests, which publishing runs +npm run test:agents # the agent tooling's tests (.agents/scripts), for changes to the tooling npm run verify # every check CI runs (lint, format, types, build, tests) ``` diff --git a/CODEBASE.md b/CODEBASE.md index 4b8ae93..8ce7f3d 100644 --- a/CODEBASE.md +++ b/CODEBASE.md @@ -45,7 +45,8 @@ that needs them (`commander`, `marked`, `marked-terminal-renderer`, ├─ README.md # Public API docs ("What's in it" table + usage) ├─ tsconfig.json # Includes src + tests (type-check, IDE) ├─ tsconfig.build.json # Excludes *.test.ts + test-support/ + __mocks__/ (build/dev) -├─ vitest.config.ts # { globals, root: 'src', include: ['**/*.test.ts'] } +├─ vitest.config.ts # { globals, root: 'src', include: ['**/*.test.ts'] } (npm test) +├─ vitest.agents.config.ts # .agents/scripts tests (npm run test:agents) ├─ lefthook.yml # Git hooks: branch guard; pre-commit lint, format, types; │ # pre-push tests └─ release.config.js # semantic-release config @@ -226,8 +227,11 @@ helpers, not suites. ## Testing -- **Runner:** vitest. `npm test` (one-shot, including the agent tooling's tests in - `.agents/scripts/`), `npm run test:watch`. +- **Runner:** vitest. `npm test` (one-shot: the package's own tests, which + publishing runs, plus the packed-tarball check in + `.agents/scripts/package-contents.test.ts`), `npm run test:watch`. + `npm run test:agents` runs the agent tooling's tests in `.agents/scripts/`; + CI runs them on every pull request. - **Location:** colocated `*.test.ts` next to the module under test. - **Account suites:** import fixtures + `buildTokenStore` / `buildSingleEntryStore` from `testing/accounts.js` and the spy/scaffold helpers from diff --git a/docs/agents.md b/docs/agents.md index 30e57e9..836d29d 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -40,7 +40,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 the package's tests (`npm test`). 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. @@ -48,12 +48,13 @@ 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`): lint, format, both type checks, the build and all tests. It takes about five 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`): lint, format, both type checks, the build, the package's tests and the agent tooling's tests. It takes about five seconds, so it checks the whole tree rather than picking the affected tests, which would save a few seconds and add a way to miss something. The one exception is the agent tooling's tests, below. - **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 runs only the format check, since `oxfmt` formats Markdown and JSON too, and records nothing. The agent instructions (`AGENTS.md`, `CODEBASE.md`, `docs/agents.md`, `.agents/`) count as code, since a test checks every reference in them, and so do the extension templates, Markdown included: they ship in the package and are copied into every new extension. 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 runs only the format check and says CI is the only other check for them. Every workflow counts as code, since a local test compares verify with the two above and checks no other workflow runs commands on pull requests. -- **Order:** lint, format, both type checks and the build start together. The tests wait for the build: `src/testing/subpath.test.ts` imports the built `./testing` entry from `dist/` when it exists, as it does in CI. +- **The agent tooling's tests** (`npm run test:agents`) run only when something they read changed since the branch left `main`: `.agents/`, `vitest.agents.config.ts`, the agent instructions, the hook configs (`.claude/`, `.codex/`, `lefthook.yml`, and any Cursor hooks file, which a test forbids), the workflows, `package.json`, the lockfile (which pins the lefthook the hook tests install), and the test helpers the `write-tests` skill names (`src/testing/`, `src/test-support/`). Otherwise verify says it skipped them, and CI runs them on every pull request. The list is `onlyWhenChanged` on the step in `.agents/scripts/lib/steps.ts`. `instructions.test.ts` also checks that every path the agent instructions name still exists, so renaming or deleting one of those files elsewhere is caught in CI, not by verify. +- **Order:** lint, format, both type checks and the build start together. The package's tests wait for the build: `src/testing/subpath.test.ts` imports the built `./testing` entry from `dist/` when it exists, as it does in CI. The agent tooling's tests wait for the package's: two vitest runs side by side slow each other down enough for the hook tests to time out. - **`CI=true`** is set for the build and the tests, as GitHub Actions sets it. Variables that change what the code under test does (`GH_TOKEN`, `GITHUB_TOKEN`, `BROWSER`, `DISPLAY`, `WAYLAND_DISPLAY`, `FORCE_COLOR`) are removed, with a note, since CI never sets them. A real GitHub token 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 end-of-turn gate reads it. @@ -142,7 +143,8 @@ 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 never ships: `package.json#files` lists only `dist`, `templates` and `CHANGELOG.md`, and `.agents/scripts/package-contents.test.ts` checks the packed tarball. - 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 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` runs what ships, plus `.agents/scripts/package-contents.test.ts`, which checks the packed tarball, and publishing runs it (`prepublishOnly`), so a slow tooling test can never hold up 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. +- The tooling's tests copy the tools into throwaway git repositories and never touch your checkout. Both vitest configs clear the variables git exports to hooks, since tests in both suites run git and `npm test` runs inside `pre-push`. ## Releases diff --git a/package.json b/package.json index bdf13b3..e4e24bf 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "fix": "oxlint src .agents/scripts --fix && oxfmt", "test": "vitest run --passWithNoTests", "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..924078a --- /dev/null +++ b/vitest.agents.config.ts @@ -0,0 +1,19 @@ +import { configDefaults, defineConfig } from 'vitest/config' +import { clearGitEnv } from './.agents/scripts/lib/git.ts' + +// The agent tooling's tests: `npm run test:agents`. They test the hooks, the guard and verify, none +// of which ship, so they stay out of `npm test`, which publishing runs. CI runs them on every pull +// request, and `npm run verify` when something they read changed. + +// These tests run git and the git hooks, and git exports GIT_DIR and friends to hooks (from a linked +// worktree, at least). Left in place, the git commands the tests run would act on this repository +// instead of their temp ones. Workers inherit this process's environment. +clearGitEnv() + +export default defineConfig({ + test: { + include: ['.agents/scripts/**/*.test.ts'], + // Checks what the published package contains, so `npm test` runs it (vitest.config.ts). + exclude: [...configDefaults.exclude, '.agents/scripts/package-contents.test.ts'], + }, +}) diff --git a/vitest.config.ts b/vitest.config.ts index 88281f4..9c6ba92 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -12,8 +12,10 @@ export default defineConfig({ test: { globals: true, root: 'src', - // The agent tooling's tests live outside `root`, next to the tooling. - include: ['**/*.test.ts', '../.agents/scripts/**/*.test.ts'], + // The package's own tests, which publishing runs (`prepublishOnly`). The agent tooling's + // tests run with `npm run test:agents` (vitest.agents.config.ts). The one exception checks + // what the published package contains, so it is a test of what ships. + include: ['**/*.test.ts', '../.agents/scripts/package-contents.test.ts'], restoreMocks: true, }, }) From 3875de5a1b90473152be18b7fa21043eebd2a189 Mon Sep 17 00:00:00 2001 From: Scott Lovegrove Date: Thu, 3 Dec 2026 16:12:38 +0000 Subject: [PATCH 2/4] chore(agents): run the package-contents check with the agent tooling tests It runs npm pack to check the tooling stays out of the tarball, so it is a test of the tooling rather than of the package, and it is slow enough to time out inside prepublishOnly. It now runs with the other agent tooling tests, as it does in the other CLIs. --- CODEBASE.md | 3 +-- docs/agents.md | 2 +- vitest.agents.config.ts | 4 +--- vitest.config.ts | 5 ++--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CODEBASE.md b/CODEBASE.md index 8ce7f3d..d4d73f7 100644 --- a/CODEBASE.md +++ b/CODEBASE.md @@ -228,8 +228,7 @@ helpers, not suites. ## Testing - **Runner:** vitest. `npm test` (one-shot: the package's own tests, which - publishing runs, plus the packed-tarball check in - `.agents/scripts/package-contents.test.ts`), `npm run test:watch`. + publishing runs), `npm run test:watch`. `npm run test:agents` runs the agent tooling's tests in `.agents/scripts/`; CI runs them on every pull request. - **Location:** colocated `*.test.ts` next to the module under test. diff --git a/docs/agents.md b/docs/agents.md index 836d29d..ec95f14 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -143,7 +143,7 @@ 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 never ships: `package.json#files` lists only `dist`, `templates` and `CHANGELOG.md`, and `.agents/scripts/package-contents.test.ts` checks the packed tarball. - 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 check` lints it. -- Their tests run apart from the package's. `npm test` runs what ships, plus `.agents/scripts/package-contents.test.ts`, which checks the packed tarball, and publishing runs it (`prepublishOnly`), so a slow tooling test can never hold up 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. +- Their tests run apart from the package's. `npm test` runs only what ships, and publishing runs it (`prepublishOnly`), so a slow tooling test can never hold up 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. - The tooling's tests copy the tools into throwaway git repositories and never touch your checkout. Both vitest configs clear the variables git exports to hooks, since tests in both suites run git and `npm test` runs inside `pre-push`. ## Releases diff --git a/vitest.agents.config.ts b/vitest.agents.config.ts index 924078a..57d98f1 100644 --- a/vitest.agents.config.ts +++ b/vitest.agents.config.ts @@ -1,4 +1,4 @@ -import { configDefaults, defineConfig } from 'vitest/config' +import { defineConfig } from 'vitest/config' import { clearGitEnv } from './.agents/scripts/lib/git.ts' // The agent tooling's tests: `npm run test:agents`. They test the hooks, the guard and verify, none @@ -13,7 +13,5 @@ clearGitEnv() export default defineConfig({ test: { include: ['.agents/scripts/**/*.test.ts'], - // Checks what the published package contains, so `npm test` runs it (vitest.config.ts). - exclude: [...configDefaults.exclude, '.agents/scripts/package-contents.test.ts'], }, }) diff --git a/vitest.config.ts b/vitest.config.ts index 9c6ba92..902cb6b 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -13,9 +13,8 @@ export default defineConfig({ globals: true, root: 'src', // The package's own tests, which publishing runs (`prepublishOnly`). The agent tooling's - // tests run with `npm run test:agents` (vitest.agents.config.ts). The one exception checks - // what the published package contains, so it is a test of what ships. - include: ['**/*.test.ts', '../.agents/scripts/package-contents.test.ts'], + // tests run with `npm run test:agents` (vitest.agents.config.ts). + include: ['**/*.test.ts'], restoreMocks: true, }, }) From 41964bfbd8da974b9b16572f6564bcea76eac69f Mon Sep 17 00:00:00 2001 From: Scott Lovegrove Date: Thu, 3 Dec 2026 16:18:42 +0000 Subject: [PATCH 3/4] chore(agents): run the agent tooling tests on deletions, merges and an unchanged tree Verify's `onlyWhenChanged` step now also runs when nothing changed since the base, as every step does then, and when a changed path no longer exists: instructions.test.ts checks that every path the agent docs name exists, so a deletion or rename can break it. test.yml runs on pushes to main and next too, so both suites run on every merge without being on the publish path. The agent tooling's tsconfig drops the vitest globals, which its vitest config does not enable. The helper folders instructions.test.ts imports come from tree.ts, shared with verify's list, and a test checks every path in that list exists. --- .agents/scripts/instructions.test.ts | 4 ++-- .agents/scripts/lib/steps.test.ts | 25 ++++++++++++++----------- .agents/scripts/lib/steps.ts | 5 ++--- .agents/scripts/lib/tree.ts | 3 +++ .agents/scripts/lib/verify.test.ts | 18 ++++++++++++++++++ .agents/scripts/lib/verify.ts | 16 ++++++++++------ .agents/scripts/tsconfig.json | 2 +- .github/workflows/test.yml | 2 ++ CODEBASE.md | 9 ++++++--- CONTRIBUTING.md | 5 +++-- docs/agents.md | 8 ++++---- vitest.agents.config.ts | 2 +- 12 files changed, 66 insertions(+), 33 deletions(-) diff --git a/.agents/scripts/instructions.test.ts b/.agents/scripts/instructions.test.ts index 57800db..e4950ec 100644 --- a/.agents/scripts/instructions.test.ts +++ b/.agents/scripts/instructions.test.ts @@ -7,7 +7,7 @@ import { describe, expect, it } from 'vitest' import { git } from './lib/git.ts' import { readJson } from './lib/state.ts' import { REPO_ROOT } from './lib/test-repo.ts' -import { AGENT_DOCS } from './lib/tree.ts' +import { AGENT_DOCS, TEST_HELPER_DIRS } from './lib/tree.ts' const SKILLS_DIR = join(REPO_ROOT, '.agents/skills') const skills = readdirSync(SKILLS_DIR).filter((name) => !name.startsWith('.')) @@ -144,7 +144,7 @@ it('names only test helpers that src/test-support/ or src/testing/ export', asyn 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 modules = ['src/test-support', 'src/testing'].flatMap((dir) => + const modules = TEST_HELPER_DIRS.flatMap((dir) => readdirSync(join(REPO_ROOT, dir)) .filter((file) => file.endsWith('.ts') && !file.endsWith('.test.ts')) .map((file) => join(REPO_ROOT, dir, file)), diff --git a/.agents/scripts/lib/steps.test.ts b/.agents/scripts/lib/steps.test.ts index 1428ef6..822cb31 100644 --- a/.agents/scripts/lib/steps.test.ts +++ b/.agents/scripts/lib/steps.test.ts @@ -1,11 +1,11 @@ -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' import { writeJson } from './state.ts' import { CI_EQUIVALENTS, preflight, removeLocalOnlyEnv, VERIFY_STEPS } from './steps.ts' import { REPO_ROOT } from './test-repo.ts' -import { AGENT_DOCS, CHECKED_WORKFLOWS } from './tree.ts' +import { CHECKED_WORKFLOWS } from './tree.ts' const WORKFLOWS_DIR = join(REPO_ROOT, '.github/workflows') const readWorkflow = (name: string) => readFileSync(join(WORKFLOWS_DIR, name), 'utf8') @@ -153,19 +153,22 @@ describe('verify covers CI', () => { expect(env).toEqual({ PATH: '/bin' }) }) - it('runs the agent tooling tests when their own files, config or the agent docs change', () => { + it('runs the agent tooling tests with their own config, after the package tests', () => { const step = VERIFY_STEPS.find((candidate) => candidate.name === 'tests:agents') expect(step?.args).toEqual(['run', '--config', 'vitest.agents.config.ts']) + expect(step?.onlyWhenChanged).toContain('vitest.agents.config.ts') expect(step?.waitFor).toEqual(['tests']) - expect(step?.onlyWhenChanged).toEqual( - expect.arrayContaining([ - '.agents/', - 'vitest.agents.config.ts', - '.github/workflows/', - 'package.json', - ...AGENT_DOCS, - ]), + }) + + it('runs the agent tooling tests only for paths that exist', () => { + const step = VERIFY_STEPS.find((candidate) => candidate.name === 'tests:agents') + const paths = step?.onlyWhenChanged ?? [] + expect(paths.length).toBeGreaterThan(0) + // hook-wiring.test.ts checks .cursor/ holds no hooks file, so adding one runs the tests. + const missing = paths.filter( + (path) => path !== '.cursor/' && !existsSync(join(REPO_ROOT, path)), ) + expect(missing).toEqual([]) }) it('starts the tests only once the build has written dist/', () => { diff --git a/.agents/scripts/lib/steps.ts b/.agents/scripts/lib/steps.ts index 03f24db..856228c 100644 --- a/.agents/scripts/lib/steps.ts +++ b/.agents/scripts/lib/steps.ts @@ -2,7 +2,7 @@ import { existsSync } from 'node:fs' import { join } from 'node:path' import { readJson } from './state.ts' import { listSome } from './text.ts' -import { AGENT_DOCS } from './tree.ts' +import { AGENT_DOCS, TEST_HELPER_DIRS } from './tree.ts' import type { Step } from './verify.ts' const bin = (tool: string) => `node_modules/.bin/${tool}` @@ -50,8 +50,7 @@ export const VERIFY_STEPS: Step[] = [ '.github/workflows/', 'package.json', 'package-lock.json', - 'src/testing/', - 'src/test-support/', + ...TEST_HELPER_DIRS, ], }, ] diff --git a/.agents/scripts/lib/tree.ts b/.agents/scripts/lib/tree.ts index 718d54d..82949be 100644 --- a/.agents/scripts/lib/tree.ts +++ b/.agents/scripts/lib/tree.ts @@ -46,6 +46,9 @@ export const CHECKED_WORKFLOWS = ['.github/workflows/lint.yml', '.github/workflo /** 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 imports them. */ +export const TEST_HELPER_DIRS = ['src/test-support/', 'src/testing/'] + /** 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 2fbc6df..78465a3 100644 --- a/.agents/scripts/lib/verify.test.ts +++ b/.agents/scripts/lib/verify.test.ts @@ -206,6 +206,24 @@ describe('a step that runs only when what it reads changed', () => { expect(lines.some((line) => line.startsWith('✓ waits-for-tools'))).toBe(true) }) + it('runs when nothing changed, since verify then checks the whole tree', async () => { + expect(await verify([tools()])).toEqual({ ok: false, recorded: false }) + expect(lines[0]).toBe('No changes since main; checking the tree anyway.') + expect(lines.some((line) => line.startsWith('✗ tools (exit 3'))).toBe(true) + }) + + it('runs when a file was deleted, since the agent docs may name it', async () => { + rmSync(join(repo.dir, 'src/a.ts')) + expect(await verify([tools()])).toEqual({ ok: false, recorded: false }) + expect(lines.some((line) => line.startsWith('✗ tools (exit 3'))).toBe(true) + }) + + it('runs when a file was renamed, since the agent docs may name the old path', async () => { + repo.git(['mv', 'src/a.ts', 'src/renamed.ts']) + expect(await verify([tools()])).toEqual({ ok: false, recorded: false }) + expect(lines.some((line) => line.startsWith('✗ tools (exit 3'))).toBe(true) + }) + it('runs without a default branch, when there is nothing to compare with', async () => { repo.write('src/a.ts', 'export const a = 2\n') expect(await verify([tools()], { base: null })).toEqual({ ok: false, recorded: false }) diff --git a/.agents/scripts/lib/verify.ts b/.agents/scripts/lib/verify.ts index d7598fd..9582091 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, git } from './git.ts' import { clearVerified, readVerified, safeName, stateDir, writeVerified } from './state.ts' @@ -21,8 +21,9 @@ export type Step = { /** Starts only after these steps have finished, passed or not: they share files on disk. */ waitFor?: string[] /** - * 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[] env?: Record @@ -111,9 +112,12 @@ function logDirFor(root: string): string { } /** Whether a step with `onlyWhenChanged` has nothing to read in these changes. */ -function nothingToRead(step: Step, changes: string[] | undefined): boolean { +function nothingToRead(root: string, step: Step, changes: string[] | undefined): boolean { const prefixes = step.onlyWhenChanged - if (!prefixes || changes === undefined) return false + // With nothing changed, verify checks the whole tree, so every step runs. + if (!prefixes || changes === undefined || changes.length === 0) return false + // A path gone from disk was deleted or renamed, and the agent docs may name it. + if (changes.some((path) => !existsSync(join(root, path)))) return false return !changes.some((path) => prefixes.some((prefix) => path.startsWith(prefix))) } @@ -129,7 +133,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 (nothingToRead(step, since.changes)) { + if (nothingToRead(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 4289e5a..875b663 100644 --- a/.agents/scripts/tsconfig.json +++ b/.agents/scripts/tsconfig.json @@ -10,7 +10,7 @@ "allowImportingTsExtensions": true, "erasableSyntaxOnly": true, "lib": ["es2023"], - "types": ["node", "vitest/globals"] + "types": ["node"] }, "include": ["."] } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6c2bae5..50efc28 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,6 +2,8 @@ name: Tests on: pull_request: + push: + branches: [main, next] permissions: contents: read diff --git a/CODEBASE.md b/CODEBASE.md index d4d73f7..f7e6fc0 100644 --- a/CODEBASE.md +++ b/CODEBASE.md @@ -48,7 +48,7 @@ that needs them (`commander`, `marked`, `marked-terminal-renderer`, ├─ vitest.config.ts # { globals, root: 'src', include: ['**/*.test.ts'] } (npm test) ├─ vitest.agents.config.ts # .agents/scripts tests (npm run test:agents) ├─ lefthook.yml # Git hooks: branch guard; pre-commit lint, format, types; -│ # pre-push tests +│ # pre-push npm test └─ release.config.js # semantic-release config ``` @@ -230,7 +230,8 @@ helpers, not suites. - **Runner:** vitest. `npm test` (one-shot: the package's own tests, which publishing runs), `npm run test:watch`. `npm run test:agents` runs the agent tooling's tests in `.agents/scripts/`; - CI runs them on every pull request. + CI runs them on every pull request and every push to `main` and `next`, and + `npm run verify` when something they read changed. - **Location:** colocated `*.test.ts` next to the module under test. - **Account suites:** import fixtures + `buildTokenStore` / `buildSingleEntryStore` from `testing/accounts.js` and the spy/scaffold helpers from @@ -265,7 +266,9 @@ helpers, not suites. `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 `npm run verify` when something they read changed). See + `docs/agents.md`. ## Conventions (quick) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c11cc96..bf0d9a3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,13 +6,14 @@ npm install ``` -This installs dependencies and registers lefthook git hooks through the `prepare` script: commits and pushes to `main` are refused, pre-commit lints, formats and type-checks, pre-push runs the tests. +This installs dependencies and registers lefthook git hooks through the `prepare` script: commits and pushes to `main` are refused, pre-commit lints, formats and type-checks, pre-push runs `npm test`, the package's tests only. The agent tooling's tests run in CI, and in `npm run verify` when something they read changed. ## Scripts - `npm run build` — compile TypeScript to `dist/` - `npm run dev` — watch-mode build -- `npm test` — run vitest +- `npm test`: run the package's tests, which publishing also runs +- `npm run test:agents`: run the agent tooling's tests (`.agents/scripts`), for changes to the tooling - `npm run type-check` — typecheck without emit - `npm run check` — oxlint + oxfmt --check - `npm run fix` — oxlint --fix + oxfmt diff --git a/docs/agents.md b/docs/agents.md index ec95f14..4d9fea2 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -19,7 +19,7 @@ This repository is set up so coding agents prove their work before they call it | No pushes to `main` | `pre-push` → `branch-guard.sh`; the "Protect default branch" ruleset | Enforced on GitHub | | Committed files are linted and formatted | `pre-commit` (lefthook, staged files only); CI | Enforced in CI | | Type check passes before a commit | `pre-commit`; CI | Enforced in CI | -| Tests pass before a push | `pre-push`; CI | Enforced in CI | +| The package's tests pass before a push | `pre-push`; CI | Enforced in CI | | Agent tooling never ships in the npm package | `.agents/scripts/package-contents.test.ts` | Enforced in CI | | `npm run verify` runs what CI runs | `.agents/scripts/lib/steps.test.ts` compares it with the pull-request workflows | Enforced in CI | | Run `npm run verify` before calling work done | `AGENTS.md` | Enforced at turn end (once); `AGENTS.md` | @@ -40,7 +40,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 package's tests (`npm test`). It checks `git push --dry-run` too. +- **`pre-push`** refuses a push to `main` (it checks `git push --dry-run` too), then runs `npm test`, the package's tests only. The agent tooling's tests run in CI, and in `npm run verify` when something they read changed. - 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. @@ -53,7 +53,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 runs only the format check, since `oxfmt` formats Markdown and JSON too, and records nothing. The agent instructions (`AGENTS.md`, `CODEBASE.md`, `docs/agents.md`, `.agents/`) count as code, since a test checks every reference in them, and so do the extension templates, Markdown included: they ship in the package and are copied into every new extension. 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 runs only the format check and says CI is the only other check for them. Every workflow counts as code, since a local test compares verify with the two 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 the branch left `main`: `.agents/`, `vitest.agents.config.ts`, the agent instructions, the hook configs (`.claude/`, `.codex/`, `lefthook.yml`, and any Cursor hooks file, which a test forbids), the workflows, `package.json`, the lockfile (which pins the lefthook the hook tests install), and the test helpers the `write-tests` skill names (`src/testing/`, `src/test-support/`). Otherwise verify says it skipped them, and CI runs them on every pull request. The list is `onlyWhenChanged` on the step in `.agents/scripts/lib/steps.ts`. `instructions.test.ts` also checks that every path the agent instructions name still exists, so renaming or deleting one of those files elsewhere is caught in CI, not by verify. +- **The agent tooling's tests** (`npm run test:agents`) run when something they read changed since the branch left `main`: `.agents/`, `vitest.agents.config.ts`, the agent instructions, the hook configs (`.claude/`, `.codex/`, `lefthook.yml`, and any Cursor hooks file, which a test forbids), the workflows, `package.json`, the lockfile (which pins the lefthook the hook tests install), and the test helpers the `write-tests` skill names (`src/testing/`, `src/test-support/`). They also run when a file was deleted or renamed, since `instructions.test.ts` checks that every path the agent instructions name still exists, and when nothing changed, since verify then checks the whole tree. Otherwise verify says it skipped them, and CI runs them on every pull request. The list is `onlyWhenChanged` on the step in `.agents/scripts/lib/steps.ts`. - **Order:** lint, format, both type checks and the build start together. The package's tests wait for the build: `src/testing/subpath.test.ts` imports the built `./testing` entry from `dist/` when it exists, as it does in CI. The agent tooling's tests wait for the package's: two vitest runs side by side slow each other down enough for the hook tests to time out. - **`CI=true`** is set for the build and the tests, as GitHub Actions sets it. Variables that change what the code under test does (`GH_TOKEN`, `GITHUB_TOKEN`, `BROWSER`, `DISPLAY`, `WAYLAND_DISPLAY`, `FORCE_COLOR`) are removed, with a note, since CI never sets them. A real GitHub token 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/`. @@ -143,7 +143,7 @@ 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 never ships: `package.json#files` lists only `dist`, `templates` and `CHANGELOG.md`, and `.agents/scripts/package-contents.test.ts` checks the packed tarball. - 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 check` lints it. -- Their tests run apart from the package's. `npm test` runs only what ships, and publishing runs it (`prepublishOnly`), so a slow tooling test can never hold up 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. +- Their tests run apart from the package's. `npm test` runs only what ships, and publishing runs it (`prepublishOnly`), so a slow tooling test can never hold up a release. `npm run test:agents` (`vitest.agents.config.ts`) runs the tooling's tests. CI (`test.yml`) runs both suites on every pull request and on every push to `main` and `next`, apart from the release, and `npm run verify` runs the tooling's tests when something they read changed. - The tooling's tests copy the tools into throwaway git repositories and never touch your checkout. Both vitest configs clear the variables git exports to hooks, since tests in both suites run git and `npm test` runs inside `pre-push`. ## Releases diff --git a/vitest.agents.config.ts b/vitest.agents.config.ts index 57d98f1..ec53010 100644 --- a/vitest.agents.config.ts +++ b/vitest.agents.config.ts @@ -3,7 +3,7 @@ import { clearGitEnv } from './.agents/scripts/lib/git.ts' // The agent tooling's tests: `npm run test:agents`. They test the hooks, the guard and verify, none // of which ship, so they stay out of `npm test`, which publishing runs. CI runs them on every pull -// request, and `npm run verify` when something they read changed. +// request and every push to main and next, and `npm run verify` when something they read changed. // These tests run git and the git hooks, and git exports GIT_DIR and friends to hooks (from a linked // worktree, at least). Left in place, the git commands the tests run would act on this repository From e3975060701a32fa76c256e3755990dcb4ef9aca Mon Sep 17 00:00:00 2001 From: Scott Lovegrove Date: Thu, 3 Dec 2026 16:19:41 +0000 Subject: [PATCH 4/4] chore(agents): name the shared test helper list TEST_HELPER_PATHS Matches the name the other CLIs use for the same list. --- .agents/scripts/instructions.test.ts | 4 ++-- .agents/scripts/lib/steps.ts | 4 ++-- .agents/scripts/lib/tree.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.agents/scripts/instructions.test.ts b/.agents/scripts/instructions.test.ts index e4950ec..ff84a5e 100644 --- a/.agents/scripts/instructions.test.ts +++ b/.agents/scripts/instructions.test.ts @@ -7,7 +7,7 @@ import { describe, expect, it } from 'vitest' import { git } from './lib/git.ts' import { readJson } from './lib/state.ts' import { REPO_ROOT } from './lib/test-repo.ts' -import { AGENT_DOCS, TEST_HELPER_DIRS } 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('.')) @@ -144,7 +144,7 @@ it('names only test helpers that src/test-support/ or src/testing/ export', asyn 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 modules = TEST_HELPER_DIRS.flatMap((dir) => + const modules = TEST_HELPER_PATHS.flatMap((dir) => readdirSync(join(REPO_ROOT, dir)) .filter((file) => file.endsWith('.ts') && !file.endsWith('.test.ts')) .map((file) => join(REPO_ROOT, dir, file)), diff --git a/.agents/scripts/lib/steps.ts b/.agents/scripts/lib/steps.ts index 856228c..854810b 100644 --- a/.agents/scripts/lib/steps.ts +++ b/.agents/scripts/lib/steps.ts @@ -2,7 +2,7 @@ import { existsSync } from 'node:fs' import { join } from 'node:path' import { readJson } from './state.ts' import { listSome } from './text.ts' -import { AGENT_DOCS, TEST_HELPER_DIRS } 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}` @@ -50,7 +50,7 @@ export const VERIFY_STEPS: Step[] = [ '.github/workflows/', 'package.json', 'package-lock.json', - ...TEST_HELPER_DIRS, + ...TEST_HELPER_PATHS, ], }, ] diff --git a/.agents/scripts/lib/tree.ts b/.agents/scripts/lib/tree.ts index 82949be..052bfef 100644 --- a/.agents/scripts/lib/tree.ts +++ b/.agents/scripts/lib/tree.ts @@ -47,7 +47,7 @@ export const CHECKED_WORKFLOWS = ['.github/workflows/lint.yml', '.github/workflo 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 imports them. */ -export const TEST_HELPER_DIRS = ['src/test-support/', 'src/testing/'] +export const TEST_HELPER_PATHS = ['src/test-support/', 'src/testing/'] /** The kind of file, as far as local checks are concerned. */ export type FileKind = 'docs' | 'unchecked' | 'code'