inspector/clients/cli/__tests__
Repository files (latest commit first)
Filename Latest commit message Latest commit date
cliffhall 93f3fb64f2 cli: reconcile --print-handoff deep-link with #1576 canonical format (#1666)
Closes #1666

#1575 shipped `--print-handoff` with an interim deep-link shape (hardcoded
`transport: "http"`, marked `TODO(#1576)`). Now that #1576 owns the canonical
`?serverUrl&transport&autoConnect` format, `--print-handoff` emits exactly it:

- New `deepLinkTransport(serverUrl, transport)` helper derives `http`|`sse`
  from the resolved server — explicit `--transport` wins, else auto-detect from
  the URL path (`/sse` → sse), else default `http`. Unlike the core resolver it
  defaults instead of throwing (the handoff is best-effort; the web parser
  defaults an unknown transport to http too).
- `buildHandoff` takes the transport, emits the normalized serverUrl +
  derived transport in the query, and keeps `autoConnect=<token>` (which #1576
  adopted as the canonical CSRF gate, so the interim guess was already correct).
- Removed the `TODO(#1576)` marker; updated the doc comment + CLI README.

Tests: handoff emits `transport=http` for `/mcp`, `transport=sse` for `/sse`
and for explicit `--transport sse`; `deepLinkTransport` unit tests cover the
explicit/auto/default/stdio/unparseable branches. CLI coverage gate green
(cli.ts 100/92.8/100/100).

Part of the #1579 decomposition (Wave 4).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BrihGWcrM9JGRyu41nzZYw
2026-07-11 23:02:45 -04:00
..
helpers cli: Wave 3 — programmatic review path (rollup of #1573–#1575) (#1655) 2026-07-11 22:14:23 -04:00
app-info.test.ts cli: Wave 3 — programmatic review path (rollup of #1573–#1575) (#1655) 2026-07-11 22:14:23 -04:00
cli.test.ts test: raise per-file coverage gate to 90 across all clients (closes #1271) (#1532) 2026-06-27 15:26:03 -04:00
cliOAuth.test.ts test(cli): cover cliOAuth.ts step-up/recovery paths to the ≥90% gate 2026-07-04 16:47:48 -04:00
e2e.test.ts test(cli,tui): add in-process source coverage gates (#1484) (#1502) 2026-06-20 15:05:58 -04:00
emit-result.test.ts cli: Wave 3 — programmatic review path (rollup of #1573–#1575) (#1655) 2026-07-11 22:14:23 -04:00
error-handler.test.ts fix(cli): guard numeric .code to HTTP range; bound cause-chain depth 2026-07-01 19:10:25 -04:00
format-json.test.ts cli: Wave 3 — programmatic review path (rollup of #1573–#1575) (#1655) 2026-07-11 22:14:23 -04:00
headers.test.ts feat: port CLI, TUI, and launcher from v1.5 into v2 (#1452) 2026-06-14 20:27:49 -04:00
metadata.test.ts feat: port CLI, TUI, and launcher from v1.5 into v2 (#1452) 2026-06-14 20:27:49 -04:00
methods.test.ts test: raise per-file coverage gate to 90 across all clients (closes #1271) (#1532) 2026-06-27 15:26:03 -04:00
oauth-interactive.test.ts All of the mid-session and step-up auth work 2026-07-02 16:35:31 -07:00
oauth-runner.test.ts Guided-auth removal, OAuth smoke testing, and TUI/CLI support (#1531) 2026-06-29 15:35:51 -04:00
programmatic-ergonomics.test.ts cli: Wave 3 — programmatic review path (rollup of #1573–#1575) (#1655) 2026-07-11 22:14:23 -04:00
README.md All of the mid-session and step-up auth work 2026-07-02 16:35:31 -07:00
stored-auth.test.ts cli: reconcile --print-handoff deep-link with #1576 canonical format (#1666) 2026-07-11 23:02:45 -04:00
tools.test.ts cli: Wave 3 — programmatic review path (rollup of #1573–#1575) (#1655) 2026-07-11 22:14:23 -04:00

CLI Tests

Running Tests

# Run all tests (pretest builds test-servers + the CLI binary)
npm test

# Run all tests under the per-file coverage gate
npm run test:coverage

# Run in watch mode (useful for test file changes)
npm run test:watch

# Run specific test file
npm run test:cli          # cli.test.ts
npm run test:cli-tools   # tools.test.ts
npm run test:cli-headers # headers.test.ts
npm run test:cli-metadata # metadata.test.ts
npx vitest run oauth-interactive.test.ts cliOAuth.test.ts  # OAuth interactive smoke parity

How the CLI is exercised

Most tests run the CLI in-process: helpers/cli-runner.ts imports runCli() from ../src/cli.ts and invokes it directly, capturing process.stdout/stderr and mapping thrown errors to an exit code. This is what lets vitest's v8 coverage instrument clients/cli/src (#1484). Because commander uses .exitOverride(), a parse/usage error throws instead of calling process.exit and tearing down the worker.

e2e.test.ts is the deliberately thin out-of-process layer: it spawns the built build/index.js as a real subprocess to cover the shebang, the index.ts isMain bootstrap, and the actual process.exit codes — the only parts the in-process runner can't reach. (scripts/smoke-cli.mjs at the repo root provides a further end-to-end check of the binary.)

Test Files

  • cli.test.ts - Basic CLI functionality: CLI mode, environment variables, config files, resources, prompts, logging, transport types
  • tools.test.ts - Tool-related tests: Tool discovery, JSON argument parsing, error handling, prompts
  • headers.test.ts - Header parsing and validation
  • metadata.test.ts - Metadata functionality: General metadata, tool-specific metadata, parsing, merging, validation
  • methods.test.ts - Method/option-validation paths not covered elsewhere (resource templates, missing/invalid options, the -- target separator)
  • error-handler.test.ts - The binary's handleError error sink, exercised in-process with process.exit stubbed
  • oauth-runner.test.ts - OAuth flag wiring (--client-config, --callback-url, CIMD overrides)
  • cliOAuth.test.ts - Unit tests for cliOAuth.ts (step-up confirm, helper wiring, retry)
  • oauth-interactive.test.ts - Integration smoke parity for CLI interactive OAuth: connect-time callback server + step-up y/N against composable TestServerHttp (auto-completes authorize URL programmatically; not a subprocess binary e2e)
  • e2e.test.ts - Out-of-process spawn of the built binary (exit codes + boot; no OAuth)

Helpers

The helpers/ directory contains shared utilities:

  • cli-runner.ts - Invokes runCli() in-process and captures stdout/stderr + exit code
  • assertions.ts - Custom assertion helpers for CLI output validation
  • fixtures.ts - Test config/catalog file generators and temporary directory management

HTTP/SSE test servers (for transport tests) come from the @modelcontextprotocol/inspector-test-server package (createTestServerHttp), and the bundled stdio server is launched via getTestMcpServerCommand().

Notes

  • Test files run in separate forked processes (pool: 'forks'), so the in-process runner's process.std*.write patching never overlaps across files; tests within a file run sequentially
  • Config files use crypto.randomUUID() for uniqueness
  • HTTP/SSE servers use dynamic port allocation to avoid conflicts
  • Coverage is enforced per-file (lines ≥ 90, statements ≥ 85, functions ≥ 80, branches ≥ 50). src/index.ts (the binary bootstrap) is excluded because it only runs in the spawned binary, which coverage can't instrument
  • All tests use the built-in MCP test servers — no external/registry dependencies