@feigi/fleet-ctl 3.23.30 → 3.23.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -169,7 +169,7 @@ rc=0
|
|
|
169
169
|
framed=$(node -e '
|
|
170
170
|
const fs = require("fs");
|
|
171
171
|
const [file, field, open, close, lenFile] = process.argv.slice(1);
|
|
172
|
-
const bad = (why) => { console.error(why); process.exit(2); };
|
|
172
|
+
const bad = (why) => { console.error(why.replace(/\0/g, "")); process.exit(2); };
|
|
173
173
|
let r;
|
|
174
174
|
try { r = JSON.parse(fs.readFileSync(file, "utf8")); } catch (e) { bad(`it does not parse: ${e.message}`); }
|
|
175
175
|
if (r === null || typeof r !== "object" || Array.isArray(r)) bad("it is not a JSON object");
|
|
@@ -191,7 +191,23 @@ process.stdout.write(open + value + close);
|
|
|
191
191
|
if [ "$rc" -ge 126 ]; then
|
|
192
192
|
unrunnable "node did not finish reading the Recipe cache (exit $rc), so its usability is unknown"
|
|
193
193
|
fi
|
|
194
|
-
|
|
194
|
+
# The reason is read back with the shell's own `read`, never `cat`: a cat that
|
|
195
|
+
# cannot be started would otherwise leave a cache node really refused with an
|
|
196
|
+
# empty reason and a stray "cat: command not found" line. Like `$(cat ...)`, the
|
|
197
|
+
# substitution drops trailing newlines; `|| [ -n "$line" ]` keeps a last line
|
|
198
|
+
# that has none. A shell string cannot hold a NUL and a `read` loop stops at
|
|
199
|
+
# one, where `cat` kept the rest, so node's `bad` above strips NULs from its
|
|
200
|
+
# reason — a cache that holds NUL bytes is quoted back in its parse error.
|
|
201
|
+
# Nothing here may end the script before `die`: a stderr file that cannot be
|
|
202
|
+
# read back (opened, or read — bash's `read` leaves `line` unset on an error,
|
|
203
|
+
# which `set -u` then trips on) fails the substitution, and the `||` names that
|
|
204
|
+
# in the reason instead of aborting on the shell's own error, which under dash
|
|
205
|
+
# would also be an exit outside 0/1/3.
|
|
206
|
+
if [ "$rc" -ne 0 ]; then
|
|
207
|
+
reason=$({ while IFS= read -r line || [ -n "$line" ]; do printf '%s\n' "$line"; done <"$errf"; } 2>/dev/null) ||
|
|
208
|
+
reason="(node's reason could not be read back from $errf)"
|
|
209
|
+
die "the Recipe cache at $cache is unusable: $reason — $derive"
|
|
210
|
+
fi
|
|
195
211
|
carriedmsg="node's stdout carried more than the framed Recipe value — expected exactly the value between '$open' and '$close', got '$framed'. The cache at $cache passed validation; the extra output comes from how node is launched here (a version-manager or proxy shim, a preload), and is refused rather than cut out of the command"
|
|
196
212
|
case $framed in
|
|
197
213
|
"$open"*"$close") ;;
|
|
@@ -371,16 +371,24 @@ test("a mktemp that runs and fails on its second call is exit 3, never the cache
|
|
|
371
371
|
// the real read — killed, or no longer runnable. Nothing was read, so that is
|
|
372
372
|
// exit 3 as well. Node's own refusal of the cache (its exit 2) and an uncaught
|
|
373
373
|
// fault of its own (exit 1) are still the cache's exit 1, with node's reason.
|
|
374
|
+
// The stripped PATH has no cat: node's reason is read back WITHOUT it, so every
|
|
375
|
+
// refusal row also proves that. The rows that give a reason a shape (several
|
|
376
|
+
// lines, no final newline, trailing newlines, a backslash and leading space)
|
|
377
|
+
// pin what the read-back must still do as cat did.
|
|
374
378
|
for (const [what, body, status, reason] of [
|
|
375
379
|
["is killed", "kill -9 $$", 3, /^derive-testcmd: node did not finish reading the Recipe cache \(exit 137\)/m],
|
|
376
380
|
["can no longer be run", "exit 127", 3, /^derive-testcmd: node did not finish reading the Recipe cache \(exit 127\)/m],
|
|
377
381
|
["refuses the cache itself", "echo 'it does not parse: boom' >&2; exit 2", 1, /is unusable: it does not parse: boom/],
|
|
378
382
|
["faults on its own", "echo 'TypeError: boom' >&2; exit 1", 1, /is unusable: TypeError: boom/],
|
|
383
|
+
["refuses with a multi-line reason", "echo 'first line' >&2; echo 'second line' >&2; exit 2", 1, /is unusable: first line\nsecond line — run the Recipe/],
|
|
384
|
+
["refuses with a last line without a newline", "printf 'no newline' >&2; exit 2", 1, /is unusable: no newline — run the Recipe/],
|
|
385
|
+
["refuses with trailing newlines", "printf 'reason\\n\\n\\n' >&2; exit 2", 1, /is unusable: reason — run the Recipe/],
|
|
386
|
+
["refuses with a backslash and leading space", "printf ' a\\\\nb\\n' >&2; exit 2", 1, /is unusable: a\\nb — run the Recipe/],
|
|
379
387
|
]) {
|
|
380
388
|
test(`a node that passes the probe and then ${what} is exit ${status}`, () => {
|
|
381
389
|
const { dir, head } = repo();
|
|
382
390
|
cache(dir, recipe(head, { test: "true" }));
|
|
383
|
-
const bin = shimPath({ node: false });
|
|
391
|
+
const bin = shimPath({ node: false, omit: "cat" });
|
|
384
392
|
writeExecStub(join(bin, "node"), `#!/bin/sh\nif [ "$1" = -e ] && [ "$2" = 0 ]; then exit 0; fi\n${body}\n`);
|
|
385
393
|
const r = derive(dir, "test", { ...process.env, PATH: bin });
|
|
386
394
|
assert.equal(r.status, status, r.err);
|
|
@@ -421,6 +429,95 @@ test("a cat that runs and fails on the byte-count file is exit 1, carrying its r
|
|
|
421
429
|
assert.doesNotMatch(r.err, /could not be started/);
|
|
422
430
|
});
|
|
423
431
|
|
|
432
|
+
// node's refusal of the cache is read back WITHOUT cat: a cat that cannot be
|
|
433
|
+
// started must not turn a cache node really refuses into a refusal with an
|
|
434
|
+
// empty reason. The cache is refused either way (exit 1), and node's own reason
|
|
435
|
+
// survives, with no shell complaint about cat.
|
|
436
|
+
const REFUSED = /is unusable: `installClean` is not true — the Install step was never proven to leave the tree clean — run the Recipe derivation step/;
|
|
437
|
+
for (const [what, stub] of [
|
|
438
|
+
["is missing", null],
|
|
439
|
+
["exits 127", "exit 127"],
|
|
440
|
+
["exits 126", "exit 126"],
|
|
441
|
+
]) {
|
|
442
|
+
test(`a cat that ${what} still lets a refused cache carry node's reason, exit 1`, () => {
|
|
443
|
+
const { dir, head } = repo();
|
|
444
|
+
cache(dir, recipe(head, { installClean: false }));
|
|
445
|
+
const bin = shimPath({ node: true, omit: "cat" });
|
|
446
|
+
if (stub) writeExecStub(join(bin, "cat"), `#!/bin/sh\n${stub}\n`);
|
|
447
|
+
const r = derive(dir, "test", { ...process.env, PATH: bin });
|
|
448
|
+
assert.equal(r.status, 1, r.err);
|
|
449
|
+
assert.equal(r.out, "");
|
|
450
|
+
assert.match(r.err, REFUSED);
|
|
451
|
+
assert.doesNotMatch(r.err, /command not found|could not be started/);
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// The control: the same stripped PATH with every tool present, same cache.
|
|
456
|
+
test("the same refused cache with cat present carries the same reason", () => {
|
|
457
|
+
const { dir, head } = repo();
|
|
458
|
+
cache(dir, recipe(head, { installClean: false }));
|
|
459
|
+
const r = derive(dir, "test", { ...process.env, PATH: shimPath({ node: true }) });
|
|
460
|
+
assert.equal(r.status, 1, r.err);
|
|
461
|
+
assert.match(r.err, REFUSED);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// A cache holding a NUL byte is quoted back, NUL and all, in node's parse
|
|
465
|
+
// error. A `read` loop stops at a NUL where cat kept the rest, so the reason
|
|
466
|
+
// must reach the shell without one. Only a sh whose `read` stops there (the
|
|
467
|
+
// bash 3.2 that is /bin/sh on macOS) loses the tail without that, so the pin
|
|
468
|
+
// bites on such a host and passes elsewhere.
|
|
469
|
+
test("a NUL byte in the cache does not cut node's parse reason short", () => {
|
|
470
|
+
const { dir } = repo();
|
|
471
|
+
cache(dir, '{"install":\u0000"x"}');
|
|
472
|
+
const r = derive(dir, "test");
|
|
473
|
+
assert.equal(r.status, 1, r.err);
|
|
474
|
+
assert.match(r.err, /is unusable: it does not parse: [^\n]*JSON[^\n]* — run the Recipe/);
|
|
475
|
+
assert.doesNotMatch(r.err, /\0/);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
// Nothing on the way to the refusal may end the script before it: the file
|
|
479
|
+
// node's reason was written to is the script's own mktemp, and one that cannot
|
|
480
|
+
// be read back must still end in this script's refusal (exit 1, naming the
|
|
481
|
+
// Recipe derivation step), not in the shell's own redirect error — which under
|
|
482
|
+
// dash is an exit outside the documented 0/1/3.
|
|
483
|
+
function mktempShim(bin, { firstArgs = "" } = {}) {
|
|
484
|
+
const real = execFileSync("sh", ["-c", "command -v mktemp"], { encoding: "utf8" }).trim();
|
|
485
|
+
const mark = join(bin, "errf-path");
|
|
486
|
+
writeExecStub(join(bin, "mktemp"), `#!/bin/sh\nif [ ! -e '${mark}' ]; then p=$('${real}' ${firstArgs} "$@") || exit $?; printf '%s' "$p" > '${mark}'; printf '%s\\n' "$p"; exit 0; fi\nexec '${real}' "$@"\n`);
|
|
487
|
+
return mark;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
test("a stderr file that cannot be opened for the read-back still reaches the refusal", () => {
|
|
491
|
+
const { dir, head } = repo();
|
|
492
|
+
cache(dir, recipe(head, { test: "true" }));
|
|
493
|
+
const bin = shimPath({ node: false, omit: "mktemp" });
|
|
494
|
+
const mark = mktempShim(bin);
|
|
495
|
+
// node writes its reason and then removes the file it wrote it to.
|
|
496
|
+
writeExecStub(join(bin, "node"), `#!/bin/sh\nif [ "$1" = -e ] && [ "$2" = 0 ]; then exit 0; fi\necho 'real reason' >&2\nread -r f < '${mark}'\nrm -f "$f"\nexit 2\n`);
|
|
497
|
+
const r = derive(dir, "test", { ...process.env, PATH: bin });
|
|
498
|
+
assert.equal(r.status, 1, r.err);
|
|
499
|
+
assert.equal(r.out, "");
|
|
500
|
+
assert.match(r.err, /^derive-testcmd: the Recipe cache at .* is unusable: \(node's reason could not be read back from [^)]+\) — /m);
|
|
501
|
+
assert.match(r.err, NAMES_STEP);
|
|
502
|
+
assert.doesNotMatch(r.err, /No such file|cannot open/);
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// A stderr file that is a directory: bash's `read` fails there without
|
|
506
|
+
// assigning `line`, and `set -u` then trips on the unbound variable inside the
|
|
507
|
+
// read-back. The refusal must still be reached, with no complaint about it.
|
|
508
|
+
test("a stderr file that is a directory still reaches the refusal", () => {
|
|
509
|
+
const { dir, head } = repo();
|
|
510
|
+
cache(dir, recipe(head, { test: "true" }));
|
|
511
|
+
const bin = shimPath({ node: true, omit: "mktemp" });
|
|
512
|
+
mktempShim(bin, { firstArgs: "-d" });
|
|
513
|
+
const r = derive(dir, "test", { ...process.env, PATH: bin });
|
|
514
|
+
assert.equal(r.status, 1, r.err);
|
|
515
|
+
assert.equal(r.out, "");
|
|
516
|
+
assert.match(r.err, /^derive-testcmd: the Recipe cache at .* is unusable: /m);
|
|
517
|
+
assert.match(r.err, NAMES_STEP);
|
|
518
|
+
assert.doesNotMatch(r.err, /unbound variable/);
|
|
519
|
+
});
|
|
520
|
+
|
|
424
521
|
// `rm` is the reader's cleanup only, so it must not decide the outcome: with
|
|
425
522
|
// it gone a good cache still reads cleanly — status 0 and nothing on stderr,
|
|
426
523
|
// the success-path invariant claim-ticket.sh relies on — and a refused cache
|
package/scripts/recipe-prove.mjs
CHANGED
|
@@ -163,15 +163,20 @@ function parseArgs(argv) {
|
|
|
163
163
|
// its own refusal. But it has no exit status and mostly no stderr, so `err`
|
|
164
164
|
// names the kill, after whatever git did write — a caller quoting `err` would
|
|
165
165
|
// otherwise quote an empty reason.
|
|
166
|
+
//
|
|
167
|
+
// A git that ignores the buffer kill can still exit 0, with no signal, after
|
|
168
|
+
// its output was cut off: any `error` on a git that ran fails it, whatever its
|
|
169
|
+
// exit status, and `err` names that error without claiming a kill.
|
|
166
170
|
function git(args, cwd) {
|
|
167
171
|
const r = spawnSync("git", args, { cwd, env: ENV, encoding: "utf8" });
|
|
168
172
|
if (r.error && !r.pid) throw cannot(`could not start git: ${r.error.message}`);
|
|
169
173
|
const err = (r.stderr ?? "").trim();
|
|
170
|
-
const
|
|
171
|
-
|
|
174
|
+
const failed = r.signal ? `git was killed by ${r.signal}` : r.error && `git exited ${r.status} after an error`;
|
|
175
|
+
const note = failed && `${failed}${errorCause(r.error)}`;
|
|
176
|
+
return { ok: r.status === 0 && !r.error, out: (r.stdout ?? "").replace(/\n$/, ""), err: [err, note].filter(Boolean).join("; ") };
|
|
172
177
|
}
|
|
173
178
|
|
|
174
|
-
function
|
|
179
|
+
function errorCause(error) {
|
|
175
180
|
if (!error) return "";
|
|
176
181
|
if (error.code === "ENOBUFS") return " (ENOBUFS: its output outgrew the spawn buffer)";
|
|
177
182
|
return ` (${error.code ?? error.message})`;
|
|
@@ -595,6 +595,32 @@ test("a git that exits non-zero is refused with exactly its stderr, naming no si
|
|
|
595
595
|
assert.doesNotMatch(r.err, /killed/);
|
|
596
596
|
});
|
|
597
597
|
|
|
598
|
+
// A `status` stub that ignores SIGTERM — and so does every command it starts —
|
|
599
|
+
// writes `?? ` and then `bytes` x's, and exits 0.
|
|
600
|
+
const trapTermStatus = (bytes) => `trap '' TERM; printf '?? '; head -c ${bytes} /dev/zero | tr '\\0' x; exit 0`;
|
|
601
|
+
|
|
602
|
+
// Past spawnSync's default 1 MiB buffer the kill that ENOBUFS sends is
|
|
603
|
+
// ignored: git exits 0 with no signal, but its output was cut off. That is a
|
|
604
|
+
// failed git, refused with a reason naming the overrun — read as ok, the
|
|
605
|
+
// truncated status would pass for a dirty tree.
|
|
606
|
+
test("a git that exits 0 after outgrowing the spawn buffer is refused, naming the overrun", () => {
|
|
607
|
+
const { dir } = repo(MAVEN_FILES);
|
|
608
|
+
const r = prove(dir, COUNT_PROOF, { env: { PATH: fakeGit("status*", trapTermStatus(2_000_000)) } });
|
|
609
|
+
assert.equal(r.status, 1, r.err);
|
|
610
|
+
assert.match(r.err, /NOT PROVEN — could not read the tree state in the throwaway worktree: git exited 0 after an error \(ENOBUFS: its output outgrew the spawn buffer\); install output: /);
|
|
611
|
+
assert.doesNotMatch(r.err, /killed|could not start git/);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
// The control: the same stub writing 1000 bytes is a git that succeeded, its
|
|
615
|
+
// output read whole — here, one untracked path the Install step left.
|
|
616
|
+
test("the same SIGTERM-trapping git with small output is ok, its output intact", () => {
|
|
617
|
+
const { dir } = repo(MAVEN_FILES);
|
|
618
|
+
const r = prove(dir, COUNT_PROOF, { env: { PATH: fakeGit("status*", trapTermStatus(997)) } });
|
|
619
|
+
assert.equal(r.status, 1, r.err);
|
|
620
|
+
assert.match(r.err, /NOT PROVEN — the Install step changed the tree \(first: \?\? x{997}\); /);
|
|
621
|
+
assert.doesNotMatch(r.err, /ENOBUFS|could not read the tree state/);
|
|
622
|
+
});
|
|
623
|
+
|
|
598
624
|
// A killed `worktree remove` is a failed one: cleanup falls back to the plain
|
|
599
625
|
// delete, and the proof's own NOT PROVEN — which keeps its log directory,
|
|
600
626
|
// the throwaway worktree's parent — stands.
|