@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.
- package/package.json +1 -1
- package/scripts/main-checkout.mjs +1 -1
- package/scripts/member-write-guard.mjs +1 -1
- package/scripts/repo-root.mjs +1 -1
- package/skills/run-team/references/reaping.md +1 -1
- package/scripts/agent-test-dir-prose.test.mjs +0 -59
- package/scripts/agent-test.test.mjs +0 -1640
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
- package/scripts/ambient-git-vars-prose.test.mjs +0 -192
- package/scripts/ancestry-check-position-prose.test.mjs +0 -175
- package/scripts/apply-ruleset.test.mjs +0 -421
- package/scripts/arg-header-probes-prose.test.mjs +0 -394
- package/scripts/arg.test.mjs +0 -1354
- package/scripts/board-cli.test.mjs +0 -710
- package/scripts/board-identity.test.mjs +0 -429
- package/scripts/board-liveness-banner.test.mjs +0 -119
- package/scripts/board-prev-shape.test.mjs +0 -228
- package/scripts/board-tryparse-null.test.mjs +0 -119
- package/scripts/board.test.mjs +0 -3121
- package/scripts/brief-after-cut-prose.test.mjs +0 -53
- package/scripts/candidates-exit3-prose.test.mjs +0 -302
- package/scripts/candidates.test.mjs +0 -2312
- package/scripts/caveat-unification-prose.test.mjs +0 -98
- package/scripts/cell-readout.test.mjs +0 -615
- package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
- package/scripts/ci-completes-premise-prose.test.mjs +0 -257
- package/scripts/ci-state-prose.test.mjs +0 -113
- package/scripts/ci-state.test.mjs +0 -1933
- package/scripts/ci-vacuous-green.test.mjs +0 -368
- package/scripts/citation-sweep-prose.test.mjs +0 -1712
- package/scripts/claim-lifecycle.test.mjs +0 -187
- package/scripts/claim-ticket.test.mjs +0 -1122
- package/scripts/closing-keyword-prose.test.mjs +0 -193
- package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
- package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
- package/scripts/compute-board.test.mjs +0 -1214
- package/scripts/compute-spend.test.mjs +0 -517
- package/scripts/consumer-technology-prose.test.mjs +0 -126
- package/scripts/cross-repo-citation-prose.test.mjs +0 -155
- package/scripts/cwd-isolation-pins.mjs +0 -83
- package/scripts/dedupe-guard-prose.test.mjs +0 -243
- package/scripts/delete-merged-branch.test.mjs +0 -576
- package/scripts/derive-testcmd.test.mjs +0 -595
- package/scripts/diff-stats.test.mjs +0 -404
- package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
- package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
- package/scripts/dispositions-check.test.mjs +0 -936
- package/scripts/dispositions-gate-prose.test.mjs +0 -129
- package/scripts/drop-merged-label.test.mjs +0 -479
- package/scripts/exec-stub.mjs +0 -93
- package/scripts/exec-stub.test.mjs +0 -69
- package/scripts/expected-jobs-prose.test.mjs +0 -80
- package/scripts/fan-out-authorization-prose.test.mjs +0 -80
- package/scripts/filing-bar-seat-prose.test.mjs +0 -242
- package/scripts/filing-claim-bar-prose.test.mjs +0 -166
- package/scripts/finisher-died-prose.test.mjs +0 -31
- package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
- package/scripts/finisher-halt-prose.test.mjs +0 -106
- package/scripts/finisher-name-prose.test.mjs +0 -134
- package/scripts/finisher-own-tree-prose.test.mjs +0 -299
- package/scripts/finisher-pin-race-prose.test.mjs +0 -339
- package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
- package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
- package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
- package/scripts/fleet-bootstrap.test.mjs +0 -75
- package/scripts/fleet-heartbeat.test.mjs +0 -450
- package/scripts/fleet-provenance.test.mjs +0 -138
- package/scripts/fleet-run.test.mjs +0 -90
- package/scripts/fleet-state.test.mjs +0 -460
- package/scripts/fleet-tick-prose.test.mjs +0 -300
- package/scripts/fleet-tick.test.mjs +0 -2444
- package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
- package/scripts/frontmatter-check.test.mjs +0 -436
- package/scripts/git-env.test.mjs +0 -149
- package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
- package/scripts/gone-walk.test.mjs +0 -213
- package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
- package/scripts/head-moved-after-label-prose.test.mjs +0 -233
- package/scripts/immutable-body-claim-prose.test.mjs +0 -204
- package/scripts/implementer-model-tier.test.mjs +0 -235
- package/scripts/inflight-citation-prose.test.mjs +0 -144
- package/scripts/inflight-exit2-prose.test.mjs +0 -81
- package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
- package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
- package/scripts/inflight.test.mjs +0 -2882
- package/scripts/injection-control-prose.test.mjs +0 -404
- package/scripts/install-root-audit.test.mjs +0 -464
- package/scripts/instrument-check-prose.test.mjs +0 -235
- package/scripts/instruments.test.mjs +0 -787
- package/scripts/is-cli.test.mjs +0 -99
- package/scripts/issue-tracker-prose.test.mjs +0 -71
- package/scripts/json.test.mjs +0 -364
- package/scripts/ledger-dispatch.test.mjs +0 -927
- package/scripts/ledger-grammar.test.mjs +0 -227
- package/scripts/ledger-read-require-file.test.mjs +0 -197
- package/scripts/ledger-rotate.test.mjs +0 -142
- package/scripts/ledger.test.mjs +0 -3436
- package/scripts/line-distance-prose.test.mjs +0 -245
- package/scripts/liveness-rationale-prose.test.mjs +0 -83
- package/scripts/locale-pin-prose.test.mjs +0 -189
- package/scripts/main-checkout.test.mjs +0 -332
- package/scripts/member-outcome-prose.test.mjs +0 -167
- package/scripts/member-outcomes-header.test.mjs +0 -129
- package/scripts/member-outcomes-prose.test.mjs +0 -63
- package/scripts/member-outcomes.test.mjs +0 -638
- package/scripts/member-prompt-prose.test.mjs +0 -165
- package/scripts/member-record.test.mjs +0 -541
- package/scripts/member-write-guard.test.mjs +0 -214
- package/scripts/merge-commit-probe-prose.test.mjs +0 -122
- package/scripts/merge-gate.test.mjs +0 -613
- package/scripts/muted-git-guard-sweep.test.mjs +0 -493
- package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
- package/scripts/net-watchdog-prose.test.mjs +0 -79
- package/scripts/net.test.mjs +0 -211
- package/scripts/no-ci-gate-prose.test.mjs +0 -108
- package/scripts/no-undo-audit.test.mjs +0 -3961
- package/scripts/no-wave.test.mjs +0 -138
- package/scripts/node-floor-sweep.test.mjs +0 -611
- package/scripts/pointer-target-prose.test.mjs +0 -186
- package/scripts/pr-cost.test.mjs +0 -521
- package/scripts/pr-overlap.test.mjs +0 -692
- package/scripts/printf-die-sweep.test.mjs +0 -384
- package/scripts/prompt-renderer.mjs +0 -40
- package/scripts/prompt-renderer.test.mjs +0 -68
- package/scripts/prose-pin.mjs +0 -807
- package/scripts/prose-pin.test.mjs +0 -1034
- package/scripts/prove-merge.test.mjs +0 -995
- package/scripts/pull-table-relabel-prose.test.mjs +0 -60
- package/scripts/quiet-payload-prose.test.mjs +0 -222
- package/scripts/reap-cherry-check-prose.test.mjs +0 -80
- package/scripts/reap.test.mjs +0 -4432
- package/scripts/reaping-prose.test.mjs +0 -239
- package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
- package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
- package/scripts/recipe-derivation-prose.test.mjs +0 -112
- package/scripts/recipe-prove.test.mjs +0 -1042
- package/scripts/refuter-scratch-prose.test.mjs +0 -135
- package/scripts/release-label-required-prose.test.mjs +0 -71
- package/scripts/release-label-split-prose.test.mjs +0 -184
- package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
- package/scripts/release-ticket.test.mjs +0 -5099
- package/scripts/renovate-release-contract.test.mjs +0 -379
- package/scripts/repo-root.test.mjs +0 -873
- package/scripts/reporter-output-rule-prose.test.mjs +0 -208
- package/scripts/review-agent-report-only.test.mjs +0 -49
- package/scripts/review-core-booking.test.mjs +0 -35
- package/scripts/review-core-cwd-isolation.test.mjs +0 -374
- package/scripts/review-core-reads.test.mjs +0 -478
- package/scripts/review-core-refuter-scratch.test.mjs +0 -148
- package/scripts/review-core-scratch-refusal.test.mjs +0 -64
- package/scripts/review-core-shared-test-run.test.mjs +0 -275
- package/scripts/review-core-snapshot-path.test.mjs +0 -830
- package/scripts/review-core-specialist-scratch.test.mjs +0 -191
- package/scripts/review-core-testcmd.test.mjs +0 -335
- package/scripts/review-core-unrun.test.mjs +0 -566
- package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
- package/scripts/review-eval-resolver-path.test.mjs +0 -55
- package/scripts/review-host-fixture.mjs +0 -89
- package/scripts/review-in-run-retry.test.mjs +0 -211
- package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
- package/scripts/review-path-default.test.mjs +0 -796
- package/scripts/review-runner-spawns.test.mjs +0 -95
- package/scripts/review-runner.test.mjs +0 -166
- package/scripts/review-tier-audit.test.mjs +0 -140
- package/scripts/run-artifact-pr-prose.test.mjs +0 -341
- package/scripts/run-merge-bot-prose.test.mjs +0 -1413
- package/scripts/run-team-local-hook.test.mjs +0 -442
- package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
- package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
- package/scripts/section-between-guard-prose.test.mjs +0 -379
- package/scripts/select-dimensions.test.mjs +0 -674
- package/scripts/shared-refusal.test.mjs +0 -388
- package/scripts/shell-traps-prose.test.mjs +0 -504
- package/scripts/shortlist.test.mjs +0 -380
- package/scripts/slow-transport.mjs +0 -72
- package/scripts/snapshot-repo.test.mjs +0 -1006
- package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
- package/scripts/spend-view.test.mjs +0 -312
- package/scripts/staleness-qualifier-prose.test.mjs +0 -251
- package/scripts/staleness-verdict-prose.test.mjs +0 -142
- package/scripts/staleness.test.mjs +0 -893
- package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
- package/scripts/stash-prohibition-prose.test.mjs +0 -313
- package/scripts/strip-comments.mjs +0 -44
- package/scripts/temp-dir.mjs +0 -47
- package/scripts/ticket-router.test.mjs +0 -981
- package/scripts/tier-check.test.mjs +0 -828
- package/scripts/tier-outcomes-header.test.mjs +0 -518
- package/scripts/tier-outcomes.test.mjs +0 -572
- package/scripts/tier-roles.test.mjs +0 -535
- package/scripts/tracker-block-copy-prose.test.mjs +0 -288
- package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
- package/scripts/unattended-git-sweep.test.mjs +0 -142
- package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
- package/scripts/verify-sha.test.mjs +0 -692
- package/scripts/watcher-degraded-block.test.mjs +0 -369
- package/scripts/watcher-key-prose.test.mjs +0 -106
- package/scripts/within-run-pair-prose.test.mjs +0 -212
- package/scripts/worktree-audit.test.mjs +0 -1408
- package/scripts/worktree-head-prose.test.mjs +0 -276
- package/scripts/worktree-listing-sweep.test.mjs +0 -217
- package/scripts/worktree-model-prose.test.mjs +0 -216
- package/scripts/worktree-porcelain.mjs +0 -35
- package/scripts/worktree-porcelain.test.mjs +0 -102
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
// The `=`-token parser (#1799, spec 2026-09-24 § 6 §2). Everything that
|
|
2
|
-
// derives liveness from the ledger reads a member's state off its token, so
|
|
3
|
-
// what this parser claims — and what it declines to claim — is the whole
|
|
4
|
-
// contract: a token it misreads is a member counted live forever, or a live
|
|
5
|
-
// one counted gone.
|
|
6
|
-
|
|
7
|
-
import { test } from "node:test";
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { existsSync } from "node:fs";
|
|
10
|
-
import { join } from "node:path";
|
|
11
|
-
import { parseMember, parseToken, memberTokens, nextMergeBot, expectedDefinition, agentDefinition, MEMBER_FAMILIES, CELL, CELL_DEF, drawCell } from "./ledger-grammar.mjs";
|
|
12
|
-
|
|
13
|
-
// Every outcome word the spec names, per family, verbatim — the must-ACCEPT
|
|
14
|
-
// half. A parser that refused everything would pass every refusal below.
|
|
15
|
-
const VOCABULARY = [
|
|
16
|
-
["impl-412", ["PR#420", "bailed", "released", "killed", "tier-mismatch"]],
|
|
17
|
-
["fix-pr-346", ["applied:73b356de", "applied:73b356de0123456789abcdef0123456789abcdef", "no-op", "failed", "killed"]],
|
|
18
|
-
["finisher-pr-346", [
|
|
19
|
-
"labelled", "failed", "killed",
|
|
20
|
-
"halted:live-editor", "halted:rebase", "halted:past-pin", "halted:unreadable", "halted:missing", "halted:absent", "halted:other",
|
|
21
|
-
]],
|
|
22
|
-
["merge-bot-2", ["done", "killed"]],
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
test("a bare member token is live, and names its family, number and binding", () => {
|
|
26
|
-
assert.deepEqual(parseToken("impl-412"), {
|
|
27
|
-
name: "impl-412", family: "impl", number: 412, retry: null, bound: "ticket", outcome: null, error: null,
|
|
28
|
-
});
|
|
29
|
-
assert.deepEqual(parseToken("fix-pr-346"), {
|
|
30
|
-
name: "fix-pr-346", family: "fix-pr", number: 346, retry: null, bound: "pr", outcome: null, error: null,
|
|
31
|
-
});
|
|
32
|
-
assert.deepEqual(parseToken("finisher-pr-346"), {
|
|
33
|
-
name: "finisher-pr-346", family: "finisher-pr", number: 346, retry: null, bound: "pr", outcome: null, error: null,
|
|
34
|
-
});
|
|
35
|
-
assert.deepEqual(parseToken("merge-bot-3"), {
|
|
36
|
-
name: "merge-bot-3", family: "merge-bot", number: 3, retry: null, bound: null, outcome: null, error: null,
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// "Replacement members (`-b`) get their own token": the suffix is part of the
|
|
41
|
-
// name, so `impl-412-b` settles apart from `impl-412` while working the same
|
|
42
|
-
// ticket. `retry` carries the suffix letter on its own, so a reader ordering
|
|
43
|
-
// a ticket's attempts reads it here rather than re-parsing the name.
|
|
44
|
-
test("a replacement member's retry suffix is its own token, bound to the same number", () => {
|
|
45
|
-
const b = parseToken("impl-412-b");
|
|
46
|
-
assert.equal(b.name, "impl-412-b");
|
|
47
|
-
assert.equal(b.number, 412);
|
|
48
|
-
assert.equal(b.retry, "b");
|
|
49
|
-
const c = parseToken("fix-pr-346-c=no-op");
|
|
50
|
-
assert.equal(c.name, "fix-pr-346-c");
|
|
51
|
-
assert.equal(c.retry, "c");
|
|
52
|
-
assert.equal(parseToken("finisher-pr-346-b").family, "finisher-pr");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("every outcome in the spec's vocabulary settles its own family", () => {
|
|
56
|
-
for (const [member, outcomes] of VOCABULARY) {
|
|
57
|
-
for (const outcome of outcomes) {
|
|
58
|
-
const t = parseToken(`${member}=${outcome}`);
|
|
59
|
-
assert.equal(t?.error, null, `${member}=${outcome} must parse: ${t?.error}`);
|
|
60
|
-
assert.equal(t.name, member);
|
|
61
|
-
assert.equal(t.outcome, outcome);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("an outcome from another family's vocabulary, or none at all, is refused by name", () => {
|
|
67
|
-
const refused = [
|
|
68
|
-
["impl-412=done", /expected PR#M \| bailed \| released \| killed \| tier-mismatch/],
|
|
69
|
-
["impl-412=labelled", /not an outcome of impl-N/],
|
|
70
|
-
["impl-412=", /'' is not an outcome of impl-N/],
|
|
71
|
-
["impl-412=PR#", /not an outcome of impl-N/],
|
|
72
|
-
["impl-412=#420", /not an outcome of impl-N/],
|
|
73
|
-
["impl-412=PR#420=x", /not an outcome of impl-N/],
|
|
74
|
-
["fix-pr-346=applied", /expected applied:<head> \| no-op \| failed \| killed/],
|
|
75
|
-
["fix-pr-346=applied:", /not an outcome of fix-pr-M/],
|
|
76
|
-
["fix-pr-346=applied:not-a-sha", /not an outcome of fix-pr-M/],
|
|
77
|
-
// The hex-length bounds themselves (7 to 40 inclusive): one hex char
|
|
78
|
-
// short of and one over the accepted range, so a bound loosened by one
|
|
79
|
-
// either way is caught rather than passing on the interior cases alone.
|
|
80
|
-
["fix-pr-346=applied:abc123", /not an outcome of fix-pr-M/],
|
|
81
|
-
["fix-pr-346=applied:73b356de0123456789abcdef0123456789abcdef0", /not an outcome of fix-pr-M/],
|
|
82
|
-
["fix-pr-346=bailed", /not an outcome of fix-pr-M/],
|
|
83
|
-
["finisher-pr-346=done", /expected labelled \| failed \| killed \| halted:<cause>/],
|
|
84
|
-
// #2083: a halt names one of the seven causes — a bare `halted`, an
|
|
85
|
-
// unknown cause, a cause with trailing text, or a cause in another case
|
|
86
|
-
// is not a halt the controller has a rule for.
|
|
87
|
-
["finisher-pr-346=halted", /expected labelled \| failed \| killed \| halted:<cause>/],
|
|
88
|
-
["finisher-pr-346=halted:", /not an outcome of finisher-pr-M/],
|
|
89
|
-
["finisher-pr-346=halted:bogus", /expected labelled \| failed \| killed \| halted:<cause>/],
|
|
90
|
-
["finisher-pr-346=halted:past-pin:x", /not an outcome of finisher-pr-M/],
|
|
91
|
-
["finisher-pr-346=halted:Rebase", /not an outcome of finisher-pr-M/],
|
|
92
|
-
["fix-pr-346=halted:rebase", /not an outcome of fix-pr-M/],
|
|
93
|
-
["merge-bot-2=labelled", /expected done \| killed/],
|
|
94
|
-
["merge-bot-2=PR#5", /not an outcome of merge-bot-n/],
|
|
95
|
-
];
|
|
96
|
-
for (const [token, why] of refused) {
|
|
97
|
-
const t = parseToken(token);
|
|
98
|
-
assert.ok(t, `${token}: still a member token — its error is the answer, not silence`);
|
|
99
|
-
assert.match(t.error ?? "", why, `${token}: got ${JSON.stringify(t.error)}`);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// The other `=`-tokens a real row carries (`class=`, `ports=`, `ci=`, and
|
|
104
|
-
// #1773's `review=`/`reviewed=` pair) are not members, and neither are the
|
|
105
|
-
// merge bot's holds nor anything that only resembles one. Claiming any of
|
|
106
|
-
// them would count a phantom member live.
|
|
107
|
-
test("tokens that are not members are not claimed", () => {
|
|
108
|
-
for (const token of [
|
|
109
|
-
"#412", "→", "·", "PR#344", "MERGED", "73b356de", "class=routine", "ports=16324", "ci=123:1:success",
|
|
110
|
-
"review=wf:abc123", "review=member:review-pr-346", "reviewed=73b356de:3/1/0", "held-behind:#313",
|
|
111
|
-
// `conflict-hold-346` — no `#` — is the fixture that actually matters:
|
|
112
|
-
// it is a real CONFLICT_HOLD spelling (`#?` is optional there) AND the
|
|
113
|
-
// exact shape MEMBER would also accept if its family alternation ever
|
|
114
|
-
// grew a careless `conflict-hold` entry. The other two spellings below
|
|
115
|
-
// carry a literal `#` where MEMBER wants a digit, so they would stay
|
|
116
|
-
// unclaimed even under that mutation — this one does not.
|
|
117
|
-
"conflict-hold:#346", "conflict-hold-#346", "conflict-hold-346",
|
|
118
|
-
"ruled:6-applies", "review-pr-346", "impl", "impl-", "impl-0", "impl-0412", "impl-412x", "impl-412-bb",
|
|
119
|
-
"impl-412-B", "merge-bot", "merge-bot-3-b", "fix-pr-", "finisher-346",
|
|
120
|
-
]) {
|
|
121
|
-
assert.equal(parseToken(token), null, `${token} must not parse as a member token`);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test("memberTokens reads a row's members in order and skips its free text", () => {
|
|
126
|
-
const row = "#324 impl-324=PR#346 → PR#346 · fix-pr-346 · class=routine · ports=16324 · ruled:6-applies · held-behind:#313";
|
|
127
|
-
assert.deepEqual(
|
|
128
|
-
memberTokens(row).map((t) => [t.name, t.outcome]),
|
|
129
|
-
[["impl-324", "PR#346"], ["fix-pr-346", null]],
|
|
130
|
-
);
|
|
131
|
-
assert.deepEqual(memberTokens("#7 nothing member-shaped here"), []);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// "n = 1 + the number of `merge-bot-` entries" — settled ones included, since
|
|
135
|
-
// a dead bot's replacement "gets a new n", and other families never counted.
|
|
136
|
-
test("nextMergeBot counts every merge-bot entry, live or settled, and nothing else", () => {
|
|
137
|
-
assert.equal(nextMergeBot([]), "merge-bot-1");
|
|
138
|
-
assert.equal(nextMergeBot(["impl-412", "fix-pr-346=no-op", "finisher-pr-346"]), "merge-bot-1");
|
|
139
|
-
assert.equal(nextMergeBot(["impl-412", "merge-bot-1=done", "fix-pr-346", "merge-bot-2=killed", "merge-bot-3"]), "merge-bot-4");
|
|
140
|
-
// A malformed entry is not a merge-bot entry, however much it starts like
|
|
141
|
-
// one: counting by prefix instead of by parseToken() inflated n past what
|
|
142
|
-
// ## Dispatched's real entries justify (measured: merge-bot-3, not -2).
|
|
143
|
-
assert.equal(nextMergeBot(["merge-bot-1=done", "merge-bot-2x-garbage"]), "merge-bot-2");
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test("expectedDefinition refuses a tier= it cannot name one definition file by", () => {
|
|
147
|
-
assert.throws(() => expectedDefinition("impl-7 · tier=alt · tier=slow-high"), /conflicting tier= tokens \(tier=alt, tier=slow-high\)/);
|
|
148
|
-
assert.throws(() => expectedDefinition("impl-7 · tier=../../etc"), /is not a definition suffix/);
|
|
149
|
-
// Lowercase only: on a case-insensitive filesystem `tier=Task-High` would
|
|
150
|
-
// find fleet-implementer-task-high.agent.md, so the existence check
|
|
151
|
-
// `ledger.mjs dispatch` adds cannot refuse a name no definition carries.
|
|
152
|
-
assert.throws(() => expectedDefinition("impl-7 · tier=Task-High"), /tier=Task-High is not a definition suffix/);
|
|
153
|
-
assert.equal(expectedDefinition("impl-7 · tier=task-high · tier=task-high"), "fleet-implementer-task-high");
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
// #2330: null is a review fix-applier's deliberate "generic `task`", so a
|
|
157
|
-
// family agentDefinition has no case for must throw, never read as one. This
|
|
158
|
-
// walks every family parseMember can yield (MEMBER is built from
|
|
159
|
-
// MEMBER_FAMILIES) — a family added to FAMILIES without a case here fails
|
|
160
|
-
// this test, not a dispatch.
|
|
161
|
-
test("agentDefinition names a definition for every member family, and throws on one it has no case for", () => {
|
|
162
|
-
const agents = join(import.meta.dirname, "..", "agents");
|
|
163
|
-
for (const family of MEMBER_FAMILIES) {
|
|
164
|
-
const member = parseMember(`${family}-7`);
|
|
165
|
-
const definition = agentDefinition(member, "", true);
|
|
166
|
-
assert.match(definition, /^fleet-/, `${family}: ${definition}`);
|
|
167
|
-
// #2129 deleted the bare `fleet-implementer`: a name with no file behind
|
|
168
|
-
// it is what `ledger.mjs dispatch` refuses, so an untiered impl row or a
|
|
169
|
-
// conflict-hold fix-applier pointing at it would stop every such dispatch.
|
|
170
|
-
assert.ok(existsSync(join(agents, `${definition}.agent.md`)), `${family}: ${definition} has no agents/${definition}.agent.md`);
|
|
171
|
-
}
|
|
172
|
-
// The must-ACCEPT half: the deliberate null is still null, not a throw.
|
|
173
|
-
assert.equal(agentDefinition(parseMember("fix-pr-7"), "", false), null);
|
|
174
|
-
assert.throws(
|
|
175
|
-
() => agentDefinition({ name: "review-pr-7", family: "review-pr", number: 7 }, "", false),
|
|
176
|
-
/no case for member family 'review-pr' \(review-pr-7\)/,
|
|
177
|
-
);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("CELL is <role>-<level> over omp's three roles and six levels; CELL_DEF is its definition name", () => {
|
|
181
|
-
for (const cell of ["slow-high", "task-max", "smol-minimal", "slow-xhigh"]) {
|
|
182
|
-
assert.ok(CELL.test(cell), cell);
|
|
183
|
-
assert.ok(CELL_DEF.test(`fleet-implementer-${cell}`), cell);
|
|
184
|
-
}
|
|
185
|
-
for (const cell of ["alt", "default", "fast-high", "slow-ultra", "slow-high-x", "Slow-High", "high-slow"]) {
|
|
186
|
-
assert.ok(!CELL.test(cell), cell);
|
|
187
|
-
assert.ok(!CELL_DEF.test(`fleet-implementer-${cell}`), cell);
|
|
188
|
-
}
|
|
189
|
-
// The family has no bare member: nothing is named `fleet-implementer` alone.
|
|
190
|
-
assert.ok(!CELL_DEF.test("fleet-implementer"));
|
|
191
|
-
assert.ok(!CELL_DEF.test("xfleet-implementer-slow-high"));
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const GRID = ["slow-high", "slow-medium", "task-high", "task-max", "smol-high"];
|
|
195
|
-
const SESSION = "01a0815e-e141-716c-b2d8-2adf310fbe55";
|
|
196
|
-
|
|
197
|
-
test("drawCell with every non-default cell withdrawn runs the policy cell at k = K = 0", () => {
|
|
198
|
-
assert.deepEqual(drawCell({ session: SESSION, ticket: 2129, policyCell: "slow-high", cells: ["slow-high"] }), { cell: "slow-high", k: 0, K: 0 });
|
|
199
|
-
assert.deepEqual(drawCell({ session: SESSION, ticket: 2129, policyCell: "slow-high", cells: [] }), { cell: "slow-high", k: 0, K: 0 });
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test("drawCell is sha256(session\\tticket)[0:8] mod K over the sorted non-policy cells", () => {
|
|
203
|
-
// Golden: sha256("<SESSION>\t2129") starts 6b9befca; 0x6b9befca % 4 = 2, so
|
|
204
|
-
// k = 3 over [slow-medium, smol-high, task-high, task-max].
|
|
205
|
-
assert.deepEqual(drawCell({ session: SESSION, ticket: 2129, policyCell: "slow-high", cells: GRID }), { cell: "task-high", k: 3, K: 4 });
|
|
206
|
-
// The input order of `cells` is not an input: the draw sorts by token.
|
|
207
|
-
assert.deepEqual(drawCell({ session: SESSION, ticket: 2129, policyCell: "slow-high", cells: [...GRID].reverse() }), { cell: "task-high", k: 3, K: 4 });
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
test("drawCell never draws the policy cell, reaches every other one, and with no policy cell draws over all", () => {
|
|
211
|
-
const drawn = new Set();
|
|
212
|
-
for (let ticket = 1; ticket <= 200; ticket++) {
|
|
213
|
-
const { cell, k, K } = drawCell({ session: "s", ticket, policyCell: "slow-high", cells: GRID });
|
|
214
|
-
assert.equal(K, 4);
|
|
215
|
-
assert.ok(k >= 1 && k <= K, `k=${k}`);
|
|
216
|
-
drawn.add(cell);
|
|
217
|
-
}
|
|
218
|
-
assert.deepEqual([...drawn].sort(), ["slow-medium", "smol-high", "task-high", "task-max"]);
|
|
219
|
-
// Burn-in (spec § 4 R4) calls it with `policyCell: null`: nothing withheld.
|
|
220
|
-
const burnIn = new Set();
|
|
221
|
-
for (let ticket = 1; ticket <= 200; ticket++) {
|
|
222
|
-
const { cell, K } = drawCell({ session: "s", ticket, policyCell: null, cells: GRID });
|
|
223
|
-
assert.equal(K, 5);
|
|
224
|
-
burnIn.add(cell);
|
|
225
|
-
}
|
|
226
|
-
assert.deepEqual([...burnIn].sort(), [...GRID].sort());
|
|
227
|
-
});
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
// The cockpit half of #816.
|
|
2
|
-
//
|
|
3
|
-
// `ledger.mjs read` answered an absent ledger and a real empty one identically
|
|
4
|
-
// — same stdout, same empty stderr, same exit 0 — and `read` is the subcommand
|
|
5
|
-
// board.mjs consumes. tryParse's fallback on a failed read is that same empty
|
|
6
|
-
// shape besides, so three distinct states (no ledger, an empty ledger, a read
|
|
7
|
-
// whose answer would not parse) reached the page as one empty board.
|
|
8
|
-
//
|
|
9
|
-
// ledger.test.mjs pins the CLI's half: the flag is honoured, and a real empty
|
|
10
|
-
// ledger is still accepted. This file pins the wiring and the rendering — that
|
|
11
|
-
// board.mjs actually passes the flag, that it keeps the three answers apart,
|
|
12
|
-
// and that the page draws two of them differently from the third.
|
|
13
|
-
//
|
|
14
|
-
// A separate file rather than more of board.test.mjs: the fleet runs several
|
|
15
|
-
// implementers at once and two PRs appending to one test file conflict, which
|
|
16
|
-
// costs the PR its CI entirely.
|
|
17
|
-
|
|
18
|
-
import { test } from "node:test";
|
|
19
|
-
import assert from "node:assert/strict";
|
|
20
|
-
import { spawnSync } from "node:child_process";
|
|
21
|
-
import { writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
22
|
-
import { tempDir } from "./temp-dir.mjs";
|
|
23
|
-
import { join } from "node:path";
|
|
24
|
-
import { fileURLToPath } from "node:url";
|
|
25
|
-
import { writeExecStub } from "./exec-stub.mjs";
|
|
26
|
-
|
|
27
|
-
const BOARD = fileURLToPath(new URL("./board.mjs", import.meta.url));
|
|
28
|
-
const REAL_SCRIPTS = fileURLToPath(new URL("./", import.meta.url));
|
|
29
|
-
const HTML = readFileSync(new URL("./board.html", import.meta.url), "utf8");
|
|
30
|
-
|
|
31
|
-
const EMPTY_LEDGER = "# Fleet run ledger\n\n## Rows\n\n\n## Filed\n\n\n## Ruled\n\n";
|
|
32
|
-
|
|
33
|
-
// gather() is driven out of process because it reads process.argv and would
|
|
34
|
-
// otherwise read the test runner's. `gh` is stubbed to fail for every read:
|
|
35
|
-
// those all degrade through tryRun to empty lists, they are not what this
|
|
36
|
-
// measures, and an unstubbed `gh` would put this repo's live issue list and the
|
|
37
|
-
// machine's network in the assertion path.
|
|
38
|
-
//
|
|
39
|
-
// `scriptDir` defaults to the REAL scripts directory, so the end-to-end arms
|
|
40
|
-
// spawn the real ledger.mjs. A stub there is free to honour a flag the real
|
|
41
|
-
// script ignores — which is the whole defect — so the two arms that decide
|
|
42
|
-
// whether the fix works must not use one.
|
|
43
|
-
function gatherLedger({ ledgerBody = null, scriptDir = REAL_SCRIPTS } = {}) {
|
|
44
|
-
const cwd = tempDir("board-ledger-");
|
|
45
|
-
const bin = tempDir("board-ledger-bin-");
|
|
46
|
-
writeExecStub(join(bin, "gh"), "#!/bin/sh\nexit 1\n");
|
|
47
|
-
const ledgerFile = join(cwd, "ledger.md");
|
|
48
|
-
if (ledgerBody !== null) writeFileSync(ledgerFile, ledgerBody);
|
|
49
|
-
|
|
50
|
-
const driver = `const { gather } = await import(${JSON.stringify(BOARD)});
|
|
51
|
-
const r = await gather({ ledgerFile: ${JSON.stringify(ledgerFile)},
|
|
52
|
-
scriptDir: ${JSON.stringify(scriptDir)}, interval: 15 });
|
|
53
|
-
console.log(JSON.stringify(r.ledger));`;
|
|
54
|
-
const r = spawnSync(process.execPath, ["--input-type=module", "-e", driver], {
|
|
55
|
-
cwd, encoding: "utf8", env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
|
|
56
|
-
});
|
|
57
|
-
assert.equal(r.status, 0, `the driver itself must not fail\n${r.stdout}${r.stderr}`);
|
|
58
|
-
return { ledger: JSON.parse(r.stdout.trim().split("\n").pop()), stderr: r.stderr };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// A stub ledger.mjs whose body is supplied per test, plus an argv sentinel so a
|
|
62
|
-
// test can assert what board.mjs actually spawned rather than inferring it.
|
|
63
|
-
function stubScripts(body) {
|
|
64
|
-
const dir = tempDir("board-ledger-stub-");
|
|
65
|
-
const argvFile = join(dir, "argv.txt");
|
|
66
|
-
writeFileSync(join(dir, "ledger.mjs"),
|
|
67
|
-
`import { writeFileSync } from "node:fs";\n` +
|
|
68
|
-
`writeFileSync(${JSON.stringify(argvFile)}, process.argv.slice(2).join("\\n"));\n${body}`);
|
|
69
|
-
return { scriptDir: dir, argvFile };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// ── the wiring ───────────────────────────────────────────────────────────────
|
|
73
|
-
|
|
74
|
-
// Without this the fix is one token from being disconnected while every state
|
|
75
|
-
// test below still passes: the stub's exit code decides the answer, so a
|
|
76
|
-
// gather() that dropped the flag would keep giving the right answer TO THE STUB
|
|
77
|
-
// and the wrong one to the real ledger.mjs, which is where it matters.
|
|
78
|
-
test("gather spawns `read` WITH --require-file (#816)", () => {
|
|
79
|
-
const { scriptDir, argvFile } = stubScripts(`console.log(JSON.stringify({ rows: [], filed: [], ruled: [] }));`);
|
|
80
|
-
gatherLedger({ scriptDir });
|
|
81
|
-
assert.equal(existsSync(argvFile), true, "the stub ledger was never spawned — this test measured nothing");
|
|
82
|
-
const argv = readFileSync(argvFile, "utf8").split("\n");
|
|
83
|
-
assert.ok(argv.includes("--require-file"), `board.mjs must pass the flag; got ${JSON.stringify(argv)}`);
|
|
84
|
-
assert.ok(argv.includes("read"), `board.mjs must still ask for read; got ${JSON.stringify(argv)}`);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// ── the three states, end to end against the real ledger.mjs ─────────────────
|
|
88
|
-
|
|
89
|
-
test("gather: no ledger file at all is `unread`, not an empty ledger (#816)", () => {
|
|
90
|
-
const { ledger } = gatherLedger({ ledgerBody: null });
|
|
91
|
-
assert.equal(ledger.state, "unread");
|
|
92
|
-
// The lists stay the shape computeBoard reads, so nothing downstream crashes
|
|
93
|
-
// on a state it cannot render — the state is additive, not a replacement.
|
|
94
|
-
assert.deepEqual({ rows: ledger.rows, filed: ledger.filed, ruled: ledger.ruled }, { rows: [], filed: [], ruled: [] });
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// The discriminating half. These two produced identical `ledger` objects before
|
|
98
|
-
// the fix, which is the defect stated as an assertion: without this arm a
|
|
99
|
-
// gather() that reported "unread" for every ledger would pass the one above.
|
|
100
|
-
test("gather: a real EMPTY ledger is `read`, and still carries its empty lists (#816)", () => {
|
|
101
|
-
const { ledger } = gatherLedger({ ledgerBody: EMPTY_LEDGER });
|
|
102
|
-
assert.equal(ledger.state, "read");
|
|
103
|
-
assert.deepEqual({ rows: ledger.rows, filed: ledger.filed, ruled: ledger.ruled }, { rows: [], filed: [], ruled: [] });
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test("gather: a ledger with rows is `read` and its rows arrive (#816)", () => {
|
|
107
|
-
const { ledger } = gatherLedger({ ledgerBody: EMPTY_LEDGER.replace("## Rows\n", "## Rows\n\n- #7 impl-7 · class=routine") });
|
|
108
|
-
assert.equal(ledger.state, "read");
|
|
109
|
-
assert.deepEqual(ledger.rows, ["#7 impl-7 · class=routine"]);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// The third state, which no real ledger.mjs can produce on demand — a stub is
|
|
113
|
-
// the only way to hand board.mjs stdout that arrives at exit 0 and will not
|
|
114
|
-
// parse. That is board.mjs's own branch under test, not ledger.mjs's flag.
|
|
115
|
-
test("gather: stdout that will not parse is `unparsed`, not `unread` and not an empty ledger (#816)", () => {
|
|
116
|
-
const { scriptDir } = stubScripts(`console.log("warning: something\\n{\\"rows\\": [");`);
|
|
117
|
-
const { ledger, stderr } = gatherLedger({ scriptDir });
|
|
118
|
-
assert.equal(ledger.state, "unparsed");
|
|
119
|
-
assert.deepEqual({ rows: ledger.rows, filed: ledger.filed, ruled: ledger.ruled }, { rows: [], filed: [], ruled: [] });
|
|
120
|
-
assert.match(stderr, /ledger read parse failed/, "a failed parse must still say so on stderr");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// A refusal and an unreachable node arrive the same way — no usable stdout —
|
|
124
|
-
// and both mean the same thing to the page: this board was not built from a
|
|
125
|
-
// ledger. The distinction that matters is against `read`, not between them.
|
|
126
|
-
test("gather: a non-zero exit from ledger.mjs is `unread` (#816)", () => {
|
|
127
|
-
const { scriptDir } = stubScripts(`process.exit(2);`);
|
|
128
|
-
assert.equal(gatherLedger({ scriptDir }).ledger.state, "unread");
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// ── the rendering ────────────────────────────────────────────────────────────
|
|
132
|
-
//
|
|
133
|
-
// board.html is served as one self-contained file with an inline script, so the
|
|
134
|
-
// decision is lifted out of its source text and evaluated, the same technique
|
|
135
|
-
// spend-view.test.mjs uses. The declaration-count guard comes first: a second
|
|
136
|
-
// top-level declaration wins at runtime by hoisting and the lift below would
|
|
137
|
-
// still read the first one.
|
|
138
|
-
|
|
139
|
-
test("board.html declares ledgerBanner exactly once at top level", () => {
|
|
140
|
-
assert.equal(HTML.match(/^function\s+ledgerBanner\s*\(/gm)?.length, 1,
|
|
141
|
-
"ledgerBanner must be declared exactly once — a second declaration wins at runtime and the lift below would still read the first");
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const BANNER_SRC = HTML.match(/^function\s+ledgerBanner\s*\(\w+\)\s*\{[\s\S]*?^\}$/m);
|
|
145
|
-
|
|
146
|
-
test("board.html still declares ledgerBanner in the shape this file lifts", () => {
|
|
147
|
-
// Named and outside the lift: an assertion thrown during the lift itself runs
|
|
148
|
-
// before node registers any test in this file, which reports one opaque
|
|
149
|
-
// file-level error instead of naming the claim that stopped holding.
|
|
150
|
-
assert.ok(BANNER_SRC, "board.html no longer declares ledgerBanner as a top-level function — update this test");
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const ledgerBanner = BANNER_SRC
|
|
154
|
-
? new Function(`${BANNER_SRC[0]}\nreturn ledgerBanner;`)()
|
|
155
|
-
: () => { throw new Error("ledgerBanner could not be lifted from board.html — see the shape test above"); };
|
|
156
|
-
|
|
157
|
-
test("ledgerBanner draws the two failure states differently from each other (#816)", () => {
|
|
158
|
-
const unread = ledgerBanner("unread");
|
|
159
|
-
const unparsed = ledgerBanner("unparsed");
|
|
160
|
-
assert.ok(unread, "an unread ledger must say so");
|
|
161
|
-
assert.ok(unparsed, "an unparseable ledger must say so");
|
|
162
|
-
// Two banners with the same words are one rendering wearing two names, which
|
|
163
|
-
// is the defect this ticket is about.
|
|
164
|
-
assert.notEqual(unread, unparsed, "the two failures must not render as the same message");
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test("ledgerBanner stays silent for a ledger that was read (#816)", () => {
|
|
168
|
-
// The accept side. A run that has just started has an empty ledger and no
|
|
169
|
-
// rows, and a warning on every first tick trains the operator to ignore this
|
|
170
|
-
// strip — which would cost the two messages above their whole point.
|
|
171
|
-
assert.equal(ledgerBanner("read"), null, "a ledger read empty is the ordinary state, not a warning");
|
|
172
|
-
assert.equal(ledgerBanner(undefined), null, "a board.json written before this field existed must not warn either");
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// The call site. Without this the whole decision can be disconnected in one
|
|
176
|
-
// token and every case above still passes against a function the page never
|
|
177
|
-
// calls — and the ordering claim is the other half: a stale board is stale
|
|
178
|
-
// whatever its ledger state, so the ledger message must not preempt it.
|
|
179
|
-
test("board.html routes the freshness banner through ledgerBanner, with stale still first (#816)", () => {
|
|
180
|
-
const render = HTML.match(/^function\s+render\s*\((\w+)\)\s*\{[\s\S]*?^\}$/m);
|
|
181
|
-
assert.ok(render, "board.html no longer declares render as a top-level function — update this test");
|
|
182
|
-
const body = render[0].split("\n").filter((l) => !/^\s*\/\//.test(l)).join("\n");
|
|
183
|
-
assert.match(body, /=\s*ledgerBanner\(\w+\.ledgerState\)/, "render must call ledgerBanner with the model's ledgerState");
|
|
184
|
-
// #1597 put a third arm between the two this pin was written for, and a
|
|
185
|
-
// non-greedy `else if` after "data stale" would happily match THAT one and
|
|
186
|
-
// go on reading like it still proved the ledger's position. So the order is
|
|
187
|
-
// asserted by INDEX over the whole chain rather than by one adjacency: a
|
|
188
|
-
// stale board is stale whatever else is true, a dead run outranks a
|
|
189
|
-
// degraded read of one input, and neither may hide the other.
|
|
190
|
-
const stale = body.indexOf("data stale");
|
|
191
|
-
const stall = body.search(/else if \(stallMsg\)/);
|
|
192
|
-
const ledger = body.search(/else if \(ledgerMsg\)/);
|
|
193
|
-
assert.ok(stale !== -1 && stall !== -1 && ledger !== -1,
|
|
194
|
-
"board.html no longer renders all three banner arms — update this test");
|
|
195
|
-
assert.ok(stale < stall, "a stale board must outrank the liveness stall it can no longer vouch for");
|
|
196
|
-
assert.ok(stall < ledger, "a stopped run must outrank a degraded read of one of its inputs");
|
|
197
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// `ledger.mjs rotate`: one ledger per run. The current file is archived
|
|
2
|
-
// byte-for-byte beside itself and nothing is carried forward, so the next
|
|
3
|
-
// write starts the empty skeleton. Every call is its own process against a
|
|
4
|
-
// scratch `--file` ledger; the heartbeat mark the liveness guard reads is the
|
|
5
|
-
// `heartbeat.json` in the same directory, which is where fleet-state.mjs keeps
|
|
6
|
-
// it beside the real `.fleet/ledger.md`.
|
|
7
|
-
|
|
8
|
-
import { test } from "node:test";
|
|
9
|
-
import assert from "node:assert/strict";
|
|
10
|
-
import { spawnSync } from "node:child_process";
|
|
11
|
-
import { mkdtempSync, mkdirSync, rmSync, writeFileSync, readFileSync, readdirSync, existsSync } from "node:fs";
|
|
12
|
-
import { tmpdir } from "node:os";
|
|
13
|
-
import { join } from "node:path";
|
|
14
|
-
import { fileURLToPath } from "node:url";
|
|
15
|
-
import { stallsAt } from "./fleet-state.mjs";
|
|
16
|
-
|
|
17
|
-
const SCRIPT = fileURLToPath(new URL("./ledger.mjs", import.meta.url));
|
|
18
|
-
|
|
19
|
-
const LEDGER = [
|
|
20
|
-
"# Fleet run ledger", "", "## Rows", "", "- #7 impl-7=killed", "- #8 excluded · behind-pr:#9", "",
|
|
21
|
-
"## Dispatched", "", "- impl-7=killed", "", "## Filed", "", "- #11 a filed subject", "",
|
|
22
|
-
"## Ruled", "", "- #9 merge as is", "", "## Drain", "", "- budget", "",
|
|
23
|
-
].join("\n");
|
|
24
|
-
|
|
25
|
-
const STAMPED = /^ledger\.\d{4}-\d{2}-\d{2}T\d{6}Z\.md$/;
|
|
26
|
-
const stamp = (ms) => new Date(ms).toISOString().replace(/\.\d{3}Z$/, "Z").replaceAll(":", "");
|
|
27
|
-
|
|
28
|
-
function fixture(t, { ledger = LEDGER, mark = null } = {}) {
|
|
29
|
-
const dir = mkdtempSync(join(tmpdir(), "ledger-rotate-"));
|
|
30
|
-
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
31
|
-
const file = join(dir, "ledger.md");
|
|
32
|
-
if (ledger !== null) writeFileSync(file, ledger);
|
|
33
|
-
if (mark !== null) writeFileSync(join(dir, "heartbeat.json"), JSON.stringify({ quiet: 0, elapsed: 0, digest: "", ...mark }));
|
|
34
|
-
const bin = join(dir, "bin");
|
|
35
|
-
mkdirSync(bin);
|
|
36
|
-
const env = { ...process.env, PATH: bin };
|
|
37
|
-
delete env.GIT_DIR;
|
|
38
|
-
delete env.GIT_WORK_TREE;
|
|
39
|
-
const cli = (args, extraEnv = {}) =>
|
|
40
|
-
spawnSync(process.execPath, [SCRIPT, "--file", file, ...args], { encoding: "utf8", env: { ...env, ...extraEnv }, cwd: dir });
|
|
41
|
-
const archives = () => readdirSync(dir).filter((n) => STAMPED.test(n)).sort();
|
|
42
|
-
return { dir, file, cli, archives };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const beat = (agoMs, interval = 300, stopped = "") => ({ beat: { at: Date.now() - agoMs, interval, stopped } });
|
|
46
|
-
|
|
47
|
-
test("rotate with no heartbeat mark moves the ledger byte-identical to ledger.<UTC stamp>.md, and the next write starts the empty skeleton", (t) => {
|
|
48
|
-
const f = fixture(t);
|
|
49
|
-
const before = Date.now();
|
|
50
|
-
const r = f.cli(["rotate"]);
|
|
51
|
-
assert.equal(r.status, 0, r.stderr);
|
|
52
|
-
const [archive] = f.archives();
|
|
53
|
-
assert.ok(archive, `no stamped archive in ${readdirSync(f.dir)}`);
|
|
54
|
-
const at = Date.parse(archive.slice("ledger.".length, -".md".length).replace(/T(\d\d)(\d\d)(\d\d)Z$/, "T$1:$2:$3Z"));
|
|
55
|
-
assert.ok(at >= Math.floor(before / 1000) * 1000 && at <= Date.now(), `${archive} is not a UTC stamp of this call`);
|
|
56
|
-
assert.deepEqual(JSON.parse(r.stdout), { rotated: true, archive: join(f.dir, archive) });
|
|
57
|
-
assert.equal(readFileSync(join(f.dir, archive), "utf8"), LEDGER, "the archive must be the ledger's own bytes");
|
|
58
|
-
assert.equal(existsSync(f.file), false, "rotate must leave no ledger behind");
|
|
59
|
-
|
|
60
|
-
const w = f.cli(["row", "12", "impl-12"]);
|
|
61
|
-
assert.equal(w.status, 0, w.stderr);
|
|
62
|
-
assert.deepEqual(JSON.parse(f.cli(["read"]).stdout), { rows: ["#12 impl-12"], filed: [], ruled: [], dispatched: [], drain: null });
|
|
63
|
-
assert.equal(readFileSync(join(f.dir, archive), "utf8"), LEDGER, "a later write must not land in the archive");
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("rotate archives a ledger the readers refuse, as-is", (t) => {
|
|
67
|
-
const bad = `${LEDGER}- a second marker\n`;
|
|
68
|
-
const f = fixture(t, { ledger: bad });
|
|
69
|
-
assert.equal(f.cli(["read"]).status, 2, "the fixture must be a ledger load() refuses");
|
|
70
|
-
const r = f.cli(["rotate"]);
|
|
71
|
-
assert.equal(r.status, 0, r.stderr);
|
|
72
|
-
assert.equal(readFileSync(join(f.dir, f.archives()[0]), "utf8"), bad);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test("rotate proceeds under a stalled mark and under a recorded stop", (t) => {
|
|
76
|
-
for (const mark of [beat(11 * 60_000), beat(10_000, 300, "budget exhausted"), { ...beat(11 * 60_000), ticked: { at: Date.now() - 60 * 60_000 } }]) {
|
|
77
|
-
const f = fixture(t, { mark });
|
|
78
|
-
const r = f.cli(["rotate"]);
|
|
79
|
-
assert.equal(r.status, 0, `${JSON.stringify(mark)}: ${r.stderr}`);
|
|
80
|
-
assert.equal(f.archives().length, 1);
|
|
81
|
-
assert.equal(existsSync(f.file), false);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("rotate refuses while the previous controller is beating, naming the last beat and when it would count as stalled", (t) => {
|
|
86
|
-
// A fresh beat, and a stale beat covered by a fresh tick — both read as
|
|
87
|
-
// beating to fleet-state.mjs's assessBeat.
|
|
88
|
-
for (const mark of [beat(10_000), { ...beat(11 * 60_000), ticked: { at: Date.now() - 5_000 } }]) {
|
|
89
|
-
const f = fixture(t, { mark });
|
|
90
|
-
const r = f.cli(["rotate"]);
|
|
91
|
-
assert.notEqual(r.status, 0, `${JSON.stringify(mark)}: rotated under a live controller`);
|
|
92
|
-
assert.equal(r.stdout, "");
|
|
93
|
-
assert.match(r.stderr, new RegExp(`last beat ${new Date(mark.beat.at).toISOString()}`));
|
|
94
|
-
const stalls = new Date(stallsAt({ beat: mark.beat, ticked: mark.ticked ?? null })).toISOString();
|
|
95
|
-
assert.match(r.stderr, new RegExp(`stalled after ${stalls.replaceAll(".", "\\.")}`));
|
|
96
|
-
assert.equal(readFileSync(f.file, "utf8"), LEDGER, "a refusal must not touch the ledger");
|
|
97
|
-
assert.deepEqual(f.archives(), []);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test("rotate refuses when the archive name already exists, moving nothing", (t) => {
|
|
102
|
-
const f = fixture(t);
|
|
103
|
-
// Every second this call can plausibly land on is taken.
|
|
104
|
-
const now = Date.now();
|
|
105
|
-
for (let s = 0; s < 30; s++) writeFileSync(join(f.dir, `ledger.${stamp(now + s * 1000)}.md`), "older archive\n");
|
|
106
|
-
const r = f.cli(["rotate"]);
|
|
107
|
-
assert.notEqual(r.status, 0, r.stderr);
|
|
108
|
-
assert.match(r.stderr, /refusing to rotate .* already exists/);
|
|
109
|
-
assert.equal(readFileSync(f.file, "utf8"), LEDGER);
|
|
110
|
-
for (const a of f.archives()) assert.equal(readFileSync(join(f.dir, a), "utf8"), "older archive\n");
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test("rotate with no ledger file says there is nothing to rotate and exits 0", (t) => {
|
|
114
|
-
const f = fixture(t, { ledger: null });
|
|
115
|
-
const r = f.cli(["rotate"]);
|
|
116
|
-
assert.equal(r.status, 0, r.stderr);
|
|
117
|
-
assert.match(r.stderr, /nothing to rotate/);
|
|
118
|
-
assert.deepEqual(JSON.parse(r.stdout), { rotated: false, archive: null });
|
|
119
|
-
assert.deepEqual(f.archives(), []);
|
|
120
|
-
assert.equal(existsSync(f.file), false);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test("rotate refuses a stray argument — an imagined --dry-run — moving nothing", (t) => {
|
|
124
|
-
const f = fixture(t);
|
|
125
|
-
for (const extra of ["--dry-run", "now"]) {
|
|
126
|
-
const r = f.cli(["rotate", extra]);
|
|
127
|
-
assert.equal(r.status, 2, `${extra}: ${r.stderr}`);
|
|
128
|
-
assert.match(r.stderr, /usage: ledger\.mjs rotate/);
|
|
129
|
-
assert.equal(readFileSync(f.file, "utf8"), LEDGER);
|
|
130
|
-
assert.deepEqual(f.archives(), []);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("rotate takes the write lock: a live holder keeps it from moving the file", (t) => {
|
|
135
|
-
const f = fixture(t);
|
|
136
|
-
writeFileSync(`${f.file}.lock`, String(process.pid));
|
|
137
|
-
const r = f.cli(["rotate"], { LEDGER_LOCK_TIMEOUT_MS: "200" });
|
|
138
|
-
assert.equal(r.status, 2, r.stderr);
|
|
139
|
-
assert.match(r.stderr, /cannot lock/);
|
|
140
|
-
assert.equal(readFileSync(f.file, "utf8"), LEDGER);
|
|
141
|
-
assert.deepEqual(f.archives(), []);
|
|
142
|
-
});
|