Skip to content

Commit 2392c9e

Browse files
cliffhallclaude
andcommitted
fix: pack:verify never deletes an --out directory; node runs the bin on Windows; the audit stops on a failed export
- --out refuses a per-server directory that exists and is not empty, instead of removing it: --out src would have deleted src/<server>. - On Windows the installed package's bin file is handed to node. npm's .cmd shim cannot be spawned without a shell, which the HTTP transports' launch does not use. - The release skill's Python audit exports to a file and stops on a failed or empty export, which pip-audit would otherwise report as clean. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 60a1850 commit 2392c9e

3 files changed

Lines changed: 179 additions & 48 deletions

File tree

‎.claude/skills/release/SKILL.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,18 @@ npm audit --audit-level=high
8282

8383
# Python: each server has its own lockfile. `uv` has no audit of its own in the
8484
# version pinned here, so the locked requirements go through pip-audit.
85+
# Exported to a file first, and stopped on a failed export: piped straight in,
86+
# a failed `uv export` hands pip-audit empty input, which it reports as clean.
8587
for s in fetch git time; do
8688
echo "== $s"
87-
(cd "src/$s" && uv export --frozen --no-emit-project --format requirements-txt \
88-
| uvx pip-audit --require-hashes --disable-pip -r /dev/stdin)
89+
REQ=$(mktemp)
90+
if (cd "src/$s" && uv export --frozen --no-emit-project --format requirements-txt) > "$REQ" \
91+
&& [ -s "$REQ" ]; then
92+
uvx pip-audit --require-hashes --disable-pip -r "$REQ"
93+
else
94+
echo "EXPORT FAILED for $s: nothing was audited" >&2
95+
fi
96+
rm -f "$REQ"
8997
done
9098
```
9199

‎scripts/pack-and-verify.mjs‎

Lines changed: 88 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -129,34 +129,80 @@ function binEntries(manifest) {
129129
}
130130

131131
/**
132-
* Where an installed package's command lives inside its consumer directory.
132+
* How to start an installed package's command from its consumer directory:
133+
* the executable, and any arguments that come before the server's own.
134+
*
135+
* On POSIX that is the file the installer put on the path (npm's `.bin`
136+
* symlink, the venv's console script), which is what a user runs. On Windows
137+
* npm's entry is a `.cmd` shim, and a `.cmd` cannot be spawned without a
138+
* shell, which the HTTP transports' launch does not use. So there the
139+
* installed package's own bin file is handed to node, as the boot smoke does
140+
* for the checkout. The venv's console script is a real `.exe` and needs no
141+
* such step.
133142
*
134143
* @param {"ts" | "py"} language
135144
* @param {string} consumer the directory the artifact was installed into
136-
* @param {string} command the bin or console-script name
145+
* @param {{ command: string, packageName?: string, target?: string }} bin
146+
* the bin or console-script name; for npm, also the package and the file
147+
* its `bin` points at
137148
* @param {string} [platform]
138-
* @returns {string}
149+
* @param {string} [node] the node executable, for the Windows npm case
150+
* @returns {{ command: string, args: string[] }}
139151
*/
140-
export function installedCommand(
152+
export function installedLaunch(
141153
language,
142154
consumer,
143-
command,
155+
bin,
144156
platform = process.platform,
157+
node = process.execPath,
145158
) {
146159
const win = platform === "win32";
147-
return language === "ts"
148-
? path.join(
149-
consumer,
150-
"node_modules",
151-
".bin",
152-
win ? `${command}.cmd` : command,
153-
)
154-
: path.join(
160+
if (language === "py")
161+
return {
162+
command: path.join(
155163
consumer,
156164
".venv",
157165
win ? "Scripts" : "bin",
158-
win ? `${command}.exe` : command,
159-
);
166+
win ? `${bin.command}.exe` : bin.command,
167+
),
168+
args: [],
169+
};
170+
if (win)
171+
return {
172+
command: node,
173+
args: [
174+
path.join(
175+
consumer,
176+
"node_modules",
177+
...bin.packageName.split("/"),
178+
bin.target,
179+
),
180+
],
181+
};
182+
return {
183+
command: path.join(consumer, "node_modules", ".bin", bin.command),
184+
args: [],
185+
};
186+
}
187+
188+
/**
189+
* Why `dir` cannot be used as a server's artifact directory, or `null` when it
190+
* can. It must not exist, or be empty: this script writes the artifact there
191+
* and the release workflow uploads the directory whole, so anything already
192+
* in it would either be uploaded with the artifact or have to be deleted, and
193+
* a path given by mistake (`--out src` resolves to `src/<server>`) must never
194+
* be deleted.
195+
*
196+
* @param {string} dir
197+
* @returns {string | null}
198+
*/
199+
export function artifactDirProblem(dir) {
200+
if (!existsSync(dir)) return null;
201+
if (!statSync(dir).isDirectory())
202+
return `${dir} exists and is not a directory`;
203+
if (readdirSync(dir).length > 0)
204+
return `${dir} already exists and is not empty. Choose a fresh --out directory, or clear that one yourself; pack:verify does not delete what it did not create.`;
205+
return null;
160206
}
161207

162208
/** Is this file name something PyPI accepts: a wheel or an sdist? */
@@ -183,7 +229,7 @@ function run(command, args, cwd) {
183229
/**
184230
* Pack a TypeScript server and install the tarball into `consumer`.
185231
*
186-
* @returns {{ command: string, artifacts: string[] }}
232+
* @returns {{ launch: { command: string, args: string[] }, artifacts: string[] }}
187233
*/
188234
function packTs(server, artifactDir, consumer) {
189235
const pkgDir = path.join(repoRoot, "src", server.name);
@@ -207,9 +253,13 @@ function packTs(server, artifactDir, consumer) {
207253
JSON.stringify({ name: "pack-verify-consumer", private: true }),
208254
);
209255
run("npm", ["install", "--no-audit", "--no-fund", tarball], consumer);
210-
const [command] = binEntries(manifest)[0];
256+
const [command, target] = binEntries(manifest)[0];
211257
return {
212-
command: installedCommand("ts", consumer, command),
258+
launch: installedLaunch("ts", consumer, {
259+
command,
260+
packageName: manifest.name,
261+
target,
262+
}),
213263
artifacts: [tarball],
214264
};
215265
}
@@ -218,7 +268,7 @@ function packTs(server, artifactDir, consumer) {
218268
* Build a Python server and install its wheel into a fresh environment in
219269
* `consumer`.
220270
*
221-
* @returns {{ command: string, artifacts: string[] }}
271+
* @returns {{ launch: { command: string, args: string[] }, artifacts: string[] }}
222272
*/
223273
function packPy(server, artifactDir, consumer) {
224274
const pkgDir = path.join(repoRoot, "src", server.name);
@@ -243,7 +293,9 @@ function packPy(server, artifactDir, consumer) {
243293
run("uv", ["venv", "--python", python, venv], consumer);
244294
run("uv", ["pip", "install", "--python", venv, wheels[0]], consumer);
245295
return {
246-
command: installedCommand("py", consumer, `mcp-server-${server.name}`),
296+
launch: installedLaunch("py", consumer, {
297+
command: `mcp-server-${server.name}`,
298+
}),
247299
artifacts: built,
248300
};
249301
}
@@ -277,18 +329,20 @@ export async function main(argv = process.argv.slice(2)) {
277329
: path.join(work, "artifact");
278330
const started = Date.now();
279331
try {
280-
// A leftover artifact from an earlier run must not be mistaken for
281-
// this run's, or uploaded next to it.
282-
rmSync(artifactDir, { recursive: true, force: true });
332+
const problem = artifactDirProblem(artifactDir);
333+
if (problem) throw new Error(problem);
283334
mkdirSync(artifactDir, { recursive: true });
284335
mkdirSync(consumer);
285-
const { command, artifacts } =
336+
const { launch, artifacts } =
286337
server.language === "ts"
287338
? packTs(server, artifactDir, consumer)
288339
: packPy(server, artifactDir, consumer);
289-
if (!existsSync(command))
340+
// The file the install was supposed to create: the command itself,
341+
// or on Windows the bin file handed to node.
342+
const entry = launch.args[0] ?? launch.command;
343+
if (!existsSync(entry))
290344
throw new Error(
291-
`the install did not create ${path.relative(work, command)}`,
345+
`the install did not create ${path.relative(work, entry)}`,
292346
);
293347
for (const transport of server.transports) {
294348
const dir = mkdtempSync(path.join(work, "run-"));
@@ -297,11 +351,14 @@ export async function main(argv = process.argv.slice(2)) {
297351
transport,
298352
{ dir, pageUrl: page.url },
299353
{
300-
command,
301-
args: serverArguments(server, transport, {
302-
dir,
303-
pageUrl: page.url,
304-
}),
354+
command: launch.command,
355+
args: [
356+
...launch.args,
357+
...serverArguments(server, transport, {
358+
dir,
359+
pageUrl: page.url,
360+
}),
361+
],
305362
// Not the checkout: a relative path that only resolves there
306363
// must not resolve here.
307364
cwd: consumer,

‎scripts/pack-and-verify.test.mjs‎

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66

77
import { test } from "node:test";
88
import assert from "node:assert/strict";
9+
import {
10+
existsSync,
11+
mkdirSync,
12+
mkdtempSync,
13+
rmSync,
14+
writeFileSync,
15+
} from "node:fs";
16+
import { tmpdir } from "node:os";
917
import path from "node:path";
1018
import {
11-
installedCommand,
19+
artifactDirProblem,
20+
installedLaunch,
1221
isDistribution,
1322
main,
1423
parseArgs,
@@ -61,26 +70,83 @@ test("the string form of bin is read, and a missing bin is a problem", () => {
6170
]);
6271
});
6372

64-
test("installedCommand finds the bin where each installer puts it", () => {
73+
test("installedLaunch runs what each installer put in place", () => {
6574
const c = path.join("tmp", "consumer");
66-
assert.equal(
67-
installedCommand("ts", c, "mcp-server-memory", "linux"),
68-
path.join(c, "node_modules", ".bin", "mcp-server-memory"),
69-
);
70-
assert.equal(
71-
installedCommand("ts", c, "mcp-server-memory", "win32"),
72-
path.join(c, "node_modules", ".bin", "mcp-server-memory.cmd"),
75+
const bin = {
76+
command: "mcp-server-memory",
77+
packageName: "@modelcontextprotocol/server-memory",
78+
target: "dist/index.js",
79+
};
80+
assert.deepEqual(installedLaunch("ts", c, bin, "linux"), {
81+
command: path.join(c, "node_modules", ".bin", "mcp-server-memory"),
82+
args: [],
83+
});
84+
assert.deepEqual(
85+
installedLaunch("py", c, { command: "mcp-server-time" }, "darwin"),
86+
{ command: path.join(c, ".venv", "bin", "mcp-server-time"), args: [] },
7387
);
74-
assert.equal(
75-
installedCommand("py", c, "mcp-server-time", "darwin"),
76-
path.join(c, ".venv", "bin", "mcp-server-time"),
88+
assert.deepEqual(
89+
installedLaunch("py", c, { command: "mcp-server-time" }, "win32"),
90+
{
91+
command: path.join(c, ".venv", "Scripts", "mcp-server-time.exe"),
92+
args: [],
93+
},
7794
);
78-
assert.equal(
79-
installedCommand("py", c, "mcp-server-time", "win32"),
80-
path.join(c, ".venv", "Scripts", "mcp-server-time.exe"),
95+
});
96+
97+
test("installedLaunch hands node the bin file on Windows, not the .cmd shim", () => {
98+
const c = path.join("tmp", "consumer");
99+
// A `.cmd` cannot be spawned without a shell, and the HTTP transports are
100+
// launched without one.
101+
assert.deepEqual(
102+
installedLaunch(
103+
"ts",
104+
c,
105+
{
106+
command: "mcp-server-everything",
107+
packageName: "@modelcontextprotocol/server-everything",
108+
target: "dist/index.js",
109+
},
110+
"win32",
111+
"node.exe",
112+
),
113+
{
114+
command: "node.exe",
115+
args: [
116+
path.join(
117+
c,
118+
"node_modules",
119+
"@modelcontextprotocol",
120+
"server-everything",
121+
"dist/index.js",
122+
),
123+
],
124+
},
81125
);
82126
});
83127

128+
test("an artifact directory must be absent or empty; nothing is deleted", () => {
129+
const root = mkdtempSync(path.join(tmpdir(), "pack-out-"));
130+
try {
131+
assert.equal(artifactDirProblem(path.join(root, "absent")), null);
132+
const empty = path.join(root, "empty");
133+
mkdirSync(empty);
134+
assert.equal(artifactDirProblem(empty), null);
135+
const full = path.join(root, "full");
136+
mkdirSync(full);
137+
writeFileSync(path.join(full, "index.ts"), "source");
138+
assert.match(artifactDirProblem(full), /already exists and is not empty/);
139+
assert.match(
140+
artifactDirProblem(path.join(full, "index.ts")),
141+
/is not a directory/,
142+
);
143+
// The refusal is the whole behavior: the file is still there.
144+
assert.equal(existsSync(path.join(full, "index.ts")), true);
145+
} finally {
146+
rmSync(root, { recursive: true, force: true });
147+
}
148+
});
149+
84150
test("only wheels and sdists are distributions", () => {
85151
assert.equal(
86152
isDistribution("mcp_server_time-2026.8.1-py3-none-any.whl"),

0 commit comments

Comments
 (0)