@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.
Files changed (245) hide show
  1. package/.claude-plugin/plugin.json +9 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/agents/fleet-finisher.agent.md +7 -0
  5. package/agents/fleet-implementer-alt.agent.md +210 -0
  6. package/agents/fleet-implementer.agent.md +210 -0
  7. package/agents/fleet-merge-bot.agent.md +7 -0
  8. package/agents/fleet-review-comments.agent.md +40 -0
  9. package/agents/fleet-review-correctness.agent.md +43 -0
  10. package/agents/fleet-review-runner.agent.md +73 -0
  11. package/agents/fleet-review-silent-failure.agent.md +49 -0
  12. package/agents/fleet-review-simplify.agent.md +46 -0
  13. package/agents/fleet-review-snapshot.agent.md +24 -0
  14. package/agents/fleet-review-tests.agent.md +46 -0
  15. package/agents/fleet-review-types.agent.md +41 -0
  16. package/agents/fleet-review-verifier.agent.md +29 -0
  17. package/commands/review-and-fix.md +98 -0
  18. package/commands/run-merge-bot.md +357 -0
  19. package/commands/run-team-help.md +17 -0
  20. package/package.json +23 -0
  21. package/scripts/agent-test-dir-prose.test.mjs +59 -0
  22. package/scripts/agent-test.test.mjs +1636 -0
  23. package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
  24. package/scripts/ambient-git-vars-prose.test.mjs +192 -0
  25. package/scripts/ancestry-check-position-prose.test.mjs +175 -0
  26. package/scripts/apply-ruleset.test.mjs +420 -0
  27. package/scripts/arg-header-probes-prose.test.mjs +393 -0
  28. package/scripts/arg.mjs +600 -0
  29. package/scripts/arg.test.mjs +1354 -0
  30. package/scripts/board-cli.test.mjs +694 -0
  31. package/scripts/board-identity.test.mjs +429 -0
  32. package/scripts/board-liveness-banner.test.mjs +119 -0
  33. package/scripts/board-prev-shape.test.mjs +229 -0
  34. package/scripts/board-tryparse-null.test.mjs +119 -0
  35. package/scripts/board.html +471 -0
  36. package/scripts/board.mjs +2037 -0
  37. package/scripts/board.test.mjs +3086 -0
  38. package/scripts/brief-after-cut-prose.test.mjs +53 -0
  39. package/scripts/candidates-exit3-prose.test.mjs +302 -0
  40. package/scripts/candidates.mjs +674 -0
  41. package/scripts/candidates.test.mjs +2101 -0
  42. package/scripts/caveat-unification-prose.test.mjs +98 -0
  43. package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
  44. package/scripts/ci-completes-premise-prose.test.mjs +257 -0
  45. package/scripts/ci-state-prose.test.mjs +113 -0
  46. package/scripts/ci-state.mjs +761 -0
  47. package/scripts/ci-state.test.mjs +1640 -0
  48. package/scripts/ci-vacuous-green.test.mjs +368 -0
  49. package/scripts/citation-sweep-prose.test.mjs +1572 -0
  50. package/scripts/claim-lifecycle.test.mjs +185 -0
  51. package/scripts/claim-ticket.sh +417 -0
  52. package/scripts/claim-ticket.test.mjs +1121 -0
  53. package/scripts/closing-keyword-prose.test.mjs +193 -0
  54. package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
  55. package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
  56. package/scripts/compute-board.mjs +579 -0
  57. package/scripts/compute-board.test.mjs +1060 -0
  58. package/scripts/compute-spend.mjs +329 -0
  59. package/scripts/compute-spend.test.mjs +451 -0
  60. package/scripts/cross-repo-citation-prose.test.mjs +156 -0
  61. package/scripts/cwd-isolation-pins.mjs +83 -0
  62. package/scripts/dedupe-guard-prose.test.mjs +243 -0
  63. package/scripts/derive-testcmd.sh +239 -0
  64. package/scripts/derive-testcmd.test.mjs +380 -0
  65. package/scripts/diff-stats.mjs +231 -0
  66. package/scripts/diff-stats.test.mjs +408 -0
  67. package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
  68. package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
  69. package/scripts/drop-merged-label.sh +173 -0
  70. package/scripts/drop-merged-label.test.mjs +480 -0
  71. package/scripts/expected-jobs-prose.test.mjs +80 -0
  72. package/scripts/filing-bar-seat-prose.test.mjs +242 -0
  73. package/scripts/filing-claim-bar-prose.test.mjs +166 -0
  74. package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
  75. package/scripts/finisher-halt-prose.test.mjs +106 -0
  76. package/scripts/finisher-name-prose.test.mjs +134 -0
  77. package/scripts/finisher-own-tree-prose.test.mjs +285 -0
  78. package/scripts/finisher-pin-race-prose.test.mjs +339 -0
  79. package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
  80. package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
  81. package/scripts/fleet-bootstrap +155 -0
  82. package/scripts/fleet-heartbeat.mjs +272 -0
  83. package/scripts/fleet-heartbeat.test.mjs +450 -0
  84. package/scripts/fleet-provenance +207 -0
  85. package/scripts/fleet-provenance.test.mjs +64 -0
  86. package/scripts/fleet-run +148 -0
  87. package/scripts/fleet-run.test.mjs +90 -0
  88. package/scripts/fleet-state.mjs +400 -0
  89. package/scripts/fleet-state.test.mjs +373 -0
  90. package/scripts/fleet-tick-prose.test.mjs +299 -0
  91. package/scripts/fleet-tick.mjs +832 -0
  92. package/scripts/fleet-tick.test.mjs +1332 -0
  93. package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
  94. package/scripts/frontmatter-allowlist.json +64 -0
  95. package/scripts/frontmatter-check.mjs +256 -0
  96. package/scripts/frontmatter-check.test.mjs +436 -0
  97. package/scripts/git-env.mjs +124 -0
  98. package/scripts/git-env.test.mjs +149 -0
  99. package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
  100. package/scripts/gone-walk.test.mjs +213 -0
  101. package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
  102. package/scripts/head-moved-after-label-prose.test.mjs +233 -0
  103. package/scripts/immutable-body-claim-prose.test.mjs +413 -0
  104. package/scripts/implementer-model-tier.test.mjs +643 -0
  105. package/scripts/inflight-citation-prose.test.mjs +144 -0
  106. package/scripts/inflight-exit2-prose.test.mjs +81 -0
  107. package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
  108. package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
  109. package/scripts/inflight.sh +1106 -0
  110. package/scripts/inflight.test.mjs +2984 -0
  111. package/scripts/injection-control-prose.test.mjs +404 -0
  112. package/scripts/install-root-audit.test.mjs +464 -0
  113. package/scripts/instrument-check-prose.test.mjs +235 -0
  114. package/scripts/instruments.sh +394 -0
  115. package/scripts/instruments.test.mjs +787 -0
  116. package/scripts/issue-tracker-prose.test.mjs +71 -0
  117. package/scripts/json.sh +248 -0
  118. package/scripts/json.test.mjs +364 -0
  119. package/scripts/ledger-dispatch.test.mjs +516 -0
  120. package/scripts/ledger-grammar.mjs +85 -0
  121. package/scripts/ledger-grammar.test.mjs +142 -0
  122. package/scripts/ledger-read-require-file.test.mjs +197 -0
  123. package/scripts/ledger.mjs +1753 -0
  124. package/scripts/ledger.test.mjs +3554 -0
  125. package/scripts/line-distance-prose.test.mjs +245 -0
  126. package/scripts/liveness-rationale-prose.test.mjs +83 -0
  127. package/scripts/locale-pin-prose.test.mjs +189 -0
  128. package/scripts/member-outcome-prose.test.mjs +167 -0
  129. package/scripts/member-outcomes-header.test.mjs +148 -0
  130. package/scripts/member-outcomes-prose.test.mjs +63 -0
  131. package/scripts/member-outcomes.mjs +231 -0
  132. package/scripts/member-outcomes.test.mjs +507 -0
  133. package/scripts/member-prompt-prose.test.mjs +161 -0
  134. package/scripts/member-record.mjs +605 -0
  135. package/scripts/member-record.test.mjs +516 -0
  136. package/scripts/member-write-guard.mjs +279 -0
  137. package/scripts/member-write-guard.test.mjs +211 -0
  138. package/scripts/merge-commit-probe-prose.test.mjs +122 -0
  139. package/scripts/merge-gate.mjs +262 -0
  140. package/scripts/merge-gate.test.mjs +613 -0
  141. package/scripts/muted-git-guard-sweep.test.mjs +493 -0
  142. package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
  143. package/scripts/net-watchdog-prose.test.mjs +79 -0
  144. package/scripts/net.sh +409 -0
  145. package/scripts/net.test.mjs +211 -0
  146. package/scripts/no-ci-gate-prose.test.mjs +108 -0
  147. package/scripts/no-undo-audit.sh +1134 -0
  148. package/scripts/no-undo-audit.test.mjs +3965 -0
  149. package/scripts/no-wave.test.mjs +138 -0
  150. package/scripts/node-floor-sweep.test.mjs +611 -0
  151. package/scripts/pointer-target-prose.test.mjs +186 -0
  152. package/scripts/pr-overlap.mjs +417 -0
  153. package/scripts/pr-overlap.test.mjs +695 -0
  154. package/scripts/printf-die-sweep.test.mjs +384 -0
  155. package/scripts/prompt-renderer.mjs +39 -0
  156. package/scripts/prompt-renderer.test.mjs +68 -0
  157. package/scripts/prose-pin.mjs +808 -0
  158. package/scripts/prose-pin.test.mjs +1034 -0
  159. package/scripts/prove-merge.sh +228 -0
  160. package/scripts/prove-merge.test.mjs +995 -0
  161. package/scripts/pull-table-relabel-prose.test.mjs +60 -0
  162. package/scripts/quiet-payload-prose.test.mjs +222 -0
  163. package/scripts/reap.sh +1768 -0
  164. package/scripts/reap.test.mjs +4395 -0
  165. package/scripts/reaping-prose.test.mjs +159 -0
  166. package/scripts/refuter-scratch-prose.test.mjs +135 -0
  167. package/scripts/release-label-required-prose.test.mjs +71 -0
  168. package/scripts/release-label-split-prose.test.mjs +169 -0
  169. package/scripts/release-ticket.sh +1716 -0
  170. package/scripts/release-ticket.test.mjs +5106 -0
  171. package/scripts/renovate-release-contract.test.mjs +379 -0
  172. package/scripts/repo-root.mjs +544 -0
  173. package/scripts/repo-root.test.mjs +873 -0
  174. package/scripts/reporter-output-rule-prose.test.mjs +208 -0
  175. package/scripts/review-agent-report-only.test.mjs +49 -0
  176. package/scripts/review-core-cwd-isolation.test.mjs +374 -0
  177. package/scripts/review-core-reads.test.mjs +478 -0
  178. package/scripts/review-core-refuter-scratch.test.mjs +148 -0
  179. package/scripts/review-core-snapshot-path.test.mjs +777 -0
  180. package/scripts/review-core-specialist-scratch.test.mjs +189 -0
  181. package/scripts/review-core-testcmd.test.mjs +288 -0
  182. package/scripts/review-core-unrun.test.mjs +530 -0
  183. package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
  184. package/scripts/review-core.mjs +1028 -0
  185. package/scripts/review-eval-resolver-path.test.mjs +55 -0
  186. package/scripts/review-eval.mjs +197 -0
  187. package/scripts/review-host-fixture.mjs +73 -0
  188. package/scripts/review-in-run-retry.test.mjs +187 -0
  189. package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
  190. package/scripts/review-path-default.test.mjs +796 -0
  191. package/scripts/review-runner-spawns.test.mjs +93 -0
  192. package/scripts/review-runner.test.mjs +155 -0
  193. package/scripts/review-tier-audit.test.mjs +140 -0
  194. package/scripts/run-artifact-pr-prose.test.mjs +341 -0
  195. package/scripts/run-merge-bot-prose.test.mjs +1391 -0
  196. package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
  197. package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
  198. package/scripts/section-between-guard-prose.test.mjs +378 -0
  199. package/scripts/select-dimensions.test.mjs +674 -0
  200. package/scripts/shared-refusal.test.mjs +388 -0
  201. package/scripts/shell-traps-prose.test.mjs +507 -0
  202. package/scripts/shortlist.mjs +355 -0
  203. package/scripts/shortlist.test.mjs +366 -0
  204. package/scripts/slow-transport.mjs +72 -0
  205. package/scripts/snapshot-repo.test.mjs +772 -0
  206. package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
  207. package/scripts/spend-view.test.mjs +312 -0
  208. package/scripts/staleness-qualifier-prose.test.mjs +251 -0
  209. package/scripts/staleness-verdict-prose.test.mjs +142 -0
  210. package/scripts/staleness.mjs +414 -0
  211. package/scripts/staleness.test.mjs +893 -0
  212. package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
  213. package/scripts/stash-prohibition-prose.test.mjs +313 -0
  214. package/scripts/strip-comments.mjs +44 -0
  215. package/scripts/tier-check.mjs +468 -0
  216. package/scripts/tier-check.test.mjs +726 -0
  217. package/scripts/tier-guard-gate-prose.test.mjs +216 -0
  218. package/scripts/tier-outcomes-header.test.mjs +586 -0
  219. package/scripts/tier-outcomes.mjs +441 -0
  220. package/scripts/tier-outcomes.test.mjs +342 -0
  221. package/scripts/tier-roles.mjs +250 -0
  222. package/scripts/tier-roles.test.mjs +316 -0
  223. package/scripts/tracker-block-copy-prose.test.mjs +288 -0
  224. package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
  225. package/scripts/unattended-git-sweep.test.mjs +142 -0
  226. package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
  227. package/scripts/verify-sha.sh +117 -0
  228. package/scripts/verify-sha.test.mjs +693 -0
  229. package/scripts/watcher-degraded-block.test.mjs +372 -0
  230. package/scripts/watcher-key-prose.test.mjs +106 -0
  231. package/scripts/within-run-pair-prose.test.mjs +208 -0
  232. package/scripts/worktree-audit.sh +482 -0
  233. package/scripts/worktree-audit.test.mjs +1407 -0
  234. package/scripts/worktree-head-prose.test.mjs +276 -0
  235. package/scripts/worktree-listing-sweep.test.mjs +217 -0
  236. package/scripts/worktree-model-prose.test.mjs +216 -0
  237. package/scripts/worktree.sh +470 -0
  238. package/skills/next-ticket/SKILL.md +138 -0
  239. package/skills/run-team/SKILL.md +3603 -0
  240. package/skills/run-team/references/ci-and-staleness.md +75 -0
  241. package/skills/run-team/references/correction-tickets.md +37 -0
  242. package/skills/run-team/references/isolation.md +23 -0
  243. package/skills/run-team/references/member-lifecycle.md +73 -0
  244. package/skills/run-team/references/reaping.md +73 -0
  245. package/skills/sizing-a-ticket/SKILL.md +39 -0
@@ -0,0 +1,726 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { spawnSync, execFileSync } from "node:child_process";
4
+ import { mkdtempSync, mkdirSync, writeFileSync, existsSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ import {
10
+ declaredPairFor,
11
+ resolveActual, evaluateMember,
12
+ formatMismatch, formatOmpExpectation, appendedLedgerText, expectedDefinition, withToken,
13
+ } from "./tier-check.mjs";
14
+ import { parseFrontmatter } from "./tier-roles.mjs";
15
+ import { deriveRun } from "./fleet-tick.mjs";
16
+
17
+ const SCRIPT = fileURLToPath(new URL("./tier-check.mjs", import.meta.url));
18
+ const LEDGER_SCRIPT = fileURLToPath(new URL("./ledger.mjs", import.meta.url));
19
+
20
+ // ---------------------------------------------------------------------------
21
+ // fixtures — shaped like member-record.test.mjs's, one line per event.
22
+ //
23
+ // Model spellings below are the REAL measured ones, not the bare family
24
+ // name: omp's own `resolvedModel`/`resolvedModelIdentity`/transcript
25
+ // `model` are ALWAYS provider-prefixed (906/906 measured), sometimes with a
26
+ // trailing `:level`. Using anything else here would let a `modelsEqual`
27
+ // regression hide behind a fixture omp never actually writes.
28
+ // ---------------------------------------------------------------------------
29
+
30
+ function agentMd(model) {
31
+ return [
32
+ "---",
33
+ "name: fixture-implementer",
34
+ "description: fixture",
35
+ `model: ${model}`,
36
+ "---",
37
+ "",
38
+ "Follow the dispatch brief.",
39
+ "",
40
+ ].join("\n");
41
+ }
42
+
43
+ // `resolvedModelIdentity` on `session_init` — written at DISPATCH, before any
44
+ // assistant turn — is what makes the fixtures below realistic: a member
45
+ // still working carries it with no assistant line at all. `agent` is the
46
+ // same line's record of the definition the dispatch named (a generic
47
+ // dispatch writes `task`).
48
+ function ompTranscript(resolvedModelIdentity, thinkingLevel, { withTurn = true, agent } = {}) {
49
+ const lines = [
50
+ { type: "session", version: 3, id: "s1", timestamp: "2026-09-09T15:11:49.444Z", cwd: "/tmp/x" },
51
+ { type: "thinking_level_change", id: "t1", parentId: null, timestamp: "2026-09-09T15:11:49.494Z", thinkingLevel, configured: null },
52
+ { type: "session_init", id: "i1", parentId: "t1", timestamp: "2026-09-09T15:11:49.495Z", task: "fixture", resolvedModelIdentity, ...(agent ? { agent } : {}) },
53
+ ];
54
+ if (withTurn) {
55
+ lines.push({
56
+ type: "message", id: "m1", parentId: "i1", timestamp: "2026-09-09T15:12:00.000Z",
57
+ message: { role: "assistant", content: [{ type: "text", text: "ok" }], model: resolvedModelIdentity, usage: { input: 2, output: 201, cacheRead: 0, cacheWrite: 100, cost: { total: 0.01 } } },
58
+ });
59
+ }
60
+ return lines.map((l) => JSON.stringify(l)).join("\n") + "\n";
61
+ }
62
+
63
+ function dir() {
64
+ return mkdtempSync(join(tmpdir(), "tier-check-"));
65
+ }
66
+
67
+ // The measured real `modelRoles` shape (ADR 0011/0014) used by every fixture
68
+ // below that needs a role to resolve through: `slow`, `task`, `smol`, each
69
+ // carrying its own baked level suffix the way a real install does.
70
+ const MODEL_ROLES = {
71
+ default: "anthropic/claude-sonnet-5:high",
72
+ slow: "anthropic/claude-opus-5:high",
73
+ task: "anthropic/claude-sonnet-5:high",
74
+ smol: "anthropic/claude-haiku-4-5:auto",
75
+ };
76
+
77
+ function modelRolesFile(d) {
78
+ const p = join(d, "model-roles.json");
79
+ writeFileSync(p, JSON.stringify(MODEL_ROLES));
80
+ return p;
81
+ }
82
+
83
+ function runCli(argv, cwd, extra = []) {
84
+ return spawnSync(process.execPath, [SCRIPT, ...argv, ...extra], { cwd, encoding: "utf8" });
85
+ }
86
+
87
+ // ---------------------------------------------------------------------------
88
+ // pure core
89
+ // ---------------------------------------------------------------------------
90
+
91
+ test("parseFrontmatter reads model, role and level together", () => {
92
+ const fm = parseFrontmatter(agentMd("@slow:xhigh"));
93
+ assert.deepEqual(fm, { model: "@slow:xhigh", role: "slow", level: "xhigh" });
94
+ });
95
+
96
+ test("declaredPairFor is the frontmatter's own model/level, no harness branch", () => {
97
+ const fm = { model: "@slow:xhigh", role: "slow", level: "xhigh" };
98
+ assert.deepEqual(declaredPairFor(fm), { model: "@slow:xhigh", level: "xhigh" });
99
+ });
100
+
101
+ test("a declared model that is not a route never reads ok, even when the resolved model would otherwise match", () => {
102
+ const r = evaluateMember({
103
+ member: "impl-1",
104
+ frontmatter: { model: "opus", role: null, level: "xhigh" },
105
+ transcriptText: ompTranscript("opus", "xhigh"),
106
+ modelRoles: MODEL_ROLES,
107
+ });
108
+ assert.equal(r.ok, false, "an unrouted declared model read as a match — null !== null slipped through");
109
+ });
110
+
111
+ test("appendedLedgerText appends to existing free text rather than replacing it", () => {
112
+ assert.equal(appendedLedgerText("impl-42 · class=routine", "note"), "impl-42 · class=routine · note");
113
+ assert.equal(appendedLedgerText("", "note"), "note");
114
+ assert.equal(appendedLedgerText(null, "note"), "note");
115
+ });
116
+
117
+ // Review finding #5 (p2): the documented loop is check, fix, re-check — a
118
+ // member that still mismatches for the SAME reason on a later run must not
119
+ // grow the row a second time. A DIFFERENT note still appends.
120
+ test("appendedLedgerText is idempotent on the identical note but still appends a genuinely different one", () => {
121
+ assert.equal(appendedLedgerText("impl-42 · class=routine · note", "note"), "impl-42 · class=routine · note");
122
+ assert.equal(appendedLedgerText("note", "note"), "note");
123
+ assert.equal(appendedLedgerText("impl-42 · class=routine · note", "different note"), "impl-42 · class=routine · note · different note");
124
+ });
125
+
126
+ // The idempotency guard keys on the note being the row's TRAILING ` · `-joined
127
+ // segment, not on the note appearing anywhere: an earlier segment carrying the
128
+ // same text (a pair that was since fixed, then re-broken) or a longer segment
129
+ // merely ending in it (a different member whose name ends in this one's) is
130
+ // not this run's note, and the new one still appends.
131
+ test("appendedLedgerText's idempotency is anchored to the trailing ` · ` segment, never a substring match", () => {
132
+ assert.equal(
133
+ appendedLedgerText("impl-42 · note · class=routine", "note"),
134
+ "impl-42 · note · class=routine · note",
135
+ );
136
+ const note = "Impl-1: declared opus/xhigh resolved anthropic/claude-opus-5/high";
137
+ assert.equal(
138
+ appendedLedgerText(`impl-42 · Fix${note}`, note),
139
+ `impl-42 · Fix${note} · ${note}`,
140
+ );
141
+ });
142
+
143
+ // The idempotency guard is on the token's EXACT presence, not a substring: a
144
+ // row already carrying a LONGER token that merely starts with a SHORTER one
145
+ // (two definitions sharing a name prefix, `fleet-implementer` vs
146
+ // `fleet-implementer-alt`) must still gain the shorter token — `.includes`
147
+ // would treat it as already present and silently drop it.
148
+ test("withToken's idempotency is exact-token, never a substring match on a token sharing a prefix", () => {
149
+ const existing = "impl-7 · class=routine · tier-ok=impl-7:fleet-implementer-alt";
150
+ assert.equal(
151
+ withToken(existing, "tier-ok=impl-7:fleet-implementer"),
152
+ "impl-7 · class=routine · tier-ok=impl-7:fleet-implementer-alt · tier-ok=impl-7:fleet-implementer",
153
+ );
154
+ });
155
+
156
+ test("formatMismatch is the ticket's exact line shape", () => {
157
+ const line = formatMismatch({
158
+ member: "impl-9",
159
+ declared: { model: "@slow:xhigh", level: "xhigh" },
160
+ resolved: { model: "anthropic/claude-opus-5", level: "high" },
161
+ });
162
+ assert.equal(line, "impl-9: declared @slow:xhigh/xhigh resolved anthropic/claude-opus-5/high");
163
+ });
164
+
165
+ // ---------------------------------------------------------------------------
166
+ // Review finding #2 (p1): the omp job-record short-circuit fires ONLY when
167
+ // BOTH fields are given; a partial record falls back to the transcript for
168
+ // the half it lacks, and never reports the missing half as `null`.
169
+ // ---------------------------------------------------------------------------
170
+
171
+ test("resolveActual: full job record (both fields) never reads transcriptText", () => {
172
+ const r = resolveActual({ transcriptText: undefined, resolvedModel: "anthropic/claude-opus-5", resolvedThinkingLevel: "high" });
173
+ assert.deepEqual(r, { model: "anthropic/claude-opus-5", level: "high", viaJobRecord: true });
174
+ });
175
+
176
+ test("resolveActual: resolvedModel alone falls back to the transcript for the thinking level, never `null`", () => {
177
+ const r = resolveActual({
178
+ resolvedModel: "anthropic/claude-opus-5", resolvedThinkingLevel: undefined,
179
+ transcriptText: ompTranscript("anthropic/claude-opus-5", "xhigh"),
180
+ });
181
+ assert.deepEqual(r, { model: "anthropic/claude-opus-5", level: "xhigh", viaJobRecord: false });
182
+ });
183
+
184
+ test("resolveActual: resolvedThinkingLevel alone falls back to the transcript for the model, never `null`", () => {
185
+ const r = resolveActual({
186
+ resolvedModel: undefined, resolvedThinkingLevel: "xhigh",
187
+ transcriptText: ompTranscript("anthropic/claude-sonnet-5", "high"),
188
+ });
189
+ assert.deepEqual(r, { model: "anthropic/claude-sonnet-5", level: "xhigh", viaJobRecord: false });
190
+ });
191
+
192
+ test("resolveActual: neither job-record field given reads both off the transcript, preferring resolvedModelIdentity over the per-turn model", () => {
193
+ const r = resolveActual({ transcriptText: ompTranscript("anthropic/claude-opus-5", "xhigh") });
194
+ assert.deepEqual(r, { model: "anthropic/claude-opus-5", level: "xhigh", viaJobRecord: false });
195
+ });
196
+
197
+ // Review finding #3 (p1): the identity exists BEFORE the first assistant
198
+ // turn — a member still working must resolve from it rather than reading a
199
+ // correctly-dispatched member as an unresolved mismatch.
200
+ test("resolveActual: a member with no assistant turn yet still resolves via resolvedModelIdentity", () => {
201
+ const r = resolveActual({ transcriptText: ompTranscript("anthropic/claude-opus-5", "xhigh", { withTurn: false }) });
202
+ assert.deepEqual(r, { model: "anthropic/claude-opus-5", level: "xhigh", viaJobRecord: false });
203
+ });
204
+
205
+ test("evaluateMember: a still-running member (no assistant turn) at its declared tier reads ok, not a mismatch", () => {
206
+ const r = evaluateMember({
207
+ member: "StillRunning",
208
+ frontmatter: parseFrontmatter(agentMd("@slow:xhigh")),
209
+ transcriptText: ompTranscript("anthropic/claude-opus-5", "xhigh", { withTurn: false }),
210
+ modelRoles: MODEL_ROLES,
211
+ });
212
+ assert.equal(r.ok, true, JSON.stringify(r));
213
+ });
214
+
215
+ // ---------------------------------------------------------------------------
216
+ // AC 1 — every fleet agent, at the declared tier -> exit 0
217
+ // ---------------------------------------------------------------------------
218
+
219
+ test("AC1: fleet-implementer (@slow:xhigh) at declared tier -> ok", () => {
220
+ const r = evaluateMember({
221
+ member: "AgentWordPair",
222
+ frontmatter: parseFrontmatter(agentMd("@slow:xhigh")),
223
+ transcriptText: ompTranscript("anthropic/claude-opus-5", "xhigh"),
224
+ modelRoles: MODEL_ROLES,
225
+ });
226
+ assert.equal(r.ok, true, JSON.stringify(r));
227
+ });
228
+
229
+ test("AC1: fleet-implementer-alt (@task:xhigh) at declared tier -> ok", () => {
230
+ const r = evaluateMember({
231
+ member: "AnotherWordPair",
232
+ frontmatter: parseFrontmatter(agentMd("@task:xhigh")),
233
+ transcriptText: ompTranscript("anthropic/claude-sonnet-5", "xhigh"),
234
+ modelRoles: MODEL_ROLES,
235
+ });
236
+ assert.equal(r.ok, true, JSON.stringify(r));
237
+ });
238
+
239
+ test("AC1 end-to-end via the CLI: a batch of both agents, every one at its declared tier -> exit 0", () => {
240
+ const d = dir();
241
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
242
+ writeFileSync(join(d, "fleet-implementer-alt.agent.md"), agentMd("@task:xhigh"));
243
+ writeFileSync(join(d, "omp-impl.jsonl"), ompTranscript("anthropic/claude-opus-5", "xhigh"));
244
+ writeFileSync(join(d, "omp-impl-alt.jsonl"), ompTranscript("anthropic/claude-sonnet-5", "xhigh"));
245
+ const batch = [
246
+ { member: "OmpWordPairOne", agentFile: "fleet-implementer.agent.md", transcript: "omp-impl.jsonl" },
247
+ { member: "OmpWordPairTwo", agentFile: "fleet-implementer-alt.agent.md", transcript: "omp-impl-alt.jsonl" },
248
+ ];
249
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
250
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
251
+ assert.equal(r.status, 0, r.stdout + r.stderr);
252
+ });
253
+
254
+ // ---------------------------------------------------------------------------
255
+ // AC 2 — the measured real case: resolved thinkingLevel `high` vs declared xhigh
256
+ // ---------------------------------------------------------------------------
257
+
258
+ test("AC2: resolved thinkingLevel `high` against declared `xhigh` -> mismatch naming both pairs", () => {
259
+ const r = evaluateMember({
260
+ member: "MeasuredRealCase",
261
+ frontmatter: parseFrontmatter(agentMd("@slow:xhigh")),
262
+ transcriptText: ompTranscript("anthropic/claude-opus-5", "high"),
263
+ modelRoles: MODEL_ROLES,
264
+ });
265
+ assert.equal(r.ok, false);
266
+ assert.deepEqual(r.declared, { model: "@slow:xhigh", level: "xhigh" });
267
+ assert.deepEqual(r.resolved, { model: "anthropic/claude-opus-5", level: "high", viaJobRecord: false });
268
+ assert.equal(formatMismatch(r), "MeasuredRealCase: declared @slow:xhigh/xhigh resolved anthropic/claude-opus-5/high");
269
+ });
270
+
271
+ test("AC2 end-to-end via the CLI: the same case exits 1 and prints the member and both pairs", () => {
272
+ const d = dir();
273
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
274
+ writeFileSync(join(d, "omp-impl.jsonl"), ompTranscript("anthropic/claude-opus-5", "high"));
275
+ const batch = [{ member: "MeasuredRealCase", agentFile: "fleet-implementer.agent.md", transcript: "omp-impl.jsonl" }];
276
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
277
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
278
+ assert.equal(r.status, 1, r.stdout + r.stderr);
279
+ assert.match(r.stderr, /MeasuredRealCase: declared @slow:xhigh\/xhigh resolved anthropic\/claude-opus-5\/high/);
280
+ });
281
+
282
+ // ---------------------------------------------------------------------------
283
+ // AC 3 — role-target mismatch -> exit 1
284
+ // ---------------------------------------------------------------------------
285
+
286
+ test("AC3: role-target mismatch (declared @task, resolved smol's model) -> mismatch", () => {
287
+ const r = evaluateMember({
288
+ member: "RoleMismatch",
289
+ frontmatter: parseFrontmatter(agentMd("@task:xhigh")),
290
+ transcriptText: ompTranscript("anthropic/claude-haiku-4-5", "xhigh"),
291
+ modelRoles: MODEL_ROLES,
292
+ });
293
+ assert.equal(r.ok, false);
294
+ assert.equal(formatMismatch(r), "RoleMismatch: declared @task:xhigh/xhigh resolved anthropic/claude-haiku-4-5/xhigh");
295
+ });
296
+
297
+ test("AC3 end-to-end via the CLI: a role-target mismatch exits 1", () => {
298
+ const d = dir();
299
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
300
+ writeFileSync(join(d, "omp-impl.jsonl"), ompTranscript("anthropic/claude-sonnet-5", "xhigh"));
301
+ const batch = [{ member: "RoleMismatchCli", agentFile: "fleet-implementer.agent.md", transcript: "omp-impl.jsonl" }];
302
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
303
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
304
+ assert.equal(r.status, 1, r.stdout + r.stderr);
305
+ assert.match(r.stderr, /RoleMismatchCli: declared @slow:xhigh\/xhigh resolved anthropic\/claude-sonnet-5\/xhigh/);
306
+ });
307
+
308
+ // ---------------------------------------------------------------------------
309
+ // AC 4 — job record present: never opens the child's session file; absent:
310
+ // it opens the file.
311
+ // ---------------------------------------------------------------------------
312
+
313
+ test("AC4: resolvedModel/resolvedThinkingLevel given -> resolveActual never reads transcriptText", () => {
314
+ const r = resolveActual({ transcriptText: undefined, resolvedModel: "anthropic/claude-opus-5", resolvedThinkingLevel: "high" });
315
+ assert.deepEqual(r, { model: "anthropic/claude-opus-5", level: "high", viaJobRecord: true });
316
+ });
317
+
318
+ test("AC4: job record present in a batch entry -> the CLI never opens (or even names) a transcript file", () => {
319
+ const d = dir();
320
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
321
+ const batch = [{
322
+ member: "JobRecordShortcut", agentFile: "fleet-implementer.agent.md",
323
+ // No `transcript`/`session` key at all — proves the CLI does not
324
+ // require, let alone open, a session file when BOTH job-record fields
325
+ // are given.
326
+ resolvedModel: "anthropic/claude-opus-5", resolvedThinkingLevel: "xhigh",
327
+ }];
328
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
329
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
330
+ assert.equal(r.status, 0, r.stdout + r.stderr);
331
+ });
332
+
333
+ test("AC4: job record absent -> the CLI opens the transcript file (and a missing one refuses, proving it tried)", () => {
334
+ const d = dir();
335
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
336
+ const batch = [{
337
+ member: "NoJobRecord", agentFile: "fleet-implementer.agent.md",
338
+ transcript: "does-not-exist.jsonl",
339
+ }];
340
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
341
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
342
+ assert.equal(r.status, 2, r.stdout + r.stderr);
343
+ assert.match(r.stderr, /ENOENT|does-not-exist\.jsonl/);
344
+ });
345
+
346
+ test("AC4b: job record PARTIAL (resolvedModel only, no transcript/session given) -> refuses rather than defaulting the missing level to null", () => {
347
+ const d = dir();
348
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
349
+ const batch = [{ member: "PartialNoFallback", agentFile: "fleet-implementer.agent.md", resolvedModel: "anthropic/claude-opus-5" }];
350
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
351
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
352
+ assert.equal(r.status, 2, r.stdout + r.stderr);
353
+ assert.match(r.stderr, /no --transcript or --session given/);
354
+ });
355
+
356
+ test("AC4c: job record PARTIAL (resolvedModel only) plus a transcript for the missing level -> resolves correctly, not a false mismatch", () => {
357
+ const d = dir();
358
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
359
+ writeFileSync(join(d, "omp-impl.jsonl"), ompTranscript("anthropic/claude-opus-5", "xhigh"));
360
+ const batch = [{
361
+ member: "PartialWithFallback", agentFile: "fleet-implementer.agent.md",
362
+ resolvedModel: "anthropic/claude-opus-5", transcript: "omp-impl.jsonl",
363
+ }];
364
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
365
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
366
+ assert.equal(r.status, 0, r.stdout + r.stderr);
367
+ });
368
+
369
+ // ---------------------------------------------------------------------------
370
+ // ADR 0011/0014 — the declared alias routes through a role, and compare is
371
+ // against THAT role's own `modelRoles.<role>` target, never against the
372
+ // alias's own spelling.
373
+ // ---------------------------------------------------------------------------
374
+
375
+ test("an explicit override suffix reaching a `modelRoles.slow` target at the SAME generation reads ok", () => {
376
+ const r = evaluateMember({
377
+ member: "impl-1",
378
+ frontmatter: parseFrontmatter(agentMd("@slow:xhigh")),
379
+ resolvedModel: "anthropic/claude-opus-5-5:xhigh", resolvedThinkingLevel: "xhigh",
380
+ modelRoles: { slow: "anthropic/claude-opus-5-5:high" },
381
+ });
382
+ assert.equal(r.ok, true, JSON.stringify(r));
383
+ });
384
+
385
+ test("the SAME declared/roles but resolved at an OLDER generation is NOT ok", () => {
386
+ const r = evaluateMember({
387
+ member: "impl-1",
388
+ frontmatter: parseFrontmatter(agentMd("@slow:xhigh")),
389
+ resolvedModel: "anthropic/claude-opus-5", resolvedThinkingLevel: "xhigh",
390
+ modelRoles: { slow: "anthropic/claude-opus-5-5:high" },
391
+ });
392
+ assert.equal(r.ok, false, JSON.stringify(r));
393
+ assert.equal(formatMismatch(r), "impl-1: declared @slow:xhigh/xhigh resolved anthropic/claude-opus-5/xhigh");
394
+ assert.equal(formatOmpExpectation(r), " impl-1: omp routes @slow:xhigh through @slow = anthropic/claude-opus-5-5");
395
+ });
396
+
397
+ test("modelRoles.slow pointing at another role (`@plan`) resolves through the chain, even to a non-Anthropic model", () => {
398
+ const r = evaluateMember({
399
+ member: "impl-1",
400
+ frontmatter: parseFrontmatter(agentMd("@slow:xhigh")),
401
+ resolvedModel: "openai/gpt-5.4", resolvedThinkingLevel: "xhigh",
402
+ modelRoles: { slow: "@plan", plan: "openai/gpt-5.4:high" },
403
+ });
404
+ assert.equal(r.ok, true, JSON.stringify(r));
405
+ });
406
+
407
+ test("an unset modelRoles.<role> reads not ok, and the expectation line names the unset role", () => {
408
+ const r = evaluateMember({
409
+ member: "impl-1",
410
+ frontmatter: parseFrontmatter(agentMd("@slow:xhigh")),
411
+ resolvedModel: "anthropic/claude-opus-5", resolvedThinkingLevel: "xhigh",
412
+ modelRoles: {},
413
+ });
414
+ assert.equal(r.ok, false, JSON.stringify(r));
415
+ assert.equal(formatOmpExpectation(r), " impl-1: omp routes @slow:xhigh through @slow = (modelRoles.slow unset)");
416
+ });
417
+
418
+ test("a non-route declared model reads not ok, and the expectation line names it as unrouted", () => {
419
+ const r = evaluateMember({
420
+ member: "impl-1",
421
+ frontmatter: parseFrontmatter(agentMd("opus")),
422
+ resolvedModel: "anthropic/claude-opus-5", resolvedThinkingLevel: "xhigh",
423
+ modelRoles: MODEL_ROLES,
424
+ });
425
+ assert.equal(r.ok, false, JSON.stringify(r));
426
+ assert.match(formatOmpExpectation(r), /no role — model: is not a route/);
427
+ });
428
+
429
+ test("CLI: no --model-roles and no `omp` on PATH refuses naming the config read", () => {
430
+ const d = dir();
431
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
432
+ writeFileSync(join(d, "omp-impl.jsonl"), ompTranscript("anthropic/claude-opus-5", "xhigh"));
433
+ const batch = [{ member: "NoPathOmp", agentFile: "fleet-implementer.agent.md", transcript: "omp-impl.jsonl" }];
434
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
435
+ const emptyPath = mkdtempSync(join(tmpdir(), "tier-check-empty-path-"));
436
+ const r = spawnSync(process.execPath, [SCRIPT, "--batch", "batch.json", "--repo", d], {
437
+ cwd: d, encoding: "utf8", env: { ...process.env, PATH: emptyPath },
438
+ });
439
+ assert.equal(r.status, 2, r.stdout + r.stderr);
440
+ assert.match(r.stderr, /omp config get modelRoles --json failed/);
441
+ });
442
+
443
+ test("CLI: --model-roles pointing at a JSON array refuses", () => {
444
+ const d = dir();
445
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
446
+ writeFileSync(join(d, "omp-impl.jsonl"), ompTranscript("anthropic/claude-opus-5", "xhigh"));
447
+ const batch = [{ member: "ArrModelRoles", agentFile: "fleet-implementer.agent.md", transcript: "omp-impl.jsonl" }];
448
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
449
+ const arrPath = join(d, "model-roles.json");
450
+ writeFileSync(arrPath, JSON.stringify(["not", "an", "object"]));
451
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", arrPath]);
452
+ assert.equal(r.status, 2, r.stdout + r.stderr);
453
+ });
454
+
455
+ // ---------------------------------------------------------------------------
456
+ // --session lookup (review finding #4): the controller supplies a session
457
+ // root it already knows instead of an exact transcript file.
458
+ // ---------------------------------------------------------------------------
459
+
460
+ test("--session: resolves via the flat <session>/<member>.jsonl file, bypassing readOmpMember's null-model gate", () => {
461
+ const sessionDir = dir();
462
+ // No assistant turn at all — proves this path does NOT filter out a
463
+ // still-running member the way readOmpMember's `if (!folded.model) return
464
+ // null` would (the exact gate this bypass exists to avoid).
465
+ writeFileSync(join(sessionDir, "OmpSessionMember.jsonl"), ompTranscript("anthropic/claude-opus-5", "xhigh", { withTurn: false }));
466
+ const d = dir();
467
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
468
+ const batch = [{ member: "OmpSessionMember", agentFile: "fleet-implementer.agent.md", session: sessionDir }];
469
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
470
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
471
+ assert.equal(r.status, 0, r.stdout + r.stderr);
472
+ });
473
+
474
+ test("--session: no <member>.jsonl under the session root refuses by name", () => {
475
+ const sessionDir = dir();
476
+ const d = dir();
477
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
478
+ const batch = [{ member: "NoSuchMember", agentFile: "fleet-implementer.agent.md", session: sessionDir }];
479
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
480
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
481
+ assert.equal(r.status, 2, r.stdout + r.stderr);
482
+ assert.match(r.stderr, /no NoSuchMember\.jsonl found under --session/);
483
+ });
484
+
485
+ // ---------------------------------------------------------------------------
486
+ // #1398 — an implementer is judged on the ledger's terms: its definition
487
+ // derived from the ticket row's `tier=`, its dispatched agent type read off
488
+ // its own transcript, and the verdict written back to the row either way —
489
+ // `tier-ok=impl-<N>:<definition>` on a pass, `settle impl-<N> tier-mismatch`
490
+ // on a failure. fleet-tick.mjs's deriveRun is the reader of both.
491
+ // ---------------------------------------------------------------------------
492
+
493
+ const ledgerCli = (file, ...args) => execFileSync(process.execPath, [LEDGER_SCRIPT, "--file", file, ...args], { encoding: "utf8" });
494
+
495
+ // One implementer's world: its definitions under <d>/agents/, its ticket row
496
+ // on a --file ledger, its transcript at <d>/session/<member>.jsonl — the flat
497
+ // `session` lookup phase 2 hands the check.
498
+ function implWorld({
499
+ ticket = 7, member = `impl-${ticket}`, row = `${member} · class=routine`,
500
+ definitions = { "fleet-implementer": "@slow:high" },
501
+ agent = "fleet-implementer", model = "anthropic/claude-opus-5", level = "high",
502
+ } = {}) {
503
+ const d = dir();
504
+ mkdirSync(join(d, "agents"));
505
+ for (const [name, route] of Object.entries(definitions)) writeFileSync(join(d, "agents", `${name}.agent.md`), agentMd(route));
506
+ const ledger = join(d, "ledger.md");
507
+ ledgerCli(ledger, "row", String(ticket), row);
508
+ mkdirSync(join(d, "session"));
509
+ writeFileSync(join(d, "session", `${member}.jsonl`), ompTranscript(model, level, { agent }));
510
+ writeFileSync(join(d, "batch.json"), JSON.stringify([{ member, session: "session" }]));
511
+ const read = () => JSON.parse(ledgerCli(ledger, "read"));
512
+ return {
513
+ ledger, read,
514
+ check: () => runCli(["--batch", "batch.json", "--repo", d, "--ledger", ledger, "--model-roles", modelRolesFile(d)], d),
515
+ row: () => read().rows.find((r) => r.split(/\s/)[0] === `#${ticket}`),
516
+ tick: () => deriveRun({ ...read(), drain: null }, []),
517
+ };
518
+ }
519
+
520
+ test("implementer pass: exit 0 writes tier-ok=impl-<N>:<definition> onto the row exactly once, however often the check re-runs", () => {
521
+ const w = implWorld();
522
+ const r = w.check();
523
+ assert.equal(r.status, 0, r.stdout + r.stderr);
524
+ assert.equal(w.row(), "#7 impl-7 · class=routine · tier-ok=impl-7:fleet-implementer");
525
+ assert.equal(w.check().status, 0);
526
+ assert.equal(w.row(), "#7 impl-7 · class=routine · tier-ok=impl-7:fleet-implementer", "a re-run grew the row");
527
+ // The token is no longer the row's tail once the member settles and the
528
+ // controller writes past it — a re-run still finds it.
529
+ ledgerCli(w.ledger, "row", "7", "impl-7 · class=routine · tier-ok=impl-7:fleet-implementer · → PR#9");
530
+ assert.equal(w.check().status, 0);
531
+ assert.equal(w.row().split("tier-ok=").length - 1, 1, w.row());
532
+ });
533
+
534
+ test("implementer mismatch: exit 1 settles the member tier-mismatch on the ledger and notes why, once", () => {
535
+ const w = implWorld({ model: "anthropic/claude-sonnet-5" });
536
+ const r = w.check();
537
+ assert.equal(r.status, 1, r.stdout + r.stderr);
538
+ assert.match(r.stderr, /impl-7: declared @slow:high\/high resolved anthropic\/claude-sonnet-5\/high/);
539
+ const row = w.row();
540
+ assert.equal(row, "#7 impl-7=tier-mismatch · class=routine · impl-7: declared @slow:high/high resolved anthropic/claude-sonnet-5/high");
541
+ assert.deepEqual(w.tick().tierMismatch, ["impl-7"]);
542
+ const again = w.check();
543
+ assert.equal(again.status, 1, again.stdout + again.stderr);
544
+ assert.equal(w.row(), row, "a re-run on an unchanged mismatch changed the row");
545
+ });
546
+
547
+ test("implementer: the expected definition follows the row's tier= — none, alt, and any other <cell>", () => {
548
+ for (const [tier, definition] of [[null, "fleet-implementer"], ["alt", "fleet-implementer-alt"], ["slow-medium", "fleet-implementer-slow-medium"]]) {
549
+ const w = implWorld({
550
+ row: `impl-7 · class=routine${tier ? ` · tier=${tier}` : ""}`,
551
+ definitions: { "fleet-implementer": "@slow:high", "fleet-implementer-alt": "@slow:high", "fleet-implementer-slow-medium": "@slow:high" },
552
+ agent: definition,
553
+ });
554
+ const r = w.check();
555
+ assert.equal(r.status, 0, `${tier}: ${r.stdout}${r.stderr}`);
556
+ assert.ok(w.row().endsWith(` · tier-ok=impl-7:${definition}`), `${tier}: ${w.row()}`);
557
+ }
558
+ // The row's tier, not the dispatch, names the definition: an alt row whose
559
+ // member ran the default definition fails even though that definition's
560
+ // tier resolved exactly.
561
+ const w = implWorld({ row: "impl-7 · tier=alt", definitions: { "fleet-implementer": "@slow:high", "fleet-implementer-alt": "@task:high" } });
562
+ const r = w.check();
563
+ assert.equal(r.status, 1, r.stdout + r.stderr);
564
+ assert.match(r.stderr, /impl-7: dispatched fleet-implementer, expected fleet-implementer-alt/);
565
+ });
566
+
567
+ test("implementer: a cell with no definition file under agents/ fails as a mismatch rather than crashing the check", () => {
568
+ const w = implWorld({ row: "impl-7 · tier=slow-medium", agent: "fleet-implementer-slow-medium" });
569
+ const r = w.check();
570
+ assert.equal(r.status, 1, r.stdout + r.stderr);
571
+ assert.match(r.stderr, /impl-7: expected fleet-implementer-slow-medium has no agents\/fleet-implementer-slow-medium\.agent\.md/);
572
+ assert.match(w.row(), /impl-7=tier-mismatch/);
573
+ });
574
+
575
+ test("implementer: a `task` dispatch fails even when the model and level it resolved match the definition's", () => {
576
+ const w = implWorld({ agent: "task" });
577
+ const r = w.check();
578
+ assert.equal(r.status, 1, r.stdout + r.stderr);
579
+ assert.match(r.stderr, /impl-7: dispatched task, expected fleet-implementer/);
580
+ assert.doesNotMatch(r.stderr, /declared @slow/, "the model half passed and must not be reported as a mismatch");
581
+ assert.match(w.row(), /impl-7=tier-mismatch/);
582
+ });
583
+
584
+ test("implementer: a member already settled another way records tier-mismatch as a row token and holds the tick", () => {
585
+ const w = implWorld({ row: "impl-7=bailed · class=routine", agent: "task" });
586
+ assert.deepEqual(w.tick().tierUnchecked, ["impl-7"], "a settled member with no verdict must hold as unchecked");
587
+ const r = w.check();
588
+ assert.equal(r.status, 1, r.stdout + r.stderr);
589
+ assert.equal(w.row(), "#7 impl-7=bailed · class=routine · tier-mismatch=impl-7:fleet-implementer · impl-7: dispatched task, expected fleet-implementer");
590
+ assert.deepEqual([w.tick().tierMismatch, w.tick().tierUnchecked], [["impl-7"], []]);
591
+ assert.equal(w.check().status, 1);
592
+ assert.equal(w.row().split("tier-mismatch=").length - 1, 1, "a re-run wrote the token twice");
593
+ });
594
+
595
+ test("tick: a settled, unchecked implementer holds; a later tier-check writes tier-ok and the hold clears", () => {
596
+ const w = implWorld({ row: "impl-7=released · class=routine" });
597
+ assert.deepEqual(w.tick().tierUnchecked, ["impl-7"]);
598
+ const r = w.check();
599
+ assert.equal(r.status, 0, r.stdout + r.stderr);
600
+ assert.deepEqual([w.tick().tierMismatch, w.tick().tierUnchecked], [[], []]);
601
+ });
602
+
603
+ test("expectedDefinition refuses a tier= it cannot name one definition file by", () => {
604
+ assert.throws(() => expectedDefinition("impl-7 · tier=alt · tier=slow-high"), /conflicting tier= tokens \(tier=alt, tier=slow-high\)/);
605
+ assert.throws(() => expectedDefinition("impl-7 · tier=../../etc"), /is not a definition suffix/);
606
+ assert.equal(expectedDefinition("impl-7 · tier=alt · tier=alt"), "fleet-implementer-alt");
607
+ });
608
+
609
+ test("ledger append: a mismatch on a member with no derivable ticket (an omp AgentId) still exits 1 but writes no ledger row", () => {
610
+ const d = dir();
611
+ execFileSync("git", ["init", "-q"], { cwd: d });
612
+ const ledgerFile = join(d, ".fleet", "ledger.md");
613
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
614
+ writeFileSync(join(d, "omp-impl.jsonl"), ompTranscript("anthropic/claude-opus-5", "high"));
615
+ const batch = [{ member: "SomeWordPair", agentFile: "fleet-implementer.agent.md", transcript: "omp-impl.jsonl" }];
616
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
617
+ const r = runCli(["--batch", "batch.json", "--repo", d, "--ledger", ledgerFile], d, ["--model-roles", modelRolesFile(d)]);
618
+ assert.equal(r.status, 1, r.stdout + r.stderr);
619
+ assert.equal(existsSync(ledgerFile), false, "a ledger file materialised for a member with no derivable ticket");
620
+ });
621
+
622
+ test("CLI: --batch given no value refuses by name", () => {
623
+ const r = runCli(["--batch"], dir());
624
+ assert.equal(r.status, 2);
625
+ assert.match(r.stderr, /--batch needs a value/);
626
+ });
627
+
628
+ test("CLI: no --batch at all refuses with the usage line", () => {
629
+ const r = runCli([], dir());
630
+ assert.equal(r.status, 2);
631
+ assert.match(r.stderr, /usage: tier-check\.mjs/);
632
+ });
633
+
634
+ test("CLI: a batch entry missing member/agentFile refuses by naming the entry, not a generic parse error", () => {
635
+ const d = dir();
636
+ writeFileSync(join(d, "batch.json"), JSON.stringify([{ member: "SomeWordPair" }]));
637
+ const r = runCli(["--batch", "batch.json", "--repo", d], d, ["--model-roles", modelRolesFile(d)]);
638
+ assert.equal(r.status, 2, r.stdout + r.stderr);
639
+ assert.match(r.stderr, /missing member\/agentFile/);
640
+ });
641
+
642
+ test("CLI: an impl- entry carrying agentFile refuses — the definition is the ledger row's, never the caller's", () => {
643
+ const d = dir();
644
+ writeFileSync(join(d, "batch.json"), JSON.stringify([{ member: "impl-1", agentFile: "agents/fleet-implementer-alt.agent.md", session: "s" }]));
645
+ const r = runCli(["--batch", "batch.json", "--repo", d, "--ledger", join(d, "ledger.md")], d, ["--model-roles", modelRolesFile(d)]);
646
+ assert.equal(r.status, 2, r.stdout + r.stderr);
647
+ assert.match(r.stderr, /impl-1: an impl- entry carries no agentFile/);
648
+ });
649
+
650
+ test("CLI: --repo defaults to the script's own plugin/ root, so the real agents/fleet-implementer.agent.md is found without --repo", () => {
651
+ const d = dir();
652
+ const ledger = join(d, "ledger.md");
653
+ ledgerCli(ledger, "row", "1", "impl-1");
654
+ writeFileSync(join(d, "omp-impl.jsonl"), ompTranscript("anthropic/claude-opus-5", "high", { agent: "fleet-implementer" }));
655
+ const batch = [{ member: "impl-1", transcript: join(d, "omp-impl.jsonl") }];
656
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
657
+ const r = runCli(["--batch", join(d, "batch.json"), "--ledger", ledger], d, ["--model-roles", modelRolesFile(d)]);
658
+ // The real fleet-implementer declares @slow:high (implementer-model-tier.test.mjs
659
+ // pins this) — this fixture's transcript matches it, so a correctly
660
+ // resolved --repo default exits 0. A wrong default (or none) finds no
661
+ // definition file and fails as a mismatch instead.
662
+ assert.equal(r.status, 0, r.stdout + r.stderr);
663
+ });
664
+
665
+ // ---------------------------------------------------------------------------
666
+ // #1669: tier-check bound only makeDie/makeArg, so a stray or misspelled flag
667
+ // was silently ignored and the run computed a real verdict against the
668
+ // DEFAULT ledger/repo instead of refusing. sweep() closes that gap.
669
+ // ---------------------------------------------------------------------------
670
+
671
+ // No agent/transcript/batch-content fixtures here: sweep() dies on the
672
+ // stray flag immediately after the arg() reads, before main() ever opens
673
+ // --batch's own file (verified by mutation — deleting this file's fixture
674
+ // writes changes no assertion's outcome), so writing them would be dead
675
+ // setup that never runs.
676
+ test("CLI: an unknown flag outside the roster refuses by name, not a computed verdict", () => {
677
+ const d = dir();
678
+ const r = runCli(["--batch", "batch.json", "--repo", d, "--zz-no-such-flag"], d);
679
+ assert.equal(r.status, 2);
680
+ assert.match(r.stderr, /unknown flag --zz-no-such-flag/);
681
+ });
682
+
683
+ // The ticket's own repro: a misspelled --ledgerr used to fall through to
684
+ // arg()'s `||`/`??` default and compute a real 0/1 verdict against the
685
+ // DEFAULT ledger, never naming the typo.
686
+ test("CLI: a misspelled --ledgerr refuses instead of computing a verdict against the default ledger", () => {
687
+ const d = dir();
688
+ const r = runCli(["--batch", "batch.json", "--repo", d, "--ledgerr", "/tmp/should-not-be-read.tsv"], d);
689
+ assert.equal(r.status, 2, r.stdout + r.stderr);
690
+ assert.match(r.stderr, /unknown flag --ledgerr/);
691
+ });
692
+
693
+ // The false-positive class the sweep addition risks: a roster flag present
694
+ // but missing its value must still answer arg()'s own "needs a value"
695
+ // message, never sweep()'s generic stray complaint — arg()'s per-flag
696
+ // guards run (and can refuse) before sweep() is ever reached. The stray
697
+ // riding after the valueless flag is what makes that ordering observable:
698
+ // with no stray in argv, sweep() has nothing to complain about and the
699
+ // "unknown flag" assertion holds under either ordering (#1711 — a stray-less
700
+ // twin of this test stayed green with sweep() hoisted to main()'s first
701
+ // statement, so it was deleted rather than kept as a second guard).
702
+ test("CLI: a stray flag riding after a valueless roster flag never pre-empts that flag's own value-guard message", () => {
703
+ const d = dir();
704
+ writeFileSync(join(d, "batch.json"), JSON.stringify([{ member: "impl-1", agentFile: "x.md" }]));
705
+ const r = runCli(["--batch", "batch.json", "--repo", "d.md", "--ledger", "--zz-no-such-flag"], d);
706
+ assert.equal(r.status, 2, r.stdout + r.stderr);
707
+ assert.ok(!r.stderr.includes("unknown flag"));
708
+ assert.match(r.stderr, /--ledger needs a value/);
709
+ });
710
+
711
+ // Review finding #1 (survived, confirmed): sweep() alone only refuses
712
+ // `--`-prefixed tokens, so the ticket's stated harm was only half closed —
713
+ // a single-dash misspelling (`-ledger`) rode through in silence the same
714
+ // way `--ledgerr` used to. Binding stray() alongside sweep(), the same
715
+ // pairing every sibling CLI (ci-state, diff-stats, board, pr-overlap)
716
+ // already uses, closes the other half.
717
+ test("CLI: a single-dash misspelling (`-ledger`) refuses as a stray, not a computed verdict", () => {
718
+ const d = dir();
719
+ writeFileSync(join(d, "fleet-implementer.agent.md"), agentMd("@slow:xhigh"));
720
+ writeFileSync(join(d, "omp-impl.jsonl"), ompTranscript("anthropic/claude-opus-5", "xhigh"));
721
+ const batch = [{ member: "impl-1", agentFile: "fleet-implementer.agent.md", transcript: "omp-impl.jsonl" }];
722
+ writeFileSync(join(d, "batch.json"), JSON.stringify(batch));
723
+ const r = runCli(["--batch", "batch.json", "--repo", d, "-ledger", "/tmp/should-not-be-read.tsv"], d);
724
+ assert.equal(r.status, 2, r.stdout + r.stderr);
725
+ assert.match(r.stderr, /unexpected argument '-ledger'/);
726
+ });