@feigi/fleet-ctl 3.23.35 → 3.23.37

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.
Files changed (204) hide show
  1. package/package.json +1 -1
  2. package/scripts/main-checkout.mjs +1 -1
  3. package/scripts/member-write-guard.mjs +1 -1
  4. package/scripts/repo-root.mjs +1 -1
  5. package/skills/run-team/references/reaping.md +1 -1
  6. package/scripts/agent-test-dir-prose.test.mjs +0 -59
  7. package/scripts/agent-test.test.mjs +0 -1640
  8. package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
  9. package/scripts/ambient-git-vars-prose.test.mjs +0 -192
  10. package/scripts/ancestry-check-position-prose.test.mjs +0 -175
  11. package/scripts/apply-ruleset.test.mjs +0 -421
  12. package/scripts/arg-header-probes-prose.test.mjs +0 -394
  13. package/scripts/arg.test.mjs +0 -1354
  14. package/scripts/board-cli.test.mjs +0 -710
  15. package/scripts/board-identity.test.mjs +0 -429
  16. package/scripts/board-liveness-banner.test.mjs +0 -119
  17. package/scripts/board-prev-shape.test.mjs +0 -228
  18. package/scripts/board-tryparse-null.test.mjs +0 -119
  19. package/scripts/board.test.mjs +0 -3121
  20. package/scripts/brief-after-cut-prose.test.mjs +0 -53
  21. package/scripts/candidates-exit3-prose.test.mjs +0 -302
  22. package/scripts/candidates.test.mjs +0 -2312
  23. package/scripts/caveat-unification-prose.test.mjs +0 -98
  24. package/scripts/cell-readout.test.mjs +0 -615
  25. package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
  26. package/scripts/ci-completes-premise-prose.test.mjs +0 -257
  27. package/scripts/ci-state-prose.test.mjs +0 -113
  28. package/scripts/ci-state.test.mjs +0 -1933
  29. package/scripts/ci-vacuous-green.test.mjs +0 -368
  30. package/scripts/citation-sweep-prose.test.mjs +0 -1712
  31. package/scripts/claim-lifecycle.test.mjs +0 -187
  32. package/scripts/claim-ticket.test.mjs +0 -1122
  33. package/scripts/closing-keyword-prose.test.mjs +0 -193
  34. package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
  35. package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
  36. package/scripts/compute-board.test.mjs +0 -1214
  37. package/scripts/compute-spend.test.mjs +0 -517
  38. package/scripts/consumer-technology-prose.test.mjs +0 -126
  39. package/scripts/cross-repo-citation-prose.test.mjs +0 -155
  40. package/scripts/cwd-isolation-pins.mjs +0 -83
  41. package/scripts/dedupe-guard-prose.test.mjs +0 -243
  42. package/scripts/delete-merged-branch.test.mjs +0 -576
  43. package/scripts/derive-testcmd.test.mjs +0 -595
  44. package/scripts/diff-stats.test.mjs +0 -404
  45. package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
  46. package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
  47. package/scripts/dispositions-check.test.mjs +0 -936
  48. package/scripts/dispositions-gate-prose.test.mjs +0 -129
  49. package/scripts/drop-merged-label.test.mjs +0 -479
  50. package/scripts/exec-stub.mjs +0 -93
  51. package/scripts/exec-stub.test.mjs +0 -69
  52. package/scripts/expected-jobs-prose.test.mjs +0 -80
  53. package/scripts/fan-out-authorization-prose.test.mjs +0 -80
  54. package/scripts/filing-bar-seat-prose.test.mjs +0 -242
  55. package/scripts/filing-claim-bar-prose.test.mjs +0 -166
  56. package/scripts/finisher-died-prose.test.mjs +0 -31
  57. package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
  58. package/scripts/finisher-halt-prose.test.mjs +0 -106
  59. package/scripts/finisher-name-prose.test.mjs +0 -134
  60. package/scripts/finisher-own-tree-prose.test.mjs +0 -299
  61. package/scripts/finisher-pin-race-prose.test.mjs +0 -339
  62. package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
  63. package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
  64. package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
  65. package/scripts/fleet-bootstrap.test.mjs +0 -75
  66. package/scripts/fleet-heartbeat.test.mjs +0 -450
  67. package/scripts/fleet-provenance.test.mjs +0 -138
  68. package/scripts/fleet-run.test.mjs +0 -90
  69. package/scripts/fleet-state.test.mjs +0 -460
  70. package/scripts/fleet-tick-prose.test.mjs +0 -300
  71. package/scripts/fleet-tick.test.mjs +0 -2444
  72. package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
  73. package/scripts/frontmatter-check.test.mjs +0 -436
  74. package/scripts/git-env.test.mjs +0 -149
  75. package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
  76. package/scripts/gone-walk.test.mjs +0 -213
  77. package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
  78. package/scripts/head-moved-after-label-prose.test.mjs +0 -233
  79. package/scripts/immutable-body-claim-prose.test.mjs +0 -204
  80. package/scripts/implementer-model-tier.test.mjs +0 -235
  81. package/scripts/inflight-citation-prose.test.mjs +0 -144
  82. package/scripts/inflight-exit2-prose.test.mjs +0 -81
  83. package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
  84. package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
  85. package/scripts/inflight.test.mjs +0 -2882
  86. package/scripts/injection-control-prose.test.mjs +0 -404
  87. package/scripts/install-root-audit.test.mjs +0 -464
  88. package/scripts/instrument-check-prose.test.mjs +0 -235
  89. package/scripts/instruments.test.mjs +0 -787
  90. package/scripts/is-cli.test.mjs +0 -99
  91. package/scripts/issue-tracker-prose.test.mjs +0 -71
  92. package/scripts/json.test.mjs +0 -364
  93. package/scripts/ledger-dispatch.test.mjs +0 -927
  94. package/scripts/ledger-grammar.test.mjs +0 -227
  95. package/scripts/ledger-read-require-file.test.mjs +0 -197
  96. package/scripts/ledger-rotate.test.mjs +0 -142
  97. package/scripts/ledger.test.mjs +0 -3436
  98. package/scripts/line-distance-prose.test.mjs +0 -245
  99. package/scripts/liveness-rationale-prose.test.mjs +0 -83
  100. package/scripts/locale-pin-prose.test.mjs +0 -189
  101. package/scripts/main-checkout.test.mjs +0 -332
  102. package/scripts/member-outcome-prose.test.mjs +0 -167
  103. package/scripts/member-outcomes-header.test.mjs +0 -129
  104. package/scripts/member-outcomes-prose.test.mjs +0 -63
  105. package/scripts/member-outcomes.test.mjs +0 -638
  106. package/scripts/member-prompt-prose.test.mjs +0 -165
  107. package/scripts/member-record.test.mjs +0 -541
  108. package/scripts/member-write-guard.test.mjs +0 -214
  109. package/scripts/merge-commit-probe-prose.test.mjs +0 -122
  110. package/scripts/merge-gate.test.mjs +0 -613
  111. package/scripts/muted-git-guard-sweep.test.mjs +0 -493
  112. package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
  113. package/scripts/net-watchdog-prose.test.mjs +0 -79
  114. package/scripts/net.test.mjs +0 -211
  115. package/scripts/no-ci-gate-prose.test.mjs +0 -108
  116. package/scripts/no-undo-audit.test.mjs +0 -3961
  117. package/scripts/no-wave.test.mjs +0 -138
  118. package/scripts/node-floor-sweep.test.mjs +0 -611
  119. package/scripts/pointer-target-prose.test.mjs +0 -186
  120. package/scripts/pr-cost.test.mjs +0 -521
  121. package/scripts/pr-overlap.test.mjs +0 -692
  122. package/scripts/printf-die-sweep.test.mjs +0 -384
  123. package/scripts/prompt-renderer.mjs +0 -40
  124. package/scripts/prompt-renderer.test.mjs +0 -68
  125. package/scripts/prose-pin.mjs +0 -807
  126. package/scripts/prose-pin.test.mjs +0 -1034
  127. package/scripts/prove-merge.test.mjs +0 -995
  128. package/scripts/pull-table-relabel-prose.test.mjs +0 -60
  129. package/scripts/quiet-payload-prose.test.mjs +0 -222
  130. package/scripts/reap-cherry-check-prose.test.mjs +0 -80
  131. package/scripts/reap.test.mjs +0 -4432
  132. package/scripts/reaping-prose.test.mjs +0 -239
  133. package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
  134. package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
  135. package/scripts/recipe-derivation-prose.test.mjs +0 -112
  136. package/scripts/recipe-prove.test.mjs +0 -1042
  137. package/scripts/refuter-scratch-prose.test.mjs +0 -135
  138. package/scripts/release-label-required-prose.test.mjs +0 -71
  139. package/scripts/release-label-split-prose.test.mjs +0 -184
  140. package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
  141. package/scripts/release-ticket.test.mjs +0 -5099
  142. package/scripts/renovate-release-contract.test.mjs +0 -379
  143. package/scripts/repo-root.test.mjs +0 -873
  144. package/scripts/reporter-output-rule-prose.test.mjs +0 -208
  145. package/scripts/review-agent-report-only.test.mjs +0 -49
  146. package/scripts/review-core-booking.test.mjs +0 -35
  147. package/scripts/review-core-cwd-isolation.test.mjs +0 -374
  148. package/scripts/review-core-reads.test.mjs +0 -478
  149. package/scripts/review-core-refuter-scratch.test.mjs +0 -148
  150. package/scripts/review-core-scratch-refusal.test.mjs +0 -64
  151. package/scripts/review-core-shared-test-run.test.mjs +0 -275
  152. package/scripts/review-core-snapshot-path.test.mjs +0 -830
  153. package/scripts/review-core-specialist-scratch.test.mjs +0 -191
  154. package/scripts/review-core-testcmd.test.mjs +0 -335
  155. package/scripts/review-core-unrun.test.mjs +0 -566
  156. package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
  157. package/scripts/review-eval-resolver-path.test.mjs +0 -55
  158. package/scripts/review-host-fixture.mjs +0 -89
  159. package/scripts/review-in-run-retry.test.mjs +0 -211
  160. package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
  161. package/scripts/review-path-default.test.mjs +0 -796
  162. package/scripts/review-runner-spawns.test.mjs +0 -95
  163. package/scripts/review-runner.test.mjs +0 -166
  164. package/scripts/review-tier-audit.test.mjs +0 -140
  165. package/scripts/run-artifact-pr-prose.test.mjs +0 -341
  166. package/scripts/run-merge-bot-prose.test.mjs +0 -1413
  167. package/scripts/run-team-local-hook.test.mjs +0 -442
  168. package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
  169. package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
  170. package/scripts/section-between-guard-prose.test.mjs +0 -379
  171. package/scripts/select-dimensions.test.mjs +0 -674
  172. package/scripts/shared-refusal.test.mjs +0 -388
  173. package/scripts/shell-traps-prose.test.mjs +0 -504
  174. package/scripts/shortlist.test.mjs +0 -380
  175. package/scripts/slow-transport.mjs +0 -72
  176. package/scripts/snapshot-repo.test.mjs +0 -1006
  177. package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
  178. package/scripts/spend-view.test.mjs +0 -312
  179. package/scripts/staleness-qualifier-prose.test.mjs +0 -251
  180. package/scripts/staleness-verdict-prose.test.mjs +0 -142
  181. package/scripts/staleness.test.mjs +0 -893
  182. package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
  183. package/scripts/stash-prohibition-prose.test.mjs +0 -313
  184. package/scripts/strip-comments.mjs +0 -44
  185. package/scripts/temp-dir.mjs +0 -47
  186. package/scripts/ticket-router.test.mjs +0 -981
  187. package/scripts/tier-check.test.mjs +0 -828
  188. package/scripts/tier-outcomes-header.test.mjs +0 -518
  189. package/scripts/tier-outcomes.test.mjs +0 -572
  190. package/scripts/tier-roles.test.mjs +0 -535
  191. package/scripts/tracker-block-copy-prose.test.mjs +0 -288
  192. package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
  193. package/scripts/unattended-git-sweep.test.mjs +0 -142
  194. package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
  195. package/scripts/verify-sha.test.mjs +0 -692
  196. package/scripts/watcher-degraded-block.test.mjs +0 -369
  197. package/scripts/watcher-key-prose.test.mjs +0 -106
  198. package/scripts/within-run-pair-prose.test.mjs +0 -212
  199. package/scripts/worktree-audit.test.mjs +0 -1408
  200. package/scripts/worktree-head-prose.test.mjs +0 -276
  201. package/scripts/worktree-listing-sweep.test.mjs +0 -217
  202. package/scripts/worktree-model-prose.test.mjs +0 -216
  203. package/scripts/worktree-porcelain.mjs +0 -35
  204. package/scripts/worktree-porcelain.test.mjs +0 -102
@@ -1,787 +0,0 @@
1
- // Regression gate for instruments.sh, the check that says whether the
2
- // controller's instrument set changed under a run (#436), re-contracted to
3
- // audit the WORKING DIRECTORY's checkout rather than the checkout the script
4
- // itself lives in (#1337). The install-only dev loop (ADR 0003) means this
5
- // script normally runs out of a plugin cache; resolving from its own
6
- // location measured whatever git checkout happens to CONTAIN that cache
7
- // path, which was the operator's unrelated personal repo, not the plugin's
8
- // own tree.
9
- //
10
- // The defect it guards is not observable from inside the fleet: a member that
11
- // edits a script in the MAIN checkout — where the controller runs every gate
12
- // probe from — changes what the controller measures with no error, no diff in
13
- // any PR and nothing in the ledger. Measured once, self-caught by the member.
14
- //
15
- // A guard against that has TWO failure classes and this file pins both, because
16
- // a suite that only feeds a guard input it must reject proves it fires, never
17
- // that it discriminates:
18
- //
19
- // REFUSE — a tracked instrument rewritten, deleted, or newly staged; no
20
- // baseline; an unreadable one; a cwd outside any git checkout.
21
- // ACCEPT — an ordinary run: nothing touched, an untracked dropping under the
22
- // set, a bare `touch`, branch and worktree churn in the shared ref
23
- // store, and any change outside the set. #436's third acceptance
24
- // criterion is that an unchanged set costs effectively nothing per
25
- // gate, and a guard that fires on ordinary runs becomes noise the
26
- // controller learns to ignore, which is the same defect wearing a
27
- // different hat.
28
- // One accepted case is NOT an ordinary run: a mode-only change to
29
- // a tracked instrument, which a content digest cannot see (#1059).
30
- //
31
- // Every case builds a throwaway checkout and runs the script with its cwd set
32
- // to it — the script resolves the tree to measure from $PWD (or --repo), so a
33
- // fixture repo is measured regardless of where the copy of instruments.sh
34
- // invoked actually lives, and the live checkout is never touched.
35
- //
36
- // Zero deps: `node --test plugin/scripts/instruments.test.mjs`.
37
-
38
- import { test } from "node:test";
39
- import assert from "node:assert/strict";
40
- import { execFileSync, spawnSync } from "node:child_process";
41
- import {
42
- chmodSync,
43
- copyFileSync,
44
- existsSync,
45
- mkdirSync,
46
- mkdtempSync,
47
- readFileSync,
48
- readdirSync,
49
- realpathSync,
50
- rmSync,
51
- symlinkSync,
52
- utimesSync,
53
- writeFileSync,
54
- } from "node:fs";
55
- import { tmpdir } from "node:os";
56
- import { join } from "node:path";
57
- import { fileURLToPath } from "node:url";
58
-
59
- const SCRIPT = fileURLToPath(new URL("./instruments.sh", import.meta.url));
60
- // #1336 nested the plugin's payload under `plugin/`, so the instrument set is
61
- // that subtree rather than the repo root itself. Every join() below reads as
62
- // "under the set".
63
- const SET = "plugin";
64
-
65
- // Pin identity and cut the developer's ~/.gitconfig out of the fixture, so a
66
- // local `core.excludesfile` or hook cannot change what these repos look like.
67
- // The GIT_* redirects would point the fixture out of its own temp dir.
68
- const ENV = {
69
- ...process.env,
70
- GIT_DIR: undefined,
71
- GIT_WORK_TREE: undefined,
72
- GIT_TEMPLATE_DIR: undefined,
73
- GIT_INDEX_FILE: undefined,
74
- GIT_AUTHOR_NAME: "t",
75
- GIT_AUTHOR_EMAIL: "t@example.com",
76
- GIT_COMMITTER_NAME: "t",
77
- GIT_COMMITTER_EMAIL: "t@example.com",
78
- GIT_CONFIG_GLOBAL: "/dev/null",
79
- GIT_CONFIG_SYSTEM: "/dev/null",
80
- };
81
-
82
- const git = (cwd, ...args) =>
83
- execFileSync("git", args, { cwd, env: ENV, encoding: "utf8" }).trim();
84
-
85
- // realpath: on macOS $TMPDIR is a symlink into /private, and `git rev-parse
86
- // --show-toplevel` reports the resolved form. Comparing the two spellings is a
87
- // fixture bug that reads as a script bug.
88
- function repo(t) {
89
- const root = realpathSync(mkdtempSync(join(tmpdir(), "instruments-")));
90
- t.after(() => rmSync(root, { recursive: true, force: true }));
91
- git(root, "init", "-q", "-b", "main");
92
- mkdirSync(join(root, SET, "scripts"), { recursive: true });
93
- mkdirSync(join(root, SET, "skills", "run-team"), { recursive: true });
94
- copyFileSync(SCRIPT, join(root, SET, "scripts", "instruments.sh"));
95
- // Two stand-ins for the class the digest covers: an executable probe and a
96
- // runbook. The controller reads the world through both, from this same tree.
97
- writeFileSync(join(root, SET, "scripts", "ci-state.mjs"), "console.log('green');\n");
98
- writeFileSync(join(root, SET, "skills", "run-team", "SKILL.md"), "# runbook\n");
99
- writeFileSync(join(root, "unrelated.md"), "outside the set\n");
100
- git(root, "add", "-A");
101
- git(root, "commit", "-qm", "fixture");
102
- return root;
103
- }
104
-
105
- // Runs the copy of instruments.sh that lives INSIDE `root`, with cwd set to
106
- // `root` by default — the audited repo is now derived from cwd, never from
107
- // where the script itself sits, so the default here is what an ordinary
108
- // invocation from inside the checkout looks like. `cwd` is overridable for
109
- // the tests that specifically exercise cwd-vs-script-location divergence, and
110
- // `env` for the one #1020 case that has to put back a variable ENV scrubs —
111
- // that scrub is what keeps every other case here deterministic, so the opt-in
112
- // is per-call rather than a hole in ENV.
113
- const run = (root, args = [], { cwd = root, env = {} } = {}) =>
114
- spawnSync(join(root, SET, "scripts", "instruments.sh"), args, {
115
- cwd,
116
- env: { ...ENV, ...env },
117
- encoding: "utf8",
118
- });
119
-
120
- const pin = (root) => {
121
- const r = run(root, ["--pin"]);
122
- assert.equal(r.status, 0, `--pin failed: ${r.stderr}`);
123
- return r.stdout.trim();
124
- };
125
-
126
- /** Every directory literally named `.fleet` anywhere under `root`, `.git` never descended. */
127
- function findFleetDirs(root) {
128
- const found = [];
129
- const walk = (dir) => {
130
- let entries;
131
- try {
132
- entries = readdirSync(dir, { withFileTypes: true });
133
- } catch {
134
- return;
135
- }
136
- for (const e of entries) {
137
- if (!e.isDirectory()) continue;
138
- const p = join(dir, e.name);
139
- if (e.name === ".fleet") found.push(p);
140
- else if (e.name !== ".git") walk(p);
141
- }
142
- };
143
- walk(root);
144
- return found;
145
- }
146
-
147
- test("--pin then an untouched check is exit 0, and reports the same digest", (t) => {
148
- const root = repo(t);
149
- const pinned = pin(root);
150
- const r = run(root);
151
- assert.equal(r.status, 0, r.stderr);
152
- assert.equal(r.stdout.trim(), pinned);
153
- });
154
-
155
- test("a rewritten tracked instrument is exit 1, and the refusal says so", (t) => {
156
- const root = repo(t);
157
- pin(root);
158
- writeFileSync(join(root, SET, "scripts", "ci-state.mjs"), "console.log('red');\n");
159
- const r = run(root);
160
- assert.equal(r.status, 1, r.stderr);
161
- assert.match(r.stderr, /instrument set CHANGED/);
162
- assert.match(r.stderr, /refuse the gate/i);
163
- // The controller has to be able to name what moved; two digests cannot.
164
- assert.match(r.stderr, /ci-state\.mjs/);
165
- });
166
-
167
- test("a rewritten runbook is exit 1 too — the instructions are read from the same tree", (t) => {
168
- const root = repo(t);
169
- pin(root);
170
- writeFileSync(join(root, SET, "skills", "run-team", "SKILL.md"), "# rewritten\n");
171
- assert.equal(run(root).status, 1);
172
- });
173
-
174
- test("restoring the bytes restores exit 0 — the digest is content, not history", (t) => {
175
- const root = repo(t);
176
- pin(root);
177
- const f = join(root, SET, "scripts", "ci-state.mjs");
178
- writeFileSync(f, "console.log('red');\n");
179
- assert.equal(run(root).status, 1);
180
- writeFileSync(f, "console.log('green');\n");
181
- assert.equal(run(root).status, 0);
182
- });
183
-
184
- test("a tracked instrument deleted from the worktree refuses, and names the file", (t) => {
185
- const root = repo(t);
186
- pin(root);
187
- rmSync(join(root, SET, "scripts", "ci-state.mjs"));
188
- const r = run(root);
189
- // Exit 2, not 1: the digest could not be computed at all. Both refuse; only
190
- // this one is honest that nothing was measured.
191
- assert.equal(r.status, 2, r.stderr);
192
- assert.match(r.stderr, /ci-state\.mjs/);
193
- });
194
-
195
- test("a newly staged file under the set is exit 1", (t) => {
196
- const root = repo(t);
197
- pin(root);
198
- writeFileSync(join(root, SET, "scripts", "smuggled.sh"), "#!/bin/sh\nexit 0\n");
199
- git(root, "add", join(SET, "scripts", "smuggled.sh"));
200
- assert.equal(run(root).status, 1);
201
- });
202
-
203
- test("no baseline refuses with exit 2 — an unpinned run is not an unchanged one", (t) => {
204
- const root = repo(t);
205
- const r = run(root);
206
- assert.equal(r.status, 2);
207
- assert.match(r.stderr, /--pin/);
208
- });
209
-
210
- test("an empty baseline refuses rather than matching an empty digest", (t) => {
211
- const root = repo(t);
212
- pin(root);
213
- writeFileSync(join(root, ".fleet", "instruments.sha"), "");
214
- const r = run(root);
215
- assert.equal(r.status, 2);
216
- assert.match(r.stderr, /empty/);
217
- });
218
-
219
- test("an unreadable baseline refuses with its own message, not the no-baseline one", (t) => {
220
- if (process.geteuid?.() === 0) return t.skip("root reads a mode-000 file regardless");
221
- const root = repo(t);
222
- pin(root);
223
- // No mode restored afterwards: `repo`'s own cleanup unlinks it, which needs
224
- // write on the directory and nothing at all on the file.
225
- chmodSync(join(root, ".fleet", "instruments.sha"), 0o000);
226
- const r = run(root);
227
- assert.equal(r.status, 2);
228
- // Distinct from "no baseline …" and explicit that `--pin` is the wrong
229
- // remedy here: `--pin` never compares, it overwrites, so re-pinning over an
230
- // unreadable-but-present baseline would discard evidence instead of
231
- // explaining the refusal. (#1058)
232
- assert.match(r.stderr, /exists but is unreadable/);
233
- assert.match(r.stderr, /do NOT --pin over it/);
234
- assert.doesNotMatch(r.stderr, /no baseline at/);
235
- });
236
-
237
- test("an unreadable .fleet directory refuses with its own message, not the no-baseline one", (t) => {
238
- if (process.geteuid?.() === 0) return t.skip("root searches a mode-600 directory regardless");
239
- const root = repo(t);
240
- pin(root);
241
- const dir = join(root, ".fleet");
242
- // Missing +x hides everything under `dir` from stat(2): `[ -e "$base" ]`
243
- // reads FALSE the same as if the baseline were never pinned. Restored
244
- // right after the assertions rather than in t.after — node:test runs
245
- // t.after callbacks in REGISTRATION order, so a later-registered restore
246
- // would fire after repo(t)'s own cleanup already tried (and failed) to
247
- // recurse into a directory it cannot search.
248
- chmodSync(dir, 0o600);
249
- try {
250
- const r = run(root);
251
- assert.equal(r.status, 2);
252
- // Same distinct-from-absent contract as the file-level case, one level
253
- // up the path — the fix stops here at the file and misses the
254
- // directory without this. (#1058)
255
- assert.match(r.stderr, /\.fleet exists but is unreadable/);
256
- assert.match(r.stderr, /do NOT --pin over it/);
257
- assert.doesNotMatch(r.stderr, /no baseline at/);
258
- } finally {
259
- chmodSync(dir, 0o755);
260
- }
261
- });
262
-
263
- test("a dangling symlink baseline refuses with its own message, not the no-baseline one", (t) => {
264
- const root = repo(t);
265
- pin(root);
266
- const base = join(root, ".fleet", "instruments.sha");
267
- rmSync(base);
268
- // `-e` dereferences: a symlink whose target is gone reads FALSE, same as
269
- // an absent baseline, even though the link entry itself is present. `-L`
270
- // is what tells the two apart. (#1058)
271
- symlinkSync(join(root, ".fleet", "missing-target"), base);
272
- const r = run(root);
273
- assert.equal(r.status, 2);
274
- assert.match(r.stderr, /exists but is unreadable/);
275
- assert.match(r.stderr, /do NOT --pin over it/);
276
- assert.doesNotMatch(r.stderr, /no baseline at/);
277
- });
278
-
279
- test("cwd outside a git checkout refuses instead of certifying nothing", (t) => {
280
- const root = realpathSync(mkdtempSync(join(tmpdir(), "instruments-bare-")));
281
- t.after(() => rmSync(root, { recursive: true, force: true }));
282
- mkdirSync(join(root, SET, "scripts"), { recursive: true });
283
- copyFileSync(SCRIPT, join(root, SET, "scripts", "instruments.sh"));
284
- const r = run(root, ["--pin"]);
285
- assert.equal(r.status, 2);
286
- // The status alone does not reach this guard. Delete it and the run falls
287
- // through to `git ls-files`, which fails on the same non-git path and dies
288
- // with the same code — so the message is what tells the two apart, and the
289
- // ABSENCE of the downstream one is what says execution stopped here.
290
- assert.match(r.stderr, /not inside a git checkout/);
291
- assert.doesNotMatch(r.stderr, /ls-files failed/);
292
- });
293
-
294
- test("a checkout with no tracked file under the set refuses to certify it", (t) => {
295
- const root = realpathSync(mkdtempSync(join(tmpdir(), "instruments-empty-")));
296
- t.after(() => rmSync(root, { recursive: true, force: true }));
297
- git(root, "init", "-q", "-b", "main");
298
- mkdirSync(join(root, SET, "scripts"), { recursive: true });
299
- copyFileSync(SCRIPT, join(root, SET, "scripts", "instruments.sh"));
300
- writeFileSync(join(root, "only.md"), "x\n");
301
- git(root, "add", "only.md");
302
- git(root, "commit", "-qm", "fixture");
303
- const r = run(root, ["--pin"]);
304
- assert.equal(r.status, 2);
305
- assert.match(r.stderr, /empty instrument set/);
306
- });
307
-
308
- test("a bad argument refuses rather than falling through to a check", (t) => {
309
- const root = repo(t);
310
- pin(root);
311
- const r = run(root, ["--pn"]);
312
- assert.equal(r.status, 2);
313
- assert.match(r.stderr, /usage/);
314
- });
315
-
316
- test("--repo with a missing path argument refuses with usage", (t) => {
317
- const root = repo(t);
318
- pin(root);
319
- const r = run(root, ["--repo"]);
320
- assert.equal(r.status, 2);
321
- assert.match(r.stderr, /usage/);
322
- });
323
-
324
- test("--repo with an empty path or a non-repo directory refuses, and writes nothing", (t) => {
325
- const root = repo(t);
326
-
327
- const empty = run(root, ["--pin", "--repo", ""]);
328
- assert.equal(empty.status, 2, empty.stderr);
329
- assert.match(empty.stderr, /--repo requires a non-empty path/);
330
-
331
- const notARepo = realpathSync(mkdtempSync(join(tmpdir(), "instruments-not-a-repo-")));
332
- t.after(() => rmSync(notARepo, { recursive: true, force: true }));
333
- const nonRepo = run(root, ["--pin", "--repo", notARepo]);
334
- assert.equal(nonRepo.status, 2, nonRepo.stderr);
335
- assert.match(nonRepo.stderr, /not inside a git checkout/);
336
-
337
- // Neither refusal writes anything: not into cwd's own repo — the silent
338
- // fallback an empty --repo took before this guard existed, measured in
339
- // PR #1350 review — and not into the directory named by the bad --repo
340
- // path either.
341
- assert.deepEqual(findFleetDirs(root), []);
342
- assert.deepEqual(findFleetDirs(notARepo), []);
343
- });
344
-
345
- // ---------------------------------------------------------------------------
346
- // ACCEPT. Everything below is an ordinary run, and every one of them must stay
347
- // exit 0. These are what keep the guard from becoming noise.
348
- // ---------------------------------------------------------------------------
349
-
350
- test("an untracked dropping under the set is accepted", (t) => {
351
- const root = repo(t);
352
- pin(root);
353
- writeFileSync(join(root, SET, "scripts", ".DS_Store"), "\0junk\n");
354
- writeFileSync(join(root, SET, "scripts", "ci-state.mjs.swp"), "editor\n");
355
- const r = run(root);
356
- assert.equal(r.status, 0, r.stderr);
357
- });
358
-
359
- test("a bare touch is accepted — content is hashed, not the stat cache", (t) => {
360
- const root = repo(t);
361
- pin(root);
362
- const later = new Date(Date.now() + 60_000);
363
- utimesSync(join(root, SET, "scripts", "ci-state.mjs"), later, later);
364
- const r = run(root);
365
- assert.equal(r.status, 0, r.stderr);
366
- });
367
-
368
- // The gap instruments.sh's own header now names, pinned from the accept side
369
- // so that folding modes into the digest goes red HERE and sends whoever does
370
- // it at that paragraph, rather than leaving the file claiming a coverage it
371
- // stopped having. Both halves of #1059's repro: the worktree bit and the
372
- // index entry.
373
- test("a mode-only change to a tracked instrument is accepted — modes are not in the digest", (t) => {
374
- const root = repo(t);
375
- pin(root);
376
- const rel = join(SET, "scripts", "ci-state.mjs");
377
- chmodSync(join(root, rel), 0o755);
378
- // `diff --summary` rather than `status --porcelain`: this file's `git`
379
- // helper trims, and porcelain's worktree-only column IS a leading space.
380
- assert.match(
381
- git(root, "diff", "--summary", "--", rel),
382
- /^mode change 100644 => 100755 /,
383
- "git sees the worktree mode flip",
384
- );
385
- const worktreeHalf = run(root);
386
- assert.equal(worktreeHalf.status, 0, worktreeHalf.stderr);
387
- // Through the index: the blob is identical, only the entry's mode moves.
388
- const before = git(root, "ls-files", "-s", "--", rel);
389
- git(root, "update-index", "--chmod=+x", "--", rel);
390
- const after = git(root, "ls-files", "-s", "--", rel);
391
- assert.match(after, /^100755 /);
392
- assert.equal(after.split(/\s+/)[1], before.split(/\s+/)[1], "the blob is untouched");
393
- const indexHalf = run(root);
394
- assert.equal(indexHalf.status, 0, indexHalf.stderr);
395
- });
396
-
397
- test("branch and worktree churn in the shared ref store is accepted", (t) => {
398
- const root = repo(t);
399
- pin(root);
400
- // Exactly what claim-ticket.sh and reap.sh do to the main checkout during
401
- // every fleet run. A ref digest would refuse here, several times per run.
402
- git(root, "branch", "fix/42-slug");
403
- git(root, "worktree", "add", "-q", join(root, "wt"), "fix/42-slug");
404
- assert.equal(run(root).status, 0);
405
- git(root, "worktree", "remove", "--force", join(root, "wt"));
406
- git(root, "branch", "-D", "fix/42-slug");
407
- assert.equal(run(root).status, 0);
408
- });
409
-
410
- test("a change outside the set is accepted", (t) => {
411
- const root = repo(t);
412
- pin(root);
413
- writeFileSync(join(root, "unrelated.md"), "rewritten by the run\n");
414
- writeFileSync(join(root, "brand-new.md"), "an output the fleet wrote\n");
415
- assert.equal(run(root).status, 0);
416
- });
417
-
418
- test("a commit that does not change the bytes is accepted", (t) => {
419
- const root = repo(t);
420
- pin(root);
421
- writeFileSync(join(root, "unrelated.md"), "rewritten\n");
422
- git(root, "commit", "-qam", "an ordinary commit outside the set");
423
- assert.equal(run(root).status, 0);
424
- });
425
-
426
- test("--pin re-baselines after a deliberate edit — the controller's own tooling-fix path", (t) => {
427
- const root = repo(t);
428
- const first = pin(root);
429
- writeFileSync(join(root, SET, "skills", "run-team", "SKILL.md"), "# fixed mid-run\n");
430
- assert.equal(run(root).status, 1);
431
- const second = pin(root);
432
- assert.notEqual(second, first);
433
- assert.equal(run(root).status, 0);
434
- });
435
-
436
- // ---------------------------------------------------------------------------
437
- // CWD CONTRACT (#1337). The audited repository comes from $PWD (or --repo),
438
- // never from where the invoked copy of instruments.sh happens to live. Every
439
- // test below places the SCRIPT somewhere other than the repo it must audit,
440
- // which the tests above never do — proving the resolution is cwd-driven, not
441
- // merely untested against $0.
442
- // ---------------------------------------------------------------------------
443
-
444
- // A plugin-cache-shaped fixture: instruments.sh nested several directories
445
- // deep inside a FOREIGN git repository — the shape a plugin cache directory
446
- // takes when it is itself nested inside the operator's personal dotfiles
447
- // checkout (#1337's own report, measured pre-cutover). Built with `git init`
448
- // in a fresh temp dir, never the real checkout or a real cache directory.
449
- function foreignAncestorCache(t) {
450
- const foreign = realpathSync(mkdtempSync(join(tmpdir(), "instruments-foreign-")));
451
- t.after(() => rmSync(foreign, { recursive: true, force: true }));
452
- git(foreign, "init", "-q", "-b", "main");
453
- writeFileSync(join(foreign, "foreign.md"), "the operator's unrelated repo\n");
454
- git(foreign, "add", "-A");
455
- git(foreign, "commit", "-qm", "foreign root");
456
- const cacheDir = join(foreign, "plugins", "cache", "fleet-plugin", "fleet", "0.1.1", "scripts");
457
- mkdirSync(cacheDir, { recursive: true });
458
- const script = join(cacheDir, "instruments.sh");
459
- copyFileSync(SCRIPT, script);
460
- return { foreign, script };
461
- }
462
-
463
- test("(1) run from an installed cache nested in a foreign repo, cwd inside a separate repo, audits the cwd repo", (t) => {
464
- const cwdRepo = repo(t);
465
- const { foreign, script } = foreignAncestorCache(t);
466
- const r = spawnSync(script, ["--pin"], { cwd: cwdRepo, env: ENV, encoding: "utf8" });
467
- assert.equal(r.status, 0, r.stderr);
468
- // The baseline path it reports names the cwd repo, not the cache's own tree.
469
- assert.match(r.stderr, /pinned/);
470
- assert.ok(
471
- r.stderr.includes(`over ${cwdRepo} (`),
472
- `expected the pin report to name ${cwdRepo}, got: ${r.stderr}`,
473
- );
474
- assert.ok(existsSync(join(cwdRepo, ".fleet", "instruments.sha")));
475
- assert.equal(findFleetDirs(foreign).length, 0, "the foreign ancestor must never gain a .fleet directory");
476
- });
477
-
478
- test("(2) cwd outside any git repository refuses, non-zero, and writes nothing anywhere in the temp tree", (t) => {
479
- const { foreign, script } = foreignAncestorCache(t);
480
- const outside = realpathSync(mkdtempSync(join(tmpdir(), "instruments-outside-")));
481
- t.after(() => rmSync(outside, { recursive: true, force: true }));
482
- const r = spawnSync(script, ["--pin"], { cwd: outside, env: ENV, encoding: "utf8" });
483
- assert.notEqual(r.status, 0);
484
- assert.equal(r.status, 2, r.stderr);
485
- assert.match(r.stderr, /not inside a git checkout/);
486
- assert.deepEqual(findFleetDirs(outside), []);
487
- assert.deepEqual(findFleetDirs(foreign), []);
488
- });
489
-
490
- test("(3) --repo audits the named repository regardless of the working directory", (t) => {
491
- const target = repo(t);
492
- const elsewhere = realpathSync(mkdtempSync(join(tmpdir(), "instruments-elsewhere-")));
493
- t.after(() => rmSync(elsewhere, { recursive: true, force: true }));
494
- git(elsewhere, "init", "-q", "-b", "main");
495
- writeFileSync(join(elsewhere, "x.md"), "a repo that must not be audited\n");
496
- git(elsewhere, "add", "-A");
497
- git(elsewhere, "commit", "-qm", "elsewhere");
498
-
499
- const r = run(target, ["--pin", "--repo", target], { cwd: elsewhere });
500
- assert.equal(r.status, 0, r.stderr);
501
- const pinnedDigest = r.stdout.trim();
502
- assert.ok(existsSync(join(target, ".fleet", "instruments.sha")));
503
- assert.deepEqual(findFleetDirs(elsewhere), []);
504
-
505
- // And the reverse: cwd IS a DIFFERENT repo but --repo points at the
506
- // already-pinned target — the flag wins either way, not merely when it
507
- // agrees with cwd, and the check reports the target's own digest, not
508
- // anything derived from `other`.
509
- const other = repo(t);
510
- const r2 = run(other, ["--repo", target]);
511
- assert.equal(r2.status, 0, r2.stderr);
512
- assert.equal(r2.stdout.trim(), pinnedDigest);
513
- assert.deepEqual(findFleetDirs(other), []);
514
- });
515
-
516
- test("(4) --pin from a directory nested inside a foreign git repo never writes into that ancestor", (t) => {
517
- // The foreign repo is the ANCESTOR directory tree, holding BOTH a
518
- // plugin-cache-shaped copy of instruments.sh AND, elsewhere under the same
519
- // ancestor, a SEPARATE nested git checkout used as cwd — the shape the
520
- // operator's dotfiles checkout takes when it is itself a git repo, the
521
- // plugin cache sits under one of its subdirectories, and a fleet-plugin
522
- // checkout is ALSO nested somewhere under that same dotfiles tree. Script
523
- // location and cwd deliberately differ here — same discriminating shape as
524
- // test (1), but with the audited repo an ANCESTOR-DESCENDANT of the
525
- // foreign repo rather than a disjoint tree, which is what "whose ancestor
526
- // is a foreign git repo" names. Old own-location resolution would walk up
527
- // from the cache script to the foreign root and pin there; this pins that
528
- // --pin never does.
529
- const foreign = realpathSync(mkdtempSync(join(tmpdir(), "instruments-nest-foreign-")));
530
- t.after(() => rmSync(foreign, { recursive: true, force: true }));
531
- git(foreign, "init", "-q", "-b", "main");
532
- writeFileSync(join(foreign, "foreign.md"), "the ancestor repo\n");
533
- git(foreign, "add", "-A");
534
- git(foreign, "commit", "-qm", "foreign root");
535
-
536
- const cacheDir = join(foreign, "plugins", "cache", "fleet-plugin", "fleet", "0.1.1", "scripts");
537
- mkdirSync(cacheDir, { recursive: true });
538
- const script = join(cacheDir, "instruments.sh");
539
- copyFileSync(SCRIPT, script);
540
-
541
- const nestedDir = join(foreign, "dev", "fleet-plugin");
542
- mkdirSync(nestedDir, { recursive: true });
543
- git(nestedDir, "init", "-q", "-b", "main");
544
- mkdirSync(join(nestedDir, "plugin", "scripts"), { recursive: true });
545
- writeFileSync(join(nestedDir, "plugin", "scripts", "ci-state.mjs"), "console.log('green');\n");
546
- git(nestedDir, "add", "-A");
547
- git(nestedDir, "commit", "-qm", "nested fixture");
548
-
549
- const r = spawnSync(script, ["--pin"], {
550
- cwd: nestedDir,
551
- env: ENV,
552
- encoding: "utf8",
553
- });
554
- assert.equal(r.status, 0, r.stderr);
555
- assert.ok(existsSync(join(nestedDir, ".fleet", "instruments.sha")));
556
- // Only the nested repo's own .fleet exists; the foreign ancestor's own root
557
- // never gains one, and no other .fleet appears anywhere under it either —
558
- // in particular not one sitting directly in the foreign root, which is
559
- // where the old own-location contract would have written it.
560
- assert.deepEqual(findFleetDirs(foreign), [join(nestedDir, ".fleet")]);
561
- });
562
-
563
- // --- #1020: the ambient GIT_WORK_TREE that moves the audited tree.
564
- //
565
- // One case, not two, and that is a measurement rather than an omission.
566
- // GIT_DIR is unset by the script alongside GIT_WORK_TREE, but it is INERT
567
- // here: `ls-files` only names paths, and both the digest and the baseline are
568
- // read from the FILES ON DISK under `$root`, so pointing the object database
569
- // elsewhere changes neither. Measured against a clean twin holding the exact
570
- // pre-tamper content, the tampered digest came back unchanged and the gate
571
- // still refused. A fixture for that half could only be vacuous — precisely
572
- // the shape PR #1015 warned about — so the line's GIT_DIR half is pinned as
573
- // source by ambient-git-vars-prose.test.mjs instead.
574
- test("(5) an ambient GIT_WORK_TREE cannot certify a tampered tree from a clean twin (#1020)", (t) => {
575
- // #1337's defect through the environment. That ticket established that the
576
- // audited tree is the WORKING DIRECTORY's checkout; `rev-parse
577
- // --show-toplevel` answers with the ambient work tree the moment one is
578
- // set, so the digest, the `ls-files` listing and the baseline path all move
579
- // together — which is exactly what makes the result LOOK coherent.
580
- const here = repo(t);
581
- const twin = repo(t);
582
-
583
- // Both trees are byte-identical, so they pin to the same digest. That is
584
- // what makes the twin a usable decoy rather than an obvious mismatch, and
585
- // asserting it is the fixture's own control: if the two ever diverged, the
586
- // poisoned run would fail for a reason that is not the retarget.
587
- assert.equal(pin(here), pin(twin),
588
- "fixture: the twin must pin to the same digest, or the decoy would be caught by arithmetic rather than by the fix");
589
-
590
- writeFileSync(join(here, SET, "scripts", "ci-state.mjs"), "console.log('TAMPERED');\n");
591
-
592
- const control = run(here);
593
- assert.equal(control.status, 1, `fixture: the tamper must really be detectable\n${control.stderr}`);
594
- assert.match(control.stderr, /instrument set CHANGED/);
595
- assert.equal(run(twin).status, 0,
596
- "fixture: the twin must be a tree that genuinely WOULD certify, or the poisoned run could not pass for its sake");
597
-
598
- const r = run(here, [], { env: { GIT_WORK_TREE: twin } });
599
-
600
- assert.equal(r.status, 1,
601
- `an ambient GIT_WORK_TREE must not let a tampered checkout be certified from a clean one — a gate that passes on a tree nobody looked at is worse than no gate; got ${r.stdout}${r.stderr}`);
602
- assert.match(r.stderr, /instrument set CHANGED/,
603
- "and it must refuse for the real reason rather than tripping over the variable");
604
- });
605
-
606
- // --- #2284: the audited tree and the state home may be different checkouts ---
607
- //
608
- // A fleet running in a workspace that does not track `plugin/…` (installed
609
- // plugin, not vendored) has no instrument set of its own: every gate leg that
610
- // hashed cwd died on the empty-set refusal, and a correctly-labelled PR could
611
- // never merge because `merge-gate.mjs`'s instruments leg could only ever read
612
- // the workspace tree. The fix names both trees: `--pin --audit <path>`
613
- // certifies a checkout that DOES track the set and records its toplevel beside
614
- // the digest, in the workspace's own `.fleet/`; a check reads the baseline
615
- // first and audits the RECORDED tree, never cwd's.
616
-
617
- // A consumer workspace: a real git checkout with no plugin/ tree at all.
618
- function wsRepo(t) {
619
- const root = realpathSync(mkdtempSync(join(tmpdir(), "instruments-ws-")));
620
- t.after(() => rmSync(root, { recursive: true, force: true }));
621
- git(root, "init", "-q", "-b", "main");
622
- writeFileSync(join(root, "README.md"), "consumer workspace — no plugin/ tree\n");
623
- git(root, "add", "-A");
624
- git(root, "commit", "-qm", "fixture");
625
- return root;
626
- }
627
-
628
- test("--pin --audit certifies another checkout, records its root beside the digest, and a later check follows it", (t) => {
629
- const plugin = repo(t);
630
- const ws = wsRepo(t);
631
-
632
- const r = run(plugin, ["--pin", "--audit", plugin], { cwd: ws });
633
- assert.equal(r.status, 0, r.stderr);
634
- const digest = r.stdout.trim();
635
- assert.match(digest, /^[0-9a-f]{64}$/);
636
- assert.match(r.stderr, new RegExp(`pinned ${digest} over`));
637
-
638
- // The STATE lives in the workspace — every later reader finds it without
639
- // configuration — and it is two lines: the digest first (a reader that knows
640
- // only the old shape still gets it), the audited root second.
641
- const lines = readFileSync(join(ws, ".fleet", "instruments.sha"), "utf8").split("\n");
642
- assert.equal(lines[0], digest);
643
- assert.equal(lines[1], `root=${plugin}`);
644
- // The audited tree gains no state of its own; a `--pin` is not allowed to
645
- // write into the tree it merely reads.
646
- assert.deepEqual(findFleetDirs(plugin), []);
647
-
648
- // A bare check from the workspace audits the RECORDED tree, not cwd's:
649
- // identical bytes elsewhere make no difference — the verdict travels with
650
- // the digest.
651
- const ok = run(plugin, [], { cwd: ws });
652
- assert.equal(ok.status, 0, ok.stderr);
653
- assert.equal(ok.stdout.trim(), digest);
654
-
655
- // Tampering the plugin tree is what the gate exists to catch, and now the
656
- // catch reaches across workspaces: exit 1, the refusal naming the change.
657
- writeFileSync(join(plugin, SET, "scripts", "ci-state.mjs"), "console.log('TAMPERED');\n");
658
- const hit = run(plugin, [], { cwd: ws });
659
- assert.equal(hit.status, 1, `a tampered instrument must still refuse across the seam\n${hit.stdout}${hit.stderr}`);
660
- assert.match(hit.stderr, /instrument set CHANGED/);
661
- // The cold-path diagnostics name the AUDITED tree, which is the one the
662
- // verdict is about — `git status` here must show the tampered file.
663
- assert.match(hit.stderr, new RegExp(` M ${SET}/scripts/ci-state\\.mjs`));
664
- });
665
-
666
- test("a bare --pin in a plugin-less workspace still refuses — naming the tree once is the only way through", (t) => {
667
- const plugin = repo(t);
668
- const ws = wsRepo(t);
669
- const r = run(plugin, ["--pin"], { cwd: ws });
670
- assert.equal(r.status, 2, r.stdout + r.stderr);
671
- assert.match(r.stderr, /empty instrument set/);
672
- assert.match(r.stderr, new RegExp(`under ${ws} for`),
673
- "the refusal names the workspace tree it found empty, which is what tells the operator to pass --audit");
674
- assert.deepEqual(findFleetDirs(ws), []);
675
- });
676
-
677
- test("--audit without --pin refuses: a check audits the tree its baseline names, never one its caller names", (t) => {
678
- const plugin = repo(t);
679
- const ws = wsRepo(t);
680
- const pinned = run(plugin, ["--pin", "--audit", plugin], { cwd: ws });
681
- assert.equal(pinned.status, 0, pinned.stderr);
682
- const baseline = readFileSync(join(ws, ".fleet", "instruments.sha"), "utf8");
683
- // If a check accepted `--audit`, whoever can spell a path could move the
684
- // gate onto a tree they control — the same repointing power a writable
685
- // `.fleet/` must not additionally buy.
686
- const r = run(plugin, ["--audit", plugin], { cwd: ws });
687
- assert.equal(r.status, 2, r.stdout + r.stderr);
688
- assert.match(r.stderr, /only accepted with --pin/);
689
- const empty = run(plugin, ["--pin", "--audit", ""], { cwd: ws });
690
- assert.equal(empty.status, 2, empty.stdout + empty.stderr);
691
- assert.match(empty.stderr, /--audit requires a non-empty path/);
692
- // Content, not directory presence: an empty-string `--pin --audit` that
693
- // got far enough to truncate the baseline before refusing would leave the
694
- // .fleet directory standing and read as untouched here.
695
- assert.equal(readFileSync(join(ws, ".fleet", "instruments.sha"), "utf8"), baseline,
696
- "neither refusal rewrote the baseline");
697
- });
698
-
699
- test("a recorded root that is no longer a checkout, or no longer THAT checkout, refuses with exit 2 — never a verdict about a different tree", (t) => {
700
- const plugin = repo(t);
701
- const ws = wsRepo(t);
702
- const digest = run(plugin, ["--pin", "--audit", plugin], { cwd: ws }).stdout.trim();
703
-
704
- // Deleted or de-repo'd: the pinned tree is simply gone.
705
- rmSync(join(plugin, ".git"), { recursive: true, force: true });
706
- const gone = run(plugin, [], { cwd: ws });
707
- assert.equal(gone.status, 2, gone.stdout + gone.stderr);
708
- assert.match(gone.stderr, /is not a git checkout/);
709
-
710
- // Moved: the recorded path now sits INSIDE another checkout, so
711
- // `--show-toplevel` answers with a different tree than the one pinned. An
712
- // attacker repointing root= at one of their own checkouts gets the same
713
- // door: to certify a decoy they must make it resolve to the recorded path.
714
- const outer = repo(t);
715
- const sub = join(outer, "sub");
716
- mkdirSync(sub);
717
- writeFileSync(join(ws, ".fleet", "instruments.sha"), `${digest}\nroot=${sub}\n`);
718
- const moved = run(outer, [], { cwd: ws });
719
- assert.equal(moved.status, 2, moved.stdout + moved.stderr);
720
- assert.match(moved.stderr, /audited tree moved/);
721
- });
722
-
723
- test("a legacy one-line baseline still audits the state home — the recorded root is an addition, not a requirement", (t) => {
724
- const root = repo(t);
725
- const digest = pin(root);
726
- // Rewrite the baseline into the pre-cross-workspace shape: one line.
727
- writeFileSync(join(root, ".fleet", "instruments.sha"), `${digest}\n`);
728
- assert.equal(run(root).status, 0, "the check must not start refusing baselines it used to read");
729
- writeFileSync(join(root, SET, "scripts", "ci-state.mjs"), "console.log('TAMPERED');\n");
730
- assert.equal(run(root).status, 1, "and it must still catch the tamper it caught before");
731
- });
732
-
733
- test("a bare re-pin after a --audit pin re-certifies the RECORDED tree, not cwd's — the controller's tooling-fix path", (t) => {
734
- const plugin = repo(t);
735
- const ws = wsRepo(t);
736
- run(plugin, ["--pin", "--audit", plugin], { cwd: ws });
737
- writeFileSync(join(plugin, SET, "skills", "run-team", "SKILL.md"), "# fixed mid-run\n");
738
- // The SKILL says: fix the tooling, then re-pin with the same bare
739
- // `instruments.sh --pin`. If the re-pin hashed cwd instead, this would die
740
- // on the empty-set refusal in the workspace — the controller could not
741
- // complete its one legitimate re-pin, and the run would strand.
742
- const again = run(plugin, ["--pin"], { cwd: ws });
743
- assert.equal(again.status, 0, again.stdout + again.stderr);
744
- const lines = readFileSync(join(ws, ".fleet", "instruments.sha"), "utf8").split("\n");
745
- assert.equal(lines[1], `root=${plugin}`, "the re-pin must keep certifying the plugin tree");
746
- assert.equal(run(plugin, [], { cwd: ws }).status, 0, "and the check now passes over the fixed text");
747
- });
748
-
749
- test("--audit on a checkout that tracks its own set is refused — the pointer exists for set-less homes only", (t) => {
750
- const home = repo(t);
751
- const decoy = repo(t); // byte-identical, so its digest would MATCH a home pin
752
- const r = run(home, ["--pin", "--audit", decoy]);
753
- assert.equal(r.status, 2, r.stdout + r.stderr);
754
- assert.match(r.stderr, /tracks no instrument set/);
755
- assert.deepEqual(findFleetDirs(home), [], "a refused pin writes no baseline");
756
- });
757
-
758
- test("a forged baseline pointing a set-tracking home at a matching clone alarms exit 2 — the #1020 twin through the file", (t) => {
759
- // The attack review measured: tamper the workspace's instrument (uncommitted),
760
- // keep the HONEST run-start digest on line 1, set root= to a pristine clone
761
- // whose bytes hash to exactly that digest. A check that trusted the pointer
762
- // exits 0 over a tree nobody read; the old script, hashing cwd, exited 1.
763
- const home = repo(t);
764
- const digest = pin(home);
765
- const clone = repo(t);
766
- assert.equal(digest, pin(clone), "fixture: the clone must really match line 1");
767
- writeFileSync(join(home, SET, "scripts", "ci-state.mjs"), "console.log('TAMPERED');\n");
768
- writeFileSync(join(home, ".fleet", "instruments.sha"), `${digest}\nroot=${clone}\n`);
769
- const r = run(home);
770
- assert.equal(r.status, 2, `a foreign root on a set-tracking home must alarm, not certify the clone\n${r.stdout}${r.stderr}`);
771
- assert.match(r.stderr, /foreign audited tree/);
772
- });
773
-
774
- test("a bare --pin over an unreadable baseline in a set-less workspace refuses rather than overwrite the recorded root blind", (t) => {
775
- const plugin = repo(t);
776
- const ws = wsRepo(t);
777
- run(plugin, ["--pin", "--audit", plugin], { cwd: ws });
778
- const base = join(ws, ".fleet", "instruments.sha");
779
- const before = readFileSync(base, "utf8");
780
- chmodSync(base, 0o000);
781
- const r = run(plugin, ["--pin"], { cwd: ws });
782
- chmodSync(base, 0o644);
783
- assert.equal(r.status, 2, r.stdout + r.stderr);
784
- assert.match(r.stderr, /exists but is unreadable/);
785
- assert.equal(readFileSync(base, "utf8"), before,
786
- "the refusal must leave the pointer it could not read intact");
787
- });