@feigi/fleet-ctl 3.24.27 → 3.24.29

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.24.27",
3
+ "version": "3.24.29",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -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
- testcmd=$("$script_dir/derive-testcmd.sh" . test 2>&1) || die "$testcmd"
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,6 +38,12 @@
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
49
  # (node, mktemp, cat) could not be started or node died mid-read, so nothing
@@ -77,10 +83,10 @@ export LC_ALL=C
77
83
  # runs it in a fresh worktree and bakes it into the runner, and review-core.mjs's
78
84
  # snapshot agent hands it to every specialist.
79
85
  #
80
- # GIT_WORK_TREE is unset alongside it and is INERT here: `rev-parse --git-dir`
81
- # and `--git-common-dir` consult no work tree. It stays on the line because the
82
- # pair is one hazard with one remedy, and "inert today" is a measurement of the
83
- # current call set, not a property of the script.
86
+ # GIT_WORK_TREE is unset alongside it: the vacuous-suite probe's `check-ignore`
87
+ # reads the ignore rules of whatever work tree git is pointed at, so an ambient
88
+ # one naming another directory would refuse a Test entrypoint whose pattern
89
+ # names this repository's gitignored build output.
84
90
  # A prose test pins the line itself.
85
91
  unset GIT_DIR GIT_WORK_TREE
86
92
 
@@ -101,7 +107,22 @@ unrunnable() { printf '%s: %s\n' "$NAME" "$1" >&2; exit 3; }
101
107
  # step, so a controller or reviewer reading any of them knows what to run.
102
108
  derive="run the Recipe derivation step (run-team phase 0, before the first claim) to derive, prove and write it"
103
109
 
104
- [ $# -eq 2 ] || die "usage: derive-testcmd.sh <repo> <install|test>"
110
+ # `--at <rev>` names the commit whose tree the Test entrypoint will run in, for
111
+ # the vacuous-suite probe below. A caller that builds its worktree from a ref
112
+ # (claim-ticket.sh cuts one from origin/main) is asking about THAT tree, which
113
+ # the repository's own checkout may not hold: after the suite moves upstream
114
+ # the checkout still lists the old layout until someone updates it. Without
115
+ # `--at` the probe reads <repo>'s own index, as for a caller that runs the
116
+ # command in <repo> itself. Three arguments is neither shape: a refusal.
117
+ usage="usage: derive-testcmd.sh <repo> <install|test> [--at <rev>]"
118
+ rev=
119
+ case $# in
120
+ 2) ;;
121
+ 4) [ "$3" = --at ] || die "$usage"
122
+ rev=$4
123
+ case $rev in ''|-*) die "--at needs a commit, got '$rev' — $usage" ;; esac ;;
124
+ *) die "$usage" ;;
125
+ esac
105
126
  repo=$1
106
127
  field=$2
107
128
 
@@ -112,6 +133,14 @@ case $field in
112
133
  *) die "unknown Recipe field '$field' — expected install or test" ;;
113
134
  esac
114
135
 
136
+ # A <rev> is only ever consulted by the probe, which only the Test entrypoint
137
+ # has; accepting it for the Install step would answer a question nothing asked.
138
+ if [ -n "$rev" ]; then
139
+ [ "$field" = test ] || die "--at applies to the test field only, not '$field' — $usage"
140
+ revc=$(git -C "$repo" rev-parse --verify "$rev^{commit}") \
141
+ || die "--at '$rev' does not resolve to a commit in $repo"
142
+ fi
143
+
115
144
  # `--path-format=absolute` so the workspace is a real directory whatever the
116
145
  # caller's cwd; the workspace is the common dir's parent, the same rule
117
146
  # git-env.mjs's workspaceDirFromGitCommonDir() applies for the ledger.
@@ -162,7 +191,7 @@ lenf=$(mktemp) || unrunnable "cannot create a temporary file to read the Recipe
162
191
  # Cleanup decides nothing: an `rm` that cannot be started would otherwise
163
192
  # replace the script's own exit status with 127 (and print a line on the
164
193
  # 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
194
+ trap 'rc=$?; rm -f "$errf" "$lenf" "$errf.idx" 2>/dev/null || :; exit $rc' EXIT
166
195
 
167
196
  open='recipe<' close='>recipe'
168
197
  rc=0
@@ -231,12 +260,14 @@ esac
231
260
  value=${framed#"$open"}
232
261
  value=${value%"$close"}
233
262
 
234
- # Both consumers append the runner's own arguments after this string
235
- # textually (claim-ticket.sh's `exec sh -c '<cmd> "$@"' agent-test "$@"`), so
236
- # a command ending in `;`, `&`, or a newline lets a real shell read the
237
- # caller's "$@" as an unrelated top-level command instead of args reaching
238
- # the Test entrypoint, and one containing a `#`-led word swallows everything
239
- # after it, "$@" included, as a comment — measured on both. A trailing
263
+ # claim-ticket.sh appends the runner's own arguments after this string
264
+ # textually (`exec sh -c '<cmd> "$@"' agent-test "$@"`), so a command ending in
265
+ # `;`, `&`, or a newline lets a real shell read the caller's "$@" as an
266
+ # unrelated top-level command instead of args reaching the Test entrypoint, and
267
+ # one containing a `#`-led word swallows everything after it, "$@" included, as
268
+ # a comment. review-core.mjs's snapshot agent appends no arguments but embeds
269
+ # the string in `{ cd <dir> && <cmd>; }`, where the same endings and `#` word
270
+ # break the wrapper as a syntax error — measured on both. A trailing
240
271
  # newline is checked here too: the frame above lets a value keep one
241
272
  # where an unframed `$(…)` capture always dropped it silently, so a value
242
273
  # that used to read as `true;` now reads as `true;\n` and would otherwise
@@ -299,4 +330,106 @@ case $1 in
299
330
  ;;
300
331
  esac
301
332
 
333
+ # The vacuous-suite probe, for the Test entrypoint only. A pattern that
334
+ # matches no tracked file selects no tests, and a runner handed one can pass
335
+ # having run nothing: `node --test` over a glob that matches nothing reports
336
+ # `tests 0` and exits 0. The suite moved and the Recipe did not, so it is
337
+ # stale, refused like a binary that is gone. Tracked, not present on disk: a
338
+ # fresh worktree holds only what is tracked. Only a word the shell globs as
339
+ # written, from <repo>, can be settled without running the command: a word
340
+ # carrying quoting or an expansion, an option, an `=` assignment or value, or a
341
+ # path outside <repo> is the program's own to read and is accepted unprobed,
342
+ # and the scan stops at a `cd`, past which a pattern no longer resolves from
343
+ # <repo>. So is a word right after an option written without `=`, unless it
344
+ # has a `/` or a `.`: it may be that option's value, which names no path. A
345
+ # pattern under a path git ignores names generated output, such as a build
346
+ # the Install step produces, which is never tracked, so it is accepted too,
347
+ # and so is one through a symlink or a submodule, which git lists as one
348
+ # entry and declines to be asked beneath, and the shell follows or the
349
+ # Install step populates. `[` is a pattern only with a `]` after it, so the
350
+ # `[` builtin is not. The probe is git's `:(glob)` pathspec, whose `*` and
351
+ # `?` match a leading dot where the shell's do not, so a pattern whose only
352
+ # tracked matches are dotfiles is accepted though the shell would match
353
+ # nothing. With `--at <rev>` the tracked files are <rev>'s tree, read into a
354
+ # private index file, and the symlink and submodule test reads that tree
355
+ # too; the ignore rules are still <repo>'s working copy's, the one place git
356
+ # reads them from. The resolvability probe of the command's leading word
357
+ # above stays <repo>'s own.
358
+ if [ "$field" = test ]; then
359
+ # An ambient index would answer `ls-files` for whatever repository or commit
360
+ # the caller is in the middle of, not for <repo>'s tracked files.
361
+ unset GIT_INDEX_FILE
362
+ where=$repo
363
+ if [ -n "$rev" ]; then
364
+ where="$repo at $rev"
365
+ export GIT_INDEX_FILE="$errf.idx"
366
+ git -C "$repo" read-tree "$revc" 2>"$errf" || {
367
+ listed=$?
368
+ die "cannot read the tree of $rev in $repo (git read-tree exit $listed): $(cat "$errf" 2>/dev/null)"
369
+ }
370
+ fi
371
+ # Whether <path> is a directory git lists as ONE entry and never beneath: a
372
+ # symlink (the shell follows it) or a submodule (a gitlink, mode 160000, that
373
+ # the Install step populates). A symlink is a link on disk in <repo> itself
374
+ # and a mode-120000 entry in <rev>'s tree; a gitlink is an index entry either
375
+ # way. Status 0 yes, 1 no, 2 git could not say (its exit status in `listed`,
376
+ # its reason in `$errf`).
377
+ opaque() {
378
+ if [ -z "$rev" ] && [ -L "$repo/$1" ]; then return 0; fi
379
+ entries=$(git -C "$repo" ls-files -s -- ":(literal)$1" 2>"$errf") || { listed=$?; return 2; }
380
+ printf '%s\n' "$entries" \
381
+ | { while read -r mode _ _ path; do
382
+ [ "$path" = "$1" ] || continue
383
+ case $mode in
384
+ 160000) exit 0 ;;
385
+ 120000) [ -n "$rev" ] && exit 0 ;;
386
+ esac
387
+ done; exit 1; }
388
+ }
389
+ set -f
390
+ prev=
391
+ # shellcheck disable=SC2086 # field splitting is the point: scanning every word
392
+ for word in $value; do
393
+ before=$prev
394
+ prev=$word
395
+ case $word in
396
+ cd|pushd|*[\(\;\&\|]cd|*[\(\;\&\|]pushd) break ;;
397
+ -*|*=*|/*|*..*|*[\'\"\\\$\`\(\)\{\}\<\>\|\&\;\~]*) continue ;;
398
+ *'*'*|*'?'*|*'['*']'*) ;;
399
+ *) continue ;;
400
+ esac
401
+ case $before in
402
+ -*=*) ;;
403
+ -*) case $word in */*|*.*) ;; *) continue ;; esac ;;
404
+ esac
405
+ # The second pathspec is the directories the word matches: the shell hands
406
+ # `tests/*` the directory `tests/unit`, which ls-files lists only as the
407
+ # prefix of the files beneath it.
408
+ tracked=$(git -C "$repo" ls-files -- ":(glob)$word" ":(glob)${word%/}/**" 2>"$errf") || {
409
+ listed=$?
410
+ 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)"
411
+ }
412
+ [ -z "$tracked" ] || continue
413
+ lead=${word%%[*?[]*}
414
+ while :; do
415
+ case $lead in */*) lead=${lead%/*} ;; *) break ;; esac
416
+ opq=0
417
+ opaque "$lead" || opq=$?
418
+ case $opq in
419
+ 0) continue 2 ;;
420
+ 1) ;;
421
+ *) 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)" ;;
422
+ esac
423
+ done
424
+ ignored=0
425
+ git -C "$repo" check-ignore -q --no-index -- "$word" 2>"$errf" || ignored=$?
426
+ case $ignored in
427
+ 0) ;;
428
+ 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" ;;
429
+ *) die "cannot ask git whether $repo ignores its test command's pattern '$word' (git check-ignore exit $ignored): $(cat "$errf" 2>/dev/null)" ;;
430
+ esac
431
+ done
432
+ set +f
433
+ fi
434
+
302
435
  printf '%s\n' "$value"
@@ -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. A cache the reader refuses is rolled
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.
@@ -313,7 +316,7 @@ function writeCache(cache, recipe, repo) {
313
316
  throw e;
314
317
  }
315
318
  for (const field of ["install", "test"]) {
316
- const r = spawnSync("sh", [READER, repo, field], { env: ENV, encoding: "utf8" });
319
+ const r = spawnSync("sh", [READER, repo, field, ...(field === "test" ? ["--at", recipe.derivedAt] : [])], { env: ENV, encoding: "utf8" });
317
320
  if (r.status === 0 && r.stdout.replace(/\n$/, "") === recipe[field]) continue;
318
321
  if (prior === null) unlinkSync(cache);
319
322
  else writeFileSync(cache, prior);