@feigi/fleet-ctl 3.23.36 → 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,450 +0,0 @@
1
- // Tests for the heartbeat — #357, the periodic resync that survives a drained
2
- // queue. The two pure functions carry the back-off arithmetic; the CLI cases
3
- // pin the things a reader would otherwise have to trust: that a long interval
4
- // really does survive being served by several short holds, and that this script
5
- // cannot clobber fleet-tick's half of the shared state file.
6
-
7
- import test from "node:test";
8
- import assert from "node:assert/strict";
9
- import { spawn, spawnSync } from "node:child_process";
10
- import { chmodSync, existsSync, mkdtempSync, writeFileSync, readFileSync, rmSync } from "node:fs";
11
- import { tmpdir } from "node:os";
12
- import { join } from "node:path";
13
- import { fileURLToPath } from "node:url";
14
-
15
- import { interval, heldThisCall } from "./fleet-heartbeat.mjs";
16
-
17
- const SCRIPT = fileURLToPath(new URL("./fleet-heartbeat.mjs", import.meta.url));
18
-
19
- function run(args, { state } = {}) {
20
- const dir = mkdtempSync(join(tmpdir(), "fleet-heartbeat-"));
21
- const path = join(dir, "heartbeat.json");
22
- if (state !== undefined) writeFileSync(path, state);
23
- const r = spawnSync(process.execPath, [SCRIPT, ...args, "--state", path], { encoding: "utf8" });
24
- const after = (() => {
25
- try {
26
- return JSON.parse(readFileSync(path, "utf8"));
27
- } catch {
28
- return null;
29
- }
30
- })();
31
- rmSync(dir, { recursive: true, force: true });
32
- return { ...r, state: after };
33
- }
34
-
35
- // The whole-file assertions below predate #1597's liveness mark, and that key
36
- // carries a clock. Dropping it here keeps each of them pinning what it was
37
- // written to pin — the patch/replace shape of the file — without either
38
- // pinning a timestamp no test can know or loosening into a field-by-field
39
- // check that a new stray key would pass straight through.
40
- const withoutMark = ({ beat, ...rest }) => rest;
41
-
42
- test("interval: doubles per quiet tick and then stops at the ceiling", () => {
43
- const p = { base: 300, ceiling: 1200, multiplier: 2 };
44
- assert.equal(interval({ ...p, quiet: 0 }), 300);
45
- assert.equal(interval({ ...p, quiet: 1 }), 600);
46
- assert.equal(interval({ ...p, quiet: 2 }), 1200);
47
- // The ceiling is the point of the whole design: supply grows from outside the
48
- // fleet with no event to announce it, so the ceiling IS the worst-case
49
- // latency for noticing work. An unbounded back-off would reintroduce #3.
50
- assert.equal(interval({ ...p, quiet: 3 }), 1200);
51
- assert.equal(interval({ ...p, quiet: 40 }), 1200);
52
- });
53
-
54
- test("interval: a quiet streak long enough to overflow still clamps, never NaN", () => {
55
- // `base * multiplier ** quiet` is Infinity past ~1000 quiet ticks. Math.min
56
- // resolves that correctly; a hand-rolled comparison ladder would have to name
57
- // the case, and an overnight run at the ceiling reaches four digits of quiet
58
- // ticks in a few days of uptime.
59
- const got = interval({ quiet: 5000, base: 300, ceiling: 1200, multiplier: 2 });
60
- assert.equal(got, 1200);
61
- });
62
-
63
- test("heldThisCall: serves the remainder of the interval, never more than the hold", () => {
64
- assert.equal(heldThisCall({ elapsed: 0, target: 1200, hold: 240 }), 240);
65
- assert.equal(heldThisCall({ elapsed: 1080, target: 1200, hold: 240 }), 120);
66
- assert.equal(heldThisCall({ elapsed: 0, target: 60, hold: 240 }), 60);
67
- });
68
-
69
- test("heldThisCall: an elapsed total past the target holds zero, not a negative", () => {
70
- // Reachable without a bug: lower --ceiling between two holds (or let a
71
- // quiet-streak reset shorten the target) and the persisted elapsed can exceed
72
- // it. A negative would reach Atomics.wait as a negative timeout.
73
- assert.equal(heldThisCall({ elapsed: 500, target: 300, hold: 240 }), 0);
74
- });
75
-
76
- test("CLI: a long interval survives being served by several short holds", () => {
77
- // The invariant that makes a 20-minute ceiling work at all, since neither
78
- // harness lets one command block that long. First call holds and reports the
79
- // remainder; the second completes the interval and resets.
80
- const first = run(["--base", "2", "--ceiling", "8", "--hold", "1"]);
81
- assert.equal(first.status, 0);
82
- assert.match(first.stdout, /1s of 2s remain/);
83
- assert.match(first.stdout, /do not end your turn/);
84
- assert.equal(first.state.elapsed, 1);
85
-
86
- const second = run(["--base", "2", "--ceiling", "8", "--hold", "1"],
87
- { state: JSON.stringify({ elapsed: 1 }) });
88
- assert.equal(second.status, 0);
89
- assert.match(second.stdout, /interval elapsed/);
90
- assert.match(second.stdout, /run fleet-tick/);
91
- // Reset on fire, so the next interval starts from zero rather than from a
92
- // total already spent.
93
- assert.equal(second.state.elapsed, 0);
94
- });
95
-
96
- test("CLI: the quiet streak it reads comes from fleet-tick and lengthens the interval", () => {
97
- const r = run(["--base", "2", "--ceiling", "64", "--hold", "1"],
98
- { state: JSON.stringify({ quiet: 4, elapsed: 0 }) });
99
- assert.equal(r.status, 0);
100
- // 2 * 2**4 = 32, under the ceiling.
101
- assert.match(r.stdout, /31s of 32s remain \(quiet=4\)/);
102
- });
103
-
104
- test("CLI: writing elapsed preserves fleet-tick's keys", () => {
105
- // Key ownership is what lets two scripts share one file without a lock. A
106
- // whole-object rewrite here would drop `digest`, which reads as "the output
107
- // changed" on the next tick and silently un-folds a quiet night — the
108
- // cheap-per-wake half of the design, lost with nothing printed about it.
109
- const r = run(["--base", "9", "--hold", "1"],
110
- { state: JSON.stringify({ quiet: 3, elapsed: 0, digest: "abc123" }) });
111
- assert.equal(r.status, 0);
112
- assert.equal(r.state.digest, "abc123");
113
- assert.equal(r.state.quiet, 3);
114
- assert.equal(r.state.elapsed, 1);
115
- });
116
-
117
- test("CLI: a ceiling below the base refuses rather than silently clamping", () => {
118
- // min() would pin every interval to the ceiling and never honour the base, so
119
- // the back-off would run backwards while looking configured.
120
- const r = run(["--base", "600", "--ceiling", "60"]);
121
- assert.equal(r.status, 2);
122
- assert.match(r.stderr, /--ceiling \(60\) is below --base \(600\)/);
123
- });
124
-
125
- test("CLI: an empty flag value refuses — it is not a zero", () => {
126
- // `--base ""` is the shape an unset shell variable produces, and Number("")
127
- // is 0: read as a real zero it turns the hold into a no-op that still prints
128
- // a working-looking heartbeat line.
129
- const r = run(["--base", ""]);
130
- assert.equal(r.status, 2);
131
- assert.match(r.stderr, /--base must be a non-negative integer/);
132
- });
133
-
134
- test("CLI: a corrupt state file beats at the base interval and says so", () => {
135
- // Fail-open, deliberately, and in the safe direction: dying here would stop
136
- // the heartbeat, and a stopped heartbeat is the defect. More frequent level
137
- // checks are the harmless error.
138
- const r = run(["--base", "1", "--hold", "1"], { state: "not json" });
139
- assert.equal(r.status, 0);
140
- assert.match(r.stderr, /WARNING .* is not JSON/);
141
- assert.match(r.stdout, /interval elapsed/);
142
- });
143
-
144
- test("CLI: a state file with a junk field keeps the fields that parsed, and a foreign key rides along", () => {
145
- // Per-field validation, not all-or-nothing: losing a good streak to one bad
146
- // key would silently reset the back-off to the base every hold.
147
- const r = run(["--base", "2", "--ceiling", "64", "--hold", "1"],
148
- { state: JSON.stringify({ quiet: 4, elapsed: "nonsense", digest: "abc123", note: "not ours" }) });
149
- assert.equal(r.status, 0);
150
- assert.match(r.stdout, /\(quiet=4\)/);
151
- // And the file it leaves behind, which is the half a stdout-only assertion
152
- // cannot see: `note` is outside the schema and belongs to nobody here, so it
153
- // rides along untouched. Patch, never replace, is what lets two scripts share
154
- // one file without a lock, and a key this script does not know about is
155
- // exactly the case that rule exists for (#1597's stage-2 keys land here).
156
- // #1597 added a fourth key, and it carries a clock — so it is lifted out
157
- // here and asserted on its own shape rather than pinned to a timestamp a
158
- // test cannot know. The mark's own behaviour has its own cases at the foot
159
- // of this file; what this one still owes is the whole-file shape around it.
160
- assert.deepEqual(withoutMark(r.state), { note: "not ours", quiet: 4, elapsed: 1, digest: "abc123" });
161
- assert.equal(r.state.beat.stopped, "");
162
- });
163
-
164
- test("CLI: the value it writes back is the SANITIZED one, not the junk it read", () => {
165
- // The junk has to sit in a key this script does not patch, or the assertion
166
- // is vacuous: a bad `elapsed` is overwritten by the write either way, so only
167
- // a bad `quiet` or `digest` can show whether the file was rebuilt from the
168
- // validated view or from the raw parse. `quiet` is fleet-tick's, and this
169
- // script must neither own it nor launder it.
170
- //
171
- // Rebuilt from the raw parse, `quiet: "bogus"` goes back to disk verbatim and
172
- // the sanitizing only ever happened in memory — so every later reader repairs
173
- // it again, and the one field that decides the interval stays corrupt in the
174
- // file for the rest of the run.
175
- const r = run(["--base", "100", "--ceiling", "200", "--hold", "1"],
176
- { state: JSON.stringify({ quiet: "bogus", elapsed: 5, digest: "abc123", note: "not ours" }) });
177
- assert.equal(r.status, 0);
178
- // A junk streak reads as 0, which is the base interval — the fail-open
179
- // direction, more level checks rather than fewer.
180
- assert.match(r.stdout, /94s of 100s remain \(quiet=0\)/);
181
- assert.deepEqual(withoutMark(r.state), { note: "not ours", quiet: 0, elapsed: 6, digest: "abc123" });
182
- });
183
-
184
- test("CLI: a JSON array state file is announced and beats at the base interval", () => {
185
- // `[1,2,3]` is JSON, and `typeof [] === "object"`, so the array guard is the
186
- // only thing between it and reading `parsed.quiet` off an array — which is
187
- // `undefined`, sanitizes to 0, and would have this run silently agree that
188
- // the file was fine.
189
- const r = run(["--base", "1", "--hold", "1"], { state: "[1,2,3]" });
190
- assert.equal(r.status, 0);
191
- assert.match(r.stderr, /WARNING .* is not an object/);
192
- assert.match(r.stdout, /interval elapsed/);
193
- // Replaced by a real object, not patched as one: an array `rest` spread into
194
- // the write would persist `{"0":1,"1":2,"2":3,…}` and the next read would
195
- // announce the same fault forever.
196
- assert.deepEqual(withoutMark(r.state), { quiet: 0, elapsed: 0, digest: "" });
197
- });
198
-
199
- test("CLI: a state file it cannot READ is announced, never silently discarded", (t) => {
200
- if (process.getuid?.() === 0) return t.skip("root reads every file");
201
- // The absent file is silent because a fresh run legitimately has none. An
202
- // EACCES on a file that EXISTS is a different event: it discards a real
203
- // streak and a real elapsed total. Sharing the absent case's silence is a
204
- // degraded read reported as a fresh run, which is the failure class this
205
- // ticket exists to close — and the direction of the damage is the long way
206
- // round, since quiet=15 here is a ceiling-length interval read as the base.
207
- const dir = mkdtempSync(join(tmpdir(), "fleet-heartbeat-unreadable-"));
208
- const path = join(dir, "heartbeat.json");
209
- writeFileSync(path, JSON.stringify({ quiet: 15, elapsed: 10, digest: "abc" }));
210
- chmodSync(path, 0o000);
211
- const r = spawnSync(process.execPath,
212
- [SCRIPT, "--base", "2", "--ceiling", "64", "--hold", "1", "--state", path], { encoding: "utf8" });
213
- chmodSync(path, 0o644);
214
- rmSync(dir, { recursive: true, force: true });
215
- assert.equal(r.status, 0);
216
- assert.match(r.stderr, /WARNING could not read .*heartbeat\.json .*EACCES/);
217
- assert.match(r.stdout, /\(quiet=0\)/);
218
- });
219
-
220
- test("CLI: a state write that cannot land FIRES rather than holding the same remainder forever", (t) => {
221
- if (process.getuid?.() === 0) return t.skip("root writes every directory");
222
- // The livelock, and the reason a failed write cannot simply be survived: the
223
- // remainder is counted in a file, so with nothing persisting it every
224
- // invocation reads the same total, holds the same seconds and prints the same
225
- // `2s of 3s remain`. The interval never completes, fleet-tick is never run,
226
- // and the controller re-issues a command that reads like a working heartbeat
227
- // for the rest of the night — #357's own defect, wearing its remedy's line.
228
- const dir = mkdtempSync(join(tmpdir(), "fleet-heartbeat-unwritable-"));
229
- chmodSync(dir, 0o555);
230
- try {
231
- // Two invocations, because one could not tell a fire from progress. Both
232
- // are fresh processes reading the same state that never landed.
233
- for (const nth of ["first", "second"]) {
234
- const r = spawnSync(process.execPath,
235
- [SCRIPT, "--base", "3", "--ceiling", "8", "--hold", "1", "--state", join(dir, "heartbeat.json")],
236
- { encoding: "utf8" });
237
- assert.equal(r.status, 0);
238
- assert.match(r.stderr, /WARNING could not write/, `${nth}: a failed write is announced, never silent`);
239
- assert.match(r.stdout, /interval elapsed/, `${nth}: unpersisted progress fires instead of accumulating`);
240
- assert.doesNotMatch(r.stdout, /remain/, `${nth}: a remainder nothing is keeping is not a remainder`);
241
- }
242
- } finally {
243
- chmodSync(dir, 0o755);
244
- rmSync(dir, { recursive: true, force: true });
245
- }
246
- });
247
-
248
- test("CLI: a fleet-tick that runs DURING the hold is not reverted when the hold ends", async () => {
249
- // The hold is up to 240s by default, and fleet-tick runs on every other wake
250
- // that owe this script nothing — so the file it wrote at the end of a hold is
251
- // not the file it read at the start. Patching the pre-hold snapshot back
252
- // reverts both of fleet-tick's keys: the streak it just reset on a busy stretch
253
- // is restored, re-arming the ceiling-length interval the stretch had shortened,
254
- // and the restored `digest` reads as "the output changed" on the next tick,
255
- // un-folding the quiet night the digest exists to fold.
256
- const dir = mkdtempSync(join(tmpdir(), "fleet-heartbeat-race-"));
257
- const path = join(dir, "heartbeat.json");
258
- // A long streak, so the interval is at the ceiling and one hold cannot serve
259
- // it — which is the state a quiet night is in when work finally arrives.
260
- writeFileSync(path, JSON.stringify({ quiet: 6, elapsed: 0, digest: "old" }));
261
- const child = spawn(process.execPath,
262
- [SCRIPT, "--base", "600", "--ceiling", "1200", "--hold", "3", "--state", path], { stdio: "ignore" });
263
- const exited = new Promise((resolve, reject) => {
264
- child.on("exit", resolve);
265
- child.on("error", reject);
266
- });
267
- // Well inside the hold, and after the read it opens with.
268
- await new Promise((r) => setTimeout(r, 700));
269
- writeFileSync(path, JSON.stringify({ quiet: 0, elapsed: 0, digest: "fresh" }));
270
- assert.equal(await exited, 0);
271
-
272
- const after = JSON.parse(readFileSync(path, "utf8"));
273
- rmSync(dir, { recursive: true, force: true });
274
- assert.equal(after.quiet, 0, "the streak fleet-tick reset during the hold must survive the hold");
275
- assert.equal(after.digest, "fresh", "the digest fleet-tick wrote during the hold must survive the hold");
276
- // And this script's own key still advanced by the hold it actually served.
277
- assert.equal(after.elapsed, 3);
278
- });
279
-
280
- test("CLI: with no --state, and with an empty one, it resolves the run's shared default", () => {
281
- // The path the shipped invocation actually uses — SKILL.md's block passes no
282
- // --state at all — and `--state ""` is the shape an unset shell variable
283
- // produces, which `??` would let through as a real, empty path. Every read
284
- // and write against `''` then fails, which is the livelock above reached by
285
- // a second route, printed as a working heartbeat.
286
- const dir = mkdtempSync(join(tmpdir(), "fleet-heartbeat-default-"));
287
- assert.equal(spawnSync("git", ["init", "-q", dir], { encoding: "utf8" }).status, 0);
288
- const expected = join(dir, ".fleet", "heartbeat.json");
289
- for (const extra of [[], ["--state", ""]]) {
290
- rmSync(join(dir, ".fleet"), { recursive: true, force: true });
291
- const r = spawnSync(process.execPath,
292
- [SCRIPT, "--base", "2", "--ceiling", "8", "--hold", "1", ...extra], { cwd: dir, encoding: "utf8" });
293
- assert.equal(r.status, 0, r.stderr);
294
- // Never through the announced cwd-relative fallback: that path is the
295
- // degraded one, and a case that resolved through it would be pinning the
296
- // degradation while looking like it pinned the resolution.
297
- assert.doesNotMatch(r.stderr, /WARNING/, `--state ${JSON.stringify(extra[1] ?? "(absent)")} degraded`);
298
- assert.match(r.stdout, /1s of 2s remain/);
299
- assert.equal(JSON.parse(readFileSync(expected, "utf8")).elapsed, 1);
300
- }
301
- rmSync(dir, { recursive: true, force: true });
302
- });
303
-
304
- test("CLI: an ambient GIT_DIR cannot relocate the run's one state file", () => {
305
- // There is ONE heartbeat per run and one file behind it, shared by every
306
- // worktree — which is why the path resolves against the git common dir
307
- // instead of the cwd. An inherited GIT_DIR answers that question for a
308
- // DIFFERENT repository, and the answer is a perfectly ordinary-looking
309
- // absolute path, so the run splits into private streaks in silence. Same
310
- // scrub run-merge-bot.md applies to this exact git command in shell.
311
- const dir = mkdtempSync(join(tmpdir(), "fleet-heartbeat-gitdir-"));
312
- const other = mkdtempSync(join(tmpdir(), "fleet-heartbeat-elsewhere-"));
313
- assert.equal(spawnSync("git", ["init", "-q", dir], { encoding: "utf8" }).status, 0);
314
- assert.equal(spawnSync("git", ["init", "-q", other], { encoding: "utf8" }).status, 0);
315
- const env = { ...process.env, GIT_DIR: join(other, ".git"), GIT_WORK_TREE: other };
316
-
317
- // Positive control first: the injected variables really do reach a child and
318
- // really do change this command's answer. Without it, a state file landing in
319
- // the right place proves only that nothing was injected.
320
- const control = spawnSync("git", ["rev-parse", "--git-common-dir"], { cwd: dir, encoding: "utf8", env });
321
- assert.equal(control.stdout.trim(), join(other, ".git"));
322
-
323
- const r = spawnSync(process.execPath,
324
- [SCRIPT, "--base", "2", "--ceiling", "8", "--hold", "1"], { cwd: dir, encoding: "utf8", env });
325
- assert.equal(r.status, 0, r.stderr);
326
- assert.doesNotMatch(r.stderr, /WARNING/);
327
- assert.equal(JSON.parse(readFileSync(join(dir, ".fleet", "heartbeat.json"), "utf8")).elapsed, 1);
328
- assert.equal(existsSync(join(other, ".fleet", "heartbeat.json")), false,
329
- "the state file followed an ambient GIT_DIR into another repository");
330
- rmSync(dir, { recursive: true, force: true });
331
- rmSync(other, { recursive: true, force: true });
332
- });
333
-
334
-
335
- // --------------------------------------------------------------------------
336
- // The liveness mark — #1597. This script is the ONLY writer of `beat`, so
337
- // everything below is about what it leaves on disk for two readers it never
338
- // talks to: fleet-tick at the next run's start, and the cockpit every tick.
339
-
340
- test("CLI: every beat marks the time and the interval that was in effect", () => {
341
- // The interval travels WITH the time because it is not a constant — the
342
- // back-off stretches it toward the ceiling — so a reader comparing an age
343
- // against a fixed threshold cries wolf on a quiet night or misses a death
344
- // on a busy one. `quiet: 4` here makes the recorded interval the BACKED-OFF
345
- // one (2 × 2⁴ = 32, under the 64s ceiling), not the base: a mark that
346
- // recorded --base would be recording a promise this beat did not make.
347
- const before = Date.now();
348
- const r = run(["--base", "2", "--ceiling", "64", "--hold", "1"],
349
- { state: JSON.stringify({ quiet: 4, elapsed: 0, digest: "abc" }) });
350
- assert.equal(r.status, 0, r.stderr);
351
- assert.equal(r.state.beat.interval, 32, "the mark must carry the interval in effect, not the base");
352
- assert.ok(r.state.beat.at >= before && r.state.beat.at <= Date.now(), "the mark must be dated by this beat");
353
- assert.equal(r.state.beat.stopped, "", "an ordinary beat records no stop reason");
354
- // And fleet-tick's keys still survive the write that added it — the mark is
355
- // a fourth key under the same one-writer rule, not a rewrite of the file.
356
- assert.equal(r.state.quiet, 4);
357
- assert.equal(r.state.digest, "abc");
358
- });
359
-
360
- test("CLI: --stop records the reason without holding or touching the back-off", () => {
361
- // A deliberate stop is not a beat: nothing is held, `elapsed` is left where
362
- // it was, and the invocation returns immediately. `--base 600` would be a
363
- // ten-minute interval if this path held at all, so the wall clock below is
364
- // the assertion that it does not.
365
- const started = Date.now();
366
- const r = run(["--base", "600", "--ceiling", "1200", "--stop", "budget exhausted"],
367
- { state: JSON.stringify({ quiet: 1, elapsed: 7, digest: "abc" }) });
368
- assert.equal(r.status, 0, r.stderr);
369
- assert.ok(Date.now() - started < 30_000, "--stop must not hold");
370
- assert.equal(r.state.beat.stopped, "budget exhausted");
371
- assert.equal(r.state.elapsed, 7, "a stop is not a beat and must not spend the interval");
372
- assert.equal(r.state.quiet, 1);
373
- assert.match(r.stdout, /stop recorded \(budget exhausted\)/);
374
- // The line says who will report it, because a controller that stops without
375
- // knowing anything reads it has to wait for the next run to find out.
376
- assert.match(r.stdout, /the next run's start and the cockpit will report it/);
377
- });
378
-
379
- test("CLI: a beat after a stop clears the reason rather than carrying it forward", () => {
380
- // A run that recorded a stop and then kept beating did not stop. A reason
381
- // surviving into a live beat has every reader announcing a death that
382
- // already un-happened — and since a recorded stop outranks staleness, that
383
- // announcement would never age out on its own.
384
- const r = run(["--base", "2", "--ceiling", "4", "--hold", "1"], {
385
- state: JSON.stringify({ quiet: 0, elapsed: 0, digest: "",
386
- beat: { at: 1_700_000_000_000, interval: 300, stopped: "budget exhausted" } }),
387
- });
388
- assert.equal(r.status, 0, r.stderr);
389
- assert.equal(r.state.beat.stopped, "");
390
- assert.ok(r.state.beat.at > 1_700_000_000_000, "the mark must be re-dated by the live beat");
391
- });
392
-
393
- test("CLI: --stop refuses an empty reason", () => {
394
- // `--stop ""` is the shape an unset shell variable produces, and recording
395
- // it would be the abrupt-death case wearing a deliberate stop's clothes: a
396
- // reader would report a recorded reason and then print nothing for it.
397
- const r = run(["--stop", ""]);
398
- assert.equal(r.status, 2);
399
- assert.match(r.stderr, /--stop must carry the reason the run is stopping/);
400
- assert.equal(r.state, null, "a refused stop writes nothing at all");
401
- });
402
-
403
- test("CLI: a mark that cannot be written is announced and the heartbeat keeps beating", (t) => {
404
- if (process.getuid?.() === 0) return t.skip("root writes every directory");
405
- // The acceptance criterion this ticket states in its own words: a liveness
406
- // mark that killed the beat it measures would be #357's defect wearing a new
407
- // hat. So the write is made to FAIL — an unwritable state directory, the
408
- // same fixture the elapsed-write case above uses — and what is pinned is
409
- // that the process survives it, says so, and still prints the line that
410
- // keeps the controller's turn alive.
411
- const dir = mkdtempSync(join(tmpdir(), "fleet-heartbeat-mark-unwritable-"));
412
- chmodSync(dir, 0o555);
413
- try {
414
- const r = spawnSync(process.execPath,
415
- [SCRIPT, "--base", "3", "--ceiling", "8", "--hold", "1", "--state", join(dir, "heartbeat.json")],
416
- { encoding: "utf8" });
417
- assert.equal(r.status, 0, "a failed mark write must never be fatal");
418
- assert.match(r.stderr, /WARNING could not write/, "a failed mark write is announced, never silent");
419
- assert.match(r.stdout, /run fleet-tick/, "the beat goes on: the controller is still told what to do next");
420
- assert.equal(existsSync(join(dir, "heartbeat.json")), false);
421
-
422
- // The same policy on the stop path, which has no next beat to keep going:
423
- // it announces on stdout as well, because writeState's stderr warning
424
- // names the file and not the consequence — that the next reader will see
425
- // a beat which stopped with no reason recorded.
426
- const s = spawnSync(process.execPath,
427
- [SCRIPT, "--stop", "budget exhausted", "--state", join(dir, "heartbeat.json")],
428
- { encoding: "utf8" });
429
- assert.equal(s.status, 0);
430
- assert.match(s.stdout, /WARNING stop NOT recorded/);
431
- assert.match(s.stdout, /the next reader will see a beat that stopped with no reason/);
432
- } finally {
433
- chmodSync(dir, 0o755);
434
- rmSync(dir, { recursive: true, force: true });
435
- }
436
- });
437
-
438
- test("CLI: an unreadable mark degrades to no mark and does not stop the beat", () => {
439
- // A corrupt `beat` must not be a corrupt heartbeat. readState repairs the
440
- // key to absent, which every reader renders as "nothing to report" — loud
441
- // in the safe direction, since the alternative is a live run announced as
442
- // dead off a field nobody can parse.
443
- const r = run(["--base", "2", "--ceiling", "4", "--hold", "1"],
444
- { state: JSON.stringify({ quiet: 0, elapsed: 0, digest: "", beat: "yesterday" }) });
445
- assert.equal(r.status, 0, r.stderr);
446
- assert.match(r.stdout, /interval elapsed|remain/);
447
- // Replaced by this beat's own mark, never left as the junk it read.
448
- assert.equal(typeof r.state.beat, "object");
449
- assert.equal(r.state.beat.stopped, "");
450
- });
@@ -1,138 +0,0 @@
1
- // The Provenance check (ADR 0021): which install kind the Install root is,
2
- // its recorded version, the scripts/ digest over the whole file set under
3
- // `<Install root>/scripts`, Resolver drift, and the exit contract (0 clean,
4
- // 1 drift, 2 nothing to resolve). Driven through the real CLI —
5
- // fleet-provenance reads `os.homedir()` directly and `process.exit()`s.
6
- //
7
- // Every fixture's env is built from scratch (never `...process.env`), so
8
- // these tests are deterministic regardless of the box they run on.
9
- import { test } from "node:test";
10
- import assert from "node:assert/strict";
11
- import { spawnSync } from "node:child_process";
12
- import { chmodSync, mkdtempSync, mkdirSync, writeFileSync, symlinkSync } from "node:fs";
13
- import { tmpdir } from "node:os";
14
- import { join } from "node:path";
15
- import { fileURLToPath } from "node:url";
16
-
17
- const PROVENANCE = fileURLToPath(new URL("./fleet-provenance", import.meta.url));
18
-
19
- function runProvenance(home) {
20
- return spawnSync(process.execPath, [PROVENANCE], {
21
- encoding: "utf8",
22
- env: { HOME: home, PATH: process.env.PATH },
23
- });
24
- }
25
-
26
- // A payload whose scripts/ holds a top-level file and one nested
27
- // subdirectory carrying a dotfile, so a walk that skipped either shrinks
28
- // the file count.
29
- function writePayload(payload) {
30
- const sub = join(payload, "scripts", "sub");
31
- mkdirSync(sub, { recursive: true });
32
- writeFileSync(join(payload, "scripts", "fleet-run"), "resolver\n");
33
- writeFileSync(join(sub, ".hidden"), "nested\n");
34
- return sub;
35
- }
36
-
37
- // An install of the given kind, with the Resolver placed byte-identical to
38
- // the installed copy so drift never decides the exit code:
39
- // marketplace — node_modules entry symlinked into omp's plugin cache;
40
- // npm — node_modules entry a real directory (what npm unpacks);
41
- // link — node_modules entry symlinked to a checkout elsewhere.
42
- function fakeInstall(kind = "marketplace") {
43
- const home = mkdtempSync(join(tmpdir(), "fleet-provenance-home-"));
44
- const nm = join(home, ".omp", "plugins", "node_modules");
45
- const entry = join(nm, "@feigi", "fleet-ctl");
46
- mkdirSync(join(nm, "@feigi"), { recursive: true });
47
- let sub;
48
- if (kind === "npm") {
49
- sub = writePayload(entry);
50
- } else {
51
- const payload = kind === "marketplace"
52
- ? join(home, ".omp", "plugins", "cache", "a")
53
- : join(home, "checkout", "plugin");
54
- sub = writePayload(payload);
55
- symlinkSync(payload, entry);
56
- }
57
- mkdirSync(join(home, ".fleet", "bin"), { recursive: true });
58
- writeFileSync(join(home, ".fleet", "bin", "fleet-run"), "resolver\n");
59
- return { home, sub };
60
- }
61
-
62
- const NOTICE = /NOTICE: Install root is a linked checkout/;
63
-
64
- for (const [kind, expected] of [["npm", "npm-install"], ["marketplace", "marketplace-install"]]) {
65
- test(`a ${kind}-shaped install reports kind ${expected}, exit 0, no linked-checkout NOTICE`, () => {
66
- const { home } = fakeInstall(kind);
67
- const r = runProvenance(home);
68
- assert.equal(r.status, 0, `expected success, got status ${r.status}: ${r.stdout}${r.stderr}`);
69
- assert.match(r.stdout, new RegExp(`^fleet-provenance: kind: ${expected}$`, "m"));
70
- assert.doesNotMatch(r.stdout, NOTICE);
71
- });
72
- }
73
-
74
- test("a link to a checkout outside omp's cache reports kind linked-checkout and a NOTICE, still exit 0", () => {
75
- const { home } = fakeInstall("link");
76
- const r = runProvenance(home);
77
- assert.equal(r.status, 0, `a link is the dev loop, not a failure: status ${r.status}: ${r.stdout}${r.stderr}`);
78
- assert.match(r.stdout, /^fleet-provenance: kind: linked-checkout$/m);
79
- assert.match(r.stdout, NOTICE);
80
- });
81
-
82
- test("the version line reads the lock entry, and says none recorded without one", () => {
83
- const { home } = fakeInstall("npm");
84
- assert.match(runProvenance(home).stdout, /^fleet-provenance: version: \(none recorded\)$/m);
85
- writeFileSync(
86
- join(home, ".omp", "plugins", "omp-plugins.lock.json"),
87
- JSON.stringify({ plugins: { "@feigi/fleet-ctl": { version: "1.2.3" } } }),
88
- );
89
- assert.match(runProvenance(home).stdout, /^fleet-provenance: version: 1\.2\.3$/m);
90
- });
91
-
92
- test("no node_modules/@feigi/fleet-ctl entry: exit 2, stderr names the missing plugin, nothing certified", () => {
93
- const home = mkdtempSync(join(tmpdir(), "fleet-provenance-home-"));
94
- const r = runProvenance(home);
95
- assert.equal(r.status, 2, `expected a resolution refusal, got status ${r.status}: ${r.stdout}`);
96
- assert.match(r.stderr, /no omp plugin "@feigi\/fleet-ctl"/);
97
- assert.equal(r.stdout, "");
98
- });
99
-
100
- test("a placed Resolver that differs from the installed copy refuses as drift, exit 1", () => {
101
- const { home } = fakeInstall("npm");
102
- writeFileSync(join(home, ".fleet", "bin", "fleet-run"), "stale resolver\n");
103
- const r = runProvenance(home);
104
- assert.equal(r.status, 1, `expected drift to fail the check, got status ${r.status}: ${r.stdout}`);
105
- assert.match(r.stdout, /Resolver drift: REFUSED/);
106
- });
107
-
108
- test("a readable nested subdirectory, dotfiles included, is digested with the rest of scripts/", () => {
109
- const { home } = fakeInstall();
110
- const r = runProvenance(home);
111
- assert.equal(r.status, 0, `expected success, got status ${r.status}: ${r.stdout}${r.stderr}`);
112
- assert.match(r.stdout, /scripts\/ digest: sha256 [0-9a-f]{64} \(2 files\)/);
113
- });
114
-
115
- test("an empty scripts/ makes the digest UNAVAILABLE rather than certifying nothing", () => {
116
- const home = mkdtempSync(join(tmpdir(), "fleet-provenance-home-"));
117
- const entry = join(home, ".omp", "plugins", "node_modules", "@feigi", "fleet-ctl");
118
- mkdirSync(join(entry, "scripts"), { recursive: true });
119
- const r = runProvenance(home);
120
- assert.match(r.stdout, /scripts\/ digest: UNAVAILABLE — no files under .*scripts — refusing to certify an empty set/);
121
- assert.doesNotMatch(r.stdout, /scripts\/ digest: sha256/);
122
- });
123
-
124
- test("an unlistable nested subdirectory makes the digest UNAVAILABLE, never a shorter file set", (t) => {
125
- if (process.platform === "win32" || process.getuid?.() === 0) {
126
- t.skip("chmod 000 does not deny a directory listing here");
127
- return;
128
- }
129
- const { home, sub } = fakeInstall();
130
- chmodSync(sub, 0o000);
131
- try {
132
- const r = runProvenance(home);
133
- assert.match(r.stdout, /scripts\/ digest: UNAVAILABLE — cannot list .*sub \(EACCES\)/);
134
- assert.doesNotMatch(r.stdout, /scripts\/ digest: sha256/);
135
- } finally {
136
- chmodSync(sub, 0o755);
137
- }
138
- });