ashlr

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

bun install
bun run test

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_COMPLETION line.

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

bun test __tests__/efficiency-server.test.ts      # one file
bun test --test-name-pattern "snipCompact"        # tests whose name matches

Run what your branch affects

Commit first, fetch the base so it matches the main CI compares against, then run:

git fetch origin
bun scripts/premerge-local.ts origin/main                     # 60-second budget
bun scripts/premerge-local.ts origin/main --budget-ms 300000  # larger diffs

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:

bun test __tests__/readme-links.test.ts __tests__/readme-commands-samples.test.ts __tests__/agent-front-door.test.ts
bun test __tests__/contributing-check-failures.test.ts __tests__/contributing-fork-path.test.ts __tests__/contributing-merge-rules.test.ts __tests__/contributing-pr-checklist.test.ts __tests__/contributing-scope-parity.test.ts __tests__/pr-template-commands.test.ts __tests__/hot-file-rule.test.ts

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

CommandWhat it covers
bun run typechecktsc --noEmit on the root tsconfig.json
bun run smoke:toolsthe 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:checktool counts quoted in docs match the code
bun run version:checkpackage.json, both plugin manifests and the marketplace manifest agree
bun run fresh:checkversion badges and the pinned install command have not drifted
bun run mdx-lintno bare angle brackets in commands/*.md or site/content/docs/skills/
bun run site/scripts/gen-docs.ts --check --skip-corpusgenerated site release facts are fresh; the fast checks step for code changes
cd server && bun run checkserver typecheck and bun test
cd site && bun run checkregenerates docs data and typechecks the site
cd integration && bun test --timeout 30000end-to-end flows that spawn real MCP server processes and the backend in a temp HOME
bun run checktool 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:

__tests__/
  efficiency-server.test.ts     ashlr__read, ashlr__grep, ashlr__edit
  bash-server.test.ts           ashlr__bash, output compression
  diff-server.test.ts           ashlr__diff modes (stat/summary/full)
  diff-semantic-server.test.ts  rename detection, signature change
  glob-server.test.ts           git ls-files vs readdir fallback
  orient-server.test.ts         routing, keyword extraction
  ask-server.test.ts            question routing table
  genome-server.test.ts         propose/consolidate cycle
  stats-*.test.ts               stats storage, sync and dispatch
  readme-*.test.ts              README links, commands and surface drift
  pipe-server-*.test.ts         pipe server cases, one topic per file

Writing a new test

import { describe, it, expect } from "bun:test";
import { myFunction } from "../servers/my-server";
 
describe("myFunction", () => {
  it("does the thing", () => {
    expect(myFunction("input")).toBe("expected output");
  });
});

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 main run fast checks and Secret-shape scan. fast checks runs version sync, and for code changes, install, typecheck and a check of the generated site release facts. On the PR run, PRs that touch only docs/, site/, video/, top-level Markdown, LICENSE or issue templates skip the install, typecheck and release-facts steps. The merge queue and main runs always do all three. Secret-shape scan runs the pinned .github/tests/secret-shape/scrub.pl over 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.mjs selects 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 checks ashlr-plugin tools --json. Gate (linux), Gate (windows) and Gate (macos) report the jobs for each platform.
  • CI Gate is the single required status check. It checks its declared dependencies: fast checks, Secret-shape scan and the daily or dispatch suites selected for the event. The affected OS checks and install smokes are outside CI Gate; the platform gates report them separately.
  • The daily schedule (10:00 UTC) and manual dispatch with the full scope 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 starts servers/efficiency-server.ts through scripts/mcp-entrypoint.ts and checks that ashlr__read, ashlr__grep and ashlr__savings each 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_scope input. full, the default, runs the full suite above, and the run is named ci/full. windows-diagnostics selects fast checks, Secret-shape scan and a bounded, metadata-only Windows diagnosis (scripts/windows-release-diagnostics.ts) for CI 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 named ci/windows-diagnostics and 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.

On this page