Skip to content

feat(cli): expand MCP editor detection and refactor for testability#960

Merged
drewlyton merged 2 commits intomainfrom
feat/mcp-editor-detection-refactor
Apr 17, 2026
Merged

feat(cli): expand MCP editor detection and refactor for testability#960
drewlyton merged 2 commits intomainfrom
feat/mcp-editor-detection-refactor

Conversation

@drewlyton
Copy link
Copy Markdown
Contributor

Description

Adds MCP auto-configuration support for 5 new editors and refactors the detection architecture to eliminate a class of test fragility caused by global mock collisions.

New editors: Antigravity, Cline CLI, Codex CLI, GitHub Copilot CLI, MCPorter

Problem: Detection functions used module-level imports (existsSync, execa, process.platform), so the only way to test them was through global mocks in a 1,400-line integration test. Editors with overlapping filesystem paths (e.g., Cline's config lives inside VS Code's directory) caused mock collisions — a test for editor A would accidentally trigger editor B's detection. Adding new editors kept breaking existing tests.

Solution: Introduce a DetectionEnv interface that each detect function receives as a parameter instead of importing side-effectful modules directly. This makes every detect function independently testable with its own isolated context, and eliminates cross-editor mock interference.

What to review

Production code (minimal surface area):

  • editorConfigs.tsDetectionEnv type, createDetectionEnv() factory, all 13 detect functions updated to accept the env parameter, doc URLs added for every editor config path
  • detectAvailableEditors.ts — accepts optional DetectionEnv, passes it through to each config.detect(ctx) call
  • knip.config.ts — removed ignoreBinaries (no longer needed since execa calls go through the execCommand abstraction)

Test code (bulk of the diff):

  • editorConfigs.test.ts — 44 new unit tests covering all 13 detect functions with isolated DetectionEnv contexts, including the exact Cline/VS Code collision case
  • configure.test.ts — replaced 21 hand-written per-editor integration tests with a table-driven approach (1,411 → 820 lines). Behavioral edge-case tests (token reuse, auth expiry, config merging, etc.) are unchanged.

Testing

  • 44 new unit tests for detect functions (each using isolated DetectionEnv — no global mock collisions)
  • Table-driven integration tests covering all 13 editors + MCPorter file-format variants
  • 12 behavioral edge-case tests preserved unchanged
  • All 172 affected tests pass locally (macOS), all 43 CI checks pass (Ubuntu + Windows, Node 20/22/24)
  • Type check, lint, dep check, and build all clean

Add detection for 5 new editors (Antigravity, Cline CLI, Codex CLI,
GitHub Copilot CLI, MCPorter) and refactor the detection architecture
to eliminate test fragility caused by global mock collisions.

Production changes:
- Introduce DetectionEnv interface so each detect function receives its
  dependencies (existsSync, execCommand, platform, homedir, env) instead
  of importing them at module level
- Update detectAvailableEditors() to create and pass the environment
- Add documentation URLs for every editor config path as inline comments
- Use defaults-with-overrides pattern to reduce duplication in EDITOR_CONFIGS

Test improvements:
- Add 44 focused unit tests for all 13 detect functions using isolated
  DetectionEnv contexts (no global mock collisions possible)
- Replace 21 hand-written per-editor integration tests with a table-driven
  approach, reducing configure.test.ts from 1411 to 820 lines
- Cross-platform path normalization in assertions for Windows CI stability
@drewlyton drewlyton requested a review from a team as a code owner April 15, 2026 19:42
@drewlyton drewlyton requested review from cngonzalez and removed request for a team April 15, 2026 19:42
@claude
Copy link
Copy Markdown

claude Bot commented Apr 15, 2026

Claude finished @drewlyton's task in 3m 27s —— View job


PR Review

  • Read CLAUDE.md for repo guidelines
  • Review changed files
  • Check changeset
  • Post review findings

Changeset

The summary is two sentences; the second describes an implementation detail rather than user-facing behavior. Per Sanity product copy conventions it should be one concise sentence for a developer audience.

Current:

Added MCP auto-configuration support for Antigravity, Cline CLI, Codex CLI, GitHub Copilot CLI, and MCPorter. Refactored editor detection to use dependency injection for improved testability and cross-platform reliability.

Suggested:

Added MCP auto-configuration support for Antigravity, Cline CLI, Codex CLI, GitHub Copilot CLI, and MCPorter.

Fix this →


detectGeminiCli — behavioral narrowing

editorConfigs.ts:128-130

The old detection checked whether ~/.gemini/ directory existed, then returned ~/.gemini/settings.json as the target path (creating it if absent). The new code checks whether ~/.gemini/settings.json already exists:

// Before: directory presence → create or update settings.json
const geminiDir = path.join(homeDir, '.gemini')
return existsSync(geminiDir) ? path.join(geminiDir, 'settings.json') : null

// After: file must already exist
const settingsPath = path.join(ctx.homedir, '.gemini/settings.json')
return ctx.existsSync(settingsPath) ? settingsPath : null

This fixes the Antigravity false-positive (documented in the comment), but it also means a fresh Gemini CLI install where settings.json doesn't exist yet will not be auto-detected. The old behavior would have created the file; the new behavior silently skips the editor. If Gemini CLI creates settings.json on first run this is fine in practice — but it's a silent detection regression worth confirming is intentional.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 15, 2026

📦 Bundle Stats — @sanity/cli

Compared against main (5a7dcbe7)

@sanity/cli

Metric Value vs main (5a7dcbe)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 10.94 MB -
Bundled (gzip) 2.05 MB -
Import time 842ms +4ms, +0.5%

bin:sanity

Metric Value vs main (5a7dcbe)
Internal (raw) 975 B -
Internal (gzip) 460 B -
Bundled (raw) 9.84 MB -
Bundled (gzip) 1.77 MB -
Import time 2.02s +8ms, +0.4%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against main (5a7dcbe7)

Metric Value vs main (5a7dcbe)
Internal (raw) 93.8 KB -
Internal (gzip) 21.9 KB -
Bundled (raw) 21.62 MB -
Bundled (gzip) 3.42 MB -
Import time 801ms +4ms, +0.5%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — create-sanity

Compared against main (5a7dcbe7)

Metric Value vs main (5a7dcbe)
Internal (raw) 976 B -
Internal (gzip) 507 B -
Bundled (raw) 50.7 KB -
Bundled (gzip) 12.6 KB -
Import time ❌ ChildProcess denied: node -
Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@drewlyton drewlyton requested review from jwoods02 and mwritter April 15, 2026 19:46
@github-actions
Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli/src/actions/mcp/detectAvailableEditors.ts 82.5% (+ 0.5%)
packages/@sanity/cli/src/actions/mcp/editorConfigs.ts 98.7% (+ 23.0%)
packages/@sanity/cli/src/commands/mcp/configure.ts 90.0% (±0%)

Comparing 3 changed files against main @ 5a7dcbe708e5f8cfa922461c64e2c5d873668bad

Overall Coverage

Metric Coverage
Statements 83.2% (+ 0.2%)
Branches 73.3% (+ 0.3%)
Functions 83.0% (+ 0.1%)
Lines 83.6% (+ 0.2%)

@drewlyton drewlyton merged commit 6045f96 into main Apr 17, 2026
44 checks passed
@drewlyton drewlyton deleted the feat/mcp-editor-detection-refactor branch April 17, 2026 15:56
@squiggler-app squiggler-app Bot mentioned this pull request Apr 17, 2026
@mwritter mwritter restored the feat/mcp-editor-detection-refactor branch April 20, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants