Skip to content

Commit f229547

Browse files
bradygasterclaude
andauthored
fix(claude): repository launcher finds squad on PATH; launcher argv tested on Windows (#2483)
* fix(claude): repository launcher finds squad on PATH; Windows argv test The repo launcher skipped every PATH entry because realpath of its (nonexistent) .squad/bin threw inside the comparison. New test/launcher-argv.test.ts checks hostile argv round-trips through a global squad, npx, SQUAD_CLI and a project install, through .cmd shims on Windows without cmd.exe. A new workflow runs the launcher tests on Windows and Linux. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(claude): launcher tests ignore the developer's recorded CLI ~/.squad/cli.json (since #2470) is found by the launcher, so tests that expect the npx fallback or a missing CLI failed on any machine that had run squad init from a source build. Point SQUAD_HOME at an empty dir. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: avoid a retired term in a test name Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(release): explain the Windows-only launcher-argv skip Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6f5d11a commit f229547

9 files changed

Lines changed: 219 additions & 9 deletions

File tree

‎.changeset/launcher-path-lookup.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@bradygaster/squad-sdk": patch
3+
"@bradygaster/squad-cli": patch
4+
---
5+
6+
The repository launcher `.squad/squad.mjs` now finds a `squad` on PATH. It skipped every PATH entry because it has no `bin` directory of its own, so a repository whose only Squad CLI was a global install failed with "no Squad CLI found". A new test checks that the launcher passes arguments through unchanged, including `&`, `|`, `%VAR%`, quotes and empty strings, on Windows (through npm's `.cmd` shims, never cmd.exe) and Linux.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Squad launcher on Windows and Linux.
2+
#
3+
# `.squad/squad.mjs` and the Claude plugin's `scripts/squad.mjs` take a different path on Windows:
4+
# npm's `squad.cmd` and `npx.cmd` shims are run through their JavaScript entry, never cmd.exe, so
5+
# arguments arrive unchanged. The main CI runs on Linux only, so this job runs the launcher tests on
6+
# both platforms whenever the launcher template or its tests change.
7+
name: Squad launcher platforms
8+
9+
on:
10+
pull_request:
11+
paths:
12+
- 'packages/squad-sdk/src/client/adapters/claude-plugin.ts'
13+
- 'packages/squad-sdk/src/client/adapters/claude-hooks.ts'
14+
- 'packages/squad-cli/src/cli/core/mcp-spec.ts'
15+
- 'plugins/squad/scripts/**'
16+
- 'test/launcher-argv.test.ts'
17+
- 'test/portable-launch.test.ts'
18+
- '.github/workflows/squad-launcher-platforms.yml'
19+
workflow_dispatch:
20+
21+
permissions:
22+
contents: read
23+
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.ref }}
26+
cancel-in-progress: true
27+
28+
jobs:
29+
launcher:
30+
name: launcher (${{ matrix.os }})
31+
runs-on: ${{ matrix.os }}
32+
timeout-minutes: 20
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
os: [ubuntu-latest, windows-latest]
37+
steps:
38+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
39+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 #v6
40+
with:
41+
node-version: 22
42+
cache: 'npm'
43+
- name: Install dependencies
44+
shell: bash
45+
run: |
46+
success=false
47+
for i in 1 2 3; do
48+
if npm install; then success=true; break; fi
49+
echo "Retry $i/3 — npm install failed, retrying in 5s..."; sleep 5
50+
done
51+
[ "$success" = true ] || { echo "::error::npm install failed after 3 attempts"; exit 1; }
52+
- name: Build (no version bump)
53+
shell: bash
54+
run: npm run build
55+
env:
56+
SKIP_BUILD_BUMP: '1'
57+
- name: Launcher tests
58+
shell: bash
59+
run: npx vitest run test/launcher-argv.test.ts test/portable-launch.test.ts --reporter=default

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Claude Code is the first host after GitHub Copilot where Squad uses the host's o
7878
- Claude hooks reach the launcher through `$CLAUDE_PROJECT_DIR`. Standalone bundle installs write `squad state-mcp`. A CLI run through `npx` keeps the exact-version `npx` command.
7979
- `squad doctor` flags machine-specific launch commands and a missing launcher. Run `squad upgrade` once to fix an existing repository.
8080
- `squad init --client claude` tells you to run `claude --agent squad --mcp-config .mcp.json`, not Copilot. With several hosts it gives one line per host (#2453).
81+
- `.squad/squad.mjs` finds a `squad` on PATH. It used to skip every PATH entry, so a repository with only a global Squad CLI failed with "no Squad CLI found". Arguments reach the CLI unchanged on Windows (through npm's `.cmd` shims, never cmd.exe) and Linux, and a new CI job runs the launcher tests on both.
8182

8283
## [2.0.0-preview.4] - 2026-11-09
8384

‎packages/squad-sdk/src/client/adapters/claude-plugin.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,14 @@ function recentEnough(entry, version) {
238238
239239
function onPath(name) {
240240
const exts = win ? (process.env.PATHEXT || '.EXE;.CMD;.BAT').split(';') : [''];
241+
// The repository launcher has no bin directory of its own; only skip one that exists.
242+
let self;
243+
try { self = canonical(ownBin); } catch { self = undefined; }
241244
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
242245
if (!dir) continue;
243-
try {
244-
if (canonical(dir) === canonical(ownBin)) continue;
245-
} catch { continue; }
246+
let here;
247+
try { here = canonical(dir); } catch { continue; }
248+
if (here === self) continue;
246249
for (const ext of exts) {
247250
const file = path.join(dir, name + ext);
248251
try {

‎plugins/squad/scripts/squad.mjs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,14 @@ function recentEnough(entry, version) {
131131

132132
function onPath(name) {
133133
const exts = win ? (process.env.PATHEXT || '.EXE;.CMD;.BAT').split(';') : [''];
134+
// The repository launcher has no bin directory of its own; only skip one that exists.
135+
let self;
136+
try { self = canonical(ownBin); } catch { self = undefined; }
134137
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
135138
if (!dir) continue;
136-
try {
137-
if (canonical(dir) === canonical(ownBin)) continue;
138-
} catch { continue; }
139+
let here;
140+
try { here = canonical(dir); } catch { continue; }
141+
if (here === self) continue;
139142
for (const ext of exts) {
140143
const file = path.join(dir, name + ext);
141144
try {

‎scripts/release/test-reconciliation.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const CATEGORY_RULES = Object.freeze([
4444
{ category: 'env-gated', file: /(claude-agent-sdk|copilot-sdk)-harness\.test\.ts$/, title: /live \(real (Agent|Copilot) SDK\)/, reason: 'SQUAD_REAL_CLI_TESTS=1 not set / execution-harness credentials absent (Anthropic API key or Bedrock/Vertex for Claude; a signed-in Copilot user for Copilot)' },
4545
{ category: 'env-gated', file: /squad-20-host-feature-matrix\.test\.ts$/, reason: 'live host evidence requires the real CLI binaries' },
4646
{ category: 'env-gated', file: /mcp-spec-init\.test\.ts$/, title: /squad\.exe/, reason: 'it.runIf(win32): Windows-only PATH/.exe resolution' },
47+
{ category: 'env-gated', file: /launcher-argv\.test\.ts$/, title: /\.cmd shim has no JavaScript entry/, reason: 'it.runIf(win32): Windows-only npm .cmd shim handling' },
4748
{
4849
category: 'env-gated',
4950
file: 'test/mcp-root-write.test.ts',

‎test/claude-plugin.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,13 @@ describe('Claude plugin: contents', () => {
178178

179179
describe('Claude plugin: launcher', () => {
180180
const launcher = path.join(PLUGIN, 'scripts', 'squad.mjs');
181+
const NO_SQUAD_HOME = path.join(os.tmpdir(), 'squad-plugin-test-no-home');
181182

182183
function run(env: Record<string, string>, cwd: string) {
183184
return spawnSync(process.execPath, [launcher, 'one', 'two words'], {
184185
cwd,
185-
env: { PATH: process.env.PATH ?? '', ...env },
186+
// An empty Squad home: the CLI recorded on the developer's machine must not be found.
187+
env: { PATH: process.env.PATH ?? '', SQUAD_HOME: NO_SQUAD_HOME, ...env },
186188
encoding: 'utf8',
187189
});
188190
}

‎test/claude-projection-v3-plugin.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ describe('Claude projection v3: plugin mode install', () => {
328328
fs.chmodSync(abs('fallback/npx'), 0o755);
329329
const result = spawnSync(process.execPath, [launcher, 'status'], {
330330
cwd: root, encoding: 'utf8', timeout: 3000,
331-
env: { PATH: `${abs('linked-bin')}:${abs('fallback')}:/usr/bin:/bin`, CLAUDE_PROJECT_DIR: root, SQUAD_ALLOW_NPX: '1' },
331+
env: { PATH: `${abs('linked-bin')}:${abs('fallback')}:/usr/bin:/bin`, CLAUDE_PROJECT_DIR: root, SQUAD_ALLOW_NPX: '1', SQUAD_HOME: abs('no-squad-home') },
332332
});
333333
expect(result.status, result.stderr).toBe(0);
334334
expect(result.stdout).toBe('fallback');
@@ -345,7 +345,7 @@ describe('Claude projection v3: plugin mode install', () => {
345345
write('global/node_modules/@bradygaster/squad-cli/dist/cli-entry.js', 'console.log(JSON.stringify(process.argv.slice(2)))');
346346
const args = ['two words', 'literal&token', 'literal"quote'];
347347
const run = () => spawnSync(process.execPath, [abs('scripts/squad.mjs'), ...args], {
348-
cwd: root, encoding: 'utf8', env: { PATH: abs('global'), PATHEXT: '.CMD', CLAUDE_PROJECT_DIR: abs('project'), SQUAD_ALLOW_NPX: '1' },
348+
cwd: root, encoding: 'utf8', env: { PATH: abs('global'), PATHEXT: '.CMD', CLAUDE_PROJECT_DIR: abs('project'), SQUAD_ALLOW_NPX: '1', SQUAD_HOME: abs('no-squad-home') },
349349
});
350350
const global = run();
351351
expect(global.status, global.stderr).toBe(0);

‎test/launcher-argv.test.ts‎

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/**
2+
* The Squad launcher (`.squad/squad.mjs`, and the plugin's `scripts/squad.mjs`, built from the
3+
* same template) passes argv to the CLI byte for byte, on every platform (#2469).
4+
*
5+
* On Windows, npm installs `squad` and `npx` as `.cmd` shims. Running a shim means going through
6+
* cmd.exe, which rewrites `&`, `|`, `%VAR%`, `^` and quotes. The launcher must instead run the
7+
* shim's JavaScript entry with Node, with no shell. These tests put fake shims on PATH that would
8+
* print `SHELL-USED` if cmd.exe ever ran them, and check every argument arrives unchanged.
9+
*
10+
* CI runs this file on Windows and Linux (`.github/workflows/squad-launcher-platforms.yml`).
11+
*/
12+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
13+
import fs from 'node:fs';
14+
import os from 'node:os';
15+
import path from 'node:path';
16+
import { spawnSync } from 'node:child_process';
17+
import { squadRepoLauncher } from '@bradygaster/squad-sdk/client';
18+
19+
const win = process.platform === 'win32';
20+
const PKG = ['@bradygaster', 'squad-cli'];
21+
22+
/** Arguments cmd.exe or a shell would rewrite, split or expand. */
23+
const HOSTILE = [
24+
'state-mcp',
25+
'two words',
26+
'quote"inside',
27+
"single'quote",
28+
'&echo pwned',
29+
'pipe|more',
30+
'%PATH%',
31+
'^caret',
32+
'!bang!',
33+
'<in>out',
34+
'$HOME',
35+
'`tick`',
36+
'',
37+
'trailing\\',
38+
'back\\"slash',
39+
'ünïcødé ✓',
40+
];
41+
42+
/** A script that prints its argv as JSON. */
43+
const ECHO = "process.stdout.write(JSON.stringify(process.argv.slice(2)));\n";
44+
45+
let root: string;
46+
let bin: string;
47+
beforeEach(() => {
48+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'squad-launcher-argv-'));
49+
bin = path.join(root, 'fake bin'); // a space in the directory, as in "Program Files"
50+
fs.mkdirSync(bin, { recursive: true });
51+
fs.mkdirSync(path.join(root, '.squad'), { recursive: true });
52+
fs.writeFileSync(path.join(root, '.squad', 'squad.mjs'), squadRepoLauncher('2.0.0', '.squad'));
53+
});
54+
afterEach(() => {
55+
fs.rmSync(root, { recursive: true, force: true });
56+
});
57+
58+
function write(file: string, body: string, mode?: number): void {
59+
fs.mkdirSync(path.dirname(file), { recursive: true });
60+
fs.writeFileSync(file, body);
61+
if (mode !== undefined) fs.chmodSync(file, mode);
62+
}
63+
64+
/** A shim that must never run: under cmd.exe it prints SHELL-USED. */
65+
function cmdShim(name: string): void {
66+
write(path.join(bin, `${name}.cmd`), '@echo SHELL-USED %*\r\n');
67+
}
68+
69+
function run(args: string[], env: Record<string, string> = {}) {
70+
const keep = ['SystemRoot', 'SYSTEMROOT', 'PATHEXT', 'TEMP', 'TMP', 'windir'];
71+
const base = Object.fromEntries(keep.filter((k) => process.env[k]).map((k) => [k, process.env[k] as string]));
72+
return spawnSync(process.execPath, [path.join(root, '.squad', 'squad.mjs'), ...args], {
73+
cwd: os.tmpdir(),
74+
encoding: 'utf8',
75+
env: {
76+
...base,
77+
// The fake bin first, then Node's own directory; no real squad or npx.
78+
PATH: [bin, path.dirname(process.execPath)].join(path.delimiter),
79+
SQUAD_HOME: path.join(root, 'squad-home'),
80+
...env,
81+
},
82+
});
83+
}
84+
85+
function parsed(out: ReturnType<typeof run>): string[] {
86+
expect(out.stderr).toBe('');
87+
expect(out.stdout).not.toContain('SHELL-USED');
88+
expect(out.status).toBe(0);
89+
return JSON.parse(out.stdout);
90+
}
91+
92+
describe('the launcher passes argv through unchanged', () => {
93+
it('to a squad CLI installed on PATH', () => {
94+
if (win) {
95+
cmdShim('squad');
96+
const pkg = path.join(bin, 'node_modules', ...PKG);
97+
write(path.join(pkg, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '2.0.0' }));
98+
write(path.join(pkg, 'dist', 'cli-entry.js'), ECHO);
99+
} else {
100+
write(path.join(bin, 'squad'), `#!/usr/bin/env node\n${ECHO}`, 0o755);
101+
}
102+
expect(parsed(run(HOSTILE))).toEqual(HOSTILE);
103+
});
104+
105+
it('to npx when SQUAD_ALLOW_NPX=1', () => {
106+
if (win) {
107+
cmdShim('npx');
108+
write(path.join(bin, 'node_modules', 'npm', 'bin', 'npx-cli.js'), ECHO);
109+
} else {
110+
write(path.join(bin, 'npx'), `#!/usr/bin/env node\n${ECHO}`, 0o755);
111+
}
112+
expect(parsed(run(HOSTILE, { SQUAD_ALLOW_NPX: '1' }))).toEqual(['-y', `${PKG.join('/')}@2.0.0`, ...HOSTILE]);
113+
});
114+
115+
it('to SQUAD_CLI given as a script', () => {
116+
const entry = path.join(root, 'cli dir', 'cli-entry.js');
117+
write(entry, ECHO);
118+
expect(parsed(run(HOSTILE, { SQUAD_CLI: entry }))).toEqual(HOSTILE);
119+
});
120+
121+
it('to the project\'s own install', () => {
122+
const pkg = path.join(root, 'node_modules', ...PKG);
123+
write(path.join(pkg, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '2.0.0' }));
124+
write(path.join(pkg, 'dist', 'cli-entry.js'), ECHO);
125+
expect(parsed(run(HOSTILE))).toEqual(HOSTILE);
126+
});
127+
128+
it.runIf(win)('fails closed when a .cmd shim has no JavaScript entry beside it', () => {
129+
cmdShim('squad');
130+
const out = run(['state-mcp']);
131+
expect(out.status).toBe(1);
132+
expect(out.stdout).not.toContain('SHELL-USED');
133+
expect(out.stderr).toContain('set SQUAD_CLI to cli-entry.js');
134+
});
135+
});

0 commit comments

Comments
 (0)