inspector/clients/cli/__tests__
Repository files (latest commit first)
Filename Latest commit message Latest commit date
cliffhall fafc8367b8
fix(web): move the app origin off 6276, bound the publish route
Copilot review round 2 on #2100, plus a collision the review did not find.

The default app-origin port was 6276 — which is already
RUNNER_OAUTH_CALLBACK_DEFAULT_PORT, the CLI/TUI loopback OAuth callback.
That port is fixed precisely so an OAuth app can pre-register
http://127.0.0.1:6276/oauth/callback, which makes it the one listener here
that cannot move when something takes it first. A running --web would hold
it and break a later --cli/--tui OAuth flow at its registered redirect URI,
and docs/mcp-app-review.md has those two running side by side. This
listener has a documented dynamic fallback, so this listener yields: the
default is now 6278 (6277 skipped — v1's retired proxy port, which the
migration guide tells people to stop forwarding). A test asserts the two
defaults stay distinct.

Review comments:

- POST /api/app-document now applies hono's bodyLimit BEFORE parsing. The
  8MiB check ran after c.req.json() had buffered and parsed the whole
  request, and bounded only `html` — so bulk in `csp`, or in keys the route
  never reads, was fully materialized before the 413.
- `csp` is validated as an HTTP header value and length-bounded. The
  controller hands it to res.writeHead() verbatim, where Node throws
  ERR_INVALID_CHAR synchronously — inside the handler for a later,
  unrelated request, outside this route's error handling.
- The app-origin port now propagates everywhere the other two do: the CLI
  --print-handoff port-forward command (and its test), the Dockerfile's ENV
  and EXPOSE, and the remote-review SSH recipe in docs/mcp-app-review.md.
  Without it an app declaring _meta.ui.domain is unreachable through every
  documented remote workflow.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177mPHAdECD18nLLCTwR5rh
Signed-off-by: cliffhall <cliff@futurescale.com>
2026-08-24 08:45:40 -04:00
..
helpers feat: allow complex JSON values in request _meta 2026-08-23 12:23:40 -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
clear-stored-auth-for-relogin.test.ts CLI: catalog listing, auth flags, and OAuth browser UX (#1782) 2026-07-26 16:55:25 -04:00
cli-oauth-navigation.test.ts CLI: catalog listing, auth flags, and OAuth browser UX (#1782) 2026-07-26 16:55:25 -04:00
cli.test.ts test(proxy): isolate proxy env per file; word the guard failure by candidate source 2026-08-23 23:00:28 -04:00
cliOAuth.test.ts test(cli,tui): typecheck the __tests__ dirs (#1791) (#1799) 2026-07-27 12:05:35 -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: catalog listing, auth flags, and OAuth browser UX (#1782) 2026-07-26 16:55:25 -04:00
error-handler.test.ts SDK v2 migration (behavior-neutral, versionNegotiation: 'legacy') (#1624) 2026-07-15 10:44:24 -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
format-output.test.ts CLI: catalog listing, auth flags, and OAuth browser UX (#1782) 2026-07-26 16:55:25 -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 fix: stop leaking metadata values into diagnostics, and salvage per key 2026-08-23 20:03:37 -04:00
method-types.test.ts feat: allow complex JSON values in request _meta 2026-08-23 12:23:40 -04:00
methods.test.ts CLI: catalog listing, auth flags, and OAuth browser UX (#1782) 2026-07-26 16:55:25 -04:00
oauth-interactive.test.ts test(cli,tui): typecheck the __tests__ dirs (#1791) (#1799) 2026-07-27 12:05:35 -04:00
oauth-runner.test.ts Guided-auth removal, OAuth smoke testing, and TUI/CLI support (#1531) 2026-06-29 15:35:51 -04:00
open-url.test.ts CLI: catalog listing, auth flags, and OAuth browser UX (#1782) 2026-07-26 16:55:25 -04:00
programmatic-ergonomics.test.ts feat: allow complex JSON values in request _meta 2026-08-23 12:23:40 -04:00
README.md CLI: catalog listing, auth flags, and OAuth browser UX (#1782) 2026-07-26 16:55:25 -04:00
run-method-mocks.test.ts CLI: catalog listing, auth flags, and OAuth browser UX (#1782) 2026-07-26 16:55:25 -04:00
run-method.test.ts fix: invoke the registered SIGINT listener directly in run-method.test instead of emitting a process-wide signal 2026-08-12 08:57:35 -07:00
servers-list.test.ts fix: redact secrets nested inside metadata in servers/show 2026-08-23 14:03:40 -04:00
stored-auth.test.ts fix(web): move the app origin off 6276, bound the publish route 2026-08-24 08:45:40 -04:00
style.test.ts CLI: catalog listing, auth flags, and OAuth browser UX (#1782) 2026-07-26 16:55:25 -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

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

File Focus
cli.test.ts Core connect / method / config matrix
tools.test.ts tools/call argument coercion
headers.test.ts --header merging
metadata.test.ts --metadata / --tool-metadata
methods.test.ts Method allow-list / rejection
app-info.test.ts --app-info probe paths
format-json.test.ts --format json envelopes
format-output.test.ts Text/json writers
emit-result.test.ts Result emission helpers
method-types.test.ts ONE_SHOT_METHODS / guards
run-method.test.ts Handler dispatch against a real test server
run-method-mocks.test.ts Handler edge cases with mocks
servers-list.test.ts servers/list / servers/show + redaction
cliOAuth.test.ts Connect / mid-RPC OAuth recovery
cli-oauth-navigation.test.ts OSC 8, arm/disarm, MCP_AUTO_OPEN_ENABLED
open-url.test.ts open package wrapper
oauth-runner.test.ts Runner client-config / CIMD flags
oauth-interactive.test.ts Loopback callback OAuth (in-process)
stored-auth.test.ts --use-stored-auth / handoff / wait
clear-stored-auth-for-relogin.test.ts Dual-key --relogin clear
programmatic-ergonomics.test.ts Flag conflicts, timeouts, ergonomics
error-handler.test.ts Exit codes / error shaping
style.test.ts ANSI / OSC 8 helpers
e2e.test.ts Out-of-process binary smoke
helpers/assertions.test.ts Assertion helpers

Helpers

Helper Role
helpers/cli-runner.ts In-process runCli with stdout/stderr capture
helpers/mock-open-url.ts Suite-wide open-url mock (vitest setupFiles)
helpers/assertions.ts expectCliSuccess / expectCliFailure / output matchers
helpers/fixtures.ts Temp config / client.json factories

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