@futurelastic/colab-handbook 1.13.0-rc.51 → 1.13.0-rc.53
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/tools/colab +109 -7
- package/tools/lib/codec/decision.d.ts +7 -0
- package/tools/lib/codec/decision.js +54 -0
- package/tools/lib/decision-record.js +42 -0
- package/tools/lib/git.js +25 -1
- package/tools/lib/landed-prs.js +58 -0
package/package.json
CHANGED
package/tools/colab
CHANGED
|
@@ -77,6 +77,7 @@ const releaseCut = require('./lib/release-cut');
|
|
|
77
77
|
const releaseFinalize = require('./lib/release-finalize');
|
|
78
78
|
const releaseChannel = require('./lib/release-channel');
|
|
79
79
|
const shippedBranch = require('./lib/shipped-branch');
|
|
80
|
+
const landedPrs = require('./lib/landed-prs');
|
|
80
81
|
const shipRoles = require('./lib/ship-roles'); // #372
|
|
81
82
|
const shipHandoff = require('./lib/ship-handoff'); // #578
|
|
82
83
|
const refsBrake = require('./lib/refs-brake'); // #385
|
|
@@ -4185,8 +4186,14 @@ TRUSTED_ASSOCIATIONS, checked on read. Same principle, a different mechanism, be
|
|
|
4185
4186
|
command TRANSCRIBES a decision made elsewhere rather than AUTHORIZING a write that did not exist
|
|
4186
4187
|
before it ran — the flag would assert nothing here that \`--ruled-by\` does not already.
|
|
4187
4188
|
|
|
4188
|
-
\`--answers <ref>\` names the
|
|
4189
|
-
|
|
4189
|
+
\`--answers <ref>\` names the question this decision resolves: an ASK ID (the \`id=\` of an open
|
|
4190
|
+
\`<!-- <tool>:ask id=<id> v=<n> -->\` record a dashboard that tracks asks wrote on the issue), or the
|
|
4191
|
+
\`<!-- decision:options -->\` comment (id or URL). Omit it only when there is neither. --record
|
|
4192
|
+
reads the issue's open asks first (#582) — an ask with no answer record, and no ⚖ record
|
|
4193
|
+
naming it, after its latest version: with ONE open ask and no --answers it prints the ask id
|
|
4194
|
+
and the exact re-run line, and says the ruling will be read as answering that ask; with TWO OR
|
|
4195
|
+
MORE it REFUSES before any write and lists every id, because a nameless ruling cannot say which
|
|
4196
|
+
one it settles.
|
|
4190
4197
|
|
|
4191
4198
|
Reopening removes \`${labels.DECISION_RECORDED_LABEL}\`, re-applies \`${labels.NEEDS_DECISION_LABEL}\`,
|
|
4192
4199
|
and posts a \`${decisionRecord.REOPEN_MARK}\` receipt — every decision on that issue up to this
|
|
@@ -4215,7 +4222,7 @@ Options:
|
|
|
4215
4222
|
and an issue number is present, for the common one-shot case)
|
|
4216
4223
|
--reopen reopen an existing decision instead of recording a new one
|
|
4217
4224
|
--ruled-by <name> required for --record/--reopen — who made this call, never the typist
|
|
4218
|
-
--answers <ref> (--record only) the decision:options comment this answers
|
|
4225
|
+
--answers <ref> (--record only) the open ask id, or the decision:options comment, this answers
|
|
4219
4226
|
--body-file <f> ruling prose (or reopen reason) to append below the marker line
|
|
4220
4227
|
--list list every issue with a live decision right now, instead of recording
|
|
4221
4228
|
--json (with --list) machine-readable output
|
|
@@ -4307,6 +4314,23 @@ function cmdDecisionRecord(repoAbs, num, opts, body) {
|
|
|
4307
4314
|
${pair.fix}`);
|
|
4308
4315
|
}
|
|
4309
4316
|
|
|
4317
|
+
// #582: show the recorder the asks still waiting on this issue, so the ruling names the one it
|
|
4318
|
+
// settles. One open ask + no --answers: a consumer reads the ruling as answering it — say so.
|
|
4319
|
+
// Two or more + no --answers: ambiguous, refuse before any write (same posture as the pair
|
|
4320
|
+
// check above) and list the ids.
|
|
4321
|
+
const asks = decisionRecord.openAsks(info.comments);
|
|
4322
|
+
const shellQuote = (v) => (/^[A-Za-z0-9_@%+=:,./-]+$/.test(String(v)) ? String(v) : `'${String(v).replace(/'/g, `'\\''`)}'`);
|
|
4323
|
+
if (asks.length > 0 && !opts.answers) {
|
|
4324
|
+
const rerun = (id) => `colab decision ${num} --record --ruled-by ${shellQuote(opts.ruledBy)} --answers ${shellQuote(id)}${opts.bodyFile ? ` --body-file ${shellQuote(opts.bodyFile)}` : ''}`;
|
|
4325
|
+
const rows = asks.map((a) => ` ${a.id} (v${a.version}, asked ${a.at || 'unknown'})\n ${rerun(a.id)}`).join('\n');
|
|
4326
|
+
if (asks.length > 1) {
|
|
4327
|
+
throw new UserError(`#${num} has ${asks.length} open asks and this record names none — a reader cannot tell which one the ruling settles. Re-run with --answers <ask id>:
|
|
4328
|
+
${rows}`);
|
|
4329
|
+
}
|
|
4330
|
+
warn(`#${num} has one open ask: ${asks[0].id} (v${asks[0].version}, asked ${asks[0].at || 'unknown'}). This ruling will be read as answering it. To name it explicitly, re-run as:
|
|
4331
|
+
${rerun(asks[0].id)}`);
|
|
4332
|
+
}
|
|
4333
|
+
|
|
4310
4334
|
const present = git.ghListLabels(repoAbs);
|
|
4311
4335
|
if (present && !present.includes(labels.DECISION_RECORDED_LABEL)) {
|
|
4312
4336
|
throw new UserError(labels.decisionRecordedMissingLabelHint(present)
|
|
@@ -4490,7 +4514,8 @@ CI grant merges into a repo whose own test suite is known-failing:
|
|
|
4490
4514
|
for the BRANCH's own current head (the same "ask by sha" check \`ship\` itself uses) — a human's
|
|
4491
4515
|
say-so alone is never enough. \`--evidence-run\` is a RECORDING-ONLY pointer for the audit trail;
|
|
4492
4516
|
it can never substitute for the measured run. If the branch has no run yet, open a PR for it
|
|
4493
|
-
(\`gh pr create\`) and let CI finish, then re-run this command.
|
|
4517
|
+
(\`gh pr create\`) and let CI finish, then re-run this command. You do not need to close that
|
|
4518
|
+
PR afterwards: \`colab ship\` closes it once the branch lands (#584).
|
|
4494
4519
|
2. NEVER STACKS. Creating a grant refuses outright if trunk is not currently red (nothing to
|
|
4495
4520
|
exempt), and refuses again if a PRIOR ci-grant already merged something and trunk has been red
|
|
4496
4521
|
continuously since — a second exemption on a still-broken repo is exactly the failure this gate
|
|
@@ -4839,7 +4864,7 @@ function cmdCiGrantCreate(repoAbs, num, opts) {
|
|
|
4839
4864
|
throw new UserError(
|
|
4840
4865
|
`"${opts.branch}" has no completed, successful CI run for its current head (${shortSha(evRun.sha)}) — ` +
|
|
4841
4866
|
`a CI grant requires MEASURED evidence, never a human's say-so alone. Open a PR for it ` +
|
|
4842
|
-
`(\`gh pr create\`) and let CI finish, then re-run this command.`);
|
|
4867
|
+
`(\`gh pr create\`) and let CI finish, then re-run this command — \`colab ship\` closes that PR once the branch lands (#584).`);
|
|
4843
4868
|
}
|
|
4844
4869
|
const evidenceSha = evRun.sha;
|
|
4845
4870
|
|
|
@@ -6306,6 +6331,9 @@ in a cleanup cron.
|
|
|
6306
6331
|
reported but never deleted (a label a triage session just created and has not
|
|
6307
6332
|
applied yet is indistinguishable from one whose members were all transferred
|
|
6308
6333
|
away — the labels API exposes no creation time, so a human decides).
|
|
6334
|
+
Also lists open PRs whose head commit already landed in trunk (#584) — CI-trigger
|
|
6335
|
+
PRs a squash ship left open. Report-only, --prune included: doctor never closes
|
|
6336
|
+
a PR. A PR whose head is not in the local clone is not judged.
|
|
6309
6337
|
`;
|
|
6310
6338
|
|
|
6311
6339
|
const EMPTY_SET = new Set();
|
|
@@ -6390,7 +6418,7 @@ function cmdDoctor(argv) {
|
|
|
6390
6418
|
const report = { deadWorktrees: [], orphanClaims: [], staleClaims: [], stalePlaces: [], unprovablePlaces: [], releasedPlaces: [], orphanPorts: [], brokenRecords: [], prunedPorts: [],
|
|
6391
6419
|
renamedHostRecords: [], unprovenHostRecords: [],
|
|
6392
6420
|
mergedFlips: [], mergedSweep: [], mergedDirty: [], mergedHookFail: [], mergedRemoveFail: [], shippedBranches: [], ghostPorts: [],
|
|
6393
|
-
spentGroupLabels: [], groupLabelsChecked: !!opts.sync, pruned: !!opts.prune };
|
|
6421
|
+
spentGroupLabels: [], groupLabelsChecked: !!opts.sync, landedPrs: [], landedPrsUnread: [], pruned: !!opts.prune };
|
|
6394
6422
|
|
|
6395
6423
|
// One answer per (repo, branch) — pass 5b asks about the same branch from a worktree and from each
|
|
6396
6424
|
// of its claims, and every miss costs two `git rev-parse` calls.
|
|
@@ -6781,6 +6809,28 @@ function cmdDoctor(argv) {
|
|
|
6781
6809
|
}
|
|
6782
6810
|
}
|
|
6783
6811
|
|
|
6812
|
+
// 9b. open PRs whose head already landed (#584) — the CI-trigger PRs a squash ship left open before
|
|
6813
|
+
// ship learned to close them, or that a ship on another machine could not close. Report-only,
|
|
6814
|
+
// --prune included: closing a PR is a write on a shared forge, and a human may still want it.
|
|
6815
|
+
// Behind --sync for the same reason as pass 9 (network). A PR whose head commit is not in this
|
|
6816
|
+
// clone is not judged — the answer would be a guess — so the list is honest, not exhaustive.
|
|
6817
|
+
if (opts.sync && git.ghAvailable()) {
|
|
6818
|
+
const repos = [...new Set([...(config.repos || []), ...knownRepos(config)].map((r) => path.resolve(r)))]
|
|
6819
|
+
.filter((r) => repoLive(r) && git.remoteUrl(r));
|
|
6820
|
+
for (const repo of repos) {
|
|
6821
|
+
const trunk = resolveTrunk(repo, projectDoc(repo));
|
|
6822
|
+
if (!trunk) continue;
|
|
6823
|
+
const listed = git.ghOpenPrs(repo);
|
|
6824
|
+
if (listed.error) { report.landedPrsUnread.push({ repo: shortRepo(repo), error: listed.error }); continue; }
|
|
6825
|
+
for (const pr of listed.prs) {
|
|
6826
|
+
if (!pr.headRefOid || pr.headRefName === trunk) continue;
|
|
6827
|
+
if (!git.git(['cat-file', '-e', `${pr.headRefOid}^{commit}`], repo).ok) continue;
|
|
6828
|
+
if (landed.landedState(repo, trunk, pr.headRefOid).state !== 'landed') continue;
|
|
6829
|
+
report.landedPrs.push({ repo: shortRepo(repo), number: pr.number, url: pr.url || '', branch: pr.headRefName || '', trunk });
|
|
6830
|
+
}
|
|
6831
|
+
}
|
|
6832
|
+
}
|
|
6833
|
+
|
|
6784
6834
|
// 10. notifyUrl against a DECLARED local observer (#414). Read-only, never pruned, never counted in
|
|
6785
6835
|
// the verdict — it is configuration, not state drift. Silent on a machine with no
|
|
6786
6836
|
// <COLAB_HOME>/notify-endpoint: unset is the right default where no observer runs.
|
|
@@ -6930,6 +6980,17 @@ function cmdDoctor(argv) {
|
|
|
6930
6980
|
print(' NOT exhaustive: a branch whose work trunk later rewrote can conflict against trunk');
|
|
6931
6981
|
print(' instead of matching it, and is omitted here rather than risk calling unmerged work spent.');
|
|
6932
6982
|
}
|
|
6983
|
+
// #584 — after the verdict, not counted: an open PR on a landed branch breaks nothing, it reads as
|
|
6984
|
+
// unmerged work on a tracker. Printed only under --sync.
|
|
6985
|
+
if (report.landedPrs.length) {
|
|
6986
|
+
print('');
|
|
6987
|
+
print(`Open PRs whose branch already landed (${report.landedPrs.length}) — the squash left them open:`);
|
|
6988
|
+
for (const p of report.landedPrs) print(` #${p.number} ${p.branch} [${p.repo}] → in ${p.trunk}${p.url ? ` ${p.url}` : ''}`);
|
|
6989
|
+
print(' `colab ship` closes these itself since #584; these predate that, or a ship could not close them.');
|
|
6990
|
+
print(' doctor never closes a PR, --prune included. To close one:');
|
|
6991
|
+
print(` gh pr close ${report.landedPrs[0].number} --comment "Landed on ${report.landedPrs[0].trunk} by squash." # in ${report.landedPrs[0].repo}`);
|
|
6992
|
+
}
|
|
6993
|
+
for (const u of report.landedPrsUnread) warn(`could not list open PRs in ${u.repo} (${u.error}) — landed-PR check skipped there`);
|
|
6933
6994
|
// Also after the verdict, and also not drift: a spent group label breaks nothing, it is picker
|
|
6934
6995
|
// noise on a tracker. Printed only under --sync, so silence here NEVER means "checked, clean" —
|
|
6935
6996
|
// which is why a --sync run that finds nothing says so explicitly below.
|
|
@@ -14062,11 +14123,13 @@ function cmdShip(argv) {
|
|
|
14062
14123
|
// a long ship these lines would otherwise scroll off above the `✓ Shipped` line — which is
|
|
14063
14124
|
// exactly how #304's failure went unnoticed in the first place.
|
|
14064
14125
|
deferredCollector = [];
|
|
14126
|
+
let reviewPrHandled = null; // #584: the #350 review PR, already closed (or warned about) above
|
|
14065
14127
|
// #350: the approved PR is spent — its work landed by squash, which the forge cannot see as a merge.
|
|
14066
14128
|
if (coreReview.verdict === 'approved' && coreReview.pr && gh) {
|
|
14067
14129
|
const closed = git.ghPrClose(repoAbs, coreReview.pr.number, `Landed on \`${target}\` as ${sha} by \`colab ship\` (#350), approved by ${coreReview.approval.by}.`);
|
|
14068
14130
|
if (closed.ok) print(` closed PR #${coreReview.pr.number} (landed as ${sha})`);
|
|
14069
14131
|
else warnDeferred(`could not close PR #${coreReview.pr.number} (${(closed.stderr || '').split('\n')[0]}) — it landed as ${sha}; close it by hand`);
|
|
14132
|
+
reviewPrHandled = coreReview.pr.number; // #584: either way the tail's landed-PR close must not touch it again
|
|
14070
14133
|
}
|
|
14071
14134
|
// Only when the target IS the shared checkout. `ephemeralTarget === false` means
|
|
14072
14135
|
// `targetDir === repoAbs` (see #234's note above); a declared integration line merged in a
|
|
@@ -14132,6 +14195,7 @@ function cmdShip(argv) {
|
|
|
14132
14195
|
// window itself now OPENS at the push (e2, #304), not here: post-ship's warnings belong in the
|
|
14133
14196
|
// same block, and re-assigning the collector here would silently discard them.
|
|
14134
14197
|
shipLandedTail({ repoAbs, sess, target, trunk, gh, sha, closeIssues, refsIssues, refsSet, integration, opts,
|
|
14198
|
+
skipPrs: reviewPrHandled ? [reviewPrHandled] : [],
|
|
14135
14199
|
evidenceExtra: (opts.humanDoorEvidence || '') + handoffEvidence(sess.handoff) }); // #525, #578
|
|
14136
14200
|
|
|
14137
14201
|
print('');
|
|
@@ -14151,6 +14215,38 @@ function cmdShip(argv) {
|
|
|
14151
14215
|
}
|
|
14152
14216
|
|
|
14153
14217
|
|
|
14218
|
+
/**
|
|
14219
|
+
* #584: close every open PR whose head is the branch this ship just landed — the PR a person or an
|
|
14220
|
+
* automation opened only to obtain branch CI. The forge never sees a squash as a merge of that PR, so
|
|
14221
|
+
* without this it stays open forever, reading as unmerged work. Only a PR whose head commit is the
|
|
14222
|
+
* landed tip (or an ancestor of it) is closed; one carrying commits that did not land is kept and
|
|
14223
|
+
* reported. Best-effort throughout: every failure defers a warning, none fails the ship.
|
|
14224
|
+
*/
|
|
14225
|
+
function shipCloseLandedPrs(repoAbs, sess, { target, sha, issues, skip = [] }) {
|
|
14226
|
+
const remoteName = git.remoteInfo(repoAbs).name || 'origin';
|
|
14227
|
+
const tipOf = (ref) => { const r = git.git(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`], repoAbs); return r.ok ? r.stdout.trim() : null; };
|
|
14228
|
+
const tip = tipOf(`refs/heads/${sess.branch}`) || tipOf(`refs/remotes/${remoteName}/${sess.branch}`);
|
|
14229
|
+
const headLanded = (oid) => {
|
|
14230
|
+
if (!tip) return false;
|
|
14231
|
+
if (oid === tip) return true;
|
|
14232
|
+
return git.git(['merge-base', '--is-ancestor', oid, tip], repoAbs).ok;
|
|
14233
|
+
};
|
|
14234
|
+
const res = landedPrs.closeLandedPrs({
|
|
14235
|
+
prs: git.ghOpenPrsForBranch(repoAbs, sess.branch),
|
|
14236
|
+
headLanded,
|
|
14237
|
+
close: (n, comment) => git.ghPrClose(repoAbs, n, comment),
|
|
14238
|
+
comment: landedPrs.landedPrComment({ target, sha, issues }),
|
|
14239
|
+
skip,
|
|
14240
|
+
});
|
|
14241
|
+
if (res.listError) {
|
|
14242
|
+
warnDeferred(`could not list open PRs for ${sess.branch} (${res.listError}) — any PR opened for its CI is still open; close it by hand (it landed as ${sha})`);
|
|
14243
|
+
return;
|
|
14244
|
+
}
|
|
14245
|
+
for (const n of res.closed) print(` closed PR #${n} — its branch ${sess.branch} landed as ${sha} (#584)`);
|
|
14246
|
+
for (const f of res.failed) warnDeferred(`could not close PR #${f.number} (${f.error}) — ${sess.branch} landed as ${sha}; close it by hand`);
|
|
14247
|
+
for (const k of res.kept) warnDeferred(`kept PR #${k.number} open: ${k.reason} (${sess.branch} landed as ${sha}) — it carries work that did not ship`);
|
|
14248
|
+
}
|
|
14249
|
+
|
|
14154
14250
|
/**
|
|
14155
14251
|
* The post-merge tail every landed branch gets — cmdShip's B3 through i2, moved here unchanged (#373)
|
|
14156
14252
|
* so a batch member gets exactly the same steps in the same order: worktree teardown (B3), the claims
|
|
@@ -14159,7 +14255,13 @@ function cmdShip(argv) {
|
|
|
14159
14255
|
* addition — '' on a serial ship (so its comment is byte-identical), the combined-run clause for a
|
|
14160
14256
|
* batch member.
|
|
14161
14257
|
*/
|
|
14162
|
-
function shipLandedTail({ repoAbs, sess, target, trunk, gh, sha, closeIssues, refsIssues, refsSet, integration, opts, evidenceExtra = '' }) {
|
|
14258
|
+
function shipLandedTail({ repoAbs, sess, target, trunk, gh, sha, closeIssues, refsIssues, refsSet, integration, opts, evidenceExtra = '', skipPrs = [] }) {
|
|
14259
|
+
// #584: the CI-trigger PR(s) this squash left behind. FIRST, while the branch ref still resolves —
|
|
14260
|
+
// B3 below may delete it, and "did the PR's head land?" is answered against that tip.
|
|
14261
|
+
if (gh && sess.branch) {
|
|
14262
|
+
try { shipCloseLandedPrs(repoAbs, sess, { target, sha, issues: closeIssues, skip: skipPrs }); }
|
|
14263
|
+
catch (e) { warnDeferred(`landed-PR close for ${sess.branch} failed (${e.message}) — the ship landed as ${sha}; close any PR for it by hand`); }
|
|
14264
|
+
}
|
|
14163
14265
|
const worktreeKept = !!(sess.name && opts.keepWorktree);
|
|
14164
14266
|
if (sess.name && !opts.keepWorktree) {
|
|
14165
14267
|
print(`B3: removing worktree ${sess.name} …`);
|
|
@@ -27,3 +27,10 @@ export const OPTIONS_RE: RegExp;
|
|
|
27
27
|
export const MOCKUP_RE: RegExp;
|
|
28
28
|
export function encodeMockup(url: string): string;
|
|
29
29
|
export function mockupUrls(body: unknown): string[];
|
|
30
|
+
|
|
31
|
+
/** An ask record a dashboard that tracks asks wrote (#582) — read-only to colab. */
|
|
32
|
+
export interface AskRecord { ns: string; id: string; version: number; index: number; }
|
|
33
|
+
/** An answer record naming an ask by id (#582). */
|
|
34
|
+
export interface AnswerRecord { ns: string; ask: string; version: number | null; index: number; }
|
|
35
|
+
export function askRecords(text: unknown): AskRecord[];
|
|
36
|
+
export function answerRecords(text: unknown): AnswerRecord[];
|
|
@@ -74,8 +74,62 @@ function mockupUrls(body) {
|
|
|
74
74
|
return out;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* ASK / ANSWER RECORDS (#582) — the structured question a dashboard that tracks asks writes onto an
|
|
79
|
+
* issue, and the answer that settles it. READ-ONLY here: colab never writes either, it only needs to
|
|
80
|
+
* know which asks are still open so `colab decision --record` can name the one a ruling settles.
|
|
81
|
+
*
|
|
82
|
+
* Wire shape, namespaced by whatever tool wrote it (the namespace is not interpreted — any tool
|
|
83
|
+
* writing this shape is read the same way):
|
|
84
|
+
* `<!-- <tool>:ask id=<id> v=<n> [key=value …] -->` + the question below it
|
|
85
|
+
* `<!-- <tool>:answer ask=<id> [v=<n>] [key=value …] -->` (+ optional note)
|
|
86
|
+
* and the same heads as a bare line form `<tool>:ask id=…` at the start of a line. Attribute values
|
|
87
|
+
* are percent-encoded and space-separated. Other kinds naming an ask (a wait, a delegation) are not
|
|
88
|
+
* answers and are not read.
|
|
89
|
+
*/
|
|
90
|
+
const RECORD_NS = '[a-z][a-z0-9_-]*';
|
|
91
|
+
function recordHeads(text, kind) {
|
|
92
|
+
if (typeof text !== 'string' || text === '') return [];
|
|
93
|
+
const heads = [];
|
|
94
|
+
const markerRe = new RegExp(`<!--\\s*(${RECORD_NS}):${kind}\\s+([^>]*?)\\s*-->`, 'g');
|
|
95
|
+
const lineRe = new RegExp(`^(${RECORD_NS}):${kind}\\s+([^\\n]*)$`, 'gm');
|
|
96
|
+
for (const re of [markerRe, lineRe]) {
|
|
97
|
+
let m;
|
|
98
|
+
while ((m = re.exec(text))) {
|
|
99
|
+
const attrs = parseRecordAttrs(m[2]);
|
|
100
|
+
if (attrs) heads.push({ index: m.index, ns: m[1], attrs });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return heads.sort((a, b) => a.index - b.index);
|
|
104
|
+
}
|
|
105
|
+
/** `k=v k2=v2` → `{k: v, k2: v2}` (values percent-decoded), or null when any token is not `k=v`. */
|
|
106
|
+
function parseRecordAttrs(raw) {
|
|
107
|
+
const out = {};
|
|
108
|
+
const toks = String(raw).trim().split(/\s+/).filter(Boolean);
|
|
109
|
+
if (toks.length === 0) return null;
|
|
110
|
+
for (const t of toks) {
|
|
111
|
+
const m = /^([a-z][a-z0-9_-]*)=(\S*)$/i.exec(t);
|
|
112
|
+
if (!m) return null;
|
|
113
|
+
try { out[m[1]] = decodeURIComponent(m[2]); } catch (_) { out[m[1]] = m[2]; }
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
/** Every ask record in `text`, in order: `{ns, id, version, index}`. Requires `id` and an integer `v >= 1`. */
|
|
118
|
+
function askRecords(text) {
|
|
119
|
+
return recordHeads(text, 'ask')
|
|
120
|
+
.filter((h) => h.attrs.id && /^\d+$/.test(h.attrs.v || '') && Number(h.attrs.v) >= 1)
|
|
121
|
+
.map((h) => ({ ns: h.ns, id: h.attrs.id, version: Number(h.attrs.v), index: h.index }));
|
|
122
|
+
}
|
|
123
|
+
/** Every answer record in `text`, in order: `{ns, ask, version, index}` (`version` null when absent). */
|
|
124
|
+
function answerRecords(text) {
|
|
125
|
+
return recordHeads(text, 'answer')
|
|
126
|
+
.filter((h) => h.attrs.ask)
|
|
127
|
+
.map((h) => ({ ns: h.ns, ask: h.attrs.ask, version: /^\d+$/.test(h.attrs.v || '') ? Number(h.attrs.v) : null, index: h.index }));
|
|
128
|
+
}
|
|
129
|
+
|
|
77
130
|
module.exports = {
|
|
78
131
|
DECISION_MARK, REOPEN_MARK, DECISION_RE, REOPEN_RE,
|
|
79
132
|
encodeDecision, decodeDecision, encodeReopen, decodeReopen,
|
|
80
133
|
OPTIONS_RE, MOCKUP_RE, encodeMockup, mockupUrls,
|
|
134
|
+
askRecords, answerRecords,
|
|
81
135
|
};
|
|
@@ -300,6 +300,47 @@ function evaluateIssue({ labels, comments, labelEvents = null, body, trust } = {
|
|
|
300
300
|
return { recorded, gated, contradiction: recorded && gated, pair, pending, decisions, ask, unshapedAsk };
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
/**
|
|
304
|
+
* #582: the ask records on this issue still waiting on an answer — what `colab decision --record`
|
|
305
|
+
* shows the recorder, so the ruling can name the ask it settles (`--answers <id>`). A consumer that
|
|
306
|
+
* tracks asks reads a nameless ruling as answering the issue's ONLY open ask; with two or more it
|
|
307
|
+
* cannot tell which one the ruling meant.
|
|
308
|
+
*
|
|
309
|
+
* An ask is OPEN when no answer comes AFTER its latest ask record (same id; a re-ask at a higher
|
|
310
|
+
* version reopens it). An answer is either an answer record naming the id, or a live `⚖ Decision
|
|
311
|
+
* recorded` whose `answers` field is that id. Order is by `createdAt`, then position inside one
|
|
312
|
+
* comment. Deliberately NOT trust-filtered: this only decides what to SHOW and whether a nameless
|
|
313
|
+
* record is ambiguous — it gates no start and authorizes nothing.
|
|
314
|
+
*
|
|
315
|
+
* Returns [{id, version, at, ns}], oldest-asked first.
|
|
316
|
+
*/
|
|
317
|
+
function openAsks(comments) {
|
|
318
|
+
const list = Array.isArray(comments) ? comments : [];
|
|
319
|
+
const sorted = list
|
|
320
|
+
.map((c, i) => ({ c, i }))
|
|
321
|
+
.sort((a, b) => (a.c.createdAt < b.c.createdAt ? -1 : a.c.createdAt > b.c.createdAt ? 1 : a.i - b.i));
|
|
322
|
+
const asks = new Map(); // id -> {id, version, at, ns, pos}
|
|
323
|
+
const answers = []; // {id, pos}
|
|
324
|
+
sorted.forEach(({ c }, ci) => {
|
|
325
|
+
const body = String(c.body || '');
|
|
326
|
+
for (const a of codec.askRecords(body)) {
|
|
327
|
+
asks.set(a.id, { id: a.id, version: a.version, at: c.createdAt || null, ns: a.ns, pos: [ci, a.index] });
|
|
328
|
+
}
|
|
329
|
+
for (const r of codec.answerRecords(body)) answers.push({ id: r.ask, pos: [ci, r.index] });
|
|
330
|
+
});
|
|
331
|
+
const live = new Set(liveDecisions(list).map((d) => d.at));
|
|
332
|
+
sorted.forEach(({ c }, ci) => {
|
|
333
|
+
if (!live.has(c.createdAt)) return;
|
|
334
|
+
const d = codec.decodeDecision(c.body);
|
|
335
|
+
if (d && d.answers && d.answers !== '-') answers.push({ id: d.answers, pos: [ci, 0] });
|
|
336
|
+
});
|
|
337
|
+
const after = (p, q) => p[0] > q[0] || (p[0] === q[0] && p[1] > q[1]);
|
|
338
|
+
return [...asks.values()]
|
|
339
|
+
.filter((a) => !answers.some((r) => r.id === a.id && after(r.pos, a.pos)))
|
|
340
|
+
.sort((a, b) => (after(a.pos, b.pos) ? 1 : -1))
|
|
341
|
+
.map(({ id, version, at, ns }) => ({ id, version, at, ns }));
|
|
342
|
+
}
|
|
343
|
+
|
|
303
344
|
module.exports = {
|
|
304
345
|
DECISION_MARK, REOPEN_MARK, DECISION_RE, REOPEN_RE,
|
|
305
346
|
decisionCommentBody, reopenCommentBody,
|
|
@@ -308,4 +349,5 @@ module.exports = {
|
|
|
308
349
|
OPTIONS_RE, PAIR_VERDICTS, pairVerdict,
|
|
309
350
|
MOCKUP_RE, mockupUrls, ASK_SHAPES, askShape,
|
|
310
351
|
evaluateIssue,
|
|
352
|
+
openAsks,
|
|
311
353
|
};
|
package/tools/lib/git.js
CHANGED
|
@@ -691,6 +691,30 @@ function ghPrForBranch(repo, branch) {
|
|
|
691
691
|
} catch (_) { return { error: 'gh pr list returned unparseable JSON' }; }
|
|
692
692
|
}
|
|
693
693
|
|
|
694
|
+
/**
|
|
695
|
+
* #584: EVERY open pull request whose head is `branch` — not just the first, as ghPrForBranch
|
|
696
|
+
* returns — so `colab ship` can close each CI-trigger PR its squash left behind. `{ prs }` on
|
|
697
|
+
* success (possibly empty), `{ error }` when the read failed; never conflate the two.
|
|
698
|
+
*/
|
|
699
|
+
function ghOpenPrsForBranch(repo, branch) {
|
|
700
|
+
const r = gh(['pr', 'list', '--head', branch, '--state', 'open', '--json', 'number,url,headRefOid,headRefName'], { cwd: repo });
|
|
701
|
+
if (!r.ok) return { error: (r.stderr || '').split('\n')[0] || `gh pr list exited ${r.code}` };
|
|
702
|
+
try {
|
|
703
|
+
const list = JSON.parse(r.stdout || '[]');
|
|
704
|
+
return { prs: Array.isArray(list) ? list : [] };
|
|
705
|
+
} catch (_) { return { error: 'gh pr list returned unparseable JSON' }; }
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/** #584: every open pull request in the repo, for `colab doctor --sync`'s landed-PR listing. */
|
|
709
|
+
function ghOpenPrs(repo) {
|
|
710
|
+
const r = gh(['pr', 'list', '--state', 'open', '--limit', '200', '--json', 'number,url,headRefOid,headRefName'], { cwd: repo });
|
|
711
|
+
if (!r.ok) return { error: (r.stderr || '').split('\n')[0] || `gh pr list exited ${r.code}` };
|
|
712
|
+
try {
|
|
713
|
+
const list = JSON.parse(r.stdout || '[]');
|
|
714
|
+
return { prs: Array.isArray(list) ? list : [] };
|
|
715
|
+
} catch (_) { return { error: 'gh pr list returned unparseable JSON' }; }
|
|
716
|
+
}
|
|
717
|
+
|
|
694
718
|
/**
|
|
695
719
|
* #367: the forge's visibility for this repo — "PUBLIC" | "PRIVATE" | "INTERNAL" — or null when it
|
|
696
720
|
* could not be read (no gh, no GitHub remote, offline). Null is "could not read", never "private":
|
|
@@ -1401,5 +1425,5 @@ module.exports = {
|
|
|
1401
1425
|
ghRunJobCount, ghRunJobs, ghWorkflowDispatch,
|
|
1402
1426
|
ghIssueListByLabel, ghLabelDelete, ghLabelCreate, ghListLabelsDetailed, ghLabelEditDescription,
|
|
1403
1427
|
ghApi, isGraphqlRateLimit, ghIssueRelease, ghClaimHolder, ghIssueLabelEvents, ghIssueLabelActors,
|
|
1404
|
-
ghPrForBranch, ghPrCreate, ghPrClose, ghRepoVisibility,
|
|
1428
|
+
ghPrForBranch, ghOpenPrsForBranch, ghOpenPrs, ghPrCreate, ghPrClose, ghRepoVisibility,
|
|
1405
1429
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* #584: a pull request opened only to obtain branch CI stays open forever once `colab ship`
|
|
4
|
+
* squash-lands its branch — the squash is a NEW commit, so the forge never sees the PR's head land,
|
|
5
|
+
* and nothing else closes it. Measured 2026-10-10: five such PRs open on two repos, all landed, the
|
|
6
|
+
* oldest 15 days old, each reading as unmerged work waiting for review.
|
|
7
|
+
*
|
|
8
|
+
* Pure rules only — tools/colab owns the gh calls. Two rules:
|
|
9
|
+
*
|
|
10
|
+
* 1. Close a PR only when its head commit LANDED: the PR head is the landed branch tip, or an
|
|
11
|
+
* ancestor of it. A PR head carrying commits the ship did NOT include (pushed to the remote
|
|
12
|
+
* branch after the local tip was cut, or from another machine) is KEPT, with a warning — closing
|
|
13
|
+
* it would hide work that is not on trunk.
|
|
14
|
+
* 2. Best-effort. A failed list or close is a warning, never a failed ship: the merge already landed
|
|
15
|
+
* and is pushed, so a non-zero exit here would read as "ship failed" and invite a re-merge.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** The comment a closed PR carries — the same shape as #350's close: where it landed, and why. */
|
|
19
|
+
function landedPrComment({ target, sha, issues }) {
|
|
20
|
+
const nums = (issues || []).map((n) => `#${n}`).join(' ');
|
|
21
|
+
return `Landed on \`${target}\` as ${sha} by \`colab ship\`${nums ? ` (${nums})` : ''}. ` +
|
|
22
|
+
'The branch was squash-merged, which the forge cannot see as a merge of this PR, so ship closes it (#584).';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Decide and act on every open PR whose head is the landed branch.
|
|
27
|
+
*
|
|
28
|
+
* prs — the open PRs listed for the branch, as git.ghOpenPrsForBranch returns them:
|
|
29
|
+
* { prs: [{ number, headRefOid, url }] } or { error }
|
|
30
|
+
* headLanded — (oid) => true when that commit is in what landed (tip or ancestor); false otherwise
|
|
31
|
+
* close — (number, comment) => { ok, stderr }
|
|
32
|
+
* comment — the closing comment (landedPrComment)
|
|
33
|
+
* skip — PR numbers already handled by another path (#350's approved review PR)
|
|
34
|
+
*
|
|
35
|
+
* Returns { closed: [n], kept: [{ number, reason }], failed: [{ number, error }], listError }.
|
|
36
|
+
*/
|
|
37
|
+
function closeLandedPrs({ prs, headLanded, close, comment, skip = [] }) {
|
|
38
|
+
const out = { closed: [], kept: [], failed: [], listError: null };
|
|
39
|
+
if (!prs || prs.error || !Array.isArray(prs.prs)) { out.listError = (prs && prs.error) || 'could not list open PRs'; return out; }
|
|
40
|
+
const skipSet = new Set(skip.map(Number));
|
|
41
|
+
for (const pr of prs.prs) {
|
|
42
|
+
const number = Number(pr.number);
|
|
43
|
+
if (!Number.isFinite(number) || skipSet.has(number)) continue;
|
|
44
|
+
let landed = false;
|
|
45
|
+
try { landed = !!(pr.headRefOid && headLanded(pr.headRefOid)); } catch (_) { landed = false; }
|
|
46
|
+
if (!landed) {
|
|
47
|
+
out.kept.push({ number, reason: `its head ${String(pr.headRefOid || '?').slice(0, 12)} is not in what landed` });
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
let r;
|
|
51
|
+
try { r = close(number, comment); } catch (e) { r = { ok: false, stderr: e.message }; }
|
|
52
|
+
if (r && r.ok) out.closed.push(number);
|
|
53
|
+
else out.failed.push({ number, error: ((r && r.stderr) || 'gh pr close failed').split('\n')[0] });
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = { landedPrComment, closeLandedPrs };
|