Skip to content

Commit c41cf22

Browse files
cliffhallclaude
andcommitted
fix: smoke no longer syncs; freshness checks manifests; retry key spellings
Copilot round 1 on #4920: - smoke launches Python servers with `uv run --no-sync` and reports a missing .venv instead of creating one; CI's smoke job syncs first. - An HTTP launch that loses its probed port to another process is relaunched on a fresh port (that failure only). - verify:install-fresh also compares each manifest with the lockfile's record of it, the mismatch `npm ci` rejects. - verify:no-test-retries matches quoted and computed `retry` keys. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent 727cf5a commit c41cf22

9 files changed

Lines changed: 284 additions & 62 deletions

File tree

‎.claude/skills/pre-push-gate/SKILL.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ Each heading is a stage or guard name as it appears in the output.
4747

4848
### `verify:install-fresh`
4949

50-
An installed package's version disagrees with `package-lock.json`:
51-
`node_modules` is older than the tree you pulled. **Run `npm install` at the
52-
repo root** and re-run. It is the first stage because a stale install otherwise
50+
An installed package's version disagrees with `package-lock.json`
51+
(`node_modules` is older than the tree you pulled), or a `package.json`
52+
declares a dependency the lockfile does not record. **Run `npm install` at the
53+
repo root**, commit the lockfile if it changed, and re-run. It is the first stage because a stale install otherwise
5354
passes every static check and fails later as a test reporting the _old_
5455
dependency's behavior. Do not "fix" that test.
5556

@@ -155,6 +156,8 @@ of the server's stderr. Re-run a subset with
155156
- **"dist/index.js does not exist — build first"**: you ran the smoke on its
156157
own before building. `npm run build -w src/<server>`. Inside the gate this
157158
cannot happen, since `validate` builds first.
159+
- **".venv does not exist — sync first"**: the same for a Python server. The
160+
smoke never creates an environment; `npm run validate:py -- <server>` does.
158161
- **The server exited before answering**: the stderr tail shows why. This is
159162
what the smoke is for: the unit tests import the source, so a wrong `bin`
160163
path, a file missing from `dist/`, or an import that only resolves under the

‎.github/workflows/typescript.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,14 @@ jobs:
116116
- name: Install dependencies and build
117117
run: npm ci
118118

119+
# The smoke launches the Python servers with `uv run --no-sync`: it tests
120+
# an environment, it does not create one. This is the sync `validate:py`
121+
# does before the smoke in the local gate.
122+
- name: Sync the Python servers
123+
run: |
124+
for server in fetch git time; do
125+
(cd "src/$server" && uv sync --locked --all-extras --dev)
126+
done
127+
119128
- name: Boot every server
120129
run: npm run smoke

‎docs/quality-gate.md‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ in this order, and the first failure stops the run.
3333

3434
| # | Stage | What it checks | CI counterpart |
3535
| --- | --- | --- | --- |
36-
| 1 | `verify:install-fresh` | Every package in `node_modules` is at the version `package-lock.json` records | None needed: CI installs with `npm ci` |
36+
| 1 | `verify:install-fresh` | Every package in `node_modules` is at the version `package-lock.json` records, and every `package.json` declares what the lockfile says it does | None needed: CI installs with `npm ci` |
3737
| 2 | `validate` → `validate:guards` | The root guards, listed [below](#the-root-guards) | `typescript.yml` → **Root guards** |
3838
| 3 | `validate` → each workspace's `validate` | Per TypeScript server: `format:check`, `lint` (`--max-warnings 0`), `typecheck`, `build`, `test` | `typescript.yml` → **Validate \<server\>** (one leg each) |
3939
| 4 | `validate:py` | Per Python server: `uv sync --locked`, `ruff check`, `ruff format --check`, `pyright`, `pytest`, `uv build` | `python.yml` → **Test \<server\>** (one leg each) |
@@ -55,12 +55,14 @@ Notes on the stages:
5555
not the one installed: it fetches it with `npx`. It is the one stage that
5656
fails offline.
5757
- **`smoke` launches what a user launches**: the built `dist/index.js` for a
58-
TypeScript server, the console script through `uv run --frozen` for a Python
58+
TypeScript server, the console script through `uv run --no-sync` for a Python
5959
one. stdio for all seven; HTTP+SSE and Streamable HTTP as well for
60-
`everything`. It touches neither the network nor your files: `fetch` is
61-
pointed at a page the smoke serves on the loopback interface, and the HTTP
62-
transports listen on ports the OS hands out. It runs after `validate`
63-
because it needs the build.
60+
`everything`. The servers are given nothing outside the machine to talk to
61+
and none of your files: `fetch` is pointed at a page the smoke serves on the
62+
loopback interface, and the HTTP transports listen on a free port rather
63+
than the default 3001. It runs after `validate` and `validate:py` because it
64+
needs the build and each Python server's synced environment; it creates
65+
neither.
6466
- `python.yml` also has a **Build \<server\>** job per server that re-runs
6567
pyright and `uv build` and uploads the built distribution. It checks nothing
6668
stage 4 does not.

‎scripts/smoke-servers.mjs‎

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,24 @@
2222
*
2323
* Why one Node script for both languages: the smoke is a client, and the
2424
* question it asks is the same whatever the server is written in. The Python
25-
* servers are launched through `uv run --frozen`, never pip, like every other
26-
* Python step here.
25+
* servers are launched through `uv run --no-sync`, never pip.
2726
*
28-
* Nothing touches the network or the user's files. `fetch` is pointed at an
29-
* HTTP server this script starts on the loopback interface; `git` and
30-
* `filesystem` get a throwaway directory; `memory` gets a throwaway graph file.
31-
* The HTTP transports listen on a port the OS hands out, not the server's
32-
* default 3001, so the smoke cannot collide with a server the developer has
33-
* running, nor two smokes with each other.
27+
* `--no-sync` because the smoke tests an environment, it does not build one. A
28+
* plain `uv run` (even `--frozen`, which only stops the lockfile being
29+
* rewritten) creates the server's `.venv` and downloads into it when it is
30+
* missing or stale, which would make this stage a second, unannounced install
31+
* step. So each Python server must already be synced: `validate:py` does that
32+
* in the gate just before the smoke, and CI's smoke job has a sync step. A
33+
* server with no `.venv` is reported as that.
34+
*
35+
* The servers themselves are given nothing outside the machine to talk to, and
36+
* none of the user's files. `fetch` is pointed at an HTTP server this script
37+
* starts on the loopback interface; `git` and `filesystem` get a throwaway
38+
* directory; `memory` gets a throwaway graph file. The HTTP transports listen
39+
* on a port the OS reported free a moment earlier, not the server's default
40+
* 3001, so the smoke does not collide with a server the developer has running.
41+
* That port is not reserved between the probe and the server's own `listen`,
42+
* so a launch that loses it to another process is relaunched on a fresh one.
3443
*
3544
* One server failing does not stop the rest: the run reports every target's
3645
* verdict and exits non-zero if any failed, so one run shows the whole picture.
@@ -72,6 +81,14 @@ export const FETCH_MARKER = "boot-smoke-marker";
7281
*/
7382
export const REQUEST_TIMEOUT_MS = 120_000;
7483

84+
/** How many ports an HTTP launch may try before a taken port is the result. */
85+
export const PORT_ATTEMPTS = 3;
86+
87+
/** Whether a server's output says it lost its port to another process. */
88+
export function isPortTaken(output) {
89+
return /EADDRINUSE|already in use/i.test(output);
90+
}
91+
7592
/** How long an HTTP server gets to start listening. */
7693
export const LISTEN_TIMEOUT_MS = 30_000;
7794

@@ -244,7 +261,7 @@ export function launchSpec(server, transport, ctx, root = repoRoot) {
244261
}
245262
return {
246263
command: "uv",
247-
args: ["run", "--frozen", `mcp-server-${server.name}`, ...serverArgs],
264+
args: ["run", "--no-sync", `mcp-server-${server.name}`, ...serverArgs],
248265
cwd,
249266
};
250267
}
@@ -342,6 +359,10 @@ async function smokeOne(server, transport, ctx) {
342359
throw new Error(
343360
`${path.relative(repoRoot, spec.args[0])} does not exist — build first (\`npm run build -w src/${server.name}\`).`,
344361
);
362+
if (server.language === "py" && !existsSync(path.join(spec.cwd, ".venv")))
363+
throw new Error(
364+
`src/${server.name}/.venv does not exist — sync first (\`npm run validate:py -- ${server.name}\`, or \`uv sync --locked --all-extras --dev\` in src/${server.name}). The smoke does not create environments.`,
365+
);
345366
server.prepare?.(ctx);
346367

347368
const client = new Client({ name: "boot-smoke", version: "0.0.0" });
@@ -372,42 +393,53 @@ async function smokeOne(server, transport, ctx) {
372393
return;
373394
}
374395

375-
const port = await freePort();
376-
let output = "";
377-
const child = spawn(spec.command, spec.args, {
378-
cwd: spec.cwd,
379-
env: envFor(server, ctx, { PORT: String(port) }),
380-
stdio: ["ignore", "pipe", "pipe"],
381-
});
382-
child.stdout.on("data", (chunk) => (output += chunk));
383-
child.stderr.on("data", (chunk) => (output += chunk));
384-
const tail = () => output.trim().split("\n").slice(-15).join("\n");
385-
try {
386-
await new Promise((resolve, reject) => {
387-
child.once("error", reject);
388-
child.once("spawn", resolve);
396+
// The probe port is free when probed, not reserved: another process can take
397+
// it before the server binds. Only that one failure is relaunched, on a fresh
398+
// port; anything else the server says on its way down is the result.
399+
for (let attempt = 1; ; attempt += 1) {
400+
const port = await freePort();
401+
let output = "";
402+
const child = spawn(spec.command, spec.args, {
403+
cwd: spec.cwd,
404+
env: envFor(server, ctx, { PORT: String(port) }),
405+
stdio: ["ignore", "pipe", "pipe"],
389406
});
390-
await waitForListen(port, child, tail);
391-
const url = new URL(
392-
`http://127.0.0.1:${port}${TRANSPORT_ENDPOINT[transport]}`,
393-
);
394-
const clientTransport =
395-
transport === "sse"
396-
? new SSEClientTransport(url)
397-
: new StreamableHTTPClientTransport(url);
407+
child.stdout.on("data", (chunk) => (output += chunk));
408+
child.stderr.on("data", (chunk) => (output += chunk));
409+
const tail = () => output.trim().split("\n").slice(-15).join("\n");
398410
try {
399-
await client.connect(clientTransport, options);
400-
await exercise(client, server, ctx);
411+
await new Promise((resolve, reject) => {
412+
child.once("error", reject);
413+
child.once("spawn", resolve);
414+
});
415+
try {
416+
await waitForListen(port, child, tail);
417+
} catch (err) {
418+
if (attempt < PORT_ATTEMPTS && isPortTaken(output)) continue;
419+
throw err;
420+
}
421+
const url = new URL(
422+
`http://127.0.0.1:${port}${TRANSPORT_ENDPOINT[transport]}`,
423+
);
424+
const clientTransport =
425+
transport === "sse"
426+
? new SSEClientTransport(url)
427+
: new StreamableHTTPClientTransport(url);
428+
try {
429+
await client.connect(clientTransport, options);
430+
await exercise(client, server, ctx);
431+
} finally {
432+
await client.close().catch(() => {});
433+
}
434+
return;
435+
} catch (err) {
436+
throw new Error(
437+
`${err?.message ?? err}${tail() ? `\n--- server output ---\n${tail()}` : ""}`,
438+
{ cause: err },
439+
);
401440
} finally {
402-
await client.close().catch(() => {});
441+
await stop(child);
403442
}
404-
} catch (err) {
405-
throw new Error(
406-
`${err?.message ?? err}${tail() ? `\n--- server output ---\n${tail()}` : ""}`,
407-
{ cause: err },
408-
);
409-
} finally {
410-
await stop(child);
411443
}
412444
}
413445

‎scripts/smoke-servers.test.mjs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { fileURLToPath } from "node:url";
1414
import {
1515
SERVERS,
1616
findUnlistedServers,
17+
isPortTaken,
1718
launchSpec,
1819
selectTargets,
1920
} from "./smoke-servers.mjs";
@@ -94,12 +95,21 @@ test("launchSpec: a TypeScript server runs its built bin, with the transport whe
9495
]);
9596
});
9697

97-
test("launchSpec: a Python server runs its console script through uv, frozen", () => {
98+
test("isPortTaken: only a lost port is relaunched", () => {
99+
assert.ok(isPortTaken("Error: listen EADDRINUSE: address already in use"));
100+
assert.ok(
101+
isPortTaken("Failed to start: Port 3001 is already in use. Set PORT…"),
102+
);
103+
assert.ok(!isPortTaken("Error: Cannot find module './x.js'"));
104+
assert.ok(!isPortTaken(""));
105+
});
106+
107+
test("launchSpec: a Python server runs its console script through uv, without syncing", () => {
98108
const git = launchSpec(byName("git"), "stdio", ctx, "/repo");
99109
assert.equal(git.command, "uv");
100110
assert.deepEqual(git.args, [
101111
"run",
102-
"--frozen",
112+
"--no-sync",
103113
"mcp-server-git",
104114
"--repository",
105115
"/tmp/x",

‎scripts/verify-install-fresh.mjs‎

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
// hidden lockfile (`node_modules/.package-lock.json`), which records what npm
2828
// last wrote, not what is on disk now.
2929
//
30+
// It also compares each manifest (the root's and every workspace's) against
31+
// the copy of it the lockfile records. A dependency added to, removed from or
32+
// re-ranged in a `package.json` without re-running `npm install` leaves the
33+
// lockfile describing a different project, which is the checkout `npm ci`
34+
// refuses in CI with "package.json and package-lock.json are not in sync". The
35+
// versions on disk can all match the lockfile while that is true, so the first
36+
// comparison alone would pass it.
37+
//
38+
// What it does NOT do is look for packages that are installed but absent from
39+
// the lockfile. That needs a walk of `node_modules`, the Inspector's guard does
40+
// not do it either, and the failure it would catch (source importing a leftover
41+
// package) fails CI's build on a fresh install rather than passing silently.
42+
//
3043
// CI installs from scratch on every run, so this never fires there. The Python
3144
// servers need no counterpart: `validate:py` starts each one with
3245
// `uv sync --locked`, which brings the environment to its lockfile.
@@ -80,6 +93,50 @@ export function compareInstall(lock, readInstalledVersion) {
8093
return { stale, missing };
8194
}
8295

96+
/** The sections of a manifest that the lockfile mirrors, and `npm ci` compares. */
97+
const MANIFEST_SECTIONS = [
98+
"dependencies",
99+
"devDependencies",
100+
"optionalDependencies",
101+
"peerDependencies",
102+
];
103+
104+
/**
105+
* Compare the lockfile's record of each manifest against the manifest itself.
106+
*
107+
* The lockfile mirrors the root manifest at `packages[""]` and each workspace's
108+
* at `packages["<dir>"]`. `readManifest(dir)` returns the parsed `package.json`
109+
* there (`""` is the root), or `undefined` when there is none. Returns one
110+
* `{ dir, section, name, manifest, lock }` per declared range that differs;
111+
* a side that does not declare the package is `undefined`.
112+
*/
113+
export function compareManifests(lock, readManifest) {
114+
const drift = [];
115+
for (const [dir, entry] of Object.entries(lock?.packages ?? {})) {
116+
if (isInstalledCopy(dir) || entry?.link) continue;
117+
const manifest = readManifest(dir);
118+
if (manifest === undefined) continue;
119+
for (const section of MANIFEST_SECTIONS) {
120+
const declared = manifest[section] ?? {};
121+
const locked = entry[section] ?? {};
122+
for (const name of new Set([
123+
...Object.keys(declared),
124+
...Object.keys(locked),
125+
])) {
126+
if (declared[name] !== locked[name])
127+
drift.push({
128+
dir,
129+
section,
130+
name,
131+
manifest: declared[name],
132+
lock: locked[name],
133+
});
134+
}
135+
}
136+
}
137+
return drift;
138+
}
139+
83140
/** The installed version at `<dir>/<entryPath>/package.json`, or `undefined`. */
84141
function installedVersionReader(dir) {
85142
return (entryPath) => {
@@ -101,6 +158,16 @@ export function main(root = repoRoot) {
101158
const lock = JSON.parse(readFileSync(lockPath, "utf8"));
102159
const { stale, missing } = compareInstall(lock, installedVersionReader(root));
103160
const problems = [];
161+
const drift = compareManifests(lock, (dir) => {
162+
const manifest = path.join(root, dir, "package.json");
163+
return existsSync(manifest)
164+
? JSON.parse(readFileSync(manifest, "utf8"))
165+
: undefined;
166+
});
167+
for (const d of drift)
168+
problems.push(
169+
` ${path.posix.join(d.dir || ".", "package.json")} ${d.section}.${d.name}: manifest ${d.manifest ?? "(absent)"}, lockfile ${d.lock ?? "(absent)"}`,
170+
);
104171
// A never-installed tree would list every package; one line says it better.
105172
if (missing.length > 0 && !existsSync(path.join(root, "node_modules"))) {
106173
problems.push(" no node_modules at all");
@@ -114,12 +181,13 @@ export function main(root = repoRoot) {
114181
}
115182
if (problems.length > 0) {
116183
console.error(
117-
`verify:install-fresh — the install disagrees with package-lock.json (${problems.length}):\n` +
184+
`verify:install-fresh — the install, lockfile and manifests disagree (${problems.length}):\n` +
118185
problems.join("\n") +
119-
"\n\nnode_modules is older than the lockfile beside it — usually a `git pull` that" +
120-
"\nbrought in a dependency bump. Run `npm install` at the repo root (one install" +
121-
"\ncovers every workspace). Tests run against a stale install report the OLD" +
122-
"\ndependency's behavior as a product failure.",
186+
"\n\nThe install, the lockfile and the manifests are out of step — usually a" +
187+
"\n`git pull` that brought in a dependency bump, or a `package.json` edited by" +
188+
"\nhand. Run `npm install` at the repo root (one install covers every workspace)" +
189+
"\nand commit the lockfile if it changed. Tests run against a stale install report" +
190+
"\nthe OLD dependency's behavior as a product failure.",
123191
);
124192
return 1;
125193
}

0 commit comments

Comments
 (0)