Skip to content

Commit 53c4bf6

Browse files
tom-at-alignclaude
andauthored
fix(mcp): write a command Windows can actually spawn (ALI-1135) (#314)
* fix(mcp): write a command Windows can actually spawn (ALI-1135) `align mcp --setup` wrote `"command": "align"` on every platform. An npm global install on Windows exposes `align.cmd`, a batch shim, and a Windows process spawn resolves a `.cmd` only through a shell - Node's own child_process refuses one outright without `shell: true` since CVE-2024-27980. So the entry named something the client cannot launch, and it failed on OUR side, silently: our write succeeded, so nothing here had an error to report, and the user saw an ENOENT from a config Align wrote for them. That is the first ten minutes after the Kentico demo, whose engineers are on Windows with Copilot in VS Code. On win32 the entry is now `cmd /c align mcp`. `cmd` is a real executable, so it launches whether or not the client spawns through a shell of its own, and cmd resolves `align` -> `align.cmd` via PATH + PATHEXT. That is the form the MCP ecosystem settled on (microsoft/vscode#299595, modelcontextprotocol/servers#3460), and the form this repo's own Windows smoke already relies on. The reported site was VS Code; it was a lower bound. Every writer of this fact is fixed through one `alignSpawn()`: - `alignServerEntry` - vscode, zed, pi, copilot and the mcpServers default, which covers Claude Desktop, Claude Code, Cursor, Windsurf and Gemini CLI - `codexBlock` - the Codex TOML, which built its own `command = "align"` line and would have been left broken by a fix to the JSON half alone - the two hand-over strings a HUMAN pastes: `align mcp --setup` with nothing detected, and `connectDetectedAgents`' no-global-config message - `align mcp --help`'s config snippet One deliberate exception, `alignServerEntry(..., { committed: true })`: the project-local `.mcp.json` stays on the bare form everywhere. It is committed and read by the whole team, and no single string spawns on both platforms, so a Windows machine wrapping it would commit a config that fails for every macOS and Linux checkout. Windows readers get the wrapper from their per-machine config instead. Pinned by a test over all three platforms. The Windows install-smoke leg could not have caught this: `align mcp --setup` writes no config there (the synthetic HOME means detectEditors finds nothing, so only the exit code is exercised), and the handshake step spawns through a shell on win32, which is exactly what VS Code does not do. `smoke-mcp-config-spawn.mjs` now drives the WRITE through the installed package and spawns what it wrote with `shell: false`, with a negative control so a clean pass cannot be a harness that sees nothing. Unverified: nobody has run this on a real Windows desktop. The mechanism is documented and the repo already carried the platform branch in its own smoke, and the new smoke step is what turns that into evidence on every PR. ## Test plan RED first, `src/__tests__/mcp-setup-windows.test.ts` against unmodified `main`, `process.platform` stubbed to win32 rather than inherited: ``` Tests 10 failed | 3 passed (13) AssertionError: expected 'align' not to be 'align' // Object.is equality (all five JSON formats) AssertionError: expected '# >>> align (managed by `align setup`...' to contain 'command = "cmd"' (the Codex TOML block) ``` The 3 that passed are the POSIX side, which must not move. Controls, because a green suite proves nothing about a branch it never took: - disabling the win32 branch in `alignSpawn` reddens 11 tests across the two new suites, including the pasted-config one - flipping `pinPlatform('linux')` to win32 in `mcp-setup.test.ts` reddens 9, so the pin is load-bearing rather than decoration - injecting an unspawnable command into the built writer makes the new smoke script exit 1 with "the config align just wrote is NOT spawnable on linux", and its own negative control fires first Gates, all of the `test` job's, on Linux: - [x] `npm run typecheck` - 0 - [x] `npm run lint` - 0 - [x] `npm run test:coverage` - 213 files, 2490 passed, 3 skipped, thresholds met - [x] `npm run build` - 0 - [x] `scripts/__tests__/test-smoke-timeout.sh` - all passed - [x] `scripts/__tests__/test-smoke-model.sh` - all passed - [x] `scripts/__tests__/test-install-assets.sh` - all passed - [x] `scripts/__tests__/test-check-test-runners.sh` - all passed - [x] `scripts/check-test-runners.sh` - 0 - [x] `scripts/smoke-mcp-config-spawn.mjs` run by hand against the built package in an isolated HOME: green on the real config, red on an injected bad one Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * test(mcp): probe whether a bare `align` really fails to spawn on Windows (ALI-1135) TEMPORARY, reverted in the next commit. The ticket's first task is to reproduce rather than to fix: nobody had run the old config on a real Windows machine, so the premise was documented upstream and unmeasured here. This asserts the defect, so a PASS on the windows-latest install-smoke leg IS the reproduction, and a PASS on the ubuntu legs is the control that POSIX was never affected. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * test(mcp): revert the Windows reproduction probe, keeping what it measured (ALI-1135) The probe did its job on the previous commit's CI run: windows-latest, node 24: PROBE: the OLD form (command:"align", shell:false) on win32: spawned=false ENOENT spawn align ENOENT ubuntu-latest, node 24: PROBE: the OLD form (command:"align", shell:false) on linux: spawned=true So the premise ALI-1135 called plausible and unconfirmed is now measured: a bare `align` cannot be spawned on Windows without a shell, and POSIX is unaffected. The error is the one a VS Code user sees against a file Align wrote for them. It is reverted rather than kept, because an assertion that a bare `align` FAILS would go red the day npm ships a real executable, and that would be good news. The numbers move into the script's docblock, where the next reader looks. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * test(smoke): derive the node --check list from scripts/ instead of listing it (ALI-1135) Copilot, low: smoke-mcp-config-spawn.mjs was added, wired into CI, and left out of NODE_HELPERS, so the parse gate did not cover it. Correct, and the miss is the point: a hand-written list one entry short goes red nowhere, which is the exact failure this suite exists to prevent, one level up. Reading scripts/ covers the next helper on arrival. The count is asserted first, so a glob that matched nothing cannot make every parse assertion vacuous. Proven by injection: an unbalanced brace appended to smoke-mcp-config-spawn.mjs reddens that file's case (1 failed | 7 passed) and nothing else; reverting restores 8 passed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(setup): stop telling a Windows user the project .mcp.json is enough (ALI-1135) Copilot, high, on #314: the portable project file is the one a Windows client cannot spawn, and `align setup` told that user "Claude Code and pi already read the project's .mcp.json, so those need nothing further". On Windows that sentence is the defect this PR fixes, restated in prose - and this branch is the only thing a user with no global agent config is ever told. The suggested fix - wrap the project entry too - is declined, and the concern it comes from is not. That file is committed: a Windows machine writing `cmd /c` into it ships a config that fails for every macOS and Linux checkout, trading a local problem for a team-wide one. What was actually wrong is the claim about it, so the claim is now platform-aware, in the command and in docs/mcp.md. Proven by injection: forcing the POSIX wording reddens the Windows case alone (1 failed | 19 passed); reverting restores 20. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent af6176f commit 53c4bf6

16 files changed

Lines changed: 572 additions & 41 deletions

‎docs/mcp.md‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ and there is a section for them below.
3333
`align mcp --setup` offers each of these and writes the ones you select. Here they are if you
3434
would rather do it by hand.
3535

36+
**Every block below is the macOS and Linux form. On Windows, replace**
37+
`"command": "align", "args": ["mcp"]` **with** `"command": "cmd", "args": ["/c", "align", "mcp"]`,
38+
keeping any other fields as they are. An npm global install exposes `align.cmd`, a batch shim,
39+
and a Windows process spawn resolves a `.cmd` only through a shell - so a bare `align` is not
40+
launchable by a client that spawns without one, which most do not. `align mcp --setup` already
41+
writes the wrapped form on Windows; this is only for the files you edit yourself.
42+
43+
One file is deliberately left on the bare form on every platform: the project-local `.mcp.json`
44+
that `align setup` writes, because it is committed and read by the whole team, and there is no
45+
one string that spawns on both platforms. A Windows machine that wrapped it would commit a
46+
config that fails for every macOS and Linux checkout.
47+
48+
**So on Windows that file is not enough by itself.** Claude Code and pi read it, and neither can
49+
spawn the bare `align` it contains, so run `align mcp --setup` as well - the per-machine entry it
50+
writes is wrapped. `align setup` says so on Windows when it finds no global agent config.
51+
3652
**Claude Desktop** - `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
3753
or `~/.config/Claude/claude_desktop_config.json` (Linux):
3854

@@ -87,21 +103,18 @@ Run `align mcp --setup --env local` instead and the args are `["mcp", "--env", "
87103
Reload the VS Code window afterwards, then open Copilot Chat in agent mode and look for
88104
`align` in its tools picker.
89105

90-
**On Windows the server may not start with `command: "align"`.** An npm global install puts
91-
`align.cmd` on your `PATH`, and a Windows process spawn resolves a `.cmd` only through a shell,
92-
so a client that spawns without one gets `ENOENT`. This repo already meets that in its own MCP
93-
handshake smoke, which passes `shell: true` on win32 (`scripts/smoke-mcp-handshake.mjs`).
94-
`align mcp --setup` writes `"command": "align"` on every platform. If VS Code reports that the
95-
align server failed to start on Windows, change that one value:
106+
**On Windows the entry is wrapped, and `align mcp --setup` writes it that way for you**
107+
(ALI-1135). An npm global install puts `align.cmd` on your `PATH`, and a Windows process spawn
108+
resolves a `.cmd` only through a shell, so `"command": "align"` names something VS Code cannot
109+
launch and you get `ENOENT` against a file Align wrote. `cmd` is a real executable, so this
110+
starts whether or not the client uses a shell of its own:
96111

97112
```json
98-
{ "servers": { "align": { "type": "stdio", "command": "align.cmd", "args": ["mcp"] } } }
113+
{ "servers": { "align": { "type": "stdio", "command": "cmd", "args": ["/c", "align", "mcp"] } } }
99114
```
100115

101-
Not verified against a Windows VS Code, and written down anyway because the failure is silent
102-
from this side: nothing the CLI can see tells you a client never launched it. Teaching the
103-
writer to emit `align.cmd` on win32 is a follow-up, and it is a code change rather than a
104-
documentation one.
116+
That is what `align mcp --setup` now writes on Windows, for every client it wires - see the
117+
Windows note under [Manual configuration](#manual-configuration) if you are pasting by hand.
105118

106119
**What Copilot gets, and what it does not.** Copilot Chat can call every tool in the table
107120
above, and it reads the managed block `align setup` writes into `CLAUDE.md` and `AGENTS.md`.

‎scripts/smoke-install.sh‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ step "align mcp --setup" 60 align mcp --setup --env local
387387
# Windows, and cmd resolves `align` -> align.cmd via PATH + PATHEXT, while the
388388
# full POSIX-style path to the sh shim is unrunnable there.
389389
step "MCP handshake" 60 node "$SCRIPT_DIR/smoke-mcp-handshake.mjs" align
390+
# ALI-1135. The two steps above cannot see a config that names an unspawnable command.
391+
# `align mcp --setup` writes NOTHING here - the synthetic HOME above means detectEditors()
392+
# finds no editor, so only its exit code is exercised - and the handshake spawns through a
393+
# shell on Windows, which is exactly what a client like VS Code does not do. This drives the
394+
# WRITE through the installed package and then spawns what it wrote with shell:false.
395+
step "MCP config spawns as written" 60 node "$SCRIPT_DIR/smoke-mcp-config-spawn.mjs" "$CLI_PKG"
390396

391397
rm -f "$TARBALL"
392398

‎scripts/smoke-mcp-config-spawn.mjs‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/usr/bin/env node
2+
/**
3+
* ALI-1135: what `align mcp --setup` WRITES must be spawnable by a client that does not use a
4+
* shell. `node smoke-mcp-config-spawn.mjs <installed-cli-package-dir>`.
5+
*
6+
* The install smoke already asserts that `align mcp --setup` exits 0, and that a bare `align`
7+
* completes an MCP handshake when spawned THROUGH a shell. Neither of those can see this
8+
* defect. The setup step writes no config at all on CI, because the harness exports a synthetic
9+
* HOME and detectEditors() then finds no editor; and the handshake step passes
10+
* `shell: process.platform === 'win32'`, which is precisely the thing VS Code does not do.
11+
*
12+
* So this drives the write itself, through the INSTALLED package's own writer, and then spawns
13+
* exactly what landed in the file with `shell: false` - the way a client spawns it. On Windows
14+
* an npm global install exposes `align.cmd`, which no shell-less spawn can launch, so a config
15+
* naming a bare `align` fails here and a `cmd /c align` one does not.
16+
*
17+
* MEASURED, rather than assumed. A temporary probe on this branch spawned the OLD form
18+
* (`command: "align"`, shell:false) on both legs of this matrix:
19+
* windows-latest -> spawned=false, `spawn align ENOENT` (the defect, reproduced)
20+
* ubuntu-latest -> spawned=true (the control: POSIX unaffected)
21+
* It was reverted rather than kept, because a permanent assertion that a bare `align` FAILS
22+
* would go red the day npm ships a real executable, which would be good news.
23+
*
24+
* Exit codes: 0 on a config that spawns and answers `initialize`; 1 on a bad config, a spawn
25+
* failure or a protocol failure; 2 on usage; 124 on timeout.
26+
*/
27+
import { spawn } from 'node:child_process';
28+
import { existsSync, mkdtempSync, readFileSync } from 'node:fs';
29+
import { tmpdir } from 'node:os';
30+
import path from 'node:path';
31+
import { pathToFileURL } from 'node:url';
32+
33+
const pkgDir = process.argv[2];
34+
if (!pkgDir) {
35+
console.error('usage: smoke-mcp-config-spawn.mjs <installed-cli-package-dir>');
36+
process.exit(2);
37+
}
38+
39+
// A missing subject passes any assertion below for the wrong reason, so it is fatal rather
40+
// than a failure (tdd.md, "make a missing subject FATAL, not a test").
41+
const writerPath = path.join(pkgDir, 'dist', 'lib', 'mcp-setup.js');
42+
if (!existsSync(writerPath)) {
43+
console.error(`FATAL: ${writerPath} does not exist - the installed package has no MCP writer to drive`);
44+
process.exit(2);
45+
}
46+
47+
const TIMEOUT_MS = 30_000;
48+
const fail = (msg) => { console.error(`smoke-mcp-config-spawn: ${msg}`); process.exit(1); };
49+
50+
/** Can this harness SEE an unspawnable command? If not, its pass below means nothing. */
51+
function negativeControl() {
52+
return new Promise((resolve) => {
53+
const bogus = spawn('align-no-such-binary-ali1135', ['mcp'], { stdio: 'ignore', shell: false });
54+
bogus.on('error', () => resolve(true));
55+
bogus.on('spawn', () => { bogus.kill(); resolve(false); });
56+
});
57+
}
58+
59+
const { writeMcpConfig } = await import(pathToFileURL(writerPath).href);
60+
61+
if (!(await negativeControl())) {
62+
fail('negative control did not fire: a command that cannot exist spawned anyway, so a clean pass here proves nothing');
63+
}
64+
console.log('smoke-mcp-config-spawn: negative control OK - an unspawnable command is detected');
65+
66+
const dir = mkdtempSync(path.join(tmpdir(), 'align-mcp-cfg-'));
67+
const configPath = path.join(dir, 'mcp.json');
68+
writeMcpConfig({ name: 'VS Code', configPath, format: 'vscode' }, 'local');
69+
70+
const entry = JSON.parse(readFileSync(configPath, 'utf8')).servers?.align;
71+
if (!entry) fail(`no servers.align entry in the config that was just written (${configPath})`);
72+
console.log(`smoke-mcp-config-spawn: wrote ${JSON.stringify(entry)}`);
73+
74+
// The command has to be spawnable AND still run our server. A config that spawns something
75+
// else would satisfy the handshake-free half of this check and ship a broken setup.
76+
const argv = [entry.command, ...(entry.args ?? [])].join(' ');
77+
if (!argv.includes('align') || !argv.includes('mcp')) fail(`the written entry does not invoke align mcp: ${argv}`);
78+
79+
const child = spawn(entry.command, entry.args, { stdio: ['pipe', 'pipe', 'inherit'], shell: false });
80+
81+
let timedOut = false;
82+
const timer = setTimeout(() => {
83+
timedOut = true;
84+
console.error(`smoke-mcp-config-spawn: no initialize response within ${TIMEOUT_MS / 1000}s`);
85+
child.kill('SIGKILL');
86+
setTimeout(() => process.exit(124), 2000).unref();
87+
}, TIMEOUT_MS);
88+
89+
let done = false;
90+
function finish(code) {
91+
if (done) return;
92+
done = true;
93+
clearTimeout(timer);
94+
try { child.kill(); } catch { /* already gone */ }
95+
process.exit(code);
96+
}
97+
98+
child.on('error', (err) => {
99+
console.error(
100+
`smoke-mcp-config-spawn: the config align just wrote is NOT spawnable on ${process.platform}: ` +
101+
`spawn ${entry.command} failed with ${err.message}`,
102+
);
103+
finish(1);
104+
});
105+
106+
child.on('exit', (code) => {
107+
if (timedOut) finish(124);
108+
else if (!done) { console.error(`smoke-mcp-config-spawn: server exited early (code ${code})`); finish(1); }
109+
});
110+
111+
let buffer = '';
112+
child.stdout.on('data', (chunk) => {
113+
buffer += chunk.toString();
114+
let idx;
115+
while ((idx = buffer.indexOf('\n')) !== -1) {
116+
const line = buffer.slice(0, idx).trim();
117+
buffer = buffer.slice(idx + 1);
118+
if (!line) continue;
119+
let msg;
120+
try {
121+
msg = JSON.parse(line);
122+
} catch {
123+
console.error(`smoke-mcp-config-spawn: non-JSON on stdout: ${line.slice(0, 200)}`);
124+
finish(1);
125+
return;
126+
}
127+
if (msg.id === 1) {
128+
if (!msg.result) { console.error(`smoke-mcp-config-spawn: initialize returned no result: ${line.slice(0, 200)}`); finish(1); return; }
129+
console.log(`smoke-mcp-config-spawn: OK - the written config spawned without a shell and answered initialize on ${process.platform}`);
130+
finish(0);
131+
}
132+
}
133+
});
134+
135+
child.stdin.write(`${JSON.stringify({
136+
jsonrpc: '2.0',
137+
id: 1,
138+
method: 'initialize',
139+
params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'align-config-spawn-smoke', version: '0.0.0' } },
140+
})}\n`);

‎src/__tests__/agent-rules.test.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
22
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
33
import { join } from 'node:path';
44
import { tmpdir } from 'node:os';
5+
import { type Platform, restorePlatform, setPlatform } from './helpers/platform.js';
56
import {
67
ALIGN_NUDGE_END,
78
ALIGN_NUDGE_START,
@@ -233,11 +234,23 @@ describe('writeCursorRule', () => {
233234
});
234235

235236
describe('writeProjectMcpConfig', () => {
236-
it('writes .mcp.json with the align stdio server', () => {
237-
writeProjectMcpConfig(dir);
238-
const cfg = readJson('.mcp.json');
239-
expect(cfg.mcpServers.align).toEqual({ command: 'align', args: ['mcp'] });
240-
});
237+
// Both platforms are stated rather than inherited (ALI-1135): what this writer emits is now
238+
// platform-conditional everywhere EXCEPT here, and a test that took the runner's platform
239+
// could not tell the exception from the rule.
240+
afterEach(restorePlatform);
241+
242+
it.each(['linux', 'darwin', 'win32'] as Platform[])(
243+
'writes .mcp.json with the align stdio server, portable on %s',
244+
(platform) => {
245+
setPlatform(platform);
246+
writeProjectMcpConfig(dir);
247+
const cfg = readJson('.mcp.json');
248+
// No `cmd /c` wrapper even on Windows: this file is committed and read by the whole
249+
// team, so a Windows-only command here breaks every other checkout. The Windows
250+
// machine's own wrapper lives in its user-level config, which mcp-setup.ts writes.
251+
expect(cfg.mcpServers.align).toEqual({ command: 'align', args: ['mcp'] });
252+
},
253+
);
241254

242255
// .mcp.json is the SHARED, committed file that pi, Claude Code and others all read,
243256
// so it must stay host-neutral. pi's directTools belongs in the pi-owned override

‎src/__tests__/connect-agents.test.ts‎

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { beforeEach, describe, expect, it, vi } from 'vitest';
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2+
import type * as McpSetup from '../lib/mcp-setup.js';
23

34
const detectEditors = vi.hoisted(() => vi.fn());
45
const writeMcpConfig = vi.hoisted(() => vi.fn());
5-
vi.mock('../lib/mcp-setup.js', () => ({ detectEditors, writeMcpConfig }));
6+
// alignServerEntry is the REAL one (ALI-1135): the hand-over message below is built from it,
7+
// and a stub would make the platform assertions at the bottom of this file about the stub.
8+
vi.mock('../lib/mcp-setup.js', async (importOriginal) => ({
9+
...(await importOriginal<typeof McpSetup>()),
10+
detectEditors,
11+
writeMcpConfig,
12+
}));
613

714
const confirm = vi.hoisted(() => vi.fn());
815
const logged: string[] = [];
@@ -17,6 +24,7 @@ vi.mock('@clack/prompts', () => ({
1724
}));
1825

1926
import { connectDetectedAgents } from '../commands/connect-agents.js';
27+
import { restorePlatform, setPlatform } from './helpers/platform.js';
2028

2129
const CLAUDE = { name: 'Claude Desktop', configPath: '/home/d/.config/Claude/x.json', format: 'mcpServers' };
2230
const CURSOR = { name: 'Cursor', configPath: '/home/d/.cursor/mcp.json', format: 'mcpServers' };
@@ -147,7 +155,11 @@ describe("connectDetectedAgents - the zero-editors message", () => {
147155
logged.length = 0;
148156
detectEditors.mockReset();
149157
writeMcpConfig.mockReset();
158+
// Stated, not inherited: the sentence about .mcp.json is platform-conditional since
159+
// ALI-1135, and this suite is about the POSIX wording.
160+
setPlatform('linux');
150161
});
162+
afterEach(restorePlatform);
151163

152164
it("does not say NOTHING was detected, since .mcp.json already covers project-scoped agents", () => {
153165
// David, 2026-08-31: he was in an active Claude Code session - .claude/settings.json
@@ -229,3 +241,66 @@ describe('connectDetectedAgents names what it wired (ALI-950)', () => {
229241
expect(r.wired).toEqual([]);
230242
});
231243
});
244+
245+
/**
246+
* ALI-1135: this message is a config the user pastes BY HAND, into a file we could not write.
247+
* A bare `"command": "align"` is the align.cmd shim on Windows, which no client that spawns
248+
* without a shell can launch - and here there is no writer left to correct it afterwards.
249+
*
250+
* Both platforms are set explicitly. Inheriting the runner's would assert one branch and
251+
* report a pass for both.
252+
*/
253+
describe('connectDetectedAgents - the hand-over config is spawnable on the reader\'s platform', () => {
254+
beforeEach(() => {
255+
logged.length = 0;
256+
detectEditors.mockReset().mockReturnValue([]);
257+
writeMcpConfig.mockReset();
258+
});
259+
afterEach(restorePlatform);
260+
261+
it('wraps the command for a Windows reader', async () => {
262+
setPlatform('win32');
263+
await connectDetectedAgents('local');
264+
const all = logged.join('\n');
265+
expect(all).toContain('"command":"cmd"');
266+
expect(all).toContain('"/c","align","mcp","--env","local"');
267+
});
268+
269+
it('leaves it bare for a macOS or Linux reader', async () => {
270+
setPlatform('linux');
271+
await connectDetectedAgents('local');
272+
const all = logged.join('\n');
273+
expect(all).toContain('"command":"align"');
274+
expect(all).not.toContain('cmd');
275+
});
276+
});
277+
278+
/**
279+
* ALI-1135, Copilot #314: the message above told a Windows user that `.mcp.json` covers Claude
280+
* Code and pi. It does not. That file is committed, so it keeps the portable bare `align` -
281+
* the one command a Windows client cannot spawn - and this branch is the only thing a user
282+
* with no global agent config is ever told.
283+
*/
284+
describe('connectDetectedAgents - what it claims .mcp.json covers', () => {
285+
beforeEach(() => {
286+
logged.length = 0;
287+
detectEditors.mockReset().mockReturnValue([]);
288+
writeMcpConfig.mockReset();
289+
});
290+
afterEach(restorePlatform);
291+
292+
it('does not tell a Windows user that the project file is enough', async () => {
293+
setPlatform('win32');
294+
await connectDetectedAgents('local');
295+
const all = logged.join('\n');
296+
expect(all).not.toContain('need nothing further');
297+
expect(all).toMatch(/Windows cannot spawn/i);
298+
expect(all).toMatch(/claude code and pi need the per-machine entry/i);
299+
});
300+
301+
it('still says the project file covers them on macOS and Linux, where it does', async () => {
302+
setPlatform('darwin');
303+
await connectDetectedAgents('local');
304+
expect(logged.join('\n')).toContain('need nothing further');
305+
});
306+
});

‎src/__tests__/helpers/platform.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Pin `process.platform` for a suite, and put it back afterwards.
3+
*
4+
* ALI-1135 made what `align mcp --setup` writes depend on the platform: on Windows an npm
5+
* global install exposes `align.cmd`, which a client cannot spawn without a shell, so the
6+
* entry goes through `cmd /c`. Every assertion on that entry is therefore conditional
7+
* behaviour, and a test that inherits the runner's platform is only testing one side of it -
8+
* green on Linux, red on this repo's Windows leg, having established nothing either way
9+
* (tdd.md, "a test must establish its own preconditions").
10+
*
11+
* One helper rather than a copy of the same three lines per suite: the restore is the part
12+
* that is easy to get wrong, and a suite that forgets it leaks the stub into every file
13+
* vitest runs after it in the same worker.
14+
*/
15+
import { afterAll, beforeEach } from 'vitest';
16+
17+
/** The set `process.platform` can hold, without naming the NodeJS global (eslint: no-undef). */
18+
export type Platform = typeof process.platform;
19+
20+
const REAL = Object.getOwnPropertyDescriptor(process, 'platform')!;
21+
22+
/** Set the platform for the next assertion. Call inside a test or a beforeEach. */
23+
export function setPlatform(value: Platform): void {
24+
Object.defineProperty(process, 'platform', { value, configurable: true });
25+
}
26+
27+
/** Restore whatever this process really runs on. */
28+
export function restorePlatform(): void {
29+
Object.defineProperty(process, 'platform', REAL);
30+
}
31+
32+
/**
33+
* Pin one platform for every test in the calling file. Registers its own restore, so the
34+
* suite cannot leave the stub behind.
35+
*/
36+
export function pinPlatform(value: Platform): void {
37+
beforeEach(() => setPlatform(value));
38+
afterAll(restorePlatform);
39+
}

0 commit comments

Comments
 (0)