@feigi/fleet-ctl 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +9 -0
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/agents/fleet-finisher.agent.md +7 -0
- package/agents/fleet-implementer-alt.agent.md +210 -0
- package/agents/fleet-implementer.agent.md +210 -0
- package/agents/fleet-merge-bot.agent.md +7 -0
- package/agents/fleet-review-comments.agent.md +40 -0
- package/agents/fleet-review-correctness.agent.md +43 -0
- package/agents/fleet-review-runner.agent.md +73 -0
- package/agents/fleet-review-silent-failure.agent.md +49 -0
- package/agents/fleet-review-simplify.agent.md +46 -0
- package/agents/fleet-review-snapshot.agent.md +24 -0
- package/agents/fleet-review-tests.agent.md +46 -0
- package/agents/fleet-review-types.agent.md +41 -0
- package/agents/fleet-review-verifier.agent.md +29 -0
- package/commands/review-and-fix.md +98 -0
- package/commands/run-merge-bot.md +357 -0
- package/commands/run-team-help.md +17 -0
- package/package.json +23 -0
- package/scripts/agent-test-dir-prose.test.mjs +59 -0
- package/scripts/agent-test.test.mjs +1636 -0
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
- package/scripts/ambient-git-vars-prose.test.mjs +192 -0
- package/scripts/ancestry-check-position-prose.test.mjs +175 -0
- package/scripts/apply-ruleset.test.mjs +420 -0
- package/scripts/arg-header-probes-prose.test.mjs +393 -0
- package/scripts/arg.mjs +600 -0
- package/scripts/arg.test.mjs +1354 -0
- package/scripts/board-cli.test.mjs +694 -0
- package/scripts/board-identity.test.mjs +429 -0
- package/scripts/board-liveness-banner.test.mjs +119 -0
- package/scripts/board-prev-shape.test.mjs +229 -0
- package/scripts/board-tryparse-null.test.mjs +119 -0
- package/scripts/board.html +471 -0
- package/scripts/board.mjs +2037 -0
- package/scripts/board.test.mjs +3086 -0
- package/scripts/brief-after-cut-prose.test.mjs +53 -0
- package/scripts/candidates-exit3-prose.test.mjs +302 -0
- package/scripts/candidates.mjs +674 -0
- package/scripts/candidates.test.mjs +2101 -0
- package/scripts/caveat-unification-prose.test.mjs +98 -0
- package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
- package/scripts/ci-completes-premise-prose.test.mjs +257 -0
- package/scripts/ci-state-prose.test.mjs +113 -0
- package/scripts/ci-state.mjs +761 -0
- package/scripts/ci-state.test.mjs +1640 -0
- package/scripts/ci-vacuous-green.test.mjs +368 -0
- package/scripts/citation-sweep-prose.test.mjs +1572 -0
- package/scripts/claim-lifecycle.test.mjs +185 -0
- package/scripts/claim-ticket.sh +417 -0
- package/scripts/claim-ticket.test.mjs +1121 -0
- package/scripts/closing-keyword-prose.test.mjs +193 -0
- package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
- package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
- package/scripts/compute-board.mjs +579 -0
- package/scripts/compute-board.test.mjs +1060 -0
- package/scripts/compute-spend.mjs +329 -0
- package/scripts/compute-spend.test.mjs +451 -0
- package/scripts/cross-repo-citation-prose.test.mjs +156 -0
- package/scripts/cwd-isolation-pins.mjs +83 -0
- package/scripts/dedupe-guard-prose.test.mjs +243 -0
- package/scripts/derive-testcmd.sh +239 -0
- package/scripts/derive-testcmd.test.mjs +380 -0
- package/scripts/diff-stats.mjs +231 -0
- package/scripts/diff-stats.test.mjs +408 -0
- package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
- package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
- package/scripts/drop-merged-label.sh +173 -0
- package/scripts/drop-merged-label.test.mjs +480 -0
- package/scripts/expected-jobs-prose.test.mjs +80 -0
- package/scripts/filing-bar-seat-prose.test.mjs +242 -0
- package/scripts/filing-claim-bar-prose.test.mjs +166 -0
- package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
- package/scripts/finisher-halt-prose.test.mjs +106 -0
- package/scripts/finisher-name-prose.test.mjs +134 -0
- package/scripts/finisher-own-tree-prose.test.mjs +285 -0
- package/scripts/finisher-pin-race-prose.test.mjs +339 -0
- package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
- package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
- package/scripts/fleet-bootstrap +155 -0
- package/scripts/fleet-heartbeat.mjs +272 -0
- package/scripts/fleet-heartbeat.test.mjs +450 -0
- package/scripts/fleet-provenance +207 -0
- package/scripts/fleet-provenance.test.mjs +64 -0
- package/scripts/fleet-run +148 -0
- package/scripts/fleet-run.test.mjs +90 -0
- package/scripts/fleet-state.mjs +400 -0
- package/scripts/fleet-state.test.mjs +373 -0
- package/scripts/fleet-tick-prose.test.mjs +299 -0
- package/scripts/fleet-tick.mjs +832 -0
- package/scripts/fleet-tick.test.mjs +1332 -0
- package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
- package/scripts/frontmatter-allowlist.json +64 -0
- package/scripts/frontmatter-check.mjs +256 -0
- package/scripts/frontmatter-check.test.mjs +436 -0
- package/scripts/git-env.mjs +124 -0
- package/scripts/git-env.test.mjs +149 -0
- package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
- package/scripts/gone-walk.test.mjs +213 -0
- package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
- package/scripts/head-moved-after-label-prose.test.mjs +233 -0
- package/scripts/immutable-body-claim-prose.test.mjs +413 -0
- package/scripts/implementer-model-tier.test.mjs +643 -0
- package/scripts/inflight-citation-prose.test.mjs +144 -0
- package/scripts/inflight-exit2-prose.test.mjs +81 -0
- package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
- package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
- package/scripts/inflight.sh +1106 -0
- package/scripts/inflight.test.mjs +2984 -0
- package/scripts/injection-control-prose.test.mjs +404 -0
- package/scripts/install-root-audit.test.mjs +464 -0
- package/scripts/instrument-check-prose.test.mjs +235 -0
- package/scripts/instruments.sh +394 -0
- package/scripts/instruments.test.mjs +787 -0
- package/scripts/issue-tracker-prose.test.mjs +71 -0
- package/scripts/json.sh +248 -0
- package/scripts/json.test.mjs +364 -0
- package/scripts/ledger-dispatch.test.mjs +516 -0
- package/scripts/ledger-grammar.mjs +85 -0
- package/scripts/ledger-grammar.test.mjs +142 -0
- package/scripts/ledger-read-require-file.test.mjs +197 -0
- package/scripts/ledger.mjs +1753 -0
- package/scripts/ledger.test.mjs +3554 -0
- package/scripts/line-distance-prose.test.mjs +245 -0
- package/scripts/liveness-rationale-prose.test.mjs +83 -0
- package/scripts/locale-pin-prose.test.mjs +189 -0
- package/scripts/member-outcome-prose.test.mjs +167 -0
- package/scripts/member-outcomes-header.test.mjs +148 -0
- package/scripts/member-outcomes-prose.test.mjs +63 -0
- package/scripts/member-outcomes.mjs +231 -0
- package/scripts/member-outcomes.test.mjs +507 -0
- package/scripts/member-prompt-prose.test.mjs +161 -0
- package/scripts/member-record.mjs +605 -0
- package/scripts/member-record.test.mjs +516 -0
- package/scripts/member-write-guard.mjs +279 -0
- package/scripts/member-write-guard.test.mjs +211 -0
- package/scripts/merge-commit-probe-prose.test.mjs +122 -0
- package/scripts/merge-gate.mjs +262 -0
- package/scripts/merge-gate.test.mjs +613 -0
- package/scripts/muted-git-guard-sweep.test.mjs +493 -0
- package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
- package/scripts/net-watchdog-prose.test.mjs +79 -0
- package/scripts/net.sh +409 -0
- package/scripts/net.test.mjs +211 -0
- package/scripts/no-ci-gate-prose.test.mjs +108 -0
- package/scripts/no-undo-audit.sh +1134 -0
- package/scripts/no-undo-audit.test.mjs +3965 -0
- package/scripts/no-wave.test.mjs +138 -0
- package/scripts/node-floor-sweep.test.mjs +611 -0
- package/scripts/pointer-target-prose.test.mjs +186 -0
- package/scripts/pr-overlap.mjs +417 -0
- package/scripts/pr-overlap.test.mjs +695 -0
- package/scripts/printf-die-sweep.test.mjs +384 -0
- package/scripts/prompt-renderer.mjs +39 -0
- package/scripts/prompt-renderer.test.mjs +68 -0
- package/scripts/prose-pin.mjs +808 -0
- package/scripts/prose-pin.test.mjs +1034 -0
- package/scripts/prove-merge.sh +228 -0
- package/scripts/prove-merge.test.mjs +995 -0
- package/scripts/pull-table-relabel-prose.test.mjs +60 -0
- package/scripts/quiet-payload-prose.test.mjs +222 -0
- package/scripts/reap.sh +1768 -0
- package/scripts/reap.test.mjs +4395 -0
- package/scripts/reaping-prose.test.mjs +159 -0
- package/scripts/refuter-scratch-prose.test.mjs +135 -0
- package/scripts/release-label-required-prose.test.mjs +71 -0
- package/scripts/release-label-split-prose.test.mjs +169 -0
- package/scripts/release-ticket.sh +1716 -0
- package/scripts/release-ticket.test.mjs +5106 -0
- package/scripts/renovate-release-contract.test.mjs +379 -0
- package/scripts/repo-root.mjs +544 -0
- package/scripts/repo-root.test.mjs +873 -0
- package/scripts/reporter-output-rule-prose.test.mjs +208 -0
- package/scripts/review-agent-report-only.test.mjs +49 -0
- package/scripts/review-core-cwd-isolation.test.mjs +374 -0
- package/scripts/review-core-reads.test.mjs +478 -0
- package/scripts/review-core-refuter-scratch.test.mjs +148 -0
- package/scripts/review-core-snapshot-path.test.mjs +777 -0
- package/scripts/review-core-specialist-scratch.test.mjs +189 -0
- package/scripts/review-core-testcmd.test.mjs +288 -0
- package/scripts/review-core-unrun.test.mjs +530 -0
- package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
- package/scripts/review-core.mjs +1028 -0
- package/scripts/review-eval-resolver-path.test.mjs +55 -0
- package/scripts/review-eval.mjs +197 -0
- package/scripts/review-host-fixture.mjs +73 -0
- package/scripts/review-in-run-retry.test.mjs +187 -0
- package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
- package/scripts/review-path-default.test.mjs +796 -0
- package/scripts/review-runner-spawns.test.mjs +93 -0
- package/scripts/review-runner.test.mjs +155 -0
- package/scripts/review-tier-audit.test.mjs +140 -0
- package/scripts/run-artifact-pr-prose.test.mjs +341 -0
- package/scripts/run-merge-bot-prose.test.mjs +1391 -0
- package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
- package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
- package/scripts/section-between-guard-prose.test.mjs +378 -0
- package/scripts/select-dimensions.test.mjs +674 -0
- package/scripts/shared-refusal.test.mjs +388 -0
- package/scripts/shell-traps-prose.test.mjs +507 -0
- package/scripts/shortlist.mjs +355 -0
- package/scripts/shortlist.test.mjs +366 -0
- package/scripts/slow-transport.mjs +72 -0
- package/scripts/snapshot-repo.test.mjs +772 -0
- package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
- package/scripts/spend-view.test.mjs +312 -0
- package/scripts/staleness-qualifier-prose.test.mjs +251 -0
- package/scripts/staleness-verdict-prose.test.mjs +142 -0
- package/scripts/staleness.mjs +414 -0
- package/scripts/staleness.test.mjs +893 -0
- package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
- package/scripts/stash-prohibition-prose.test.mjs +313 -0
- package/scripts/strip-comments.mjs +44 -0
- package/scripts/tier-check.mjs +468 -0
- package/scripts/tier-check.test.mjs +726 -0
- package/scripts/tier-guard-gate-prose.test.mjs +216 -0
- package/scripts/tier-outcomes-header.test.mjs +586 -0
- package/scripts/tier-outcomes.mjs +441 -0
- package/scripts/tier-outcomes.test.mjs +342 -0
- package/scripts/tier-roles.mjs +250 -0
- package/scripts/tier-roles.test.mjs +316 -0
- package/scripts/tracker-block-copy-prose.test.mjs +288 -0
- package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
- package/scripts/unattended-git-sweep.test.mjs +142 -0
- package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
- package/scripts/verify-sha.sh +117 -0
- package/scripts/verify-sha.test.mjs +693 -0
- package/scripts/watcher-degraded-block.test.mjs +372 -0
- package/scripts/watcher-key-prose.test.mjs +106 -0
- package/scripts/within-run-pair-prose.test.mjs +208 -0
- package/scripts/worktree-audit.sh +482 -0
- package/scripts/worktree-audit.test.mjs +1407 -0
- package/scripts/worktree-head-prose.test.mjs +276 -0
- package/scripts/worktree-listing-sweep.test.mjs +217 -0
- package/scripts/worktree-model-prose.test.mjs +216 -0
- package/scripts/worktree.sh +470 -0
- package/skills/next-ticket/SKILL.md +138 -0
- package/skills/run-team/SKILL.md +3603 -0
- package/skills/run-team/references/ci-and-staleness.md +75 -0
- package/skills/run-team/references/correction-tickets.md +37 -0
- package/skills/run-team/references/isolation.md +23 -0
- package/skills/run-team/references/member-lifecycle.md +73 -0
- package/skills/run-team/references/reaping.md +73 -0
- package/skills/sizing-a-ticket/SKILL.md +39 -0
|
@@ -0,0 +1,450 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The Provenance check (#1335, ADR 0003 point 4, ADR 0021, CONTEXT.md § Install
|
|
3
|
+
// "Provenance check"). Names the live Install root — the realpath of omp's
|
|
4
|
+
// `node_modules/@feigi/fleet-ctl` package entry, the one path every install kind
|
|
5
|
+
// places (ADR 0021) — its kind and recorded version, and hashes the placed
|
|
6
|
+
// Resolver (`~/.fleet/bin/fleet-run`) against each install's own copy and
|
|
7
|
+
// refuses on drift. Writes nothing, mutates no config — every path below is
|
|
8
|
+
// read-only.
|
|
9
|
+
//
|
|
10
|
+
// The `enabledProviders: ["claude-plugins"]` assertion retired here (ADR
|
|
11
|
+
// 0021): omp's #11362 fix (shipped 18.2.1) exempts omp-origin installs from
|
|
12
|
+
// that provider gate, and the native package route never depended on it.
|
|
13
|
+
// Asserting it refused correct setups.
|
|
14
|
+
//
|
|
15
|
+
// SEPARATE FILE, not `fleet-run --check`. `fleet-run` is deliberately a
|
|
16
|
+
// single self-contained file because it alone gets copied to
|
|
17
|
+
// `~/.fleet/bin/fleet-run` (see that file's own header) — folding a second,
|
|
18
|
+
// unrelated responsibility into it would grow the one artefact outside the
|
|
19
|
+
// plugin for a feature that never needs to travel there. This script stays
|
|
20
|
+
// inside the install and is reached like every other one, through the
|
|
21
|
+
// Resolver: `fleet-run fleet-provenance`.
|
|
22
|
+
"use strict";
|
|
23
|
+
|
|
24
|
+
const fs = require("node:fs");
|
|
25
|
+
const path = require("node:path");
|
|
26
|
+
const os = require("node:os");
|
|
27
|
+
const crypto = require("node:crypto");
|
|
28
|
+
|
|
29
|
+
const NAME = "fleet-provenance";
|
|
30
|
+
const PLUGIN_KEY = "@feigi/fleet-ctl"; // ADR 0006 name; ADR 0021 — the node_modules package dir.
|
|
31
|
+
|
|
32
|
+
// Same resolution point as scripts/fleet-run (its header names the shape of
|
|
33
|
+
// each install kind). Duplicated rather than shared because a module the
|
|
34
|
+
// Resolver requires would have to travel with its placed copy — see
|
|
35
|
+
// fleet-run's own header.
|
|
36
|
+
function resolveInstall(home) {
|
|
37
|
+
const packagePath = path.join(home, ".omp", "plugins", "node_modules", PLUGIN_KEY);
|
|
38
|
+
let stat;
|
|
39
|
+
try {
|
|
40
|
+
stat = fs.lstatSync(packagePath);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return { present: false, packagePath, reason: `no omp plugin "${PLUGIN_KEY}" at ${packagePath} (${e.code || e.message})` };
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return { present: true, packagePath, isLink: stat.isSymbolicLink(), installPath: fs.realpathSync(packagePath) };
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return { present: false, packagePath, reason: `omp plugin "${PLUGIN_KEY}" at ${packagePath} does not resolve (${e.code || e.message})` };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Version lives in omp's runtime plugin lock, which every install kind writes
|
|
52
|
+
// (ADR 0021 point 4) — a link records the manifest's own `package.json`
|
|
53
|
+
// version (measured on 18.4.8: `0.0.0`, the placeholder), so the number never
|
|
54
|
+
// identifies a link; `kind:` does. Read tolerantly: any shape problem degrades
|
|
55
|
+
// to null, it never fails the check, because the version is informational.
|
|
56
|
+
function readLockVersion(home) {
|
|
57
|
+
const lockPath = path.join(home, ".omp", "plugins", "omp-plugins.lock.json");
|
|
58
|
+
let json;
|
|
59
|
+
try {
|
|
60
|
+
json = JSON.parse(fs.readFileSync(lockPath, "utf8"));
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const entry = json && json.plugins && json.plugins[PLUGIN_KEY];
|
|
65
|
+
return entry && typeof entry.version === "string" ? entry.version : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Every regular file under `<root>/scripts`, repo-relative, sorted — a
|
|
69
|
+
// filesystem walk rather than `git ls-files`: an installed copy need not
|
|
70
|
+
// carry a .git at all (a directory-source install can exclude it, ADR 0003),
|
|
71
|
+
// so git is not an instrument this check can rely on being present.
|
|
72
|
+
function walkFiles(dir, base = dir, out = []) {
|
|
73
|
+
let entries;
|
|
74
|
+
try {
|
|
75
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
76
|
+
} catch (e) {
|
|
77
|
+
return { error: `cannot list ${dir} (${e.code || e.message})` };
|
|
78
|
+
}
|
|
79
|
+
for (const entry of entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
|
|
80
|
+
const full = path.join(dir, entry.name);
|
|
81
|
+
if (entry.isDirectory()) {
|
|
82
|
+
// A subtree that cannot be listed must fail the digest, never shrink it:
|
|
83
|
+
// a partial file set would certify as complete.
|
|
84
|
+
const sub = walkFiles(full, base, out);
|
|
85
|
+
if (sub.error) return sub;
|
|
86
|
+
} else if (entry.isFile()) out.push({ rel: path.relative(base, full), full });
|
|
87
|
+
}
|
|
88
|
+
return { files: out };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function sha256(buf) {
|
|
92
|
+
return crypto.createHash("sha256").update(buf).digest("hex");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// One digest over every file's content under `<root>/scripts`, keyed by
|
|
96
|
+
// relative path so a rename changes it and a mtime-only touch does not.
|
|
97
|
+
function digestScriptsDir(root) {
|
|
98
|
+
const scriptsDir = path.join(root, "scripts");
|
|
99
|
+
const listed = walkFiles(scriptsDir);
|
|
100
|
+
if (listed.error) return { error: listed.error };
|
|
101
|
+
if (listed.files.length === 0) return { error: `no files under ${scriptsDir} — refusing to certify an empty set` };
|
|
102
|
+
const lines = listed.files.map((f) => `${sha256(fs.readFileSync(f.full))} ${f.rel}`);
|
|
103
|
+
return { digest: sha256(Buffer.from(lines.join("\n") + "\n", "utf8")), fileCount: listed.files.length };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Which install kind produced this root, from where the package entry points:
|
|
107
|
+
// a symlink resolving inside omp's plugin cache → a marketplace install; the
|
|
108
|
+
// entry itself a real directory under node_modules (not a symlink) → an npm
|
|
109
|
+
// install; a symlink pointing anywhere else → a linked checkout. Compare
|
|
110
|
+
// canonicalized paths — macOS resolves /tmp through /private/tmp (measured;
|
|
111
|
+
// the same reason fleet-bootstrap's canonical() exists), so a raw string
|
|
112
|
+
// prefix misreports an npm install as an unknown shape on those boxes.
|
|
113
|
+
function kindOf(res) {
|
|
114
|
+
const { packagePath, installPath, isLink } = res;
|
|
115
|
+
let nodeModules;
|
|
116
|
+
try {
|
|
117
|
+
nodeModules = fs.realpathSync(path.dirname(packagePath));
|
|
118
|
+
} catch {
|
|
119
|
+
nodeModules = path.dirname(packagePath);
|
|
120
|
+
}
|
|
121
|
+
if (isLink) {
|
|
122
|
+
if (installPath.includes(`${path.sep}.omp${path.sep}plugins${path.sep}cache${path.sep}`)) return "marketplace-install";
|
|
123
|
+
return "linked-checkout";
|
|
124
|
+
}
|
|
125
|
+
if (installPath.startsWith(nodeModules + path.sep)) return "npm-install";
|
|
126
|
+
return "unrecognized-install-shape";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function main() {
|
|
130
|
+
const argv = process.argv.slice(2);
|
|
131
|
+
for (let i = 0; i < argv.length; i++) {
|
|
132
|
+
process.stderr.write(`${NAME}: unrecognized argument ${argv[i]}\n`);
|
|
133
|
+
process.exit(2);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const home = os.homedir();
|
|
137
|
+
const reg = resolveInstall(home);
|
|
138
|
+
|
|
139
|
+
if (!reg.present) {
|
|
140
|
+
process.stderr.write(`${NAME}: ${reg.reason}\n`);
|
|
141
|
+
process.exit(2);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const placedPath = path.join(home, ".fleet", "bin", "fleet-run");
|
|
145
|
+
let placedBuf = null;
|
|
146
|
+
let placedError = null;
|
|
147
|
+
try {
|
|
148
|
+
placedBuf = fs.readFileSync(placedPath);
|
|
149
|
+
} catch (e) {
|
|
150
|
+
placedError = `${e.code || e.message}`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let failed = false;
|
|
154
|
+
|
|
155
|
+
const kind = kindOf(reg);
|
|
156
|
+
const version = readLockVersion(home);
|
|
157
|
+
process.stdout.write(`${NAME}: Install root: ${reg.installPath}\n`);
|
|
158
|
+
process.stdout.write(`${NAME}: kind: ${kind}\n`);
|
|
159
|
+
process.stdout.write(`${NAME}: version: ${version ?? "(none recorded)"}\n`);
|
|
160
|
+
|
|
161
|
+
const digest = digestScriptsDir(reg.installPath);
|
|
162
|
+
if (digest.error) {
|
|
163
|
+
process.stdout.write(`${NAME}: scripts/ digest: UNAVAILABLE — ${digest.error}\n`);
|
|
164
|
+
} else {
|
|
165
|
+
process.stdout.write(`${NAME}: scripts/ digest: sha256 ${digest.digest} (${digest.fileCount} files)\n`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const installedRunPath = path.join(reg.installPath, "scripts", "fleet-run");
|
|
169
|
+
let installedRunBuf = null;
|
|
170
|
+
let installedRunError = null;
|
|
171
|
+
try {
|
|
172
|
+
installedRunBuf = fs.readFileSync(installedRunPath);
|
|
173
|
+
} catch (e) {
|
|
174
|
+
installedRunError = `${e.code || e.message}`;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (placedError) {
|
|
178
|
+
process.stdout.write(`${NAME}: Resolver drift: REFUSED — placed copy ${placedPath} unreadable (${placedError})\n`);
|
|
179
|
+
failed = true;
|
|
180
|
+
} else if (installedRunError) {
|
|
181
|
+
process.stdout.write(`${NAME}: Resolver drift: REFUSED — installed copy ${installedRunPath} unreadable (${installedRunError})\n`);
|
|
182
|
+
failed = true;
|
|
183
|
+
} else if (!placedBuf.equals(installedRunBuf)) {
|
|
184
|
+
process.stdout.write(
|
|
185
|
+
`${NAME}: Resolver drift: REFUSED — ${placedPath} (sha256 ${sha256(placedBuf)}) `
|
|
186
|
+
+ `!= ${installedRunPath} (sha256 ${sha256(installedRunBuf)})\n`,
|
|
187
|
+
);
|
|
188
|
+
failed = true;
|
|
189
|
+
} else {
|
|
190
|
+
process.stdout.write(`${NAME}: Resolver drift: none — ${placedPath} matches ${installedRunPath}\n`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (kind === "linked-checkout") {
|
|
194
|
+
// Not a failure: a link is the dev loop (ADR 0021). It is a NOTICE on
|
|
195
|
+
// every other install's answer, because a linked root outranks an
|
|
196
|
+
// installed copy of the same names in omp's own discovery — the check
|
|
197
|
+
// above certified the LINK, not what a session without the link runs.
|
|
198
|
+
process.stdout.write(
|
|
199
|
+
`${NAME}: NOTICE: Install root is a linked checkout (${reg.installPath}) — this box develops the plugin; `
|
|
200
|
+
+ "every fleet-run answer above came from that checkout, not from an installed release.\n",
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
process.exit(failed ? 1 : 0);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
main();
|