Testing
How tests are organized, how to run them, and what CI runs before and after merge.
Test runner
ashlr uses Bun's built-in test runner. Plugin tests live under __tests__/ (about 550 files). The optional Pro backend in server/ and the end-to-end suite in integration/ have their own tests and dependency trees.
Run the plugin suite
Use bun run test, not plain bun test. The wrapper (scripts/run-root-tests.ts):
- prepares the derived docs that some tests read (
scripts/prepare-root-test-docs.ts) - runs every file in isolated workers (
--parallel=4), and on CI scales Bun's 5-second default timeout for slow shared runners - checks a JUnit report from the run, so every test file has to report back. A child process that exits 0 early cannot pass for a finished suite. On success it prints a
ROOT_TEST_COMPLETIONline.
On CI, the wrapper stops after the first failure (--bail=1). The annotation prefers the failing test's location, and the step summary includes the test name and up to 20 assertion lines. The captured output, including snapshot diffs, is saved as test-results/unit-failure.log and uploaded as unit-test-failure-<OS> (Linux, macOS or Windows). Download that artifact for the full failure output. Local runs omit --bail=1.
Run part of the suite
Run what your branch affects
Commit first, fetch the base so it matches the main CI compares against, then run:
From a fork, origin/main is your fork's main, which stops moving once you fork. Run git fetch upstream and pass upstream/main instead. In a new git worktree, run bun install there first, or the check can fail on module errors before any test runs.
scripts/affected-tests.ts maps the committed diff (base...HEAD; staged and untracked files are left out) to test targets. A changed test file selects itself. A source change under servers/, scripts/, hooks/ or a similar folder selects every suite that can reach it (__tests__, server/tests, integration/tests). A config change selects everything, and text docs select nothing: .md, .mdx, .rst and .txt files in a docs/ folder, README, CHANGELOG, CONTRIBUTING and LICENSE files, and top-level files such as AGENTS.md. Other files under site/, video/ or .github/ select everything, even though CI's PR run treats site/ and video/ as docs-only. The script runs those targets and bun run typecheck concurrently and prints one JSON verdict ("kind":"ashlr.premerge-local") with each step's status and output tail. It exits 0 only on a pass; a selection failure or an exhausted budget is a fail, never a skip. It is a local check and replaces no CI gate.
A source or config change also runs server/tests and integration/tests, which have their own dependencies. Run bun install in server/ and integration/ first and pass a larger --budget-ms, or leave that run to the daily full suite.
Docs checks
The docs checks that AGENTS.md lists are a fast pre-PR set for docs changes. A docs-only diff selects no tests in the pre-merge check, and the PR run of CI skips them, so run both lines yourself:
The first line covers the README and the agent entry files. The second guards the contributor docs (CONTRIBUTING.md, AGENTS.md, the PR template and these contributing pages) against the scripts, CI rules and paths they describe.
Other suites and checks
| Command | What it covers |
|---|---|
bun run typecheck | tsc --noEmit on the root tsconfig.json |
bun run smoke:tools | the router registers the expected number of default tools (EXPECTED_TOOL_COUNT in scripts/smoke-tools.ts, which bun run tool-counts:sync keeps equal to the catalog's default tools; ashlr__pipe is left out because it needs ASHLR_PIPE_ENABLE=1) |
bun run tool-counts:check | tool counts quoted in docs match the code |
bun run version:check | package.json, both plugin manifests and the marketplace manifest agree |
bun run fresh:check | version badges and the pinned install command have not drifted |
bun run mdx-lint | no bare angle brackets in commands/*.md or site/content/docs/skills/ |
bun run site/scripts/gen-docs.ts --check --skip-corpus | generated site release facts are fresh; the fast checks step for code changes |
cd server && bun run check | server typecheck and bun test |
cd site && bun run check | regenerates docs data and typechecks the site |
cd integration && bun test --timeout 30000 | end-to-end flows that spawn real MCP server processes and the backend in a temp HOME |
bun run check | tool counts, tool smoke test, typecheck, MDX lint, unit tests, then the server, site and VS Code extension checks |
Test organization
Test files are named after the server or module they cover. Some examples:
Writing a new test
Tests that need the filesystem should use temp directories created with mkdtemp and removed in afterAll.
Two hot-file rules keep parallel agent PRs from colliding (__tests__/hot-file-rule.test.ts keeps them in AGENTS.md):
- New pipe server cases go in a new file such as
__tests__/pipe-server-<topic>.test.ts, not in__tests__/pipe-server.test.ts. - Do not commit a regenerated
site/lib/docs.generated.json.
CI
.github/workflows/ci.yml follows "merge fast, test later, fix forward":
- Pull requests, the merge queue and pushes to
mainrunfast checksandSecret-shape scan.fast checksruns version sync, and for code changes, install, typecheck and a check of the generated site release facts. On the PR run, PRs that touch onlydocs/,site/,video/, top-level Markdown,LICENSEor issue templates skip the install, typecheck and release-facts steps. The merge queue andmainruns always do all three.Secret-shape scanruns the pinned.github/tests/secret-shape/scrub.plover the change's diff from its merge base (the added lines plus the unchanged context lines around them; removed lines are skipped) and fails if any look like a token or private key. Fork PRs restore caches but do not save them; the secret scan checks out the advertised PR ref. - Pull requests and merge-queue entries also run a Linux install smoke. When
scripts/os-path-gate.mjsselects the diff, Windows and macOS run typecheck, affected root tests and install smoke. Selected paths include shell scripts, installers, manifests, lockfiles, workflows and OS-specific source. The install smoke packs the checkout, installs it under a temporary npm prefix and checksashlr-plugin tools --json.Gate (linux),Gate (windows)andGate (macos)report the jobs for each platform. CI Gateis the single required status check. It checks its declared dependencies:fast checks,Secret-shape scanand the daily or dispatch suites selected for the event. The affected OS checks and install smokes are outsideCI Gate; the platform gates report them separately.- The daily schedule (10:00 UTC) and manual dispatch with the
fullscope run the full suite: one Linux job (tool count, typecheck, unit tests, smoke tests, server, site and VS Code checks, a benchmark dry run, integration tests), typecheck, unit tests and smoke tests on macOS and Windows, a Windows MCP server smoke, and a benchmark refresh on the schedule only. The Windows smoke startsservers/efficiency-server.tsthroughscripts/mcp-entrypoint.tsand checks thatashlr__read,ashlr__grepandashlr__savingseach answer without an error. The Windows smoke and the macOS and Windows jobs run only when the Linux job passes and the change touched code. - Manual dispatch takes a
validation_scopeinput.full, the default, runs the full suite above, and the run is namedci/full.windows-diagnosticsselectsfast checks,Secret-shape scanand a bounded, metadata-only Windows diagnosis (scripts/windows-release-diagnostics.ts) forCI Gate. Install smokes also run on every dispatch, including diagnostics, and on the daily schedule: each platform checks both the checkout and the published npm release. The diagnostics run is namedci/windows-diagnosticsand never counts as release qualification. Dispatching needs write access:gh workflow run ci.yml --repo ashlrai/ashlr-plugin --ref main -f validation_scope=windows-diagnostics.
A red daily run is fixed forward on main. The Daily fixup queue job turns each failed job into one line for the fix-forward queue, with no logs or environment values. Windows is the hardest target. CI turns off CRLF conversion there, and the test wrapper runs hook-timings-bounded.test.ts in its own pass on Windows. Flake fixes are welcome.
Releases do not rely on the fast gate. Each release tag needs its own full CI run first. See Releases.