@futurelastic/colab-handbook 1.14.0-rc.10 → 1.14.0-rc.11
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 +196 -25
- package/tools/lib/git.js +6 -1
- package/tools/lib/ship-batch.js +71 -2
package/package.json
CHANGED
package/tools/colab
CHANGED
|
@@ -10595,7 +10595,7 @@ function ciCureTrailerLine(cureVerdict, branch, trunk) {
|
|
|
10595
10595
|
}
|
|
10596
10596
|
|
|
10597
10597
|
const HELP_SHIP = `colab ship [--repo <path>] [--worktree <name> | --branch <br> | --direct] [--message "<msg>"] [--refs <N[,M]>] [--keep-worktree] [--delete-branch | --keep-branch] [--adopt | --handoff <comment-url>] [--answered-by <name>] [--session <id>] [--session-name <s>] [--dry] [--json]
|
|
10598
|
-
colab ship --batch <b1,b2[@<handoff-url>][,…]> [--split] [--repo <path>] [--keep-worktree] [--delete-branch | --keep-branch] [--session <id>] [--session-name <s>] [--dry]
|
|
10598
|
+
colab ship --batch <b1,b2[@<handoff-url>][,…]> [--split] [--onto ship-batch/<sha7>] [--repo <path>] [--keep-worktree] [--delete-branch | --keep-branch] [--session <id>] [--session-name <s>] [--dry [--json]]
|
|
10599
10599
|
|
|
10600
10600
|
The ONE sanctioned door for code-wrap Phase B: squash-merge a session branch into the BASE IT WAS
|
|
10601
10601
|
CUT FROM — trunk for an ordinary session, or the declared integration line recorded on its worktree
|
|
@@ -10884,7 +10884,20 @@ The batch also holds the trunk LANE (#581): while a ship-batch/<trunk-sha7> ref
|
|
|
10884
10884
|
combined run in flight — or green within ${shipBatch.LANE_GRACE_SEC / 60}m, so its lander can land it — a serial
|
|
10885
10885
|
\`colab ship --branch\` into trunk pauses with exit 3 (⏸ BATCH-IN-FLIGHT; its --dry --json row
|
|
10886
10886
|
'no batch in flight (#581)' reads self-clearing) instead of moving trunk under it and discarding the run.
|
|
10887
|
-
A red batch, or one with no run / not landed past that grace, holds nothing.
|
|
10887
|
+
A red batch, or one with no run / not landed past that grace, holds nothing. A TRUNK RED: cure is never held.
|
|
10888
|
+
SPECULATIVE CHAIN (#605): --onto ship-batch/<sha7> builds the batch on that in-flight batch's HEAD
|
|
10889
|
+
instead of trunk's tip, named ship-batch/<parent-head-sha7> (one batch per base still holds). The chain
|
|
10890
|
+
is read from ls-remote alone: a ref's parent is the ref whose head its name starts with, and it is kept
|
|
10891
|
+
while that chain ends at a batch on trunk's tip (at most ${shipBatch.MAX_CHAIN_DEPTH} deep); a ref whose parent is gone or rebuilt,
|
|
10892
|
+
or whose root trunk moved past, is deleted by the next --batch call (its run cancelled if still going).
|
|
10893
|
+
- refused (1): the named ref has no combined run in flight or green, is not rooted at trunk's tip,
|
|
10894
|
+
or is already ${shipBatch.MAX_CHAIN_DEPTH} deep; a member the chain below already carries does not join (✗, the rest go on);
|
|
10895
|
+
- lands in order: green and its parent not landed yet → ⏸ BATCH-CHAINED (exit 3); once trunk's tip IS
|
|
10896
|
+
the parent's head, the same command (with or without --onto) lands it — no second build, no second run;
|
|
10897
|
+
- declined (4): the parent is red, gone, or trunk moved some other way — the child is deleted, → SERIAL.
|
|
10898
|
+
Every ref of a chain rooted at trunk's tip holds the lane, exactly as one batch does.
|
|
10899
|
+
--dry --json: one JSON document on stdout ({ batch: { ref, parentRef, rootSha, base, depth, step, exit,
|
|
10900
|
+
members: [{ branch, sha, eligible, inBatch, why }] } }), the prose on stderr.
|
|
10888
10901
|
A member that conflicts with the members already in is dropped to the next batch; the rest go on —
|
|
10889
10902
|
unless every conflicting path is generated (defaults + project.yml generated:): then .colab/hooks/pre-ship
|
|
10890
10903
|
regenerates them on the combined head and the member stays in (#387). No hook, or a failing one → dropped.
|
|
@@ -12560,7 +12573,7 @@ function cmdShipDryJson(opts) {
|
|
|
12560
12573
|
// lane would discard the batch's run. SELF_CLEARING: the batch lands or is declined on its own.
|
|
12561
12574
|
// Never for a batch member read (the batch IS the lane) nor for evidence-close (trunk does not move).
|
|
12562
12575
|
if (!dryMode.evidenceClose && !opts._batchMember) {
|
|
12563
|
-
const laneJson = shipBatchLaneCheck(repoAbs, doc, trunk, target, gh);
|
|
12576
|
+
const laneJson = shipBatchLaneCheck(repoAbs, doc, trunk, target, gh, ciResultJson);
|
|
12564
12577
|
if (laneJson) {
|
|
12565
12578
|
checks.push({ name: 'no batch in flight (#581)', ok: !laneJson.held, class: laneJson.held ? SELF_CLEARING : null,
|
|
12566
12579
|
detail: laneJson.detail, ...(laneJson.held ? { batchRef: laneJson.ref } : {}) });
|
|
@@ -13435,7 +13448,7 @@ function shipRefFor(repoAbs, branch) {
|
|
|
13435
13448
|
|
|
13436
13449
|
function cmdShip(argv) {
|
|
13437
13450
|
const opts = parseArgs(argv, {
|
|
13438
|
-
values: { '--repo': 'repo', '--worktree': 'worktree', '--branch': 'branch', '--message': 'message', '--session': 'session', '--session-name': 'sessionName', '--batch': 'batch', '--answered-by': 'answeredBy', '--handoff': 'handoff' },
|
|
13451
|
+
values: { '--repo': 'repo', '--worktree': 'worktree', '--branch': 'branch', '--message': 'message', '--session': 'session', '--session-name': 'sessionName', '--batch': 'batch', '--answered-by': 'answeredBy', '--handoff': 'handoff', '--onto': 'onto' },
|
|
13439
13452
|
// #479: a repeated --refs used to keep only its LAST value, and every dropped issue then became a
|
|
13440
13453
|
// `Closes` line on trunk — an issue meant to stay open, auto-closed by the push. --refs now
|
|
13441
13454
|
// accumulates (a repeat is the same as one comma list); every OTHER value flag to ship refuses a
|
|
@@ -13455,6 +13468,9 @@ function cmdShip(argv) {
|
|
|
13455
13468
|
if (opts.handoff && opts.batch) throw new UserError('--handoff names one --branch ship; in a batch, attach it to its member: --batch <b1>,<b2>@<hand-off-url> (#591, see `colab ship --help`)');
|
|
13456
13469
|
if (opts.handoff && opts.direct) throw new UserError('--handoff applies to one --branch ship — not to --direct (see `colab ship --help`)');
|
|
13457
13470
|
if (opts.split && !opts.batch) throw new UserError('--split applies to a red combined run of --batch only (#557) — run `colab ship --batch <b1,b2,…> --split` with the members the red batch carries');
|
|
13471
|
+
if (opts.onto && !opts.batch) throw new UserError('--onto applies to --batch only (#605) — run `colab ship --batch <b1,b2,…> --onto ship-batch/<sha7>`');
|
|
13472
|
+
if (opts.onto && !shipBatch.parseBatchRef(opts.onto)) throw new UserError(`--onto ${opts.onto}: not a batch ref — expected ship-batch/<sha7> (#605)`);
|
|
13473
|
+
if (opts.batch && opts.json) return cmdShipBatchJson(opts); // #605: the batch's facts as JSON, prose on stderr
|
|
13458
13474
|
if (opts.batch) return cmdShipBatch(opts); // #373 — its own re-entrant path; nothing below changes
|
|
13459
13475
|
// A fully separate code path, deliberately: the prose/table path below is unchanged by this
|
|
13460
13476
|
// feature (CONVENTIONS/#77 requires it stay byte-identical), so --dry --json does its own
|
|
@@ -13657,7 +13673,7 @@ function cmdShip(argv) {
|
|
|
13657
13673
|
|
|
13658
13674
|
// #581: a batch in flight at trunk's tip holds the lane. Like the core-path review's 'pending', a
|
|
13659
13675
|
// hold is not a failed precondition — it is a pause, taken below once every real one has passed.
|
|
13660
|
-
const lane = shipBatchLaneCheck(repoAbs, doc, trunk, target, gh);
|
|
13676
|
+
const lane = shipBatchLaneCheck(repoAbs, doc, trunk, target, gh, ciResult);
|
|
13661
13677
|
if (lane) checks.push([lane.held ? '⏸' : '✓', 'no batch in flight (#581)', lane.detail]);
|
|
13662
13678
|
for (const w of coreReview.warnings) warn(`${coreReview.codeownersPath}: ${w}`);
|
|
13663
13679
|
|
|
@@ -14110,7 +14126,7 @@ function cmdShip(argv) {
|
|
|
14110
14126
|
}
|
|
14111
14127
|
// #581: re-read the lane right before the merge — B0 sits between the table and here, and a batch
|
|
14112
14128
|
// built in that window is exactly as live as one the table saw.
|
|
14113
|
-
const laneB1 = lane ? shipBatchLaneCheck(repoAbs, doc, trunk, target, gh) : null;
|
|
14129
|
+
const laneB1 = lane ? shipBatchLaneCheck(repoAbs, doc, trunk, target, gh, ciCureForTrailer ? { cureVerdict: ciCureForTrailer } : null) : null;
|
|
14114
14130
|
if (laneB1 && laneB1.held) { cleanupEphemeral(); printBatchLanePause(laneB1, trunk); return 3; }
|
|
14115
14131
|
// WHERE the squash happens. Into trunk it is the main checkout, which is on trunk by invariant
|
|
14116
14132
|
// (and was just verified to be). Into a declared line it must NOT be: checking the main checkout
|
|
@@ -14684,21 +14700,29 @@ function shipDryJsonReport(opts) {
|
|
|
14684
14700
|
* Inert (null, no git or gh call) unless project.yml declares ship-batch > 1, the merge target is
|
|
14685
14701
|
* trunk, and gh is usable. Out: null, or `{ held, ref, why, released, detail }`.
|
|
14686
14702
|
*/
|
|
14687
|
-
function shipBatchLaneCheck(repoAbs, doc, trunk, target, gh) {
|
|
14703
|
+
function shipBatchLaneCheck(repoAbs, doc, trunk, target, gh, ciResult = null) {
|
|
14688
14704
|
if (target !== trunk || !gh || shipBatch.parseShipBatch(doc).n <= 1) return null;
|
|
14705
|
+
// #605: a TRUNK RED: cure is never held by a batch (or a chain) — trunk is red, and the cure is the
|
|
14706
|
+
// way out; no batch can land on a red trunk anyway.
|
|
14707
|
+
if (ciResult && ciResult.cureVerdict && ciResult.cureVerdict.ok) {
|
|
14708
|
+
return { held: false, released: [], detail: 'a TRUNK RED: cure is never held by a batch (#605)' };
|
|
14709
|
+
}
|
|
14689
14710
|
const remote = git.remoteFor(repoAbs);
|
|
14690
14711
|
const ls = git.git(['ls-remote', remote, `refs/heads/${trunk}`, 'refs/heads/ship-batch/*'], repoAbs);
|
|
14691
14712
|
if (!ls.ok) return { held: false, released: [], detail: `could not read ${remote} — no batch provably in flight` };
|
|
14692
14713
|
const rows = ls.stdout.split('\n').map((l) => l.split('\t')).filter(([sha, ref]) => sha && ref);
|
|
14693
14714
|
const trunkNow = ((rows.find(([, ref]) => ref.trim() === `refs/heads/${trunk}`) || [])[0] || '').trim();
|
|
14694
|
-
|
|
14695
|
-
|
|
14715
|
+
// #605: the lane holder is the CHAIN rooted at trunk's tip — a batch built --onto another batch's head
|
|
14716
|
+
// reaches trunk only through it, so its run holds the lane exactly as the root's does.
|
|
14717
|
+
const refs = rows.map(([sha, ref]) => ({ sha: sha.trim(), parsed: shipBatch.parseBatchRef(ref.trim()) })).filter((x) => x.parsed);
|
|
14718
|
+
const chains = shipBatch.batchChains({ refs: refs.map((x) => ({ ref: x.parsed.ref, base7: x.parsed.base7, sha: x.sha })), trunkNow });
|
|
14719
|
+
const atTip = refs.filter((x) => chains.get(x.parsed.ref).rooted);
|
|
14696
14720
|
const batches = atTip.map((x) => {
|
|
14697
14721
|
const runs = git.ghRunsForRef(repoAbs, x.parsed.ref, x.sha);
|
|
14698
14722
|
let t = git.git(['log', '-1', '--format=%cI', x.sha], repoAbs);
|
|
14699
14723
|
if (!t.ok) { git.git(['fetch', '-q', remote, `refs/heads/${x.parsed.ref}`], repoAbs); t = git.git(['log', '-1', '--format=%cI', x.sha], repoAbs); }
|
|
14700
14724
|
const built = t.ok ? Date.parse(t.stdout.trim()) : NaN;
|
|
14701
|
-
return { ref: x.parsed.ref, base7: x.parsed.base7, verdict: shipBatch.combinedVerdict(runs),
|
|
14725
|
+
return { ref: x.parsed.ref, base7: x.parsed.base7, rooted: true, verdict: shipBatch.combinedVerdict(runs),
|
|
14702
14726
|
builtAtMs: Number.isFinite(built) ? built : null, settledAtMs: shipBatch.settledAt(runs) };
|
|
14703
14727
|
});
|
|
14704
14728
|
const r = shipBatch.laneHold({ batches, trunkNow, nowMs: Date.now() });
|
|
@@ -14715,8 +14739,32 @@ function printBatchLanePause(lane, trunk) {
|
|
|
14715
14739
|
print(' or be declined (bounded, B1a — the same wait as any CI run), then run this command again.');
|
|
14716
14740
|
}
|
|
14717
14741
|
|
|
14742
|
+
/**
|
|
14743
|
+
* #605: `colab ship --batch … --dry --json` — the same single step as the prose path (it IS the prose
|
|
14744
|
+
* path, with its prose moved to stderr), plus one JSON document on stdout carrying the facts a caller
|
|
14745
|
+
* keys on: the batch ref, the ref it is chained onto, the trunk sha its chain is rooted at, the step
|
|
14746
|
+
* taken and the exit class, and one row per member. A caller never parses prose for the chain.
|
|
14747
|
+
*/
|
|
14748
|
+
function cmdShipBatchJson(opts) {
|
|
14749
|
+
const batch = { trunk: null, trunkSha: null, ref: null, parentRef: null, rootSha: null, base: null, depth: null, step: null, exit: null, error: null, members: [] };
|
|
14750
|
+
const was = PRINT_TO_STDERR;
|
|
14751
|
+
PRINT_TO_STDERR = true;
|
|
14752
|
+
let code;
|
|
14753
|
+
try { code = cmdShipBatch({ ...opts, _json: batch }); }
|
|
14754
|
+
catch (e) {
|
|
14755
|
+
if (!(e instanceof UserError)) throw e;
|
|
14756
|
+
process.stderr.write(`✗ ${e.message}\n`);
|
|
14757
|
+
batch.error = e.message;
|
|
14758
|
+
batch.step = batch.step || 'refused';
|
|
14759
|
+
code = 1;
|
|
14760
|
+
} finally { PRINT_TO_STDERR = was; }
|
|
14761
|
+
batch.exit = code;
|
|
14762
|
+
process.stdout.write(`${JSON.stringify({ batch }, null, 2)}\n`);
|
|
14763
|
+
return code;
|
|
14764
|
+
}
|
|
14765
|
+
|
|
14718
14766
|
function cmdShipBatch(opts) {
|
|
14719
|
-
for (const [key, flag] of [['direct', '--direct'], ['worktree', '--worktree'], ['branch', '--branch'], ['message', '--message'], ['refs', '--refs'], ['adopt', '--adopt'], ['json', '--json']]) {
|
|
14767
|
+
for (const [key, flag] of [['direct', '--direct'], ['worktree', '--worktree'], ['branch', '--branch'], ['message', '--message'], ['refs', '--refs'], ['adopt', '--adopt'], ...(opts._json ? [] : [['json', '--json']])]) {
|
|
14720
14768
|
if (opts[key]) throw new UserError(`--batch does not combine with ${flag} — each member ships with its own recorded claims and composed message (#373)`);
|
|
14721
14769
|
}
|
|
14722
14770
|
const repoAbs = resolveRepo(opts);
|
|
@@ -14730,7 +14778,12 @@ function cmdShipBatch(opts) {
|
|
|
14730
14778
|
const members = entries.members;
|
|
14731
14779
|
const handoffs = entries.handoffs;
|
|
14732
14780
|
if (members.includes(trunk)) throw new UserError(`Refusing: ${trunk} is the trunk itself — it cannot be a batch member`);
|
|
14781
|
+
const J = opts._json || {}; // #605: the --dry --json report, filled as the facts are read
|
|
14782
|
+
J.trunk = trunk;
|
|
14733
14783
|
const serial = (why, list = members) => {
|
|
14784
|
+
J.step = J.step && J.step !== 'build' ? J.step : 'serial';
|
|
14785
|
+
J.reason = why;
|
|
14786
|
+
if (!J.members || !J.members.length) J.members = list.map((b) => ({ branch: b, sha: null, eligible: null, inBatch: false, why }));
|
|
14734
14787
|
print(`✗ ship-batch: ${why}`);
|
|
14735
14788
|
print(shipBatch.serialLine(list));
|
|
14736
14789
|
return 4;
|
|
@@ -14791,6 +14844,7 @@ function cmdShipBatch(opts) {
|
|
|
14791
14844
|
const lsTrunk = git.git(['ls-remote', remote, `refs/heads/${trunk}`], repoAbs);
|
|
14792
14845
|
const trunkNow = lsTrunk.ok ? (lsTrunk.stdout.split('\t')[0] || '').trim() : '';
|
|
14793
14846
|
if (!trunkNow) throw new UserError(`could not read ${trunk} on ${remote}`);
|
|
14847
|
+
J.trunkSha = trunkNow;
|
|
14794
14848
|
const lsBatch = git.git(['ls-remote', remote, 'refs/heads/ship-batch/*'], repoAbs);
|
|
14795
14849
|
const batchRefs = (lsBatch.ok ? lsBatch.stdout.split('\n') : []).map((l) => l.split('\t'))
|
|
14796
14850
|
.map(([sha, ref]) => ({ sha: (sha || '').trim(), parsed: shipBatch.parseBatchRef((ref || '').trim()) }))
|
|
@@ -14802,14 +14856,102 @@ function cmdShipBatch(opts) {
|
|
|
14802
14856
|
if (!d.ok) warn(`could not delete ${remote}/${ref}: ${git.gitFailureLine(d.stderr)} — delete it by hand`);
|
|
14803
14857
|
return d.ok;
|
|
14804
14858
|
};
|
|
14805
|
-
|
|
14806
|
-
|
|
14859
|
+
// #605: the sweep is chain-aware. A ref built `--onto` another batch's head is kept while its chain
|
|
14860
|
+
// ends at a batch on trunk's tip (lib/ship-batch.js batchChains, read from ls-remote alone); a ref
|
|
14861
|
+
// whose parent is gone, or whose root trunk has moved past, is deleted. Without any chained ref this
|
|
14862
|
+
// is exactly the old sweep: every ref not built on trunk's tip goes.
|
|
14863
|
+
const chains = shipBatch.batchChains({ refs: batchRefs.map((x) => ({ ref: x.parsed.ref, base7: x.parsed.base7, sha: x.sha })), trunkNow });
|
|
14864
|
+
const carriedBy = (ref, from, sha) => {
|
|
14865
|
+
const lg = git.git(['log', '--format=%B%x00', `${from}..${sha}`], repoAbs);
|
|
14866
|
+
return shipBatch.parseMemberTrailers(lg.ok ? lg.stdout.split('\0') : []).filter((m) => m.ref === ref).reverse();
|
|
14867
|
+
};
|
|
14868
|
+
const swept = [];
|
|
14869
|
+
for (const b of batchRefs.filter((x) => !chains.get(x.parsed.ref).rooted)) {
|
|
14870
|
+
const c = chains.get(b.parsed.ref);
|
|
14871
|
+
// A ref built on a head trunk never reached (an orphaned chain link) may still have its run going;
|
|
14872
|
+
// nothing can ever land it, so cancel that run. A ref on an OLD trunk tip is today's case, untouched.
|
|
14873
|
+
const baseFull = git.git(['rev-parse', '--verify', '-q', `${b.parsed.base7}^{commit}`], repoAbs);
|
|
14874
|
+
const offTrunk = !baseFull.ok || !git.git(['merge-base', '--is-ancestor', baseFull.stdout.trim(), trunkNow], repoAbs).ok;
|
|
14875
|
+
if (offTrunk) {
|
|
14876
|
+
print(` ${b.parsed.ref} is not rooted at ${trunk}'s tip — ${c.why}; nothing landed from it; deleting it`);
|
|
14877
|
+
for (const r of (git.ghRunsForRef(repoAbs, b.parsed.ref, b.sha) || []).filter((x) => x.status !== 'completed' && x.databaseId)) {
|
|
14878
|
+
if (opts.dry) { print(` [dry] would cancel run ${r.databaseId} on ${b.parsed.ref}`); continue; }
|
|
14879
|
+
const cx = git.ghRunCancel(repoAbs, r.databaseId);
|
|
14880
|
+
if (!cx.ok) warn(`could not cancel run ${r.databaseId} on ${b.parsed.ref} — it will finish on a ref that is gone`);
|
|
14881
|
+
}
|
|
14882
|
+
} else {
|
|
14883
|
+
print(` trunk moved since ${b.parsed.ref} was built (${b.parsed.base7} → ${shortSha(trunkNow)}) — nothing landed; rebuilding`);
|
|
14884
|
+
}
|
|
14885
|
+
swept.push({ ref: b.parsed.ref, members: offTrunk ? carriedBy(b.parsed.ref, trunkNow, b.sha) : [] });
|
|
14807
14886
|
deleteRef(b.parsed.ref);
|
|
14808
14887
|
}
|
|
14809
|
-
const
|
|
14888
|
+
const rooted = batchRefs.filter((x) => chains.get(x.parsed.ref).rooted);
|
|
14889
|
+
// Every member the chain up to `sha` carries (branch → the ref carrying it), read from its trailers.
|
|
14890
|
+
const carriedByChain = (sha) => new Map(shipBatch.parseMemberTrailers((() => {
|
|
14891
|
+
const lg = git.git(['log', '--format=%B%x00', `${trunkNow}..${sha}`], repoAbs);
|
|
14892
|
+
return lg.ok ? lg.stdout.split('\0') : [];
|
|
14893
|
+
})()).map((m) => [m.branch, m.ref]));
|
|
14894
|
+
|
|
14895
|
+
// #605: --onto <ship-batch ref> builds on that ref's HEAD instead of trunk's tip. `base` is what the
|
|
14896
|
+
// batch sits on from here on; without --onto it is trunk's tip, and nothing below changes.
|
|
14897
|
+
let base = trunkNow;
|
|
14898
|
+
let parent = null; // { ref, sha, chain, verdict } while the parent has not landed
|
|
14899
|
+
if (opts.onto) {
|
|
14900
|
+
const want = shipBatch.parseBatchRef(opts.onto).ref;
|
|
14901
|
+
const p = batchRefs.find((x) => x.parsed.ref === want) || null;
|
|
14902
|
+
const ours = swept.find((x) => x.members.some((m) => members.includes(m.branch)));
|
|
14903
|
+
if (p && p.sha === trunkNow) {
|
|
14904
|
+
print(` ${want} has landed — ${trunk} is at its head ${shortSha(trunkNow)}; this batch sits on ${trunk}'s tip`);
|
|
14905
|
+
} else if (!p || !chains.get(want).rooted) {
|
|
14906
|
+
if (ours) {
|
|
14907
|
+
print(`✗ ship-batch: ${ours.ref} was built on ${want}, which ${p ? `is no longer rooted at ${trunk}'s tip (${chains.get(want).why})` : `is gone from ${remote}`} — nothing landed; ${ours.ref} ${opts.dry ? 'would be deleted [DRY RUN]' : 'deleted'}. Rebuild with the same command without --onto.`);
|
|
14908
|
+
J.step = 'chained-decline';
|
|
14909
|
+
return serial('its parent batch was discarded, or trunk moved some other way — the chain cannot land in order', ours.members.map((m) => m.branch));
|
|
14910
|
+
}
|
|
14911
|
+
// The parent landed and its lander deleted the ref: our batch (if staged) now sits on trunk's tip.
|
|
14912
|
+
const atTip = rooted.find((x) => trunkNow.startsWith(x.parsed.base7));
|
|
14913
|
+
const landedParent = !p && atTip && carriedBy(atTip.parsed.ref, trunkNow, atTip.sha).some((m) => members.includes(m.branch));
|
|
14914
|
+
if (!landedParent && p) {
|
|
14915
|
+
throw new UserError(`--onto ${want}: it is not rooted at ${trunk}'s tip (${chains.get(want).why}) — build on ${trunk} instead (drop --onto)`);
|
|
14916
|
+
}
|
|
14917
|
+
if (!landedParent) {
|
|
14918
|
+
// ls-remote cannot tell "never existed" from "discarded" or "trunk moved some other way" — and
|
|
14919
|
+
// for the last two the issue's rule is a decline. So a missing parent declines: nothing of
|
|
14920
|
+
// this chain can land in order, and the members go back to the queue (#605).
|
|
14921
|
+
J.step = 'chained-decline';
|
|
14922
|
+
print(`✗ ship-batch: --onto ${want}: no such batch ref on ${remote} — it was discarded, landed under other members, or never existed.`);
|
|
14923
|
+
return serial(`nothing to chain onto — build on ${trunk} instead (the same command without --onto)`);
|
|
14924
|
+
}
|
|
14925
|
+
print(` ${want} is gone and ${atTip.parsed.ref} at ${trunk}'s tip carries this batch — its parent landed; resuming on ${trunk}'s tip`);
|
|
14926
|
+
} else {
|
|
14927
|
+
const pc = chains.get(want);
|
|
14928
|
+
const verdict = shipBatch.combinedVerdict(git.ghRunsForRef(repoAbs, want, p.sha));
|
|
14929
|
+
const child = rooted.find((x) => x !== p && p.sha.startsWith(x.parsed.base7)) || null;
|
|
14930
|
+
if (verdict.state === 'red') {
|
|
14931
|
+
if (child) {
|
|
14932
|
+
const carried = carriedBy(child.parsed.ref, p.sha, child.sha);
|
|
14933
|
+
print(`✗ ship-batch: ${want} is red (${verdict.why}) — it will not land at ${shortSha(p.sha)}, so ${child.parsed.ref} built on it cannot land in order. Nothing landed; ${child.parsed.ref} ${opts.dry ? 'would be deleted [DRY RUN]' : 'deleted'}. Rebuild with the same command without --onto once ${want} is settled.`);
|
|
14934
|
+
deleteRef(child.parsed.ref);
|
|
14935
|
+
J.step = 'chained-decline';
|
|
14936
|
+
return serial(`its parent ${want} was declined — rebuild on ${trunk} once it is settled`, carried.length ? carried.map((m) => m.branch) : members);
|
|
14937
|
+
}
|
|
14938
|
+
throw new UserError(`--onto ${want}: its combined run is red (${verdict.why}) — nothing to chain onto; build on ${trunk} instead (drop --onto)`);
|
|
14939
|
+
}
|
|
14940
|
+
if (verdict.state === 'none' && !child) {
|
|
14941
|
+
throw new UserError(`--onto ${want}: it has no combined run in flight or green yet — wait for its run to start, then run this command again`);
|
|
14942
|
+
}
|
|
14943
|
+
if (!child && pc.depth >= shipBatch.MAX_CHAIN_DEPTH) {
|
|
14944
|
+
throw new UserError(`--onto ${want}: it is already ${pc.depth} deep from ${trunk}'s tip — a chain is at most ${shipBatch.MAX_CHAIN_DEPTH} batches (#605); wait for its root to land`);
|
|
14945
|
+
}
|
|
14946
|
+
base = p.sha;
|
|
14947
|
+
parent = { ref: want, sha: p.sha, chain: pc, verdict };
|
|
14948
|
+
}
|
|
14949
|
+
}
|
|
14950
|
+
Object.assign(J, { base, parentRef: parent ? parent.ref : null, rootSha: trunkNow, depth: parent ? parent.chain.depth + 1 : 1, ref: shipBatch.batchRefName(base) });
|
|
14951
|
+
const atBase = rooted.find((x) => (!parent || x.parsed.ref !== parent.ref) && base.startsWith(x.parsed.base7)) || null;
|
|
14810
14952
|
let existing = null;
|
|
14811
14953
|
if (atBase) {
|
|
14812
|
-
const log = git.git(['log', '--format=%B%x00', `${
|
|
14954
|
+
const log = git.git(['log', '--format=%B%x00', `${base}..${atBase.sha}`], repoAbs);
|
|
14813
14955
|
const inBatch = shipBatch.parseMemberTrailers(log.ok ? log.stdout.split('\0') : []).reverse();
|
|
14814
14956
|
const foreign = inBatch.filter((m) => !members.includes(m.branch));
|
|
14815
14957
|
// #391: a DECLINED batch (combined run red) is not in flight — clear it and build the one asked for.
|
|
@@ -14839,7 +14981,10 @@ function cmdShipBatch(opts) {
|
|
|
14839
14981
|
}
|
|
14840
14982
|
}
|
|
14841
14983
|
const verdict = existing && existing.matches ? shipBatch.combinedVerdict(git.ghRunsForRef(repoAbs, existing.ref, existing.sha)) : null;
|
|
14842
|
-
|
|
14984
|
+
// #605: a chained batch is measured against its own base (the parent's head), not trunk's tip.
|
|
14985
|
+
let step = shipBatch.nextStep({ enabled: true, wired: true, trunkCi, eligibleCount: members.length, existing, trunkNow: base, verdict, split: !!opts.split });
|
|
14986
|
+
J.step = step.step;
|
|
14987
|
+
if (existing) J.members = existing.members.map((m) => ({ branch: m.branch, sha: m.sha, eligible: true, inBatch: true, why: `staged in ${existing.ref}` }));
|
|
14843
14988
|
if (opts.split && !(verdict && verdict.state === 'red')) {
|
|
14844
14989
|
print(` --split ignored: ${existing ? `${existing.ref} is not red (${verdict ? verdict.state : 'members changed'})` : 'no batch is staged at this base'} — only a red combined run splits (#557)`);
|
|
14845
14990
|
}
|
|
@@ -14888,15 +15033,33 @@ function cmdShipBatch(opts) {
|
|
|
14888
15033
|
print(shipBatch.serialLine(existing.members.map((m) => m.branch)));
|
|
14889
15034
|
return 4;
|
|
14890
15035
|
}
|
|
15036
|
+
if (step.step === 'land' && parent) {
|
|
15037
|
+
// #605: land in order — only once trunk's tip IS the parent's head. Until then the parent is in
|
|
15038
|
+
// flight (wait, exit 3); a parent that is red will never land at that sha (delete, exit 4).
|
|
15039
|
+
const ls = shipBatch.chainedLandStep({ parent: parent.chain, parentVerdict: parent.verdict });
|
|
15040
|
+
J.step = ls.step === 'wait' ? 'chained-wait' : 'chained-decline';
|
|
15041
|
+
J.reason = ls.why;
|
|
15042
|
+
if (ls.step === 'wait') {
|
|
15043
|
+
print(`⏸ BATCH-CHAINED ${existing.ref}@${shortSha(existing.sha)} — combined run green; it lands after ${parent.ref}: ${ls.why}. Nothing landed.`);
|
|
15044
|
+
print(` Wait for ${parent.ref} to land (bounded, B1a), then run this command again — it lands with no second run.`);
|
|
15045
|
+
return 3;
|
|
15046
|
+
}
|
|
15047
|
+
print(`✗ ship-batch: ${existing.ref} cannot land in order — ${ls.why}. Nothing landed; ${existing.ref} ${opts.dry ? 'would be deleted [DRY RUN]' : 'deleted'}. Rebuild with the same command without --onto.`);
|
|
15048
|
+
deleteRef(existing.ref);
|
|
15049
|
+
return serial('its parent batch was discarded', existing.members.map((m) => m.branch));
|
|
15050
|
+
}
|
|
14891
15051
|
if (step.step === 'land') return shipBatchLand(repoAbs, doc, trunk, remote, trunkNow, existing, verdict, opts);
|
|
14892
15052
|
|
|
14893
15053
|
// ---- (d) pick the members — each through its OWN ship gates ----
|
|
14894
15054
|
const st = state.loadState();
|
|
14895
15055
|
const evaluated = [];
|
|
15056
|
+
// #605: a member the chain below already carries lands with that batch — it never joins a second one.
|
|
15057
|
+
const inChain = parent ? carriedByChain(parent.sha) : new Map();
|
|
14896
15058
|
for (const b of members) {
|
|
14897
15059
|
const refs = git.branchRefs(repoAbs, b, remote);
|
|
14898
15060
|
let why = null, report = null, ciClass = null, files = [];
|
|
14899
15061
|
if (!refs.remoteSha) why = `not on ${remote} — push it first; its CI has never seen it`;
|
|
15062
|
+
else if (inChain.has(b)) why = `already in ${inChain.get(b)} — it lands with that batch, not this one`;
|
|
14900
15063
|
else if (refs.localSha && refs.localSha !== refs.remoteSha) why = `local ${shortSha(refs.localSha)} ≠ ${remote} ${shortSha(refs.remoteSha)} — its CI never saw this head`;
|
|
14901
15064
|
if (!why) {
|
|
14902
15065
|
// #591: a hand-off member is read through the SAME door a single --handoff ship uses
|
|
@@ -14929,12 +15092,13 @@ function cmdShipBatch(opts) {
|
|
|
14929
15092
|
return { selected: sel, overflow: eligible.filter((e) => !sel.includes(e)) };
|
|
14930
15093
|
})()
|
|
14931
15094
|
: shipBatch.selectMembers(eligible, size, { isGenerated: (f) => isGeneratedPath(f, generated) });
|
|
14932
|
-
print(`ship --batch ${shortRepo(repoAbs)} → ${trunk} @ ${shortSha(trunkNow)} (${splitHalf ? `split of a red batch of ${splitHalf.first.length + splitHalf.held.length}` : sizeLabel})${opts.dry ? ' [DRY RUN]' : ''}`);
|
|
15095
|
+
print(`ship --batch ${shortRepo(repoAbs)} → ${trunk} @ ${shortSha(trunkNow)}${parent ? ` · onto ${parent.ref}@${shortSha(parent.sha)} (depth ${parent.chain.depth + 1}, lands after it)` : ''} (${splitHalf ? `split of a red batch of ${splitHalf.first.length + splitHalf.held.length}` : sizeLabel})${opts.dry ? ' [DRY RUN]' : ''}`);
|
|
14933
15096
|
print(table(evaluated.map((e) => [e.ok ? (selected.includes(e) ? '✓' : '·') : '✗', e.branch,
|
|
14934
15097
|
e.ok && !selected.includes(e) ? (splitHalf ? 'eligible — held by the split for the next batch' : `eligible — waits for the next batch (cap ${size})`) : e.why]), ['', 'MEMBER', 'DETAIL']));
|
|
14935
15098
|
const notJoining = evaluated.filter((e) => !selected.includes(e)).map((e) => e.branch);
|
|
15099
|
+
J.members = evaluated.map((e) => ({ branch: e.branch, sha: e.sha || null, eligible: e.ok, inBatch: selected.includes(e), why: e.why }));
|
|
14936
15100
|
step = shipBatch.nextStep({ enabled: true, wired: true, trunkCi, eligibleCount: selected.length, existing: null, trunkNow });
|
|
14937
|
-
if (step.step === 'build' && selected.length === 1 && waitCfg.sec > 0 && !splitHalf) {
|
|
15101
|
+
if (step.step === 'build' && selected.length === 1 && waitCfg.sec > 0 && !splitHalf && !parent) {
|
|
14938
15102
|
// #555: the lane is idle here (trunk's run finished, no batch in flight at this base), and one
|
|
14939
15103
|
// member is ready. Wait for a partner until the repo's window, counted from when it became ready.
|
|
14940
15104
|
const lone = selected[0];
|
|
@@ -14953,10 +15117,11 @@ function cmdShipBatch(opts) {
|
|
|
14953
15117
|
if (step.step === 'serial') return serial('no member can join — each one above says why');
|
|
14954
15118
|
|
|
14955
15119
|
// ---- (e) build: trunk head + one squash commit per member, in an ephemeral detached worktree ----
|
|
14956
|
-
|
|
15120
|
+
// #605: on a chain, the batch is built on the parent's head and named after it — one batch per base.
|
|
15121
|
+
const ref = shipBatch.batchRefName(base);
|
|
14957
15122
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'colab-ship-batch-'));
|
|
14958
|
-
const add = git.git(['worktree', 'add', '--detach', dir,
|
|
14959
|
-
if (!add.ok) { try { fs.rmdirSync(dir); } catch (_) {} throw new UserError(`could not check out ${shortSha(
|
|
15123
|
+
const add = git.git(['worktree', 'add', '--detach', dir, base], repoAbs);
|
|
15124
|
+
if (!add.ok) { try { fs.rmdirSync(dir); } catch (_) {} throw new UserError(`could not check out ${shortSha(base)} to build the batch: ${git.gitFailureLine(add.stderr)}`); }
|
|
14960
15125
|
const cleanup = () => git.git(['worktree', 'remove', '--force', dir], repoAbs);
|
|
14961
15126
|
const machineLine = shipMachineTrailerDecision(repoAbs, doc).line;
|
|
14962
15127
|
const built = [];
|
|
@@ -15024,6 +15189,8 @@ function cmdShipBatch(opts) {
|
|
|
15024
15189
|
built.push({ ...m, regenerated, commit: git.git(['rev-parse', 'HEAD'], dir).stdout });
|
|
15025
15190
|
}
|
|
15026
15191
|
for (const d of dropped) print(` ✗ ${d.branch}: ${d.why}`);
|
|
15192
|
+
for (const d of dropped) Object.assign(J.members.find((r) => r.branch === d.branch) || {}, { inBatch: false, why: d.why });
|
|
15193
|
+
J.step = 'build';
|
|
15027
15194
|
// #554: a drop leaves a durable trace — one Ship-Batch-Dropped trailer per dropped member on the
|
|
15028
15195
|
// batch head, so it reaches trunk with a landed batch and rides a red combined run's head message.
|
|
15029
15196
|
// Only when the batch is built (≥1 member, #562): a build that collapses to serial pushes nothing.
|
|
@@ -15049,8 +15216,10 @@ function cmdShipBatch(opts) {
|
|
|
15049
15216
|
}
|
|
15050
15217
|
if (opts.dry) {
|
|
15051
15218
|
cleanup();
|
|
15052
|
-
print(`→ READY: would push ${ref} = ${shortSha(
|
|
15053
|
-
print(
|
|
15219
|
+
print(`→ READY: would push ${ref} = ${shortSha(base)} + ${built.length} squash commit(s): ${built.map((b) => b.branch).join(', ')}`);
|
|
15220
|
+
print(parent
|
|
15221
|
+
? ` then wait on ONE combined run, and fast-forward trunk to it only once ${parent.ref} has landed at ${shortSha(parent.sha)} (#605).`
|
|
15222
|
+
: ' then wait on ONE combined run, and fast-forward trunk to it only if trunk has not moved.');
|
|
15054
15223
|
if (notJoining.length || dropped.length) print(` not in this batch: ${[...new Set([...notJoining, ...dropped.map((d) => d.branch)])].join(', ')}`);
|
|
15055
15224
|
return 0;
|
|
15056
15225
|
}
|
|
@@ -15058,7 +15227,7 @@ function cmdShipBatch(opts) {
|
|
|
15058
15227
|
const push = git.run('git', ['push', '--force', remote, `${head}:refs/heads/${ref}`], { cwd: repoAbs });
|
|
15059
15228
|
cleanup();
|
|
15060
15229
|
if (!push.ok) throw new UserError(`could not push ${ref}: ${git.gitFailureLine(push.stderr)} — nothing landed`);
|
|
15061
|
-
print(` pushed ${ref} = ${shortSha(
|
|
15230
|
+
print(` pushed ${ref} = ${shortSha(base)} + ${built.length} commit(s) @ ${shortSha(head)} (${built.map((b) => b.branch).join(', ')})${parent ? ` — chained onto ${parent.ref}; it lands after it` : ''}`);
|
|
15062
15231
|
if (overflow.length) print(` eligible but ${splitHalf ? 'held by the split' : 'over the cap'} (next batch): ${overflow.map((o) => o.branch).join(', ')}`);
|
|
15063
15232
|
print(`⏸ BATCH-PENDING ${ref}@${shortSha(head)} — wait on the combined run (bounded, B1a), then run this command again. Nothing landed yet.`);
|
|
15064
15233
|
return 3;
|
|
@@ -16854,7 +17023,9 @@ re-running install.sh; \`colab update\` reports it when it is behind. \`colab --
|
|
|
16854
17023
|
which of the two you are talking to.
|
|
16855
17024
|
`;
|
|
16856
17025
|
|
|
16857
|
-
|
|
17026
|
+
// #605: `ship --batch --dry --json` keeps stdout for its one JSON document; the prose goes to stderr.
|
|
17027
|
+
let PRINT_TO_STDERR = false;
|
|
17028
|
+
function print(s) { (PRINT_TO_STDERR ? process.stderr : process.stdout).write(s.endsWith('\n') ? s : s + '\n'); return 0; }
|
|
16858
17029
|
function warn(s) { process.stderr.write(`! ${s}\n`); }
|
|
16859
17030
|
/**
|
|
16860
17031
|
* `colab ship` sets this to an array while it runs B3 (worktree teardown) through B4 (per-issue
|
package/tools/lib/git.js
CHANGED
|
@@ -755,6 +755,11 @@ function ghPrClose(repo, num, comment) {
|
|
|
755
755
|
return gh(['pr', 'close', String(num), '--comment', comment], { cwd: repo });
|
|
756
756
|
}
|
|
757
757
|
|
|
758
|
+
/** #605: cancel one workflow run (a deleted batch ref's run still in flight). The run result, ok or not. */
|
|
759
|
+
function ghRunCancel(repo, id) {
|
|
760
|
+
return gh(['run', 'cancel', String(id)], { cwd: repo });
|
|
761
|
+
}
|
|
762
|
+
|
|
758
763
|
function ghIssueComment(repo, issueNum, body) {
|
|
759
764
|
const r = gh(['issue', 'comment', String(issueNum), '--body', body], { cwd: repo });
|
|
760
765
|
if (r.ok || !isGraphqlRateLimit(r.stderr)) return r;
|
|
@@ -1441,5 +1446,5 @@ module.exports = {
|
|
|
1441
1446
|
ghRunJobCount, ghRunJobs, ghWorkflowDispatch,
|
|
1442
1447
|
ghIssueListByLabel, ghLabelDelete, ghLabelCreate, ghListLabelsDetailed, ghLabelEditDescription,
|
|
1443
1448
|
ghApi, isGraphqlRateLimit, ghIssueRelease, ghClaimHolder, ghIssueLabelEvents, ghIssueLabelActors,
|
|
1444
|
-
ghPrForBranch, ghOpenPrsForBranch, ghOpenPrs, ghPrCreate, ghPrClose, ghRepoVisibility,
|
|
1449
|
+
ghPrForBranch, ghOpenPrsForBranch, ghOpenPrs, ghPrCreate, ghPrClose, ghRepoVisibility, ghRunCancel,
|
|
1445
1450
|
};
|
package/tools/lib/ship-batch.js
CHANGED
|
@@ -513,7 +513,10 @@ function laneHold({ batches, trunkNow, nowMs, graceSec = LANE_GRACE_SEC } = {})
|
|
|
513
513
|
const fresh = (atMs) => Number.isFinite(atMs) && Number.isFinite(nowMs) && (nowMs - atMs) < graceSec * 1000;
|
|
514
514
|
const mins = (atMs) => `${Math.max(0, Math.round((nowMs - atMs) / 60000))}m ago`;
|
|
515
515
|
for (const b of (Array.isArray(batches) ? batches : [])) {
|
|
516
|
-
|
|
516
|
+
// #605: a chained batch (`rooted`, from batchChains) is part of the one holder its root is —
|
|
517
|
+
// built on another batch's head, so it reaches trunk only through that chain. Without the flag,
|
|
518
|
+
// only a batch built on trunk's tip counts, exactly as before.
|
|
519
|
+
if (!b || !b.base7 || !(b.rooted === undefined ? now.startsWith(b.base7) : b.rooted)) continue;
|
|
517
520
|
const v = b.verdict || { state: 'pending', why: 'the run list could not be read' };
|
|
518
521
|
if (v.state === 'red') { released.push({ ref: b.ref, why: `declined — ${v.why}` }); continue; }
|
|
519
522
|
if (v.state === 'pending') return { held: true, ref: b.ref, why: `combined run in flight (${v.why})` };
|
|
@@ -532,6 +535,72 @@ function laneHold({ batches, trunkNow, nowMs, graceSec = LANE_GRACE_SEC } = {})
|
|
|
532
535
|
return { held: false, released };
|
|
533
536
|
}
|
|
534
537
|
|
|
538
|
+
/**
|
|
539
|
+
* #605: speculative chains. A batch built with `--onto <ship-batch ref>` sits on that ref's HEAD, and
|
|
540
|
+
* its name already says so: `ship-batch/<parent-head-sha7>`. So the whole chain is read from
|
|
541
|
+
* `ls-remote` alone — a ref's parent is the ref whose head sha starts with its base7, and a ref is
|
|
542
|
+
* ROOTED when following parents ends at a ref built on trunk's tip. No chain state is kept anywhere.
|
|
543
|
+
*
|
|
544
|
+
* In: refs `[{ ref, base7, sha }]` (every ship-batch/* on the remote), `trunkNow`.
|
|
545
|
+
* Out: Map ref → `{ ref, base7, sha, parentRef, rootRef, rootSha, depth, rooted, why }`:
|
|
546
|
+
* - parentRef null for a batch built on trunk's tip, else the ref it was built on (null too
|
|
547
|
+
* when that ref is gone — then `rooted` is false);
|
|
548
|
+
* - rootSha trunk's tip when rooted, else null;
|
|
549
|
+
* - depth 1 at trunk's tip, 2 for its child, …;
|
|
550
|
+
* - why for an unrooted ref, the reason it is (the sweep deletes it, and says this).
|
|
551
|
+
* A chain deeper than MAX_CHAIN_DEPTH is not rooted: every link pins trunk for one more combined run,
|
|
552
|
+
* and a wrong guess low in the chain throws away every run above it.
|
|
553
|
+
*/
|
|
554
|
+
const MAX_CHAIN_DEPTH = 3;
|
|
555
|
+
|
|
556
|
+
function batchChains({ refs, trunkNow } = {}) {
|
|
557
|
+
const now = String(trunkNow || '');
|
|
558
|
+
const all = (Array.isArray(refs) ? refs : []).filter((r) => r && r.ref && r.base7 && r.sha);
|
|
559
|
+
const parentOf = (r) => all.find((p) => p !== r && String(p.sha).startsWith(r.base7)) || null;
|
|
560
|
+
const out = new Map();
|
|
561
|
+
for (const r of all) {
|
|
562
|
+
const atTip = !!now && now.startsWith(r.base7);
|
|
563
|
+
const parent = atTip ? null : parentOf(r);
|
|
564
|
+
let cur = r, depth = 1, why = null, root = null;
|
|
565
|
+
const seen = new Set([r.ref]);
|
|
566
|
+
while (true) {
|
|
567
|
+
if (now && now.startsWith(cur.base7)) { root = cur; break; }
|
|
568
|
+
const p = parentOf(cur);
|
|
569
|
+
if (!p) {
|
|
570
|
+
why = cur === r ? `its base ${r.base7} is neither trunk's tip nor the head of another batch ref — trunk moved, or its parent was rebuilt or deleted`
|
|
571
|
+
: `its chain breaks at ${cur.ref}, whose base ${cur.base7} is neither trunk's tip nor another batch's head`;
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
if (seen.has(p.ref)) { why = `its chain loops at ${p.ref}`; break; }
|
|
575
|
+
seen.add(p.ref);
|
|
576
|
+
cur = p;
|
|
577
|
+
depth += 1;
|
|
578
|
+
if (depth > MAX_CHAIN_DEPTH) { why = `its chain is deeper than ${MAX_CHAIN_DEPTH}`; break; }
|
|
579
|
+
}
|
|
580
|
+
out.set(r.ref, {
|
|
581
|
+
ref: r.ref, base7: r.base7, sha: r.sha, parentRef: parent ? parent.ref : null,
|
|
582
|
+
rootRef: root ? root.ref : null, rootSha: root ? now : null, depth, rooted: !!root, why,
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
return out;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* #605: what a chained batch (built `--onto` a parent) does when it is ready to land but its parent
|
|
590
|
+
* has not landed yet — trunk's tip is not its base. Facts: the parent's chain entry (null = gone)
|
|
591
|
+
* and the parent's combined verdict.
|
|
592
|
+
* wait the parent is rooted and its run is in flight, not yet run, or green → exit 3
|
|
593
|
+
* decline the parent is gone, unrooted, or red → nothing of this chain can land in order: delete
|
|
594
|
+
* this batch and decline it (exit 4)
|
|
595
|
+
*/
|
|
596
|
+
function chainedLandStep({ parent, parentVerdict } = {}) {
|
|
597
|
+
if (!parent) return { step: 'decline', why: 'its parent batch is gone — discarded, or rebuilt on another head' };
|
|
598
|
+
if (!parent.rooted) return { step: 'decline', why: `its parent ${parent.ref} is no longer rooted at trunk's tip (${parent.why})` };
|
|
599
|
+
const v = parentVerdict || { state: 'pending', why: 'the run list could not be read' };
|
|
600
|
+
if (v.state === 'red') return { step: 'decline', why: `its parent ${parent.ref} is red (${v.why}) — it will not land at the sha this batch was built on` };
|
|
601
|
+
return { step: 'wait', why: `its parent ${parent.ref} has not landed yet (${v.state === 'green' ? 'green, waiting for its lander' : (v.why || v.state)})` };
|
|
602
|
+
}
|
|
603
|
+
|
|
535
604
|
/** #581: when a batch's combined run settled — the newest `updatedAt` among its finished rows, else null. */
|
|
536
605
|
function settledAt(rows) {
|
|
537
606
|
const t = (Array.isArray(rows) ? rows : []).filter((r) => r && r.status === 'completed')
|
|
@@ -599,5 +668,5 @@ module.exports = {
|
|
|
599
668
|
droppedTrailer, parseDroppedTrailers, appendTrailers,
|
|
600
669
|
branchCiClass, memberEligibility, selectMembers, wiring, combinedVerdict, nextStep, foreignBatchStep,
|
|
601
670
|
batchGreenCoversTrunk, evidenceSuffix, serialLine, notStaged, landPushFailure,
|
|
602
|
-
LANE_GRACE_SEC, laneHold, settledAt,
|
|
671
|
+
LANE_GRACE_SEC, laneHold, settledAt, MAX_CHAIN_DEPTH, batchChains, chainedLandStep,
|
|
603
672
|
};
|