inspector icon indicating copy to clipboard operation
inspector copied to clipboard

TUI tests append to the developer's real ~/.mcp-inspector/auth.log (App.test.tsx mounts the real getTuiLogger)

Open nosmile99 opened this issue 1 month ago • 4 comments

Bug report

Which version line? v2 — current Which client? TUI Inspector version: 2.11.0 (v2/main @ 074b8108) Node version: v24.20.0 Operating system: Linux (also applies anywhere HOME resolves) Transport: Not applicable / never connected

Problem

The TUI test suite writes to the developer's real ~/.mcp-inspector/auth.log. clients/tui/src/logger.ts's getTuiLogger() is a lazy singleton that resolves its log directory from MCP_INSPECTOR_LOG_DIR ?? HOME/.mcp-inspector, and __tests__/App.test.tsx mounts App, which calls getTuiLogger() on startup — so a normal test run appends ~155 lines of test noise ("msg":"TUI started", test-process pid/hostname) to the real log. Concurrent worktree gates interleave into the same file. This is the same class of bug as #2670 / #2719 (tests touching the real ~/.mcp-inspector), one directory up: the log file rather than the OAuth state.

logger.test.ts itself is clean — it tests each resolution arm with vi.resetModules(), per-test env save/restore, and a temp HOME. The leak comes from the app-mounting suites, which never set the override.

Reproduce

Point HOME at an empty scratch dir and run the suite; the log file appears under the scratch home:

cd clients/tui
H=$(mktemp -d)
HOME=$H npx vitest run __tests__/App.test.tsx
find $H -name 'auth.log'   # → $H/.mcp-inspector/auth.log, ~155 lines of {"msg":"TUI started",...}

Scope checked (same scratch-HOME sweep)

  • All 49 clients/tui/__tests__ files swept individually: only App.test.tsx leaks; the rest are clean.
  • clients/mcpdo OAuth-touching suites (connection-stored-auth, daemon-connections, ema, ema-login-helper, mcp-auth-coverage) are clean — they set MCP_INSPECTOR_OAUTH_STATE_PATH per test.
  • clients/launcher has no storage-touching tests.
  • clients/web unit tests use a recording backend for OAuth persistence (integration was isolated in #2677).

Expected

No TUI test reads or writes the developer's real ~/.mcp-inspector/auth.log.

Suggested fix shape

The #2677 shape, one directory over: a TUI vitest setup file that pins MCP_INSPECTOR_LOG_DIR at a per-file mkdtemp directory (plus a guard that fails if the resolved path escapes tmpdir). logger.test.ts's fallback-arm cases are unaffected — they delete the variable and set their own HOME per test with a fresh module import. The tui project already pins MCP_INSPECTOR_SECRET_STORE: "memory" in vitest.config.ts; this would be the log-dir counterpart.

Actual behavior

~/.mcp-inspector/auth.log is created/appended on the developer's real home directory on every tui test run that mounts App.


I searched existing issues and this is not a duplicate (nearest are #2670 / #2719, which cover the OAuth state file, not the TUI log). This is not a security vulnerability report.

nosmile99 avatar Oct 14 '26 12:10 nosmile99

Confirming the report, with a verified prototype. (Posting the detail here rather than a PR, per this repo's maintainer-only PR rule.)

Reproduced on a fresh clone of v2/main: with HOME pointed at an empty scratch directory, running

HOME= vitest run tests/App.test.tsx

from clients/tui passes (130 tests) and leaves exactly 155 lines in /.mcp-inspector/auth.log, matching the count in the report.

Prototype I verified: in clients/tui/tests/setup.ts, the setupFile every TUI test file already inherits, create a per-test-file temporary directory (fs.mkdtempSync under os.tmpdir()), set process.env.MCP_INSPECTOR_LOG_DIR to it before anything mounts the App, and remove the directory on process exit. Nothing else changes. logger.test.ts sets and restores this variable itself per test, so it is unaffected, and the lazy logger singleton resolves the override on first use in each test file, so per-file isolation also stops concurrent worktrees interleaving into one file.

Results with the prototype in place: the full TUI suite passes (47 files, 636 tests), the scratch HOME is left completely empty, and the setup file is prettier-clean.

If you would rather see the override somewhere else (a vitest config env entry, or per-suite setup in the mounting tests), I can re-run the verification against that shape instead.

CloudCorpRecords avatar Oct 15 '26 21:10 CloudCorpRecords

Triage: Priority Low (total 5)

  • Severity 2: test noise appended to the developer's real ~/.mcp-inspector/auth.log. No user-facing or data-integrity impact, and it's milder than the OAuth-state siblings (#2670, #2719).
  • Urgency 2: wanted eventually, and nothing is blocked on it.
  • Bonuses: +1 bug

Board: #28, Status Incoming, awaiting maintainer review (no milestone yet).

cliffhall avatar Oct 20 '26 00:10 cliffhall

Shipped in #2735.

cliffhall avatar Oct 20 '26 03:10 cliffhall

Thanks for shipping this, cliffhall — appreciate the triage and the quick fix in #2735.

nosmile99 avatar Oct 20 '26 03:10 nosmile99