Skip to content

Commit 39c682f

Browse files
Elon Muskclaude
andauthored
test(spec): end the publish-smoke collision harness with exit 0 (#10916)
The harness had `set +e +o pipefail` after sourcing publish-smoke.sh but no trailing `exit 0`, so its exit status was whatever the last command returned — and every case ends by killing its stubs. Reaping a stub that has already exited returns 1, execFileSync then throws, and the failure arrives as a bare `Command failed` with the vacuity guard that would have named the problem never reached. This is the second half of the reporting fix PR #10456 landed for the sdui sibling; this file had only the first. Claude-Session: https://claude.ai/code/session_01B4h3medzvhB9rpfoja9jcw Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9990319 commit 39c682f

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

packages/spec/scripts/publish-smoke-port-collision.test.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,25 @@ function have(bin: string): boolean {
118118
// pinned is an agent-container one, and the helpers read `/proc`-backed liveness.
119119
const RUNNABLE = process.platform === 'linux' && ['bash', 'curl', 'jq', 'node'].every(have);
120120

121-
/** A tiny HTTP server on $STUB_PORT announcing $STUB_NAME, as a `node -e` program. */
121+
/**
122+
* A tiny HTTP server on $STUB_PORT announcing $STUB_NAME, as a `node -e` program.
123+
*
124+
* ⛔ Deliberately WITHOUT the `s.once("error", …)` guard `OWNED_HTTP_STUB` below
125+
* carries — the asymmetry was measured, not overlooked, so that the next reader
126+
* comparing the two does not close it on symmetry grounds. Losing a bind here
127+
* does kill the stub with an unhandled `'error'` event rather than a clean
128+
* exit, but every one of this stub's call sites spells `>/dev/null 2>&1`, and
129+
* against that spelling the two forms are indistinguishable to the harness:
130+
*
131+
* unguarded → stub exit 1 · cleanup `kill` rc 1 · 896 stderr bytes
132+
* guarded → stub exit 1 · cleanup `kill` rc 1 · 0 stderr bytes
133+
*
134+
* The only difference is a stack trace on a stream nothing reads. What made the
135+
* lost bind illegible was never the trace — it was the harness having no
136+
* trailing `exit 0`, so the cleanup `kill` of the dead stub became the harness's
137+
* exit status and `Command failed` pre-empted the guard. That is fixed in
138+
* `runHarness`; adding four inert guards on top would not have reported it.
139+
*/
122140
const HTTP_STUB = [
123141
'const http = require("node:http");',
124142
'http.createServer((_q, r) => {',
@@ -189,6 +207,27 @@ function runHarness(body: string[]): Record<string, string> {
189207
'trap \'for j in $(jobs -p); do kill "$j" 2>/dev/null; done\' EXIT',
190208
'echo "SOURCED=ok"',
191209
...body,
210+
// Grading belongs to the assertions, not to whatever the last cleanup
211+
// returned. Every case above ends by killing its stubs, and reaping one
212+
// that has ALREADY EXITED returns 1. The `set +e` above stops that from
213+
// aborting the harness mid-line — which is all it buys — but not from
214+
// becoming the harness's EXIT STATUS; `execFileSync` then throws in the
215+
// test body and the failure arrives as a bare `Command failed: bash
216+
// /tmp/publish-smoke-collision-*/harness.sh`, pre-empting the vacuity
217+
// guard written to name the problem. Measured on this file, one rig, one
218+
// mutation, differing only in whether the stub survives to be reaped:
219+
//
220+
// stub exits → Error: Command failed … at runHarness, no assertion
221+
// stub alive → AssertionError: expected '' to be 'holder'
222+
//
223+
// The harness's exit status is not a measurement. Every measurement is a
224+
// printed KEY=VALUE line and the assertions grade those. This is the
225+
// second half of the reporting fix PR #10456 landed for the sdui sibling;
226+
// this file had only the `set +e` half. It sits AFTER the body but the
227+
// EXIT trap above still runs, and a trap that does not itself exit leaves
228+
// the status alone — so the stubs are still reaped, and 0 is still what
229+
// `execFileSync` sees.
230+
'exit 0',
192231
].join('\n'),
193232
{ mode: 0o755 },
194233
);

0 commit comments

Comments
 (0)