@feigi/fleet-ctl 3.119.0 → 3.120.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/ledger.mjs +39 -9
- package/scripts/merge-gate.mjs +24 -2
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/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
|
}
|