CLI Tests

July 26, 2026 · View on GitHub

Tests live under __tests__/ and run via Vitest.

  • Most tests import runCli() in-process (see helpers/cli-runner.ts) so clients/cli/src is measured under the coverage gate. Suite-wide helpers/mock-open-url.ts (vitest setupFiles) mocks open-url so an armed interactive OAuth path cannot launch a real browser.
  • e2e.test.ts (and root scripts/smoke-cli.mjs) spawn the built binary for shebang / process.exit paths — pretest builds test-servers + the CLI bundle first.

Scripts (from clients/cli/)

npm test                  # pretest build + all tests
npm run test:cli          # subset: cli.test.ts
npm run test:cli-tools    # subset: tools.test.ts
npm run test:cli-headers  # subset: headers.test.ts
npm run test:cli-metadata # subset: metadata.test.ts
npm run test:coverage     # build + ≥90 per-file coverage gate
npm run validate          # format:check && lint && typecheck && test

Test files

FileFocus
cli.test.tsCore connect / method / config matrix
tools.test.tstools/call argument coercion
headers.test.ts--header merging
metadata.test.ts--metadata / --tool-metadata
methods.test.tsMethod allow-list / rejection
app-info.test.ts--app-info probe paths
format-json.test.ts--format json envelopes
format-output.test.tsText/json writers
emit-result.test.tsResult emission helpers
method-types.test.tsONE_SHOT_METHODS / guards
run-method.test.tsHandler dispatch against a real test server
run-method-mocks.test.tsHandler edge cases with mocks
servers-list.test.tsservers/list / servers/show + redaction
cliOAuth.test.tsConnect / mid-RPC OAuth recovery
cli-oauth-navigation.test.tsOSC 8, arm/disarm, MCP_AUTO_OPEN_ENABLED
open-url.test.tsopen package wrapper
oauth-runner.test.tsRunner client-config / CIMD flags
oauth-interactive.test.tsLoopback callback OAuth (in-process)
stored-auth.test.ts--use-stored-auth / handoff / wait
clear-stored-auth-for-relogin.test.tsDual-key --relogin clear
programmatic-ergonomics.test.tsFlag conflicts, timeouts, ergonomics
error-handler.test.tsExit codes / error shaping
style.test.tsANSI / OSC 8 helpers
e2e.test.tsOut-of-process binary smoke
helpers/assertions.test.tsAssertion helpers

Helpers

HelperRole
helpers/cli-runner.tsIn-process runCli with stdout/stderr capture
helpers/mock-open-url.tsSuite-wide open-url mock (vitest setupFiles)
helpers/assertions.tsexpectCliSuccess / expectCliFailure / output matchers
helpers/fixtures.tsTemp config / client.json factories

OAuth interactive tests stub or drive the loopback callback in-process rather than requiring a real browser.