@feigi/fleet-ctl 3.18.1 → 3.18.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.18.1",
3
+ "version": "3.18.2",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -201,7 +201,8 @@ const COVERED_MJS = {
201
201
  // children (`node candidates.mjs`, `node ledger.mjs`, `sh inflight.sh`)
202
202
  // name no git.
203
203
  "shortlist.mjs": 2,
204
- // TWO, the same pair shortlist.mjs carries (#1803). `shortlistPath()`'s
204
+ // THREE. The first two are the pair shortlist.mjs carries (#1803), the
205
+ // third is below (#2485). `shortlistPath()`'s
205
206
  // `--git-common-dir` probe names the `.fleet/shortlist.json` the tick PULLs
206
207
  // from; an ambient GIT_DIR would read another repository's shortlist and
207
208
  // name its tickets. Measured in fleet-tick.test.mjs, "an ambient GIT_DIR
@@ -211,7 +212,11 @@ const COVERED_MJS = {
211
212
  // measured in fleet-tick.test.mjs, "an inherited GIT_DIR cannot retarget
212
213
  // the behind-issue premise probe". Its other children (`gh pr list`,
213
214
  // `node ledger.mjs`, `node shortlist.mjs`) are not git-invoking primitives.
214
- "fleet-tick.mjs": 2,
215
+ // `closedTickets()`'s `gh issue view` asks whether a tier-mismatched
216
+ // implementer's ticket is already closed, and resolves the repository the
217
+ // same way; measured in fleet-tick.test.mjs, "an inherited GIT_DIR cannot
218
+ // retarget the tier-mismatch closed-ticket probe".
219
+ "fleet-tick.mjs": 3,
215
220
  // ONE spawn primitive, `git(args, cwd)`, behind both of the file's git calls
216
221
  // — `resolveMainRoot()`'s `rev-parse --git-common-dir` and `checkIgnored()`'s
217
222
  // `check-ignore` (#1411). An ambient GIT_DIR would answer the first for
@@ -36,7 +36,10 @@
36
36
  // refresh, never a refusal: the depth only ever bounds PULLs
37
37
  // downward.
38
38
  // gh The open PRs, by label and by whether they close an issue — the
39
- // merge queue, and which PRs are owed a review.
39
+ // merge queue, and which PRs are owed a review. Also, for each ticket
40
+ // holding the implementer row on a tier mismatch, whether its issue
41
+ // is CLOSED (`gh issue view`, #2485): a closed ticket's mismatch
42
+ // holds nothing.
40
43
  // main The main checkout against the run-start baseline
41
44
  // `.fleet/main-checkout.sha`, through main-checkout.mjs (#2210).
42
45
  // Anything but `clean` — dirty, unknown, no baseline — prints one
@@ -434,7 +437,7 @@ export function unlabelledFinishers(ledger, unqueued) {
434
437
  .map((u) => ({ pr: u.pr, labelled: u.attempts.filter((a) => a.outcome === "labelled").map((a) => a.name) }));
435
438
  }
436
439
 
437
- export function deriveRun({ rows, dispatched, drain }, prs) {
440
+ export function deriveRun({ rows, dispatched, drain }, prs, closed = new Set()) {
438
441
  // One entry per member name across `## Dispatched` and every row. A member
439
442
  // settled ANYWHERE is settled: `settle` is the only writer of an outcome, and
440
443
  // a bare copy beside it is what a whole-line `row` rewrite leaves behind.
@@ -656,8 +659,13 @@ export function deriveRun({ rows, dispatched, drain }, prs) {
656
659
  // say whether one exists; a settled member whose transcript was never
657
660
  // written gets `tier-unverifiable=` from it, which clears the hold here.
658
661
  const newest = impls.filter((m, i) => !impls.some((o, j) => j > i && o.number === m.number));
662
+ // A mismatch on a ticket whose issue is CLOSED holds nothing (#2485): there
663
+ // is nothing left for `impl-<N>-b` to replace, and a retired definition can
664
+ // never re-check. `closed` is the ticket numbers the caller has probed; the
665
+ // pure fold cannot probe, so none is the default and every mismatch holds.
666
+ // A still-open ticket keeps its hold.
659
667
  const mismatched = (m) => m.outcome === "tier-mismatch" || verdicts.mismatch.has(m.name);
660
- const tierMismatch = newest.filter(mismatched).map((m) => m.name);
668
+ const tierMismatch = newest.filter((m) => mismatched(m) && !closed.has(m.number)).map((m) => m.name);
661
669
  const cleared = (m) => verdicts.ok.has(m.name) || verdicts.unverifiable.has(m.name);
662
670
  const tierUnchecked = newest.filter((m) => !mismatched(m) && !cleared(m)).map((m) => m.name);
663
671
  const isQueued = (p) => p.labels.some((l) => l && l.name === "ready-to-merge");
@@ -1013,6 +1021,32 @@ function liftedPremise(excluded, entries, prs) {
1013
1021
  return null;
1014
1022
  }
1015
1023
 
1024
+ // The tickets, of those holding the implementer row on a tier mismatch, whose
1025
+ // issue is CLOSED (#2485): the one live read deriveRun needs to lift a hold
1026
+ // whose replacement has nothing left to replace. One `gh issue view` per
1027
+ // mismatched ticket, and none when nothing is mismatched. A probe that cannot
1028
+ // answer — a nonzero exit, or a reply carrying no issue state — is disclosed
1029
+ // and the hold stands.
1030
+ function closedTickets(mismatched) {
1031
+ const closed = new Set();
1032
+ for (const { number } of mismatched.map(parseMember)) {
1033
+ const r = spawnSync("gh", ["issue", "view", String(number), "--json", "state"], { encoding: "utf8", env: gitEnv({ GH_REPO: "" }) });
1034
+ if (r.error || r.status !== 0) {
1035
+ console.error(`${NAME}: ${failure(r, `gh issue view ${number}`)} — tier mismatch on #${number} unconfirmed closed, hold stands`);
1036
+ continue;
1037
+ }
1038
+ let st = null;
1039
+ try { st = JSON.parse(r.stdout).state; } catch { /* no state: disclosed below */ }
1040
+ if (st === "CLOSED") closed.add(number);
1041
+ else if (typeof st !== "string") {
1042
+ // Exit 0 with a body that is not an issue (an HTML error page, a proxy's
1043
+ // text, JSON with no state) is as unanswered as a nonzero exit.
1044
+ console.error(`${NAME}: gh issue view ${number} printed no state — tier mismatch on #${number} unconfirmed closed, hold stands`);
1045
+ }
1046
+ }
1047
+ return closed;
1048
+ }
1049
+
1016
1050
  // shortlist.mjs, run by the tick itself (§ 6 §3). Its per-ticket stderr is
1017
1051
  // captured and dropped rather than billed to the controller's context; only a
1018
1052
  // failure's last line rides along.
@@ -1067,7 +1101,10 @@ function main() {
1067
1101
  const prs = openPrs();
1068
1102
  let run;
1069
1103
  try {
1070
- run = deriveRun(readLedger(), prs);
1104
+ const ledger = readLedger();
1105
+ run = deriveRun(ledger, prs);
1106
+ const closed = closedTickets(run.tierMismatch);
1107
+ if (closed.size) run = deriveRun(ledger, prs, closed);
1071
1108
  } catch (e) {
1072
1109
  if (e instanceof LedgerError) die(e.message);
1073
1110
  throw e;
@@ -365,7 +365,7 @@ const pr = (number, labels = [], closes = [number + 1000], headRefOid = HEAD_B)
365
365
  closingIssuesReferences: closes.map((n) => ({ number: n })),
366
366
  headRefOid,
367
367
  });
368
- const run = (ledger, prs = []) => deriveRun({ rows: [], dispatched: [], drain: null, ...ledger }, prs);
368
+ const run = (ledger, prs = [], closed) => deriveRun({ rows: [], dispatched: [], drain: null, ...ledger }, prs, closed);
369
369
 
370
370
  test("deriveRun: live implementers are the unsettled impl- tokens — the #1692 shape, read rather than recited", () => {
371
371
  // #1692 was two sources disagreeing about the same fleet. There is one
@@ -951,6 +951,21 @@ test("deriveRun: drain and tier mismatches come off the file", () => {
951
951
  assert.deepEqual(r.tierMismatch, ["impl-7"], "#8's replacement is the fix");
952
952
  });
953
953
 
954
+ // #2485: a mismatch on a ticket whose issue is CLOSED holds nothing.
955
+ test("deriveRun: a tier mismatch on a closed ticket stops holding; one on an open ticket still does", () => {
956
+ const ledger = { rows: ["#7 impl-7=tier-mismatch", "#8 impl-8 · tier-mismatch=impl-8:fleet-implementer"], dispatched: ["impl-7=tier-mismatch", "impl-8"] };
957
+ assert.deepEqual(run(ledger).tierMismatch, ["impl-7", "impl-8"], "no probe answer: every mismatch holds");
958
+ const r = run(ledger, [], new Set([7]));
959
+ assert.deepEqual(r.tierMismatch, ["impl-8"], "#7 is closed, #8 is not");
960
+ assert.deepEqual(r.tierUnchecked, [], "a lifted mismatch does not fall through to unchecked");
961
+ assert.deepEqual(run(ledger, [], new Set([7, 8])).tierMismatch, []);
962
+ });
963
+
964
+ test("deriveRun: a closed ticket lifts only its own mismatch, not a replacement's on another ticket", () => {
965
+ const r = run({ rows: ["#7 impl-7=tier-mismatch · impl-7-b=tier-mismatch", "#9 impl-9=tier-mismatch"] }, [], new Set([9]));
966
+ assert.deepEqual(r.tierMismatch, ["impl-7-b"]);
967
+ });
968
+
954
969
  test("deriveRun: tier mismatch holds while the LATEST replacement is also tier-mismatch", () => {
955
970
  const r = run({
956
971
  rows: ["#8 impl-8=tier-mismatch · impl-8-b=tier-mismatch"],
@@ -1172,6 +1187,7 @@ case "$1 $2" in
1172
1187
  "issue view")
1173
1188
  echo "$3" >> "$ISSUE_VIEW_LOG"
1174
1189
  [ -n "$ISSUE_VIEW_FAIL" ] && { echo "gh: issue view failed" >&2; exit 1; }
1190
+ [ -n "$ISSUE_VIEW_BODY" ] && { printf '%s\n' "$ISSUE_VIEW_BODY"; exit 0; }
1175
1191
  # Real gh answers for the repository an inherited GIT_DIR or GH_REPO names;
1176
1192
  # this one answers CLOSED for every issue there, so a probe that forgot to
1177
1193
  # scrub them lifts an exclusion the case's own repository still holds.
@@ -1519,6 +1535,78 @@ test("CLI: a behind-issue exclusion already reflected in the current file names
1519
1535
  assert.match(r.stdout, /^implementers 0\/3 → PULL #1 #2 #50 /m);
1520
1536
  });
1521
1537
 
1538
+ // #2485: the mismatch hold is lifted by the mismatched ticket's own issue
1539
+ // being CLOSED, probed live; an open one, or a probe that cannot answer, holds.
1540
+ test("CLI: a tier mismatch on a CLOSED ticket no longer holds the implementer row", () => {
1541
+ const mismatch = { rows: ["#7 impl-7=tier-mismatch"], dispatched: ["impl-7=tier-mismatch"] };
1542
+ const base = { shortlist: shortlistText([1, 2, 3]) };
1543
+ const closed = runCli([], { ...base, ledger: mismatch, issueStates: { 7: "CLOSED" } });
1544
+ assert.equal(closed.status, 0, closed.stderr);
1545
+ assert.match(closed.stdout, /^implementers 0\/2 → PULL #1 #2 /m);
1546
+ assert.doesNotMatch(closed.stdout, /tier mismatch/);
1547
+ assert.deepEqual(closed.issueViews, ["7"]);
1548
+ const open = runCli([], { ...base, ledger: mismatch, issueStates: { 7: "OPEN" } });
1549
+ assert.match(open.stdout, /^implementers 0\/2 → HOLD \(tier mismatch impl-7\)/m);
1550
+ const none = runCli([], { ...base, ledger: { rows: ["#7 impl-7 · tier-ok=impl-7:fleet-implementer"], dispatched: ["impl-7"] } });
1551
+ assert.deepEqual(none.issueViews, [], "nothing mismatched: no probe");
1552
+ });
1553
+
1554
+ test("CLI: a failed probe of a mismatched ticket is disclosed and the hold stands", () => {
1555
+ const r = runCli([], {
1556
+ shortlist: shortlistText([1, 2, 3]), ledger: { rows: ["#7 impl-7=tier-mismatch"], dispatched: ["impl-7=tier-mismatch"] },
1557
+ issueStates: { 7: "CLOSED" }, env: { ISSUE_VIEW_FAIL: "1" },
1558
+ });
1559
+ assert.equal(r.status, 0, r.stderr);
1560
+ assert.match(r.stdout, /^implementers 0\/2 → HOLD \(tier mismatch impl-7\)/m);
1561
+ assert.match(r.stderr, /fleet-tick: gh issue view 7 exited 1: gh: issue view failed — tier mismatch on #7 unconfirmed closed, hold stands/);
1562
+ });
1563
+
1564
+ test("CLI: a probe answering exit 0 with no issue state is disclosed and the hold stands", () => {
1565
+ for (const body of ["<html>rate limited</html>", "{}", "null"]) {
1566
+ const r = runCli([], {
1567
+ shortlist: shortlistText([1, 2, 3]), ledger: { rows: ["#7 impl-7=tier-mismatch"], dispatched: ["impl-7=tier-mismatch"] },
1568
+ issueStates: { 7: "CLOSED" }, env: { ISSUE_VIEW_BODY: body },
1569
+ });
1570
+ assert.equal(r.status, 0, r.stderr);
1571
+ assert.match(r.stdout, /^implementers 0\/2 → HOLD \(tier mismatch impl-7\)/m, body);
1572
+ assert.match(r.stderr, /fleet-tick: gh issue view 7 printed no state — tier mismatch on #7 unconfirmed closed, hold stands/, body);
1573
+ }
1574
+ });
1575
+
1576
+ // Only the exact string CLOSED lifts the hold: another casing, a prefix, or a
1577
+ // state an issue never has (MERGED) is a state, but not a closed one.
1578
+ test("CLI: a state other than exactly CLOSED leaves the mismatch hold standing", () => {
1579
+ for (const state of ["closed", "REOPENED", "MERGED", "CLOSED_AS_DUPLICATE"]) {
1580
+ const r = runCli([], {
1581
+ shortlist: shortlistText([1, 2, 3]), ledger: { rows: ["#7 impl-7=tier-mismatch"], dispatched: ["impl-7=tier-mismatch"] },
1582
+ issueStates: { 7: "CLOSED" }, env: { ISSUE_VIEW_BODY: JSON.stringify({ state }) },
1583
+ });
1584
+ assert.equal(r.status, 0, r.stderr);
1585
+ assert.match(r.stdout, /^implementers 0\/2 → HOLD \(tier mismatch impl-7\)/m, state);
1586
+ }
1587
+ });
1588
+
1589
+ // Every mismatched ticket is probed on its own: one CLOSED does not lift, and
1590
+ // one failed or OPEN does not hold back, another.
1591
+ test("CLI: each mismatched ticket is probed and released or held on its own issue", () => {
1592
+ const two = { rows: ["#7 impl-7=tier-mismatch", "#8 impl-8=tier-mismatch"], dispatched: ["impl-7=tier-mismatch", "impl-8=tier-mismatch"] };
1593
+ const base = { shortlist: shortlistText([1, 2, 3]), ledger: two };
1594
+ const mixed = runCli([], { ...base, issueStates: { 7: "CLOSED", 8: "OPEN" } });
1595
+ assert.equal(mixed.status, 0, mixed.stderr);
1596
+ assert.deepEqual(mixed.issueViews, ["7", "8"]);
1597
+ assert.match(mixed.stdout, /HOLD \(tier mismatch impl-8\)/);
1598
+ assert.doesNotMatch(mixed.stdout, /impl-7/);
1599
+ const reversed = runCli([], { ...base, issueStates: { 7: "OPEN", 8: "CLOSED" } });
1600
+ assert.deepEqual(reversed.issueViews, ["7", "8"]);
1601
+ assert.match(reversed.stdout, /HOLD \(tier mismatch impl-7\)/);
1602
+ assert.doesNotMatch(reversed.stdout, /impl-8/);
1603
+ const both = runCli([], { ...base, issueStates: { 7: "CLOSED", 8: "CLOSED" } });
1604
+ assert.deepEqual(both.issueViews, ["7", "8"]);
1605
+ assert.doesNotMatch(both.stdout, /tier mismatch/);
1606
+ const failed = runCli([], { ...base, issueStates: { 7: "CLOSED" }, env: { ISSUE_VIEW_FAIL: "1" } });
1607
+ assert.deepEqual(failed.issueViews, ["7", "8"], "a failed probe of #7 does not stop the probe of #8");
1608
+ });
1609
+
1522
1610
  test("CLI: a failed gh issue view probe is disclosed, not silently swallowed", () => {
1523
1611
  const full = { shortlist: shortlistText([1, 2, 3]), refresh: shortlistText([1, 2, 3, 50]) };
1524
1612
  const r = runCli([], {
@@ -1599,6 +1687,19 @@ test("CLI: an ambient GIT_DIR naming another repository cannot move the shortlis
1599
1687
  assert.match(r.stdout, /^implementers 0\/2 → PULL #7 #8 /m);
1600
1688
  });
1601
1689
 
1690
+ test("CLI: an inherited GIT_DIR cannot retarget the tier-mismatch closed-ticket probe", () => {
1691
+ const decoy = realpathSync(mkdtempSync(join(tmpdir(), "fleet-tick-decoy-tier-")));
1692
+ spawnBounded("git", ["init", "-q", decoy]);
1693
+ const r = runCli([], {
1694
+ shortlist: shortlistText([1, 2, 3]), ledger: { rows: ["#7 impl-7=tier-mismatch"], dispatched: ["impl-7=tier-mismatch"] },
1695
+ issueStates: { 7: "OPEN" }, env: { GIT_DIR: join(decoy, ".git"), GH_REPO: "someone/else" },
1696
+ });
1697
+ rmSync(decoy, { recursive: true, force: true });
1698
+ assert.equal(r.status, 0, r.stderr);
1699
+ assert.deepEqual(r.issueViews, ["7"], "the probe must still run");
1700
+ assert.match(r.stdout, /^implementers 0\/2 → HOLD \(tier mismatch impl-7\)/m, "#7 is OPEN in the case's own repository - the hold stands");
1701
+ });
1702
+
1602
1703
  test("CLI: an inherited GIT_DIR cannot retarget the behind-issue premise probe", () => {
1603
1704
  const decoy = realpathSync(mkdtempSync(join(tmpdir(), "fleet-tick-decoy-gh-")));
1604
1705
  spawnBounded("git", ["init", "-q", decoy]);
@@ -986,7 +986,9 @@ newest `impl-` member of a ticket whose row carries none of the three
986
986
  verdicts, whether that member is still running or already settled `bailed`,
987
987
  `killed` or `released`, and `HOLD (tier mismatch impl-<N>)` for a mismatched
988
988
  one. Only the newest member counts, so a replacement (`impl-<N>-b`) is what
989
- clears a mismatch — and is then owed its own check. The tick never reads a
989
+ clears a mismatch — and is then owed its own check. A mismatch on a ticket
990
+ whose issue is already CLOSED holds nothing: the tick probes that issue and
991
+ drops it, since there is nothing left to replace. The tick never reads a
990
992
  transcript: clear an unchecked hold by running the check on that member with
991
993
  `session`. A settled member's check works only when its transcript exists;
992
994
  without one, the verdict is `tier-unverifiable` for a member settled `killed`