@feigi/fleet-ctl 3.119.0 → 3.121.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.
- package/package.json +1 -1
- package/scripts/finisher-label.mjs +23 -5
- package/scripts/fleet-event.mjs +39 -19
- package/scripts/ledger.mjs +39 -9
- package/scripts/merge-gate.mjs +24 -2
- package/scripts/pull.mjs +46 -31
package/package.json
CHANGED
|
@@ -39,6 +39,13 @@
|
|
|
39
39
|
// head record names this pin is left as it is — no comment, no label write —
|
|
40
40
|
// and still answers 0 off the read-back, `added: false`.
|
|
41
41
|
//
|
|
42
|
+
// `ready-to-merge` above is a Label role (label-map.mjs): the label written,
|
|
43
|
+
// and the one the idempotence check and the read-back look for, is the Label
|
|
44
|
+
// map's string for it, read once from the repository `--repo` names (the cwd
|
|
45
|
+
// when omitted) before step 0. The head record is not a label: its prefix is
|
|
46
|
+
// `ready-to-merge-head:` whatever the map says, the grammar the merge bot
|
|
47
|
+
// parses back.
|
|
48
|
+
//
|
|
42
49
|
// Stdout is always one JSON line, the receipt:
|
|
43
50
|
//
|
|
44
51
|
// {pr, pin, ticketless, releaseLabels, patchAdded, inert, commented, added,
|
|
@@ -54,8 +61,8 @@
|
|
|
54
61
|
// added this run wrote the label
|
|
55
62
|
// readBack every label name the step 4 read carried, null if it never ran
|
|
56
63
|
// firstRead every label name step 1 read carried, null if it never ran
|
|
57
|
-
// step on exit 2 only, the step that failed: `pin`, `repo`,
|
|
58
|
-
// step whose `gh` call failed
|
|
64
|
+
// step on exit 2 only, the step that failed: `pin`, `repo`,
|
|
65
|
+
// `label-map`, or the step whose `gh` call failed
|
|
59
66
|
// error on exit 2 only, what `gh` (or the invocation) said
|
|
60
67
|
//
|
|
61
68
|
// A usage error that never reaches `gh` — a missing or unknown flag — is a
|
|
@@ -64,8 +71,10 @@
|
|
|
64
71
|
// Exit vocabulary:
|
|
65
72
|
//
|
|
66
73
|
// 0 the read-back carries `ready-to-merge`
|
|
67
|
-
// 2 the invocation or a `gh` call failed,
|
|
68
|
-
//
|
|
74
|
+
// 2 the invocation or a `gh` call failed, the Label map could not be read
|
|
75
|
+
// (an absent or invalid map's error names `label-map.mjs ensure`), or the
|
|
76
|
+
// Ticketless test could not look — its stderr is in the receipt and on
|
|
77
|
+
// stderr, and no later step ran
|
|
69
78
|
// 3 the PR does not carry exactly one release label — nothing was written
|
|
70
79
|
// 4 every write returned 0 and the read-back does not carry the label
|
|
71
80
|
// 5 a Ticketless PR whose diff is not inert, or whose verdict could not
|
|
@@ -79,10 +88,10 @@ import { makeDie, defineFlags, writeAll } from "./arg.mjs";
|
|
|
79
88
|
import { inertVerdict } from "./finisher-scope.mjs";
|
|
80
89
|
import { gitEnv } from "./git-env.mjs";
|
|
81
90
|
import { LABEL_LIST_ARGS, LABEL_LIST_LIMIT, releaseLabelsDefined, releaseLabelsIn } from "./release-labels.mjs";
|
|
91
|
+
import { readLabelMap } from "./label-map.mjs";
|
|
82
92
|
import { ticketlessVerdict } from "./ticketless.mjs";
|
|
83
93
|
|
|
84
94
|
const NAME = "finisher-label";
|
|
85
|
-
const LABEL = "ready-to-merge";
|
|
86
95
|
|
|
87
96
|
const die = makeDie(NAME);
|
|
88
97
|
const { arg, numArg, sweep, stray } = defineFlags(die, {
|
|
@@ -140,6 +149,15 @@ if (repo !== null && !statSync(repo, { throwIfNoEntry: false })?.isDirectory())
|
|
|
140
149
|
fail("repo", `--repo is not a directory: ${repo}`);
|
|
141
150
|
}
|
|
142
151
|
|
|
152
|
+
// The tracker's string for the `ready-to-merge` role, in the repository `gh`
|
|
153
|
+
// runs in.
|
|
154
|
+
let LABEL;
|
|
155
|
+
try {
|
|
156
|
+
LABEL = readLabelMap({ cwd: resolve(repo ?? ".") })["ready-to-merge"];
|
|
157
|
+
} catch (e) {
|
|
158
|
+
fail("label-map", e.message);
|
|
159
|
+
}
|
|
160
|
+
|
|
143
161
|
// `gh` resolves its repository from the cwd's git remotes, so an ambient
|
|
144
162
|
// GIT_DIR would retarget every call at another repository.
|
|
145
163
|
const GH_ENV = gitEnv();
|
package/scripts/fleet-event.mjs
CHANGED
|
@@ -168,6 +168,10 @@
|
|
|
168
168
|
// `NEED <what> …` line, at the left margin, for the controller to make by
|
|
169
169
|
// hand.
|
|
170
170
|
//
|
|
171
|
+
// The labels this script compares and writes are the Label map's strings
|
|
172
|
+
// (label-map.mjs), read once at the command's entry; the label names in this
|
|
173
|
+
// header are Label roles, and the map's string stands where it says one.
|
|
174
|
+
//
|
|
171
175
|
// Exit: 0 every write made and the tick exited 0. 2 a usage error, refused
|
|
172
176
|
// before anything is written or ticked: an unknown kind or flag, a `--reason`
|
|
173
177
|
// that is empty or beside any kind but `drain` and `undrain`, a `--session`
|
|
@@ -175,7 +179,8 @@
|
|
|
175
179
|
// a name that is no ledger member, no session directory, a session directory
|
|
176
180
|
// that cannot be listed, a heartbeat file that cannot be used), a member of
|
|
177
181
|
// the wrong family, a review path outside the PR's partition or a file that
|
|
178
|
-
// is no review result, a ledger or phase-0 receipt that cannot be read
|
|
182
|
+
// is no review result, a ledger or phase-0 receipt that cannot be read, no
|
|
183
|
+
// valid Label map (the message names `label-map.mjs ensure`). A
|
|
179
184
|
// ledger write's own refusal — `settle`'s 3 (the report's claim and the world
|
|
180
185
|
// disagree) or 2, `token`'s or `review`'s 2 — passes its exit and message
|
|
181
186
|
// through, as do `closeout.mjs begin`'s and `reopen`'s 2 or 3 and the
|
|
@@ -194,6 +199,7 @@ import { makeDie, defineFlags, isDigits, writeAll } from "./arg.mjs";
|
|
|
194
199
|
import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
|
|
195
200
|
import { gitEnv } from "./git-env.mjs";
|
|
196
201
|
import { isCLI } from "./is-cli.mjs";
|
|
202
|
+
import { LabelMapUnreadable, readLabelMap } from "./label-map.mjs";
|
|
197
203
|
import { BRIEFS, REVIEW, REVIEWED, REVIEWER, dispositionsToken, memberTokens, nextReviewerName, parseDispatchedEntry, parseMember, parseToken, readRetired, rowNums } from "./ledger-grammar.mjs";
|
|
198
204
|
import { NO_TRANSCRIPT_AFTER_DEFAULT, PARKS, controllerState, foldLedger, parkedToken } from "./fleet-tick.mjs";
|
|
199
205
|
import { phase0Gate, readRunReceipt, tickCaps } from "./phase0-receipt.mjs";
|
|
@@ -206,7 +212,6 @@ const SCRIPTS = dirname(fileURLToPath(import.meta.url));
|
|
|
206
212
|
const MAX_BUFFER = 64 * 1024 * 1024;
|
|
207
213
|
const GH_TIMEOUT_MS = 60_000;
|
|
208
214
|
const CHILD_TIMEOUT_MS = 300_000;
|
|
209
|
-
const READY = "ready-to-merge";
|
|
210
215
|
|
|
211
216
|
const KINDS = {
|
|
212
217
|
"impl-report": { args: ["<member>"], family: "impl" },
|
|
@@ -227,14 +232,16 @@ const FLAGS = { "in-flight": "value", reason: "value", session: "value" };
|
|
|
227
232
|
const USAGE = `usage: ${NAME}.mjs <kind> <args> [--in-flight <n>] — kinds: `
|
|
228
233
|
+ Object.entries(KINDS).map(([k, { args, flag }]) => [k, ...args, ...(flag ? [flag] : [])].join(" ")).join(", ");
|
|
229
234
|
|
|
230
|
-
// The
|
|
231
|
-
//
|
|
232
|
-
//
|
|
235
|
+
// The Label role each `bailCause` demotes to, and the relabel template's kind;
|
|
236
|
+
// the tracker's string for the role is the map's, resolved where the label is
|
|
237
|
+
// written. `fixed` takes no role: it closes the ticket once `verify-sha.sh`
|
|
238
|
+
// finds the commit on origin/main, and demotes to `needs-triage` when it does
|
|
239
|
+
// not.
|
|
233
240
|
export const BAILS = {
|
|
234
|
-
undecided: {
|
|
235
|
-
fork: {
|
|
236
|
-
hands: {
|
|
237
|
-
covered: {
|
|
241
|
+
undecided: { role: "needs-triage", kind: "needs-triage", flag: "line" },
|
|
242
|
+
fork: { role: "ready-for-human", kind: "fork", flag: "options" },
|
|
243
|
+
hands: { role: "ready-for-human", kind: "hands" },
|
|
244
|
+
covered: { role: "ready-for-human", kind: "covered", flag: "detail" },
|
|
238
245
|
fixed: { kind: "fixed", flag: "detail" },
|
|
239
246
|
};
|
|
240
247
|
// The commit a `fixed` bail's detail opens with.
|
|
@@ -415,7 +422,8 @@ function relabelArgs(cause, detail) {
|
|
|
415
422
|
}
|
|
416
423
|
|
|
417
424
|
// The comment `dispatch-prompt.mjs render relabel` renders for a bail, or null
|
|
418
|
-
// when there is none (the NEED, named `what`, is printed here).
|
|
425
|
+
// when there is none (the NEED, named `what`, is printed here). The template
|
|
426
|
+
// names the role `ready-for-agent`; the comment filed names the map's string.
|
|
419
427
|
function rendered(ev, ticket, cause, detail, what) {
|
|
420
428
|
const relabel = relabelArgs(cause, detail);
|
|
421
429
|
if (relabel.why !== undefined) {
|
|
@@ -427,18 +435,23 @@ function rendered(ev, ticket, cause, detail, what) {
|
|
|
427
435
|
ev.need(`${what} #${ticket} — dispatch-prompt.mjs render relabel refused: ${said(r)}`);
|
|
428
436
|
return null;
|
|
429
437
|
}
|
|
430
|
-
return r.stdout;
|
|
438
|
+
return r.stdout.replaceAll("`ready-for-agent`", `\`${ev.labels["ready-for-agent"]}\``);
|
|
431
439
|
}
|
|
432
440
|
|
|
441
|
+
// The map's strings for the labels a pulled ticket carries, which a demotion
|
|
442
|
+
// or a close takes off.
|
|
443
|
+
const pulledLabels = (ev) => [ev.labels["ready-for-agent"], ev.labels["in-progress"]];
|
|
444
|
+
|
|
433
445
|
// Moves #ticket to `label`, then posts the comment `body()` returns, if any.
|
|
434
446
|
// False when the move could not be made, so nothing after it may run.
|
|
435
447
|
function demote(ev, ticket, label, cause, body) {
|
|
436
448
|
const seen = ev.comments("issue", ticket, `relabel #${ticket} ${label}`);
|
|
437
449
|
if (seen === null) return false;
|
|
438
|
-
|
|
450
|
+
const pulled = pulledLabels(ev);
|
|
451
|
+
if (seen.labels.includes(label) && !pulled.some((l) => seen.labels.includes(l))) {
|
|
439
452
|
ev.note(`#${ticket} already ${label}`);
|
|
440
453
|
} else {
|
|
441
|
-
const e = gh(["issue", "edit", String(ticket),
|
|
454
|
+
const e = gh(["issue", "edit", String(ticket), ...pulled.flatMap((l) => ["--remove-label", l]), "--add-label", label]);
|
|
442
455
|
if (e.status !== 0) {
|
|
443
456
|
ev.need(`relabel #${ticket} ${label} — gh issue edit failed: ${said(e)}`);
|
|
444
457
|
return false;
|
|
@@ -461,7 +474,7 @@ function fixed(ev, ticket, detail) {
|
|
|
461
474
|
}
|
|
462
475
|
const v = run("sh", [join(SCRIPTS, "verify-sha.sh"), "main", sha]);
|
|
463
476
|
if (v.status === 1) {
|
|
464
|
-
return demote(ev, ticket, "needs-triage", "fixed", () => `*Relabelled by the fleet controller.* Pulled for implementation and returned as already fixed by ${sha}: ${sha} not on origin/main.`);
|
|
477
|
+
return demote(ev, ticket, ev.labels["needs-triage"], "fixed", () => `*Relabelled by the fleet controller.* Pulled for implementation and returned as already fixed by ${sha}: ${sha} not on origin/main.`);
|
|
465
478
|
}
|
|
466
479
|
if (v.status !== 0) {
|
|
467
480
|
ev.need(`close #${ticket} — verify-sha.sh main ${sha} could not answer (${v.how}): ${said(v)}`);
|
|
@@ -482,7 +495,7 @@ function fixed(ev, ticket, detail) {
|
|
|
482
495
|
}
|
|
483
496
|
ev.note(`closed #${ticket}: fixed by ${sha}`);
|
|
484
497
|
}
|
|
485
|
-
const stale =
|
|
498
|
+
const stale = pulledLabels(ev).filter((l) => seen.labels.includes(l));
|
|
486
499
|
if (stale.length > 0) {
|
|
487
500
|
const e = gh(["issue", "edit", String(ticket), ...stale.flatMap((l) => ["--remove-label", l])]);
|
|
488
501
|
if (e.status !== 0) ev.need(`unlabel #${ticket} ${stale.join(" ")} — gh issue edit failed: ${said(e)}`);
|
|
@@ -501,7 +514,7 @@ function bailed(ev, member) {
|
|
|
501
514
|
const detail = read.report.bailDetail;
|
|
502
515
|
const moved = cause === "fixed"
|
|
503
516
|
? fixed(ev, ticket, detail)
|
|
504
|
-
: demote(ev, ticket, BAILS[cause].
|
|
517
|
+
: demote(ev, ticket, ev.labels[BAILS[cause].role], cause, () => rendered(ev, ticket, cause, detail, "relabel-comment"));
|
|
505
518
|
if (!moved) return;
|
|
506
519
|
const release = run("sh", [join(SCRIPTS, "release-ticket.sh"), String(ticket), `impl-${ticket}`, "implementer", "--apply"]);
|
|
507
520
|
if (release.status === 0) ev.note(`released #${ticket}`);
|
|
@@ -616,7 +629,7 @@ function finisherReport(ev, member) {
|
|
|
616
629
|
}
|
|
617
630
|
// The escalation is for a repair finisher that claims the label and reads
|
|
618
631
|
// back none; a halt says why in its own comment above.
|
|
619
|
-
if (self.retry === null || report?.outcome !== "labelled" || report.labelsReadBack.includes(
|
|
632
|
+
if (self.retry === null || report?.outcome !== "labelled" || report.labelsReadBack.includes(ev.labels["ready-to-merge"])) return;
|
|
620
633
|
const earlier = ledgerMembers(ev.ledger)
|
|
621
634
|
.filter((t) => t.family === "finisher-pr" && t.number === pr && (t.retry ?? "") < self.retry)
|
|
622
635
|
.sort((a, b) => (a.retry ?? "").localeCompare(b.retry ?? "")).at(-1)?.name;
|
|
@@ -625,7 +638,7 @@ function finisherReport(ev, member) {
|
|
|
625
638
|
const prior = ev.report(earlier);
|
|
626
639
|
before = prior.state === "ok" ? `${earlier} read back: ${listed(prior.report.labelsReadBack)}` : `${earlier}'s report ${prior.path} is ${prior.state}`;
|
|
627
640
|
}
|
|
628
|
-
const body = `**${member}, a repair finisher, read back no \`${
|
|
641
|
+
const body = `**${member}, a repair finisher, read back no \`${ev.labels["ready-to-merge"]}\` on PR #${pr}.**\n\n`
|
|
629
642
|
+ `- ${member} read back: ${listed(report.labelsReadBack)}\n- ${before}`;
|
|
630
643
|
const seen = ev.comments("pr", pr, `escalation-comment PR #${pr}`);
|
|
631
644
|
if (seen !== null) ev.comment("pr", pr, body, seen, "escalation comment");
|
|
@@ -977,7 +990,14 @@ function main() {
|
|
|
977
990
|
const caps = tickCaps(fleetDir);
|
|
978
991
|
if (caps.error) die(`${caps.error} — nothing written`);
|
|
979
992
|
const tickArgs = ["--apply", ...(inFlight === null ? caps.args : ["--in-flight", inFlight]), ...(kind === "heartbeat" ? ["--fold-unchanged"] : [])];
|
|
980
|
-
|
|
993
|
+
let labels;
|
|
994
|
+
try {
|
|
995
|
+
labels = readLabelMap();
|
|
996
|
+
} catch (e) {
|
|
997
|
+
if (!(e instanceof LabelMapUnreadable)) throw e;
|
|
998
|
+
die(`${e.message} — nothing written`);
|
|
999
|
+
}
|
|
1000
|
+
const ev = new Event({ fleetDir, scratch, labels, ledger: readLedger() });
|
|
981
1001
|
if (kind === "impl-report") implReport(ev, args[0]);
|
|
982
1002
|
else if (kind === "fix-report") fixReport(ev, args[0]);
|
|
983
1003
|
else if (kind === "finisher-report") finisherReport(ev, args[0]);
|
package/scripts/ledger.mjs
CHANGED
|
@@ -72,6 +72,7 @@ import { mergeBotVerdicts } from "./report-schema.mjs";
|
|
|
72
72
|
import { ownClosingIssues } from "./closing-refs.mjs";
|
|
73
73
|
import { isTicketless } from "./ticketless.mjs";
|
|
74
74
|
import { RELEASE_LABELS, LABEL_LIST_ARGS, LABEL_LIST_LIMIT, releaseLabelsIn, releaseLabelsDefined } from "./release-labels.mjs";
|
|
75
|
+
import { LabelMapUnreadable, readLabelMap } from "./label-map.mjs";
|
|
75
76
|
|
|
76
77
|
const NAME = "ledger";
|
|
77
78
|
// The plugin's own agent definitions — the directory tier-check.mjs reads
|
|
@@ -2160,20 +2161,40 @@ function releaseLabelRefusal(member, tickets, refs) {
|
|
|
2160
2161
|
return `${missing} and ${closes} — add exactly one, the bump its change calls for: gh pr edit ${pr} --add-label <${RELEASE_LABELS.join("|")}>`;
|
|
2161
2162
|
}
|
|
2162
2163
|
|
|
2164
|
+
// The tracker's string for the `ready-to-merge` Label role, off the Label map
|
|
2165
|
+
// of the repository `dir` belongs to (label-map.mjs). Only the two paths that
|
|
2166
|
+
// compare or list that label read it — `dispatch merge-bot`'s queueSnapshot()
|
|
2167
|
+
// and settle --from-report's finisher and merge-bot checks — so every other
|
|
2168
|
+
// verb runs with no map at all. A map that cannot be read, or no repository
|
|
2169
|
+
// to find one in, is exit 2 under `where`, carrying the reader's message (an
|
|
2170
|
+
// absent or invalid map's names `label-map.mjs ensure`); nothing written.
|
|
2171
|
+
function readyLabel(dir, where) {
|
|
2172
|
+
try {
|
|
2173
|
+
return readLabelMap({ cwd: dir })["ready-to-merge"];
|
|
2174
|
+
} catch (e) {
|
|
2175
|
+
if (!(e instanceof LabelMapUnreadable) && !(e instanceof FleetDirUnresolvable)) throw e;
|
|
2176
|
+
die(`${where}: ${e.message}; nothing written`);
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2163
2180
|
// The open `ready-to-merge` PRs, ascending, as gh answers from the ledger's
|
|
2164
2181
|
// own directory with runCheck()'s environment: the queue a merge bot is
|
|
2165
2182
|
// dispatched against, recorded on its `## Dispatched` entry. Anything but a
|
|
2166
2183
|
// JSON array of PR numbers, or an answer filling the limit — gh stops there
|
|
2167
|
-
// at exit 0 — could not read the queue: refused, nothing written.
|
|
2184
|
+
// at exit 0 — could not read the queue: refused, nothing written. The label
|
|
2185
|
+
// gh lists by is the Label map's string for the role, see readyLabel().
|
|
2168
2186
|
function queueSnapshot() {
|
|
2169
2187
|
const limit = 1000;
|
|
2170
|
-
|
|
2188
|
+
let dir = dirname(resolve(file));
|
|
2189
|
+
while (!existsSync(dir) && dirname(dir) !== dir) dir = dirname(dir);
|
|
2190
|
+
const ready = readyLabel(dir, "dispatch merge-bot");
|
|
2191
|
+
// An argv, never `what` split on spaces: a mapped string may hold one.
|
|
2192
|
+
const args = ["pr", "list", "--state", "open", "--label", ready, "--limit", String(limit), "--json", "number"];
|
|
2193
|
+
const what = `gh ${args.join(" ")}`;
|
|
2171
2194
|
const env = { ...process.env, GH_REPO: "" };
|
|
2172
2195
|
delete env.GIT_DIR;
|
|
2173
2196
|
delete env.GIT_WORK_TREE;
|
|
2174
|
-
|
|
2175
|
-
while (!existsSync(dir) && dirname(dir) !== dir) dir = dirname(dir);
|
|
2176
|
-
const r = spawnSync("gh", what.split(" ").slice(1), { encoding: "utf8", cwd: dir, env, timeout: 60_000, stdio: ["ignore", "pipe", "pipe"] });
|
|
2197
|
+
const r = spawnSync("gh", args, { encoding: "utf8", cwd: dir, env, timeout: 60_000, stdio: ["ignore", "pipe", "pipe"] });
|
|
2177
2198
|
const refuse = (why) => die(`dispatch merge-bot: could not read the queue to record — ${what}${why}; nothing written`);
|
|
2178
2199
|
if (r.status !== 0) {
|
|
2179
2200
|
const why = cause(r.error && r.error.message, r.stderr);
|
|
@@ -2637,6 +2658,11 @@ function recordFiled(id, subject) {
|
|
|
2637
2658
|
// conflictHold or refused, or no longer reads
|
|
2638
2659
|
// OPEN with ready-to-merge
|
|
2639
2660
|
//
|
|
2661
|
+
// `ready-to-merge` in both rows is the Label map's string for the role, read
|
|
2662
|
+
// by readyLabel() only when one of the two checks runs: on a finisher's
|
|
2663
|
+
// `labelled`, and on a merge bot's report that leaves a PR queued at dispatch
|
|
2664
|
+
// without a verdict.
|
|
2665
|
+
//
|
|
2640
2666
|
// THE CHECK-STEP RECORD, for `impl-N=PR#M` and `fix-pr-M=applied:<head>`:
|
|
2641
2667
|
// recipe-check.mjs writes `<reports>/<member>.check.json` on the member's
|
|
2642
2668
|
// staged tree, and settle requires that it exists and parses, that the Check
|
|
@@ -2655,8 +2681,9 @@ function recordFiled(id, subject) {
|
|
|
2655
2681
|
// stderr names each failed check; nothing written. Exit 2: the report is
|
|
2656
2682
|
// absent, unreadable or invalid, a check could not look (a `gh`, `git` or
|
|
2657
2683
|
// verify-sha.sh call that failed, printed what it was not asked for, or never
|
|
2658
|
-
// finished), a merge bot's `## Dispatched` entry records no queued=,
|
|
2659
|
-
// refusal the bare form makes; nothing
|
|
2684
|
+
// finished), a merge bot's `## Dispatched` entry records no queued=, the
|
|
2685
|
+
// Label map could not be read, or a refusal the bare form makes; nothing
|
|
2686
|
+
// written either.
|
|
2660
2687
|
//
|
|
2661
2688
|
// After the settle, in the same write: every `unrecorded` entry goes to `##
|
|
2662
2689
|
// Filed` the way `filed` records one, for a fix-applier every `deferred`
|
|
@@ -2690,7 +2717,6 @@ function mismatch(msg) {
|
|
|
2690
2717
|
async function runSettleFromReport() {
|
|
2691
2718
|
const usage = "usage: ledger.mjs settle <member> --from-report [--reports <dir>]";
|
|
2692
2719
|
const deriveTestcmd = join(dirname(fileURLToPath(import.meta.url)), "derive-testcmd.sh");
|
|
2693
|
-
const ready = "ready-to-merge";
|
|
2694
2720
|
let member;
|
|
2695
2721
|
let reports = null;
|
|
2696
2722
|
for (let k = 0; k < rest.length; k++) {
|
|
@@ -2842,6 +2868,7 @@ async function runSettleFromReport() {
|
|
|
2842
2868
|
} else if (live.family === "finisher-pr") {
|
|
2843
2869
|
if (report.outcome === "labelled") {
|
|
2844
2870
|
outcome = "labelled";
|
|
2871
|
+
const ready = readyLabel(repoDir(), where);
|
|
2845
2872
|
const pr = prView(live.number, "labels");
|
|
2846
2873
|
check(`PR #${live.number} carries ${ready}`, pr.labels.some((l) => l?.name === ready));
|
|
2847
2874
|
check(`labelsReadBack carries ${ready}`, report.labelsReadBack.includes(ready));
|
|
@@ -2865,7 +2892,10 @@ async function runSettleFromReport() {
|
|
|
2865
2892
|
die(`${where}: ## Dispatched records no queued= for ${member}, so whether its report gives every PR queued at dispatch a verdict cannot be judged — settle it by hand; nothing written`);
|
|
2866
2893
|
}
|
|
2867
2894
|
const given = new Set(mergeBotVerdicts(report).map((v) => v.pr));
|
|
2868
|
-
|
|
2895
|
+
const unjudged = queued.filter((n) => !given.has(n));
|
|
2896
|
+
// The map is read only when a queued PR's labels are to be looked at.
|
|
2897
|
+
const ready = unjudged.length > 0 ? readyLabel(repoDir(), where) : null;
|
|
2898
|
+
for (const pr of unjudged) {
|
|
2869
2899
|
const v = prView(pr, "state,labels");
|
|
2870
2900
|
const left = v.state !== "OPEN" || !v.labels.some((l) => l?.name === ready);
|
|
2871
2901
|
check(`PR #${pr}, queued at dispatch, has a verdict in merged, held, conflictHold or refused, or has left the queue`, left);
|
package/scripts/merge-gate.mjs
CHANGED
|
@@ -34,7 +34,11 @@
|
|
|
34
34
|
// main-gain.mjs's own payload — hits, acknowledged removals, edited lines and unchecked
|
|
35
35
|
// files — or null when it did not run or printed no JSON object; an unusable
|
|
36
36
|
// payload is still echoed. Stderr: the children's own diagnostics, passed
|
|
37
|
-
// straight through and never folded into stdout.
|
|
37
|
+
// straight through and never folded into stdout. A refusal (exit 2 with its
|
|
38
|
+
// reason on stderr: a usage error, a Label map that cannot be read — see THE
|
|
39
|
+
// LABEL MAP below — an `--out` that cannot be written, a gate that failed)
|
|
40
|
+
// prints no JSON line, and one made before any child runs writes no `--out`
|
|
41
|
+
// file.
|
|
38
42
|
//
|
|
39
43
|
// Exit vocabulary — the same three-way contract as inflight.sh, prove-merge.sh
|
|
40
44
|
// and staleness.mjs:
|
|
@@ -50,6 +54,7 @@
|
|
|
50
54
|
// could-not-evaluate row fires further down instead:
|
|
51
55
|
//
|
|
52
56
|
// label `ready-to-merge` absent 1 label-pulled
|
|
57
|
+
// (the Label map's string for the role)
|
|
53
58
|
// reviewDecision CHANGES_REQUESTED 1 changes-requested
|
|
54
59
|
// PR head not in {pre, post} and not a 1 head-moved-after-label
|
|
55
60
|
// proven rebase-carry of pre
|
|
@@ -79,6 +84,13 @@
|
|
|
79
84
|
// so a conflict-free rebase keeps it. Anything the proof cannot establish —
|
|
80
85
|
// a missing object, an unresolvable base, a git failure, a merge conflict — is
|
|
81
86
|
// no carry, and the head row blocks exactly as it does for any other moved head.
|
|
87
|
+
//
|
|
88
|
+
// THE LABEL MAP: `ready-to-merge` is a Label role (label-map.mjs). Its string
|
|
89
|
+
// is read off the Label map once, after the arguments are checked and before
|
|
90
|
+
// any child runs, and the label row compares the PR's labels against that
|
|
91
|
+
// string. A map that cannot be read, or no repository to find one in, is a
|
|
92
|
+
// refusal at exit 2 carrying the reader's message (an absent or invalid map's
|
|
93
|
+
// names `label-map.mjs ensure`); nothing runs.
|
|
82
94
|
|
|
83
95
|
import { spawnSync } from "node:child_process";
|
|
84
96
|
import { createHash } from "node:crypto";
|
|
@@ -87,6 +99,7 @@ import { dirname, join } from "node:path";
|
|
|
87
99
|
import { fileURLToPath } from "node:url";
|
|
88
100
|
import { makeDie, defineFlags, writeAll } from "./arg.mjs";
|
|
89
101
|
import { gitEnv, mainCheckoutDirFromGitCommonDir } from "./git-env.mjs";
|
|
102
|
+
import { readLabelMap } from "./label-map.mjs";
|
|
90
103
|
|
|
91
104
|
const NAME = "merge-gate";
|
|
92
105
|
|
|
@@ -129,6 +142,15 @@ const pre = sha("pre", preArg);
|
|
|
129
142
|
const post = postArg === null ? null : sha("post", postArg);
|
|
130
143
|
const heads = new Set([pre, post ?? pre]);
|
|
131
144
|
|
|
145
|
+
// The tracker's string for the `ready-to-merge` role. Every refusal here,
|
|
146
|
+
// typed or not, is exit 2: an uncaught throw would exit 1, "blocked".
|
|
147
|
+
let ready;
|
|
148
|
+
try {
|
|
149
|
+
ready = readLabelMap()["ready-to-merge"];
|
|
150
|
+
} catch (e) {
|
|
151
|
+
die(e.message);
|
|
152
|
+
}
|
|
153
|
+
|
|
132
154
|
// --- rebase-carry proof ----------------------------------------------------
|
|
133
155
|
// Same net change: `git diff-tree` of each head against its own merge base
|
|
134
156
|
// with `origin/main`, in the main checkout, compared byte for byte after
|
|
@@ -358,7 +380,7 @@ function decide(instruments, prView, mainGain, ciRead, rebaseCarry) {
|
|
|
358
380
|
// at ci-state's read is still not one of them.
|
|
359
381
|
const accepted = rebaseCarry === null ? heads : new Set([...heads, rebaseCarry.accepted]);
|
|
360
382
|
if (prView !== null) {
|
|
361
|
-
if (!prView.labels.some((l) => l.name ===
|
|
383
|
+
if (!prView.labels.some((l) => l.name === ready)) return blocked("label-pulled");
|
|
362
384
|
if (prView.reviewDecision === "CHANGES_REQUESTED") return blocked("changes-requested");
|
|
363
385
|
if (!accepted.has(prView.headRefOid)) return blocked("head-moved-after-label");
|
|
364
386
|
}
|
package/scripts/pull.mjs
CHANGED
|
@@ -24,17 +24,19 @@
|
|
|
24
24
|
// a Pull for a ticket whose ledger row is an exclusion naming no premise,
|
|
25
25
|
// or one whose premise still stands, is this exit as well.
|
|
26
26
|
// 2 could not look, named on stderr: a probe that did not answer, a write
|
|
27
|
-
// that failed, a router that refused
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
27
|
+
// that failed, a router that refused, or no valid Label map (the message
|
|
28
|
+
// names `label-map.mjs ensure`; the labels the Pull compares, writes and
|
|
29
|
+
// names in its comments are the map's strings, read once at the command's
|
|
30
|
+
// entry). `next --head <N>` runs a step that failed again; when the failure
|
|
31
|
+
// came from applying an answer, the question stands and the answer is given
|
|
32
|
+
// again. A router that refused has its claim released and the Pull is over,
|
|
33
|
+
// `next --head <N>` starting the ticket over; one whose claim could not be
|
|
34
|
+
// released leaves the Pull at the route step with the claim standing, and
|
|
35
|
+
// `next` routes again. An exclusion premise `gh` could not read is exit 2
|
|
36
|
+
// when no other entry is left, and always exit 2 when `next --head <N>`
|
|
37
|
+
// starts a Pull for the ticket that holds it, the exclusion standing and no
|
|
38
|
+
// record written. An unknown flag is exit 2 as well, as for every script
|
|
39
|
+
// that holds a command line of its own.
|
|
38
40
|
// 3 usage: any other mistake in the command line, or an answer the pending
|
|
39
41
|
// question does not take. Nothing is recorded.
|
|
40
42
|
// 10 a question is pending: its `QUESTION <qid>:` block, with the tokens it
|
|
@@ -136,6 +138,7 @@ import { isDigits, makeDie } from "./arg.mjs";
|
|
|
136
138
|
import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
|
|
137
139
|
import { gitEnv } from "./git-env.mjs";
|
|
138
140
|
import { isCLI } from "./is-cli.mjs";
|
|
141
|
+
import { LabelMapUnreadable, readLabelMap } from "./label-map.mjs";
|
|
139
142
|
import { EXCLUDED_REASON, POLICY_CELL, memberTokens, parseRouting, premisesOf, pullEnded, tierValues } from "./ledger-grammar.mjs";
|
|
140
143
|
import { sessionFromReceipt } from "./phase0-receipt.mjs";
|
|
141
144
|
import { briefPaths, briefText, defang, outOfScope, strandedRuling, ticketText } from "./ticket-text.mjs";
|
|
@@ -155,10 +158,6 @@ const EXPLORE_EVERY = 5;
|
|
|
155
158
|
// The states that lift an exclusion's premise.
|
|
156
159
|
const LIFTED = new Set(["MERGED", "CLOSED"]);
|
|
157
160
|
|
|
158
|
-
const READY = "ready-for-agent";
|
|
159
|
-
const TRIAGE = "needs-triage";
|
|
160
|
-
const HUMAN = "ready-for-human";
|
|
161
|
-
|
|
162
161
|
const USAGE = `usage: ${NAME}.mjs next [--head <N>] | ${NAME}.mjs answer <N> <qid> <token> [--path <p>] [--] [<text>…]`;
|
|
163
162
|
|
|
164
163
|
// ── the comments the script posts ────────────────────────────────────────────
|
|
@@ -181,28 +180,31 @@ function handsParts(text) {
|
|
|
181
180
|
}
|
|
182
181
|
|
|
183
182
|
/**
|
|
184
|
-
* The comment, and the label that replaces `ready-for-agent
|
|
185
|
-
* other than `decided` — or, for `stranded-ruling`, for a ruling or
|
|
186
|
-
* comment newer than the brief, `text` naming its heading line and its
|
|
183
|
+
* The comment, and the label that replaces the `ready-for-agent` label, for a
|
|
184
|
+
* Q2 answer other than `decided` — or, for `stranded-ruling`, for a ruling or
|
|
185
|
+
* triage comment newer than the brief, `text` naming its heading line and its
|
|
186
|
+
* URL. `labels` is the Label map (role -> the tracker's string): the label
|
|
187
|
+
* returned and the labels the comment names are its strings.
|
|
187
188
|
*/
|
|
188
|
-
export function relabel(token, text) {
|
|
189
|
+
export function relabel(token, text, labels) {
|
|
190
|
+
const { "ready-for-agent": ready, "ready-for-human": human } = labels;
|
|
189
191
|
if (token === "stranded-ruling") {
|
|
190
192
|
return {
|
|
191
|
-
label:
|
|
192
|
-
comment: `${RELABELLED} a ruling or triage comment is newer than the brief, and the Pull does not read it: ${text}. To make it the brief, rename its heading to \`## Agent Brief — ruling\` and drop anything that is not decided scope, or delete it; then restore \`${
|
|
193
|
+
label: human,
|
|
194
|
+
comment: `${RELABELLED} a ruling or triage comment is newer than the brief, and the Pull does not read it: ${text}. To make it the brief, rename its heading to \`## Agent Brief — ruling\` and drop anything that is not decided scope, or delete it; then restore \`${ready}\`.`,
|
|
193
195
|
};
|
|
194
196
|
}
|
|
195
197
|
if (token === "needs-triage") {
|
|
196
198
|
return {
|
|
197
|
-
label:
|
|
198
|
-
comment: `${RELABELLED} the brief does not decide what to build. Missing decision: ${text}. Returning to /triage; \`${
|
|
199
|
+
label: labels["needs-triage"],
|
|
200
|
+
comment: `${RELABELLED} the brief does not decide what to build. Missing decision: ${text}. Returning to /triage; \`${ready}\` restored once decided.`,
|
|
199
201
|
};
|
|
200
202
|
}
|
|
201
203
|
if (token === "ready-for-human-fork") {
|
|
202
|
-
return { label:
|
|
204
|
+
return { label: human, comment: `${RELABELLED} the brief leaves a decision open. Open fork: ${text}.` };
|
|
203
205
|
}
|
|
204
206
|
const { cause, line } = handsParts(text);
|
|
205
|
-
return { label:
|
|
207
|
+
return { label: human, comment: `${RELABELLED} needs human hands — ${HANDS[cause]}: ${line}.` };
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
/** The comment a `yes` to Q1b closes the issue with. */
|
|
@@ -809,7 +811,7 @@ class Pull {
|
|
|
809
811
|
} catch (e) {
|
|
810
812
|
return this.stop(`cannot write ${this.p.issue}: ${e.message}`);
|
|
811
813
|
}
|
|
812
|
-
if (!issue.labels.some((l) => l?.name ===
|
|
814
|
+
if (!issue.labels.some((l) => l?.name === this.p.labels["ready-for-agent"])) return this.leave("relabelled elsewhere");
|
|
813
815
|
const stranded = strandedRuling(issue);
|
|
814
816
|
if (stranded !== null) {
|
|
815
817
|
if (typeof stranded.url !== "string") return this.stop(`gh issue view printed a ruling comment with no url: "${stranded.heading}"`);
|
|
@@ -1100,17 +1102,20 @@ class Pull {
|
|
|
1100
1102
|
|
|
1101
1103
|
// Posts the cause's comment and swaps `ready-for-agent` for its label. One
|
|
1102
1104
|
// comment per cause: an edit that failed after its comment landed is run
|
|
1103
|
-
// again without a second comment.
|
|
1105
|
+
// again without a second comment. The cause is the token and its text, never
|
|
1106
|
+
// the comment, whose wording takes the Label map's strings and so moves with
|
|
1107
|
+
// the map between the failed edit and the retry.
|
|
1104
1108
|
relabelled(token, text) {
|
|
1105
1109
|
const { st } = this;
|
|
1106
|
-
const { label, comment } = relabel(token, text);
|
|
1107
|
-
|
|
1110
|
+
const { label, comment } = relabel(token, text, this.p.labels);
|
|
1111
|
+
const cause = JSON.stringify([token, text]);
|
|
1112
|
+
if (st.commented !== cause) {
|
|
1108
1113
|
const c = this.gh("relabel", ["issue", "comment", String(st.ticket), "--body", comment]);
|
|
1109
1114
|
if (c.status !== 0) return this.stop(withText(`gh issue comment failed (${c.how})`, c));
|
|
1110
|
-
st.commented =
|
|
1115
|
+
st.commented = cause;
|
|
1111
1116
|
this.save();
|
|
1112
1117
|
}
|
|
1113
|
-
const e = this.gh("relabel", ["issue", "edit", String(st.ticket), "--remove-label",
|
|
1118
|
+
const e = this.gh("relabel", ["issue", "edit", String(st.ticket), "--remove-label", this.p.labels["ready-for-agent"], "--add-label", label]);
|
|
1114
1119
|
if (e.status !== 0) return this.stop(withText(`gh issue edit failed (${e.how}) — the comment is posted`, e));
|
|
1115
1120
|
return this.leave(`relabelled ${label}: ${token}`);
|
|
1116
1121
|
}
|
|
@@ -1257,11 +1262,21 @@ function setup() {
|
|
|
1257
1262
|
}
|
|
1258
1263
|
const root = spawn(process.execPath, [join(SCRIPTS, "scratch-root.mjs")], { cwd });
|
|
1259
1264
|
if (root.status !== 0) throw new Refusal(withText(`scratch-root.mjs ${root.how}`, root));
|
|
1265
|
+
// The Label map, read once here: every label the Pull compares, writes or names in a comment is its string. No
|
|
1266
|
+
// valid map is exit 2, the reader's message naming `label-map.mjs ensure`; never the exit that reads as "left".
|
|
1267
|
+
let labels;
|
|
1268
|
+
try {
|
|
1269
|
+
labels = readLabelMap({ cwd });
|
|
1270
|
+
} catch (e) {
|
|
1271
|
+
if (!(e instanceof LabelMapUnreadable)) throw e;
|
|
1272
|
+
throw new Refusal(e.message);
|
|
1273
|
+
}
|
|
1260
1274
|
const scratch = root.stdout;
|
|
1261
1275
|
const dir = (n) => join(scratch, `impl-${n}`);
|
|
1262
1276
|
return {
|
|
1263
1277
|
cwd,
|
|
1264
1278
|
scratch,
|
|
1279
|
+
labels,
|
|
1265
1280
|
shortlist: join(fleetDir, "shortlist.json"),
|
|
1266
1281
|
guard: join(fleetDir, "cost-guard.json"),
|
|
1267
1282
|
statePath: (n) => join(dir(n), STATE),
|