@feigi/fleet-ctl 3.24.28 → 3.24.30
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 +1 -1
- package/scripts/claim-ticket.sh +8 -1
- package/scripts/derive-testcmd.sh +164 -19
- package/scripts/recipe-prove.mjs +22 -15
package/package.json
CHANGED
package/scripts/claim-ticket.sh
CHANGED
|
@@ -188,7 +188,14 @@ script_dir=$(dirname -- "$0")
|
|
|
188
188
|
rederive="the Recipe cache is invalid; run the Recipe derivation step (run-team phase 0, before the first claim) to re-derive it"
|
|
189
189
|
install=$("$script_dir/derive-testcmd.sh" . install 2>&1) || die "$install"
|
|
190
190
|
echo " Install step → $install" >&2
|
|
191
|
-
|
|
191
|
+
# The Test entrypoint is probed against origin/main, not the main checkout: the
|
|
192
|
+
# worktree is cut from origin/main (below), so that tree is where the command
|
|
193
|
+
# runs. Nothing here updates the main checkout, so after the suite moves on
|
|
194
|
+
# origin/main it still lists the old layout, and a pattern into it is accepted
|
|
195
|
+
# by a probe of the checkout and then selects nothing in the worktree — a run
|
|
196
|
+
# that reports `tests 0` at exit 0. The Install step takes no ref: the probe
|
|
197
|
+
# is the Test entrypoint's alone.
|
|
198
|
+
testcmd=$("$script_dir/derive-testcmd.sh" . test --at origin/main 2>&1) || die "$testcmd"
|
|
192
199
|
echo " test entrypoint → $testcmd" >&2
|
|
193
200
|
|
|
194
201
|
# The Test entrypoint is a shell COMMAND, not an argv: the runner hands it to
|
|
@@ -38,9 +38,16 @@
|
|
|
38
38
|
# PATH entry, an executable path). A red suite is a finding, not a stale
|
|
39
39
|
# Recipe, so nothing here ever runs the command.
|
|
40
40
|
#
|
|
41
|
+
# A Test entrypoint is also INVALID when a glob in it matches no tracked file
|
|
42
|
+
# (the vacuous-suite probe, below): such a suite selects no tests and passes
|
|
43
|
+
# having run nothing. The optional trailing `--at <rev>` names the commit whose
|
|
44
|
+
# tree that probe reads instead of <repo>'s own index, for a caller that runs
|
|
45
|
+
# the command in a worktree cut from a ref.
|
|
46
|
+
#
|
|
41
47
|
# Exit status: 0 the command is printed; 1 a refusal about the cache, the
|
|
42
48
|
# repository or the arguments; 3 a tool this script needs to read the cache
|
|
43
|
-
# (node, mktemp, cat) could not be started
|
|
49
|
+
# (git, node, mktemp, cat) could not be started, mktemp could not create its
|
|
50
|
+
# temp file, git did not run to an answer, or node died mid-read, so nothing
|
|
44
51
|
# was read and the cache's usability is unknown.
|
|
45
52
|
set -eu
|
|
46
53
|
|
|
@@ -77,10 +84,10 @@ export LC_ALL=C
|
|
|
77
84
|
# runs it in a fresh worktree and bakes it into the runner, and review-core.mjs's
|
|
78
85
|
# snapshot agent hands it to every specialist.
|
|
79
86
|
#
|
|
80
|
-
# GIT_WORK_TREE is unset alongside it
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
87
|
+
# GIT_WORK_TREE is unset alongside it: the vacuous-suite probe's `check-ignore`
|
|
88
|
+
# reads the ignore rules of whatever work tree git is pointed at, so an ambient
|
|
89
|
+
# one naming another directory would refuse a Test entrypoint whose pattern
|
|
90
|
+
# names this repository's gitignored build output.
|
|
84
91
|
# A prose test pins the line itself.
|
|
85
92
|
unset GIT_DIR GIT_WORK_TREE
|
|
86
93
|
|
|
@@ -89,11 +96,11 @@ NAME=derive-testcmd
|
|
|
89
96
|
die() { printf '%s: %s\n' "$NAME" "$1" >&2; exit 1; }
|
|
90
97
|
|
|
91
98
|
# A refusal about the environment, not the cache: a tool this script needs to
|
|
92
|
-
# read the cache (the interpreter, mktemp, cat) could not be started,
|
|
99
|
+
# read the cache (git, the interpreter, mktemp, cat) could not be started,
|
|
100
|
+
# mktemp could not create its temp file, git did not run to an answer, or the
|
|
93
101
|
# interpreter died mid-read, so nothing was read and the cache's usability is
|
|
94
102
|
# unknown. Exit 3, where every refusal about the cache, the repository or the
|
|
95
|
-
# arguments is exit 1. A
|
|
96
|
-
# as no repository, exit 1. A consumer that only tests for non-zero sees no
|
|
103
|
+
# arguments is exit 1. A consumer that only tests for non-zero sees no
|
|
97
104
|
# difference.
|
|
98
105
|
unrunnable() { printf '%s: %s\n' "$NAME" "$1" >&2; exit 3; }
|
|
99
106
|
|
|
@@ -101,22 +108,56 @@ unrunnable() { printf '%s: %s\n' "$NAME" "$1" >&2; exit 3; }
|
|
|
101
108
|
# step, so a controller or reviewer reading any of them knows what to run.
|
|
102
109
|
derive="run the Recipe derivation step (run-team phase 0, before the first claim) to derive, prove and write it"
|
|
103
110
|
|
|
104
|
-
|
|
111
|
+
# `--at <rev>` names the commit whose tree the Test entrypoint will run in, for
|
|
112
|
+
# the vacuous-suite probe below. A caller that builds its worktree from a ref
|
|
113
|
+
# (claim-ticket.sh cuts one from origin/main) is asking about THAT tree, which
|
|
114
|
+
# the repository's own checkout may not hold: after the suite moves upstream
|
|
115
|
+
# the checkout still lists the old layout until someone updates it. Without
|
|
116
|
+
# `--at` the probe reads <repo>'s own index, as for a caller that runs the
|
|
117
|
+
# command in <repo> itself. Three arguments is neither shape: a refusal.
|
|
118
|
+
usage="usage: derive-testcmd.sh <repo> <install|test> [--at <rev>]"
|
|
119
|
+
rev=
|
|
120
|
+
case $# in
|
|
121
|
+
2) ;;
|
|
122
|
+
4) [ "$3" = --at ] || die "$usage"
|
|
123
|
+
rev=$4
|
|
124
|
+
case $rev in ''|-*) die "--at needs a commit, got '$rev' — $usage" ;; esac ;;
|
|
125
|
+
*) die "$usage" ;;
|
|
126
|
+
esac
|
|
105
127
|
repo=$1
|
|
106
128
|
field=$2
|
|
107
129
|
|
|
108
|
-
git
|
|
130
|
+
# git's own fatal — no repository there, or no such directory — exits 128, the
|
|
131
|
+
# one status that is a verdict on the repository. Any other non-zero status is
|
|
132
|
+
# git not running to an answer: 126 or 127 from a git that cannot be started,
|
|
133
|
+
# 128+N from a signal. Both git calls below tell the two apart.
|
|
134
|
+
gitout=$(git -C "$repo" rev-parse --git-dir 2>&1) || {
|
|
135
|
+
gitrc=$?
|
|
136
|
+
case $gitrc in 128) die "$repo is not a git repository" ;; esac
|
|
137
|
+
unrunnable "git did not answer whether $repo is a git repository (exit $gitrc), so the Recipe cache was not read${gitout:+ — $gitout}"
|
|
138
|
+
}
|
|
109
139
|
|
|
110
140
|
case $field in
|
|
111
141
|
install|test) ;;
|
|
112
142
|
*) die "unknown Recipe field '$field' — expected install or test" ;;
|
|
113
143
|
esac
|
|
114
144
|
|
|
145
|
+
# A <rev> is only ever consulted by the probe, which only the Test entrypoint
|
|
146
|
+
# has; accepting it for the Install step would answer a question nothing asked.
|
|
147
|
+
if [ -n "$rev" ]; then
|
|
148
|
+
[ "$field" = test ] || die "--at applies to the test field only, not '$field' — $usage"
|
|
149
|
+
revc=$(git -C "$repo" rev-parse --verify "$rev^{commit}") \
|
|
150
|
+
|| die "--at '$rev' does not resolve to a commit in $repo"
|
|
151
|
+
fi
|
|
152
|
+
|
|
115
153
|
# `--path-format=absolute` so the workspace is a real directory whatever the
|
|
116
154
|
# caller's cwd; the workspace is the common dir's parent, the same rule
|
|
117
155
|
# git-env.mjs's workspaceDirFromGitCommonDir() applies for the ledger.
|
|
118
|
-
common=$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir 2>&1)
|
|
119
|
-
|
|
156
|
+
common=$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir 2>&1) || {
|
|
157
|
+
gitrc=$?
|
|
158
|
+
case $gitrc in 128) die "cannot resolve the common git dir of $repo — $common" ;; esac
|
|
159
|
+
unrunnable "git did not resolve the common git dir of $repo (exit $gitrc), so the Recipe cache was not read${common:+ — $common}"
|
|
160
|
+
}
|
|
120
161
|
cache="${common%/*}/.fleet/recipe.json"
|
|
121
162
|
|
|
122
163
|
# Absent is its own refusal, ahead of the interpreter probe: it is the one
|
|
@@ -162,7 +203,7 @@ lenf=$(mktemp) || unrunnable "cannot create a temporary file to read the Recipe
|
|
|
162
203
|
# Cleanup decides nothing: an `rm` that cannot be started would otherwise
|
|
163
204
|
# replace the script's own exit status with 127 (and print a line on the
|
|
164
205
|
# success path), so the status the script was leaving with is kept.
|
|
165
|
-
trap 'rc=$?; rm -f "$errf" "$lenf" 2>/dev/null || :; exit $rc' EXIT
|
|
206
|
+
trap 'rc=$?; rm -f "$errf" "$lenf" "$errf.idx" 2>/dev/null || :; exit $rc' EXIT
|
|
166
207
|
|
|
167
208
|
open='recipe<' close='>recipe'
|
|
168
209
|
rc=0
|
|
@@ -231,12 +272,14 @@ esac
|
|
|
231
272
|
value=${framed#"$open"}
|
|
232
273
|
value=${value%"$close"}
|
|
233
274
|
|
|
234
|
-
#
|
|
235
|
-
# textually (
|
|
236
|
-
#
|
|
237
|
-
#
|
|
238
|
-
#
|
|
239
|
-
#
|
|
275
|
+
# claim-ticket.sh appends the runner's own arguments after this string
|
|
276
|
+
# textually (`exec sh -c '<cmd> "$@"' agent-test "$@"`), so a command ending in
|
|
277
|
+
# `;`, `&`, or a newline lets a real shell read the caller's "$@" as an
|
|
278
|
+
# unrelated top-level command instead of args reaching the Test entrypoint, and
|
|
279
|
+
# one containing a `#`-led word swallows everything after it, "$@" included, as
|
|
280
|
+
# a comment. review-core.mjs's snapshot agent appends no arguments but embeds
|
|
281
|
+
# the string in `{ cd <dir> && <cmd>; }`, where the same endings and `#` word
|
|
282
|
+
# break the wrapper as a syntax error — measured on both. A trailing
|
|
240
283
|
# newline is checked here too: the frame above lets a value keep one
|
|
241
284
|
# where an unframed `$(…)` capture always dropped it silently, so a value
|
|
242
285
|
# that used to read as `true;` now reads as `true;\n` and would otherwise
|
|
@@ -299,4 +342,106 @@ case $1 in
|
|
|
299
342
|
;;
|
|
300
343
|
esac
|
|
301
344
|
|
|
345
|
+
# The vacuous-suite probe, for the Test entrypoint only. A pattern that
|
|
346
|
+
# matches no tracked file selects no tests, and a runner handed one can pass
|
|
347
|
+
# having run nothing: `node --test` over a glob that matches nothing reports
|
|
348
|
+
# `tests 0` and exits 0. The suite moved and the Recipe did not, so it is
|
|
349
|
+
# stale, refused like a binary that is gone. Tracked, not present on disk: a
|
|
350
|
+
# fresh worktree holds only what is tracked. Only a word the shell globs as
|
|
351
|
+
# written, from <repo>, can be settled without running the command: a word
|
|
352
|
+
# carrying quoting or an expansion, an option, an `=` assignment or value, or a
|
|
353
|
+
# path outside <repo> is the program's own to read and is accepted unprobed,
|
|
354
|
+
# and the scan stops at a `cd`, past which a pattern no longer resolves from
|
|
355
|
+
# <repo>. So is a word right after an option written without `=`, unless it
|
|
356
|
+
# has a `/` or a `.`: it may be that option's value, which names no path. A
|
|
357
|
+
# pattern under a path git ignores names generated output, such as a build
|
|
358
|
+
# the Install step produces, which is never tracked, so it is accepted too,
|
|
359
|
+
# and so is one through a symlink or a submodule, which git lists as one
|
|
360
|
+
# entry and declines to be asked beneath, and the shell follows or the
|
|
361
|
+
# Install step populates. `[` is a pattern only with a `]` after it, so the
|
|
362
|
+
# `[` builtin is not. The probe is git's `:(glob)` pathspec, whose `*` and
|
|
363
|
+
# `?` match a leading dot where the shell's do not, so a pattern whose only
|
|
364
|
+
# tracked matches are dotfiles is accepted though the shell would match
|
|
365
|
+
# nothing. With `--at <rev>` the tracked files are <rev>'s tree, read into a
|
|
366
|
+
# private index file, and the symlink and submodule test reads that tree
|
|
367
|
+
# too; the ignore rules are still <repo>'s working copy's, the one place git
|
|
368
|
+
# reads them from. The resolvability probe of the command's leading word
|
|
369
|
+
# above stays <repo>'s own.
|
|
370
|
+
if [ "$field" = test ]; then
|
|
371
|
+
# An ambient index would answer `ls-files` for whatever repository or commit
|
|
372
|
+
# the caller is in the middle of, not for <repo>'s tracked files.
|
|
373
|
+
unset GIT_INDEX_FILE
|
|
374
|
+
where=$repo
|
|
375
|
+
if [ -n "$rev" ]; then
|
|
376
|
+
where="$repo at $rev"
|
|
377
|
+
export GIT_INDEX_FILE="$errf.idx"
|
|
378
|
+
git -C "$repo" read-tree "$revc" 2>"$errf" || {
|
|
379
|
+
listed=$?
|
|
380
|
+
die "cannot read the tree of $rev in $repo (git read-tree exit $listed): $(cat "$errf" 2>/dev/null)"
|
|
381
|
+
}
|
|
382
|
+
fi
|
|
383
|
+
# Whether <path> is a directory git lists as ONE entry and never beneath: a
|
|
384
|
+
# symlink (the shell follows it) or a submodule (a gitlink, mode 160000, that
|
|
385
|
+
# the Install step populates). A symlink is a link on disk in <repo> itself
|
|
386
|
+
# and a mode-120000 entry in <rev>'s tree; a gitlink is an index entry either
|
|
387
|
+
# way. Status 0 yes, 1 no, 2 git could not say (its exit status in `listed`,
|
|
388
|
+
# its reason in `$errf`).
|
|
389
|
+
opaque() {
|
|
390
|
+
if [ -z "$rev" ] && [ -L "$repo/$1" ]; then return 0; fi
|
|
391
|
+
entries=$(git -C "$repo" ls-files -s -- ":(literal)$1" 2>"$errf") || { listed=$?; return 2; }
|
|
392
|
+
printf '%s\n' "$entries" \
|
|
393
|
+
| { while read -r mode _ _ path; do
|
|
394
|
+
[ "$path" = "$1" ] || continue
|
|
395
|
+
case $mode in
|
|
396
|
+
160000) exit 0 ;;
|
|
397
|
+
120000) [ -n "$rev" ] && exit 0 ;;
|
|
398
|
+
esac
|
|
399
|
+
done; exit 1; }
|
|
400
|
+
}
|
|
401
|
+
set -f
|
|
402
|
+
prev=
|
|
403
|
+
# shellcheck disable=SC2086 # field splitting is the point: scanning every word
|
|
404
|
+
for word in $value; do
|
|
405
|
+
before=$prev
|
|
406
|
+
prev=$word
|
|
407
|
+
case $word in
|
|
408
|
+
cd|pushd|*[\(\;\&\|]cd|*[\(\;\&\|]pushd) break ;;
|
|
409
|
+
-*|*=*|/*|*..*|*[\'\"\\\$\`\(\)\{\}\<\>\|\&\;\~]*) continue ;;
|
|
410
|
+
*'*'*|*'?'*|*'['*']'*) ;;
|
|
411
|
+
*) continue ;;
|
|
412
|
+
esac
|
|
413
|
+
case $before in
|
|
414
|
+
-*=*) ;;
|
|
415
|
+
-*) case $word in */*|*.*) ;; *) continue ;; esac ;;
|
|
416
|
+
esac
|
|
417
|
+
# The second pathspec is the directories the word matches: the shell hands
|
|
418
|
+
# `tests/*` the directory `tests/unit`, which ls-files lists only as the
|
|
419
|
+
# prefix of the files beneath it.
|
|
420
|
+
tracked=$(git -C "$repo" ls-files -- ":(glob)$word" ":(glob)${word%/}/**" 2>"$errf") || {
|
|
421
|
+
listed=$?
|
|
422
|
+
die "cannot list the files tracked in $where to check its test command's pattern '$word' (git ls-files exit $listed): $(cat "$errf" 2>/dev/null)"
|
|
423
|
+
}
|
|
424
|
+
[ -z "$tracked" ] || continue
|
|
425
|
+
lead=${word%%[*?[]*}
|
|
426
|
+
while :; do
|
|
427
|
+
case $lead in */*) lead=${lead%/*} ;; *) break ;; esac
|
|
428
|
+
opq=0
|
|
429
|
+
opaque "$lead" || opq=$?
|
|
430
|
+
case $opq in
|
|
431
|
+
0) continue 2 ;;
|
|
432
|
+
1) ;;
|
|
433
|
+
*) die "cannot ask git whether '$lead' is a symlink or a submodule in $where, to check its test command's pattern '$word' (git ls-files exit $listed): $(cat "$errf" 2>/dev/null)" ;;
|
|
434
|
+
esac
|
|
435
|
+
done
|
|
436
|
+
ignored=0
|
|
437
|
+
git -C "$repo" check-ignore -q --no-index -- "$word" 2>"$errf" || ignored=$?
|
|
438
|
+
case $ignored in
|
|
439
|
+
0) ;;
|
|
440
|
+
1) die "the Recipe cache at $cache is invalid: its test command's pattern '$word' matches no file tracked in $where — a Test entrypoint that selects no tests passes having run nothing, so the Recipe is stale, not a finding; $derive" ;;
|
|
441
|
+
*) die "cannot ask git whether $repo ignores its test command's pattern '$word' (git check-ignore exit $ignored): $(cat "$errf" 2>/dev/null)" ;;
|
|
442
|
+
esac
|
|
443
|
+
done
|
|
444
|
+
set +f
|
|
445
|
+
fi
|
|
446
|
+
|
|
302
447
|
printf '%s\n' "$value"
|
package/scripts/recipe-prove.mjs
CHANGED
|
@@ -43,7 +43,10 @@
|
|
|
43
43
|
// On proof, the cache is written atomically to <workspace>/.fleet/recipe.json
|
|
44
44
|
// — <workspace> being the directory holding the repository's common git dir,
|
|
45
45
|
// the place derive-testcmd.sh reads it from — and then read back through
|
|
46
|
-
// derive-testcmd.sh for both fields
|
|
46
|
+
// derive-testcmd.sh for both fields, the Test entrypoint against `derivedAt`'s
|
|
47
|
+
// tree (`--at`): the tree the proof ran in, and the one a claim probes, so a
|
|
48
|
+
// main checkout still on an older layout cannot refuse a Recipe that holds
|
|
49
|
+
// where it runs. A cache the reader refuses is rolled
|
|
47
50
|
// back to whatever stood before, as is one whose read-back is no verdict, so
|
|
48
51
|
// the reader stays the one authority on what a usable cache is. A failed
|
|
49
52
|
// proof never touches an existing cache.
|
|
@@ -58,10 +61,11 @@
|
|
|
58
61
|
// a git or filesystem fault stopped it before the cache was settled
|
|
59
62
|
// (a git command could not be started, the reader's own git
|
|
60
63
|
// included, or that git started and could not run; the reader's `sh`,
|
|
61
|
-
// `node`, `mktemp` or `cat` could not be started, its `
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
64
|
+
// `node`, `mktemp` or `cat` could not be started, its `mktemp` could
|
|
65
|
+
// not create its temp file, its `sh` was killed by a signal, or its
|
|
66
|
+
// `node` died mid-read — a `cat` that ran and failed stays the
|
|
67
|
+
// reader's refusal, exit 1; the cache or its temp file could not be
|
|
68
|
+
// written). The log directory under $TMPDIR is
|
|
65
69
|
// removed.
|
|
66
70
|
|
|
67
71
|
import { spawnSync } from "node:child_process";
|
|
@@ -115,8 +119,8 @@ const cannot = (message) => new Refusal(2, message);
|
|
|
115
119
|
const notProven = (message) => new Refusal(1, message);
|
|
116
120
|
|
|
117
121
|
// The exit status derive-testcmd.sh uses for a refusal about its own
|
|
118
|
-
// environment — a tool it needs would not start,
|
|
119
|
-
// every refusal about the cache is 1.
|
|
122
|
+
// environment — a tool it needs would not start, git did not run to an answer,
|
|
123
|
+
// or node died mid-read — where every refusal about the cache is 1.
|
|
120
124
|
const READER_COULD_NOT_RUN = 3;
|
|
121
125
|
|
|
122
126
|
function parseArgs(argv) {
|
|
@@ -294,13 +298,16 @@ function prove(o, wt, logs) {
|
|
|
294
298
|
// cache is undone just the same when the read-back is no verdict: an `sh` that
|
|
295
299
|
// could not be started read nothing; an `sh` killed by a signal has no exit
|
|
296
300
|
// status and reached no verdict; a reader that exits READER_COULD_NOT_RUN
|
|
297
|
-
// could not start its `node`, `mktemp` or `cat`,
|
|
298
|
-
//
|
|
299
|
-
//
|
|
300
|
-
//
|
|
301
|
-
//
|
|
302
|
-
//
|
|
303
|
-
//
|
|
301
|
+
// could not start its git, `node`, `mktemp` or `cat`, could not create its
|
|
302
|
+
// temp file, saw git end on any status but git's own 128, or lost its `node`
|
|
303
|
+
// mid-read; and the reader reads a git that ends on 128 as no repository at
|
|
304
|
+
// all, so its refusal is a verdict on what was proven only while git still
|
|
305
|
+
// runs. `git --version` is the probe for that exit-1 refusal: a working git
|
|
306
|
+
// always passes it, so a git that cannot be started fails it, and so does one
|
|
307
|
+
// that starts and cannot run — one that exits 128 on every call, or one that
|
|
308
|
+
// stopped running after the reader's own git calls answered. A git that exits
|
|
309
|
+
// 126 or 127, or is killed, on those calls never reaches the probe: the reader
|
|
310
|
+
// exits READER_COULD_NOT_RUN first.
|
|
304
311
|
function writeCache(cache, recipe, repo) {
|
|
305
312
|
mkdirSync(dirname(cache), { recursive: true });
|
|
306
313
|
const prior = existsSync(cache) ? readFileSync(cache) : null;
|
|
@@ -313,7 +320,7 @@ function writeCache(cache, recipe, repo) {
|
|
|
313
320
|
throw e;
|
|
314
321
|
}
|
|
315
322
|
for (const field of ["install", "test"]) {
|
|
316
|
-
const r = spawnSync("sh", [READER, repo, field], { env: ENV, encoding: "utf8" });
|
|
323
|
+
const r = spawnSync("sh", [READER, repo, field, ...(field === "test" ? ["--at", recipe.derivedAt] : [])], { env: ENV, encoding: "utf8" });
|
|
317
324
|
if (r.status === 0 && r.stdout.replace(/\n$/, "") === recipe[field]) continue;
|
|
318
325
|
if (prior === null) unlinkSync(cache);
|
|
319
326
|
else writeFileSync(cache, prior);
|