@feigi/fleet-ctl 3.130.4 → 3.131.0

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.130.4",
3
+ "version": "3.131.0",
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": {
@@ -186,15 +186,16 @@ script_dir=$(dirname -- "$0")
186
186
  # copies could drift apart, and derive-testcmd.sh already keeps its own
187
187
  # version the same way (`$derive`).
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
- install=$("$script_dir/derive-testcmd.sh" . install 2>&1) || die "$install"
189
+ # Both are probed against origin/main, not the main checkout: the worktree is
190
+ # cut from origin/main (below), so that tree is where the commands run.
191
+ # Nothing here updates the main checkout, so after a path moves on origin/main
192
+ # the checkout still holds the old layout: an Install step or Test entrypoint
193
+ # whose script origin/main lost reads as runnable there and then fails in the
194
+ # worktree, and a test pattern into the old layout is accepted by a probe of
195
+ # the checkout and then selects nothing in the worktree — a run that reports
196
+ # `tests 0` at exit 0.
197
+ install=$("$script_dir/derive-testcmd.sh" . install --at origin/main 2>&1) || die "$install"
190
198
  echo " Install step → $install" >&2
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
199
  testcmd=$("$script_dir/derive-testcmd.sh" . test --at origin/main 2>&1) || die "$testcmd"
199
200
  echo " test entrypoint → $testcmd" >&2
200
201
 
@@ -58,8 +58,9 @@
58
58
  # A Test entrypoint is also INVALID when a glob in it matches no tracked file
59
59
  # (the vacuous-suite probe, below): such a suite selects no tests and passes
60
60
  # having run nothing. The optional trailing `--at <rev>` names the commit whose
61
- # tree that probe reads instead of <repo>'s own index, for a caller that runs
62
- # the command in a worktree cut from a ref.
61
+ # tree the probes read instead of <repo>'s own, for a caller that runs the
62
+ # command in a worktree cut from a ref: the leading word's resolvability probe
63
+ # for any command field, and the vacuous-suite probe for the Test entrypoint.
63
64
  #
64
65
  # A Test entrypoint is ONE simple command: a join or a group (an unquoted
65
66
  # newline, or an unquoted `;`, `&`, `|`, `(` or `)` outside a redirection) is
@@ -139,13 +140,13 @@ unrunnable() { printf '%s: %s\n' "$NAME" "$1" >&2; exit 3; }
139
140
  # step, so a controller or reviewer reading any of them knows what to run.
140
141
  derive="run the Recipe derivation step (run-team phase 0, before the first claim) to derive, prove and write it"
141
142
 
142
- # `--at <rev>` names the commit whose tree the Test entrypoint will run in, for
143
- # the vacuous-suite probe below. A caller that builds its worktree from a ref
144
- # (claim-ticket.sh cuts one from origin/main) is asking about THAT tree, which
145
- # the repository's own checkout may not hold: after the suite moves upstream
146
- # the checkout still lists the old layout until someone updates it. Without
147
- # `--at` the probe reads <repo>'s own index, as for a caller that runs the
148
- # command in <repo> itself. Three arguments is neither shape: a refusal.
143
+ # `--at <rev>` names the commit whose tree the command will run in. A caller
144
+ # that builds its worktree from a ref (claim-ticket.sh cuts one from
145
+ # origin/main) is asking about THAT tree, which the repository's own checkout
146
+ # may not hold: after a path moves upstream the checkout still has the old
147
+ # layout until someone updates it. Without `--at` the probes read <repo>'s own
148
+ # working tree and index, as for a caller that runs the command in <repo>
149
+ # itself. Three arguments is neither shape: a refusal.
149
150
  usage="usage: derive-testcmd.sh <repo> <install|check|test|uncovered> [--at <rev>]
150
151
  derive-testcmd.sh --propose <repo> <install|check|test> <command> [--at <rev>]"
151
152
  propose=
@@ -185,10 +186,11 @@ case $field in
185
186
  *) die "unknown Recipe field '$field' — expected install, check, test or uncovered" ;;
186
187
  esac
187
188
 
188
- # A <rev> is only ever consulted by the probe, which only the Test entrypoint
189
- # has; accepting it for the Install step would answer a question nothing asked.
189
+ # A <rev> is consulted by the probes, which only a command field has:
190
+ # `uncovered` is data that nothing runs, so accepting it there would answer a
191
+ # question nothing asked.
190
192
  if [ -n "$rev" ]; then
191
- [ "$field" = test ] || die "--at applies to the test field only, not '$field' — $usage"
193
+ [ "$field" != uncovered ] || die "--at applies to the install, check and test fields, not '$field' — $usage"
192
194
  revc=$(git -C "$repo" rev-parse --verify "$rev^{commit}") \
193
195
  || die "--at '$rev' does not resolve to a commit in $repo"
194
196
  fi
@@ -463,20 +465,93 @@ while [ $# -gt 0 ]; do
463
465
  esac
464
466
  done
465
467
  [ $# -gt 0 ] || die "$subj $field command names no command, only assignments — $tail"
468
+ # On disk, in <repo>, so a relative `./run-tests.sh` resolves where the command
469
+ # itself will run from. `command -v` alone is not exec-bit-aware for a
470
+ # `/`-containing word under dash (Ubuntu's default /bin/sh): it only stat()s
471
+ # the path there, never checking execute permission — measured: `dash -c
472
+ # 'command -v ./run.sh'` on a chmod 0644 file exits 0. `[ -x ]` is the
473
+ # exec-bit-aware check that closes the gap; a bare name (builtin or a PATH
474
+ # match) has no path to test and is left to `command -v`.
475
+ ondisk() {
476
+ (cd "$repo" && command -v -- "$1" || exit 1
477
+ case $1 in */*) [ -x "$1" ] || exit 1 ;; esac) >/dev/null 2>&1 \
478
+ || die "$subj $field command '$1' is not found or not executable from $repo — $stale; $tail"
479
+ }
480
+ # The path a relative `/`-containing word names under <repo>, its `.` and `..`
481
+ # segments folded, in `inrepo`. Status 1, nothing set, for an absolute word, a
482
+ # word that climbs out of <repo>, or one that names <repo> itself: none of them
483
+ # is a path <rev>'s tree can hold, so the disk answers for them.
484
+ inside() {
485
+ case $1 in /*) return 1 ;; esac
486
+ in_rest=$1/
487
+ inrepo=
488
+ while [ -n "$in_rest" ]; do
489
+ in_seg=${in_rest%%/*}
490
+ in_rest=${in_rest#*/}
491
+ case $in_seg in
492
+ ''|.) ;;
493
+ ..)
494
+ [ -n "$inrepo" ] || return 1
495
+ case $inrepo in */*) inrepo=${inrepo%/*} ;; *) inrepo= ;; esac ;;
496
+ *) inrepo=${inrepo:+$inrepo/}$in_seg ;;
497
+ esac
498
+ done
499
+ [ -n "$inrepo" ]
500
+ }
501
+ # The mode <rev>'s tree records at the <repo> path $1 — 100755, 100644, 120000,
502
+ # 160000 or 040000 — in `mode`, empty when the tree holds no entry there. A
503
+ # git that cannot list it is no verdict: exit 3.
504
+ revmode() {
505
+ mode=$(git -C "$repo" ls-tree "$revc" -- ":(literal)$1" 2>"$errf") || {
506
+ listed=$?
507
+ unrunnable "cannot list '$1' in the tree of $rev in $repo to check its $field command (git ls-tree exit $listed): $(cat "$errf" 2>/dev/null)"
508
+ }
509
+ mode=${mode%% *}
510
+ }
511
+ # Whether the word $2, naming the <repo> path $1, runs in <rev>'s tree. An
512
+ # executable file there runs. A symlink or a submodule entry — the path's own
513
+ # or a directory's on the way to it — is accepted unprobed, as the
514
+ # vacuous-suite probe accepts one: the shell follows a link, the Install step
515
+ # populates a submodule. A path the tree does not hold runs only when git
516
+ # ignores it, as generated output such as an Install step's product, with the
517
+ # ignore rules read from <repo>'s working copy, the one place git reads them
518
+ # from. Anything else — a file without the exec bit, a directory, an absent
519
+ # path git does not ignore — is refused.
520
+ atrev() {
521
+ refusal="$subj $field command '$2' is not found or not executable from $repo at $rev — $stale; $tail"
522
+ # A word ending in `/` or `/.` asks for a directory, and the shell runs no
523
+ # directory — measured: with bin/run.sh an executable file, `sh -c
524
+ # './bin/run.sh/'` and `sh -c './bin/run.sh/.'` each exit 126 — though
525
+ # inside() folds it to the path of the entry it ends in.
526
+ case $2 in */|*/.) die "$refusal" ;; esac
527
+ revmode "$1"
528
+ case $mode in
529
+ 100755|120000|160000) return 0 ;;
530
+ '') ;;
531
+ *) die "$refusal" ;;
532
+ esac
533
+ at_lead=$1
534
+ while :; do
535
+ case $at_lead in */*) at_lead=${at_lead%/*} ;; *) break ;; esac
536
+ revmode "$at_lead"
537
+ case $mode in 120000|160000) return 0 ;; esac
538
+ done
539
+ ignored=0
540
+ git -C "$repo" check-ignore -q --no-index -- "$1" 2>"$errf" || ignored=$?
541
+ case $ignored in
542
+ 0) ;;
543
+ 1) die "$refusal" ;;
544
+ *) unrunnable "cannot ask git whether $repo ignores its $field command '$2' (git check-ignore exit $ignored): $(cat "$errf" 2>/dev/null)" ;;
545
+ esac
546
+ }
547
+ # With `--at`, a `/`-containing word that names a path inside <repo> is judged
548
+ # against <rev>'s tree, the one the command will run in; an absolute or
549
+ # escaping one, and a bare name, keep the disk's answer.
466
550
  case $1 in
467
551
  *[\'\"\\\$\`\(\)\{\}\<\>\|\&\;\*\?\[\~]*) ;;
468
- *)
469
- # In <repo>, so a relative `./run-tests.sh` resolves where the command
470
- # itself will run from. `command -v` alone is not exec-bit-aware for a
471
- # `/`-containing word under dash (Ubuntu's default /bin/sh): it only
472
- # stat()s the path there, never checking execute permission — measured:
473
- # `dash -c 'command -v ./run.sh'` on a chmod 0644 file exits 0. `[ -x ]`
474
- # is the exec-bit-aware check that closes the gap; a bare name (builtin
475
- # or a PATH match) has no path to test and is left to `command -v`.
476
- (cd "$repo" && command -v -- "$1" || exit 1
477
- case $1 in */*) [ -x "$1" ] || exit 1 ;; esac) >/dev/null 2>&1 \
478
- || die "$subj $field command '$1' is not found or not executable from $repo — $stale; $tail"
479
- ;;
552
+ */*)
553
+ if [ -n "$rev" ] && inside "$1"; then atrev "$inrepo" "$1"; else ondisk "$1"; fi ;;
554
+ *) ondisk "$1" ;;
480
555
  esac
481
556
 
482
557
  # The vacuous-suite probe, for the Test entrypoint only. A pattern that
@@ -525,8 +600,7 @@ esac
525
600
  # nothing. With `--at <rev>` the tracked files are <rev>'s tree, read into a
526
601
  # private index file, and the symlink and submodule test reads that tree
527
602
  # too; the ignore rules are still <repo>'s working copy's, the one place git
528
- # reads them from. The resolvability probe of the command's leading word
529
- # above stays <repo>'s own. A git call of the probe that fails is git not
603
+ # reads them from. A git call of the probe that fails is git not
530
604
  # running to an answer, exit 3: no verdict on the cache or on a proposal, so
531
605
  # recipe-prove.mjs never reads it as NOT PROVEN.
532
606
  if [ "$field" = test ]; then
@@ -62,7 +62,7 @@
62
62
  // --scratch <scratch>`, its stdout printed. That script writes its own
63
63
  // verdict token; its exit 1 is a verdict, its exit 2 a NEED.
64
64
  // A `failed` outcome takes no dispositions check and runs the Recipe read, below.
65
- // The Recipe read, after an `impl-report` settled `blocked` or a `fix-report` settled `failed`, whatever the member's cause: `derive-testcmd.sh . install`, `. check` and `. test --at origin/main` from the main checkout, the three reads phase0.mjs's `recipe` step makes (recipe-read.mjs is the one reader of both). All three exit 0: nothing printed, the cache is valid. One refused (exit 1): the refused reads, then `NEED derive-recipe`, which is phase 0's mid-run trigger; a refusal naming `--at` is no cache fault, and the controller fetches and reads again. Exit 3 or any other failure of a read: a `NEED recipe-read …` line carrying the environment fault, since the cache's state is unknown and deriving would not help. A cause local to the member's worktree reads valid from the main checkout and prints nothing. No other outcome runs the reads.
65
+ // The Recipe read, after an `impl-report` settled `blocked` or a `fix-report` settled `failed`, whatever the member's cause: `derive-testcmd.sh . install`, `. check` and `. test`, each `--at origin/main`, from the main checkout, the three reads phase0.mjs's `recipe` step makes (recipe-read.mjs is the one reader of both). All three exit 0: nothing printed, the cache is valid. One refused (exit 1): the refused reads, then `NEED derive-recipe`, which is phase 0's mid-run trigger; a refusal naming `--at` is no cache fault, and the controller fetches and reads again. Exit 3 or any other failure of a read: a `NEED recipe-read …` line carrying the environment fault, since the cache's state is unknown and deriving would not help. A cause local to the member's worktree reads valid from the main checkout and prints nothing. No other outcome runs the reads.
66
66
  // finisher-report <finisher-pr-M[-x]>
67
67
  // `settle --from-report`. Settled `halted:<cause>`: `gh pr comment <M>`
68
68
  // with the report's cause and evidence. A repair finisher (a retry
@@ -2821,12 +2821,17 @@ async function runSettleFromReport() {
2821
2821
  // runs either command — the record is the member's word, at the trust level
2822
2822
  // of its report. A repository whose Recipe cache derive-testcmd.sh refuses
2823
2823
  // (exit 1: absent, unproven, invalid) has no Check step to have run, so no
2824
- // gate applies; any other answer from it could not look. `head`'s commit
2825
- // object must be local when the tree is read: `fetchHead`, when given, puts
2826
- // it there, and runs only once a gate applies.
2824
+ // gate applies; any other answer from it could not look. Both reads judge
2825
+ // the cache against origin/main's tree, the one members' worktrees are cut
2826
+ // from. The reader refuses an `--at` that does not resolve with the same
2827
+ // exit 1 as a cache it refuses, so origin/main is resolved first: one that
2828
+ // does not resolve could not look, never a repository with no gate.
2829
+ // `head`'s commit object must be local when the tree is read: `fetchHead`,
2830
+ // when given, puts it there, and runs only once a gate applies.
2827
2831
  const recipeGate = (head, fetchHead) => {
2832
+ look("git rev-parse --verify origin/main^{commit}", "git", ["rev-parse", "--verify", "--quiet", "origin/main^{commit}"]);
2828
2833
  for (const field of ["check", "test"]) {
2829
- if (look(`derive-testcmd.sh . ${field}`, "sh", [deriveTestcmd, repoDir(), field], [0, 1]).status === 1) return;
2834
+ if (look(`derive-testcmd.sh . ${field} --at origin/main`, "sh", [deriveTestcmd, repoDir(), field, "--at", "origin/main"], [0, 1]).status === 1) return;
2830
2835
  }
2831
2836
  const rec = readCheckRecordIn(reports, member);
2832
2837
  const label = rec.state === "absent" ? `a Check-step record exists at ${rec.path}`
@@ -70,8 +70,8 @@
70
70
  // for the other keys under the scratch parent, which runs
71
71
  // whatever the first answered. What either receipt's failed[]
72
72
  // names is listed. Recorded; never fails the run.
73
- // recipe `derive-testcmd.sh . install`, `. check` and `. test --at
74
- // origin/main` (recipe-read.mjs, which the settle wakes of
73
+ // recipe `derive-testcmd.sh . install`, `. check` and `. test`, each
74
+ // `--at origin/main` (recipe-read.mjs, which the settle wakes of
75
75
  // fleet-event.mjs read the cache through as well). Any
76
76
  // exiting 1 is a cache with nothing valid in it: pending,
77
77
  // `NEED derive-recipe`. Exit 3 (a tool the reader could not run)
@@ -74,10 +74,10 @@
74
74
  // — <workspace> being the directory workspaceDirFromGitCommonDir() names for the repository,
75
75
  // the place derive-testcmd.sh reads it from — and then read back through
76
76
  // derive-testcmd.sh for every field, `uncovered` byte for byte as the compact
77
- // JSON of the list given, the Test entrypoint against `derivedAt`'s
78
- // tree (`--at`): the tree the proof ran in, and the one a claim probes, so a
79
- // main checkout still on an older layout cannot refuse a Recipe that holds
80
- // where it runs. A cache the reader refuses is rolled
77
+ // JSON of the list given, the Install step, the Check step and the Test
78
+ // entrypoint against `derivedAt`'s tree (`--at`): the tree the proof ran in,
79
+ // and the one a claim probes, so a main checkout still on an older layout
80
+ // cannot refuse a Recipe that holds where it runs. A cache the reader refuses is rolled
81
81
  // back to whatever stood before, as is one whose read-back is no verdict, so
82
82
  // the reader stays the one authority on what a usable cache is. A failed
83
83
  // proof never touches an existing cache.
@@ -261,9 +261,11 @@ function checkCovered(json, uncovered, check) {
261
261
 
262
262
  // The reader's shape check, before any command runs: `--propose` holds a
263
263
  // proposed command to the rules the cache is held to, with no cache read and no
264
- // command run, so one the cache would refuse is refused before the proof.
264
+ // command run, so one the cache would refuse is refused before the proof. `at`
265
+ // is the commit the proof runs against, so a command path only it holds is
266
+ // judged in the tree it will run in, not in the main checkout.
265
267
  function preflight(field, command, repo, at) {
266
- const args = [READER, "--propose", repo, field, command, ...(field === "test" ? ["--at", at] : [])];
268
+ const args = [READER, "--propose", repo, field, command, "--at", at];
267
269
  const r = spawnSync("sh", args, { env: ENV, encoding: "utf8" });
268
270
  if (r.error && !r.pid) throw cannot(`could not start sh to check the ${field} command: ${r.error.message}`);
269
271
  if (r.signal) throw cannot(`the reader's sh was killed by ${r.signal}${errorCause(r.error)}, so the ${field} command was not checked`);
@@ -496,7 +498,7 @@ function writeCache(cache, recipe, repo) {
496
498
  throw e;
497
499
  }
498
500
  for (const field of ["install", "check", "test", "uncovered"]) {
499
- const r = spawnSync("sh", [READER, repo, field, ...(field === "test" ? ["--at", recipe.derivedAt] : [])], { env: ENV, encoding: "utf8" });
501
+ const r = spawnSync("sh", [READER, repo, field, ...(field === "uncovered" ? [] : ["--at", recipe.derivedAt])], { env: ENV, encoding: "utf8" });
500
502
  const expected = field === "uncovered" ? JSON.stringify(recipe.uncovered) : String(recipe[field]);
501
503
  const got = r.status === 0 ? r.stdout.replace(/\n$/, "") : null;
502
504
  if (got === expected) continue;
@@ -4,9 +4,11 @@
4
4
  //
5
5
  // readRecipe(cwd, { timeoutMs }) -> { state, output }
6
6
  //
7
- // `derive-testcmd.sh . install`, `. check` and `. test --at origin/main`, each
8
- // run from `cwd`, the main checkout — the one place the cache is read from —
9
- // and all three always run, so every refused read is named. `timeoutMs`, when
7
+ // `derive-testcmd.sh . install --at origin/main`, `. check --at origin/main`
8
+ // and `. test --at origin/main`, each run from `cwd`, the main checkout — the
9
+ // one place the cache is read from — and judged against origin/main's tree,
10
+ // the one members' worktrees are cut from, which the main checkout may lag.
11
+ // All three always run, so every refused read is named. `timeoutMs`, when
10
12
  // given, bounds each read; one that outlives it is killed and reads `broken`.
11
13
  // `state` is:
12
14
  //
@@ -33,7 +35,7 @@ const DERIVE = join(dirname(fileURLToPath(import.meta.url)), "derive-testcmd.sh"
33
35
  const MAX_BUFFER = 64 * 1024 * 1024;
34
36
 
35
37
  /** The reads, as arguments after the repository `.`. */
36
- const RECIPE_READS = [["install"], ["check"], ["test", "--at", "origin/main"]];
38
+ const RECIPE_READS = ["install", "check", "test"].map((field) => [field, "--at", "origin/main"]);
37
39
 
38
40
  const trimmed = (s) => String(s ?? "").trim();
39
41
  const lines = (s) => trimmed(s).split("\n").filter((l) => l.trim() !== "");
@@ -424,8 +424,8 @@ step and bakes its Test entrypoint into the member's runner, and every
424
424
  review reads the Test entrypoint, all out of the **Recipe cache**
425
425
  (`.fleet/recipe.json` beside the common git dir); no script infers either
426
426
  command. Check it first: `~/.fleet/bin/fleet-run derive-testcmd.sh .
427
- install`, `~/.fleet/bin/fleet-run derive-testcmd.sh . check` and
428
- `~/.fleet/bin/fleet-run derive-testcmd.sh . test --at
427
+ install --at origin/main`, `~/.fleet/bin/fleet-run derive-testcmd.sh . check
428
+ --at origin/main` and `~/.fleet/bin/fleet-run derive-testcmd.sh . test --at
429
429
  origin/main`. **All three exit
430
430
  0 → the cache is present and valid: use it as it stands and derive
431
431
  nothing.** Any exits 1 (a refusal about the cache) → derive it; a refusal
@@ -451,8 +451,8 @@ a deliberate mutation of a tracked file, and the Test entrypoint must be shown t
451
451
  runner's own non-zero count, or a deliberate mutation of one test that
452
452
  turns the run red. Only a proof writes the cache, with `derivedAt` (the
453
453
  `origin/main` commit it ran against) and the proof itself. **`RECIPE
454
- PROVEN`** → re-run the three reads above (`derive-testcmd.sh . install`,
455
- `derive-testcmd.sh . check` and `derive-testcmd.sh . test --at origin/main`);
454
+ PROVEN`** → re-run the three reads above (`derive-testcmd.sh . install --at origin/main`,
455
+ `derive-testcmd.sh . check --at origin/main` and `derive-testcmd.sh . test --at origin/main`);
456
456
  their output is the Recipe this run uses. **`RECIPE NOT PROVEN`** →
457
457
  stall, below.
458
458
 
@@ -367,7 +367,7 @@ read them off `git branch -r` or `git worktree list`: human branches on origin
367
367
  free text, so a pair copied from one claims under that shape at exit 0.
368
368
 
369
369
  **The Install step comes from the Recipe cache — never pass or infer one.** The
370
- claim reads it through `derive-testcmd.sh . install`, and the Test entrypoint
370
+ claim reads it through `derive-testcmd.sh . install --at origin/main`, and the Test entrypoint
371
371
  through `derive-testcmd.sh . test --at origin/main`, runs the
372
372
  Install step in the fresh worktree and refuses if it left any file changed: an
373
373
  install that rewrites the tree in a throwaway worktree corrupts it for everyone.