feat(cli): expand MCP editor detection and refactor for testability#960
feat(cli): expand MCP editor detection and refactor for testability#960
Conversation
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
|
Claude finished @drewlyton's task in 3m 27s —— View job PR Review
ChangesetThe 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: Suggested:
|
📦 Bundle Stats —
|
| 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.
Coverage Delta
Comparing 3 changed files against main @ Overall Coverage
|
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
DetectionEnvinterface 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.ts—DetectionEnvtype,createDetectionEnv()factory, all 13 detect functions updated to accept the env parameter, doc URLs added for every editor config pathdetectAvailableEditors.ts— accepts optionalDetectionEnv, passes it through to eachconfig.detect(ctx)callknip.config.ts— removedignoreBinaries(no longer needed sinceexecacalls go through theexecCommandabstraction)Test code (bulk of the diff):
editorConfigs.test.ts— 44 new unit tests covering all 13 detect functions with isolatedDetectionEnvcontexts, including the exact Cline/VS Code collision caseconfigure.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
DetectionEnv— no global mock collisions)