@futurelastic/colab-handbook 1.16.0-rc.15 → 1.16.0-rc.16

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
@@ -33,5 +33,5 @@
33
33
  "engines": {
34
34
  "node": ">=18"
35
35
  },
36
- "version": "1.16.0-rc.15"
36
+ "version": "1.16.0-rc.16"
37
37
  }
package/tools/colab CHANGED
@@ -11515,8 +11515,9 @@ function resolveCloseRefsSplit(repoAbs, gh, issues, refsFromFlag, declaredHolds
11515
11515
  if (gh) {
11516
11516
  for (const num of issues) {
11517
11517
  if (!refsFromFlag.has(num)) continue;
11518
- const info = git.ghIssueView(repoAbs, num, ['body', 'labels']);
11518
+ const info = git.ghIssueView(repoAbs, num, ['body', 'labels', 'state']);
11519
11519
  if (!info) continue; // read failed — a reminder never fires on a read we could not attempt
11520
+ if (String(info.state || '').toUpperCase() === 'CLOSED') continue; // #647: nothing re-takes a closed issue
11520
11521
  const f = refsBrake.refsBrakeFinding({ issue: num, body: info.body, labels: info.labels, declaredHolds });
11521
11522
  if (f) brakeFindings.push(f);
11522
11523
  }
@@ -12729,9 +12730,7 @@ function cmdShipDryJson(opts) {
12729
12730
 
12730
12731
  // #74/#263: same close-gate split the prose path runs, reported via the additive fields above —
12731
12732
  // AND, since #263, folded into `checks` as its own precondition row (below).
12732
- const refsFromFlagJson = new Set(
12733
- String(opts.refs || '').split(',').map((s) => s.trim().replace(/^#/, '')).filter(Boolean).map(Number),
12734
- );
12733
+ const refsFromFlagJson = shipRefsFromFlag(opts, sess); // #647: + the hand-off's closed-before issues
12735
12734
  const split = resolveCloseRefsSplit(repoAbs, gh, sess.issues, refsFromFlagJson, descriptorHolds(doc));
12736
12735
  closeIssues = split.closeIssues; refsIssues = split.refsIssues; checklistFindings = split.gateFindings;
12737
12736
  refsBrakeFindings = split.brakeFindings;
@@ -13746,27 +13745,48 @@ function applyShipHandoff(repoAbs, sess, opts, trunk) {
13746
13745
  syncChain = shipHandoff.syncMergeChain((a) => git.git(a, repoAbs), refs.remoteSha, `refs/remotes/${remote}/${trunk}`);
13747
13746
  }
13748
13747
  const claimsByIssue = {};
13748
+ const issueStates = {}; // #647: an issue closed before the hand-off needs no claim — read state too
13749
13749
  if (u && comment) {
13750
13750
  for (const n of shipguard.branchIssueNumbers(sess.branch)) {
13751
- const info = git.ghIssueView(repoAbs, n, ['comments']);
13751
+ const info = git.ghIssueView(repoAbs, n, ['comments', 'state', 'closedAt']);
13752
13752
  claimsByIssue[n] = info ? liveClaimComments(info.comments || []).map((c) => ({ ...c })) : null;
13753
+ if (info) issueStates[n] = { state: info.state || '', closedAt: info.closedAt || '' };
13753
13754
  }
13754
13755
  }
13755
- const v = shipHandoff.handoffVerdict({ url: opts.handoff, comment, branch: sess.branch, refs, claimsByIssue, syncChain });
13756
+ const v = shipHandoff.handoffVerdict({ url: opts.handoff, comment, branch: sess.branch, refs, claimsByIssue, syncChain,
13757
+ issueStates, refNumbers: refsFlagNumbers(opts.refs) });
13756
13758
  if (!v.ok) return v;
13757
13759
  sess.issues = v.issues;
13758
13760
  sess.handoff = v;
13761
+ // #647: the closed-before-hand-off issues — Refs in the squash, no 🚢/🔖 comment in the tail.
13762
+ sess.handoffRefs = new Set(v.refIssues || []);
13759
13763
  // #372: the implementer is the executor that handed off — name it, never leave it reading as the shipper.
13760
- const ex = (claimsByIssue[v.issues[0]] || []).find((c) => c.branch === sess.branch && c.login === v.executor.login);
13764
+ const claimed = v.issues.find((n) => !sess.handoffRefs.has(n));
13765
+ const ex = (claimsByIssue[claimed] || []).find((c) => c.branch === sess.branch && c.login === v.executor.login);
13761
13766
  if (ex && (ex.session || ex.sessionName)) sess.holder = { session: ex.session || '', sessionName: ex.sessionName || '' };
13762
13767
  return v;
13763
13768
  }
13764
13769
 
13770
+ /** The `--refs` value as issue numbers (`12,#13` → [12, 13]). */
13771
+ function refsFlagNumbers(refs) {
13772
+ return String(refs || '').split(',').map((x) => x.trim().replace(/^#/, '')).filter(Boolean).map(Number);
13773
+ }
13774
+
13775
+ /** #647: --refs ∪ the hand-off's closed-before issues — the set resolveCloseRefsSplit writes as Refs. */
13776
+ function shipRefsFromFlag(opts, sess) {
13777
+ const set = new Set(refsFlagNumbers(opts.refs));
13778
+ for (const n of (sess && sess.handoffRefs) || []) set.add(n);
13779
+ return set;
13780
+ }
13781
+
13765
13782
  function handoffDetail(v) {
13766
13783
  const head = v.syncMerges
13767
13784
  ? `${shortSha(v.handedOff)}, under ${v.syncMerges} clean base-sync merge${v.syncMerges === 1 ? '' : 's'} to the remote head ${shortSha(v.sha)} (#579)`
13768
13785
  : `${shortSha(v.sha)} = the remote head`;
13769
- return `${v.url} hands off ${head}; executor ${v.executor.login}'s live claim on ${v.issues.map((n) => '#' + n).join(' ')}`;
13786
+ const refd = new Set(v.refIssues || []);
13787
+ const closed = v.issues.filter((n) => !refd.has(n));
13788
+ const tail = refd.size ? `; ${[...refd].map((n) => '#' + n).join(' ')} closed before the hand-off — Refs only, no claim needed (#647)` : '';
13789
+ return `${v.url} hands off ${head}; executor ${v.executor.login}'s live claim on ${closed.map((n) => '#' + n).join(' ')}${tail}`;
13770
13790
  }
13771
13791
 
13772
13792
  /** The clause the 🚢 comment carries for a hand-off land — the executor still holds its claim. */
@@ -13922,9 +13942,7 @@ function cmdShip(argv) {
13922
13942
  // resolveCloseRefsSplit (#48, #74): --refs, the tracking label, and #74's close gate (an
13923
13943
  // unticked ## Plan checklist with no declared Remainder: #M). The claim is still released
13924
13944
  // unconditionally either way (B3, unchanged) — only Closes→Refs changes.
13925
- const refsFromFlag = new Set(
13926
- String(opts.refs || '').split(',').map((s) => s.trim().replace(/^#/, '')).filter(Boolean).map(Number),
13927
- );
13945
+ const refsFromFlag = shipRefsFromFlag(opts, sess); // #647: + the hand-off's closed-before issues
13928
13946
  for (const n of refsFromFlag) {
13929
13947
  if (!sess.issues.includes(n)) warn(`--refs #${n} is not a claimed issue on this branch — ignored`);
13930
13948
  }
@@ -14985,6 +15003,8 @@ function shipLandedTail({ repoAbs, sess, target, trunk, gh, sha, closeIssues, re
14985
15003
  const closedByShip = []; // the issues this ship actually closed — for (i2) below (#371)
14986
15004
  if (gh) {
14987
15005
  for (const num of sess.issues) {
15006
+ // #647: closed before the hand-off — history the branch name carries, not work this ship did.
15007
+ if (sess.handoffRefs && sess.handoffRefs.has(num)) continue;
14988
15008
  const isRef = refsSet.has(num);
14989
15009
  const info = git.ghIssueView(repoAbs, num, ['state', 'labels']);
14990
15010
  // A closed issue must have auto-closed; a ref'd (tracking) issue must have STAYED open. The
@@ -15834,6 +15854,14 @@ function shipBatchLand(repoAbs, doc, trunk, remote, base, existing, verdict, opt
15834
15854
  const sess = sessions[i];
15835
15855
  const closeIssues = sess.issues.filter((n) => closed.has(n));
15836
15856
  const refsIssues = sess.issues.filter((n) => !closed.has(n));
15857
+ // #647: a hand-off member's Refs issue that is already CLOSED is one the build exempted as
15858
+ // closed before the hand-off (an open one needed a claim) — history, so no 🔖 comment on it.
15859
+ if (sess.handoff && gh && refsIssues.length) {
15860
+ sess.handoffRefs = new Set(refsIssues.filter((n) => {
15861
+ const info = git.ghIssueView(repoAbs, n, ['state']);
15862
+ return info && String(info.state || '').toUpperCase() === 'CLOSED';
15863
+ }));
15864
+ }
15837
15865
  shipBatchMemberTail({ repoAbs, doc, trunk, sess, sha: shortSha(c.sha), closeIssues, refsIssues, suffix, opts, gh });
15838
15866
  });
15839
15867
 
@@ -35,6 +35,13 @@
35
35
  * 7. every issue the branch carries has a LIVE `🔒 Claimed` comment naming this branch, posted by
36
36
  * the hand-off's author before the hand-off — the claim really does live elsewhere, and the
37
37
  * party handing off is the party holding it.
38
+ * ONE exemption (#647): an issue the trailing run carries that was already CLOSED before the
39
+ * hand-off was posted only names history (a flaky test named after it) — it needs no claim, and
40
+ * goes back in `refIssues` so the squash says `Refs #A` and ship neither closes it nor posts a
41
+ * ship comment on it. Closed AFTER the hand-off is no exemption: closing an issue must never
42
+ * launder away the claim it lacked. An issue whose state could not be read is not exempt. Every
43
+ * OPEN issue still needs its claim, `--refs` or not — `--refs` decides Closes vs Refs, never who
44
+ * may land; and at least one issue must remain to close, or there is nothing handed off.
38
45
  *
39
46
  * Pure: every input is already read. tools/colab does the IO (`gh api`, `git fetch`, issue views).
40
47
  */
@@ -72,11 +79,15 @@ function namedShas(body) {
72
79
  * or null for an issue whose comments could not be read
73
80
  * syncChain — (#579) the first-parent ancestors of the remote head reached through pure
74
81
  * base-sync merges only, nearest first (syncMergeChain's output); [] or absent = none
75
- * Returns { ok: true, issues, sha, handedOff, syncMerges, executor, url } or { ok: false, reason, detail }.
82
+ * issueStates — (#647) { [n]: { state, closedAt } } per issue as read now; a missing entry is
83
+ * unknown and earns no exemption
84
+ * refNumbers — (#647) the --refs numbers; used only to say why they do not waive a claim
85
+ * Returns { ok: true, issues, refIssues, sha, handedOff, syncMerges, executor, url } or { ok: false, reason, detail }.
86
+ * `issues` is the whole trailing run; `refIssues` is its closed-before-the-hand-off subset (#647).
76
87
  * `sha` is what lands (the remote head); `handedOff` is the sha the hand-off named — equal to `sha`
77
88
  * unless the head was synced, in which case `syncMerges` counts the merges between them.
78
89
  */
79
- function handoffVerdict({ url, comment, branch, refs, claimsByIssue, syncChain }) {
90
+ function handoffVerdict({ url, comment, branch, refs, claimsByIssue, syncChain, issueStates, refNumbers }) {
80
91
  const no = (reason, detail) => ({ ok: false, reason, detail });
81
92
  const u = parseHandoffUrl(url);
82
93
  if (!u) return no('bad-url', `--handoff ${url || '(empty)'} is not an issue-comment URL (…/issues/<N>#issuecomment-<id>)`);
@@ -109,18 +120,36 @@ function handoffVerdict({ url, comment, branch, refs, claimsByIssue, syncChain }
109
120
  ? `the hand-off names ${shas.map((s) => s.slice(0, 8)).join(', ')}, but the remote ${branch} is at ${head.slice(0, 8)}${synced} — the branch moved after it was handed off by more than a clean merge of its base; ask its executor for a new hand-off`
110
121
  : `the hand-off names no head sha — it must say which commit it hands off (the remote is at ${head.slice(0, 8)})`);
111
122
  }
123
+ const refIssues = issues.filter((n) => closedBefore(issueStates && issueStates[n], comment.createdAt));
124
+ if (refIssues.length === issues.length) {
125
+ return no('nothing-to-close', `every issue ${branch} carries (${issues.map((n) => '#' + n).join(' ')}) was closed before the hand-off — there is no open, claimed issue for it to land`);
126
+ }
127
+ const waived = new Set((refNumbers || []).map(Number));
112
128
  let executor = null;
113
129
  for (const n of issues) {
130
+ if (refIssues.includes(n)) continue;
114
131
  const live = claimsByIssue ? claimsByIssue[n] : null;
115
132
  if (!live) return no('claims-unreadable', `#${n}'s comments could not be read — the executor's claim cannot be checked`);
116
133
  const match = live.find((c) => c.branch === branch && c.login === comment.login && c.at < comment.createdAt);
117
134
  if (!match) {
118
- return no('no-executor-claim', `#${n} has no live 🔒 claim on ${branch} by ${comment.login || 'the hand-off author'} posted before the hand-off — ` +
135
+ const st = issueStates && issueStates[n];
136
+ const why = st && String(st.state).toUpperCase() === 'CLOSED'
137
+ ? ` (it was closed at ${st.closedAt || 'an unreadable time'}, not before the hand-off at ${comment.createdAt} — only an issue already closed when the hand-off was posted needs no claim)`
138
+ : waived.has(n) ? ' (--refs keeps it open in the squash; it does not waive the claim of an open issue)' : '';
139
+ return no('no-executor-claim', `#${n} has no live 🔒 claim on ${branch} by ${comment.login || 'the hand-off author'} posted before the hand-off${why} — ` +
119
140
  'the hand-off must come from the party holding the claim');
120
141
  }
121
142
  if (!executor) executor = { login: match.login, host: match.host, machine: match.machine || '' };
122
143
  }
123
- return { ok: true, issues, sha: refs.remoteSha, handedOff: lineage[at], syncMerges: at, executor, url: String(url).trim() };
144
+ return { ok: true, issues, refIssues, sha: refs.remoteSha, handedOff: lineage[at], syncMerges: at, executor, url: String(url).trim() };
145
+ }
146
+
147
+ /** #647: was this issue CLOSED strictly before `at` (the hand-off's createdAt)? Unknown ⇒ false. */
148
+ function closedBefore(st, at) {
149
+ if (!st || String(st.state || '').toUpperCase() !== 'CLOSED') return false;
150
+ const c = Date.parse(st.closedAt || '');
151
+ const h = Date.parse(at || '');
152
+ return Number.isFinite(c) && Number.isFinite(h) && c < h;
124
153
  }
125
154
 
126
155
  /**
@@ -209,4 +238,4 @@ function parseHandoffTrailer(body) {
209
238
  return m ? { url: m[1], handedOff: m[2] } : null;
210
239
  }
211
240
 
212
- module.exports = { parseHandoffUrl, namesBranch, namedShas, handoffVerdict, handoffTrailer, syncMergeChain, parseBatchEntries, parseHandoffTrailer };
241
+ module.exports = { parseHandoffUrl, namesBranch, namedShas, handoffVerdict, closedBefore, handoffTrailer, syncMergeChain, parseBatchEntries, parseHandoffTrailer };