mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 16:41:35 +01:00
A crashed merge no longer blocks every other merge, and a one-call count of PRs waiting to merge (GST-3549) (#4712)
When `gstack-ship-queue land --pin` dies in the middle of a merge, the next merge now takes over its lock by itself (the process has exited, its machine restarted, or 90 minutes passed) and logs it; a merge that is still running is never interrupted. New `gstack-ship-queue count` says how many finished PRs are waiting to merge, and the docs now say how to drain that queue and how to time a revert drill. Nothing to do: the next `land --pin` uses the new lock on its own. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=security Review-Finding: p1/specialist-batched#2 reader=testing Review-Finding: p1/red-team#2 reader=red-team Review-Finding: p1/red-team#3 reader=red-team Review-Finding: p2/outside-voice#1 reader=outside-voice Review-Finding: p2/outside-voice#3 reader=outside-voice Review-Finding: p2/outside-voice#4 reader=outside-voice Review-Finding: p2/red-team#1 reader=red-team Review-Finding: p2/adversarial-native#1 reader=adversarial-native Review-Finding: p2/outside-voice#5 reader=outside-voice Review-Finding: p2/outside-voice#6 reader=outside-voice Review-Finding: p2/specialist-batched#2 reader=testing
This commit is contained in:
1 parent
d3aed00dbe
commit
2ab2aad705
13 files changed
+696
-22
No files matched your search
@@ -694,7 +694,9 @@ describe('capy skill: factory.md, the auto-loaded "how we work" page', () => {
|
||||
// R105 and R109, each the owner's standing rule).
|
||||
// 5,050 for point 7's two clauses that a green fake or dry run isn't done and that a check must see the change and count
|
||||
// what its name says (the second batch of crew rules, G4 and G10, each reached by three crews on their own).
|
||||
expect(Buffer.byteLength(text)).toBeLessThanOrEqual(5050);
|
||||
// 5,300 for point 16's queue drain (R119, Garry's rule of 2026-11-22: every Captain that lands PRs runs a standing process
|
||||
// that stops finished PRs piling up; the procedure is crew/docs/captain.md's Drain the queue).
|
||||
expect(Buffer.byteLength(text)).toBeLessThanOrEqual(5300);
|
||||
expect(text).toMatch(/^# How we work/);
|
||||
expect(citationProblems(text)).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* gstack-ship-queue count (lib/ship-queue-count.ts, R119): the finished-PR count a Captain reads at every wake, from
|
||||
* one gh call. Fixtures stand in for that call's GraphQL page.
|
||||
*/
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { COUNT_QUERY, queueCount } from '../lib/ship-queue-count';
|
||||
import type { QueueContext } from '../lib/ship-queue';
|
||||
|
||||
const NOW = new Date('2026-11-22T16:00:00Z');
|
||||
const hoursAgo = (h: number) => new Date(NOW.getTime() - h * 3_600_000).toISOString();
|
||||
type Over = Partial<{ isDraft: boolean; mergeable: string; baseRefName: string; login: string | null; rollup: string | null; committed: string }>;
|
||||
const pr = (number: number, hours: number, o: Over = {}) => ({
|
||||
number, title: `Change ${number}`, isDraft: o.isDraft ?? false, mergeable: o.mergeable ?? 'MERGEABLE', baseRefName: o.baseRefName ?? 'main',
|
||||
author: o.login === null ? null : { login: o.login ?? 'garrytan' },
|
||||
commits: { nodes: [{ commit: { committedDate: o.committed ?? hoursAgo(hours), statusCheckRollup: o.rollup === null ? null : { state: o.rollup ?? 'SUCCESS' } } }] },
|
||||
});
|
||||
function run(nodes: unknown[], o: { totalCount?: number; authors?: string[]; fail?: string } = {}) {
|
||||
const calls: string[][] = [];
|
||||
const ctx: QueueContext = {
|
||||
repoRoot: '/nonexistent', base: 'main',
|
||||
gh: args => { calls.push(args); return o.fail ? { ok: false, out: '', err: o.fail } : { ok: true, out: JSON.stringify({ data: { repository: { pullRequests: { totalCount: o.totalCount ?? nodes.length, nodes } } } }), err: '' }; },
|
||||
};
|
||||
return { out: queueCount(ctx, { now: NOW, authors: o.authors }), calls };
|
||||
}
|
||||
|
||||
describe('gstack-ship-queue count', () => {
|
||||
test('makes exactly one gh call and counts only finished PRs: our authors, on the base, not draft, not conflicting, green at the head', () => {
|
||||
const { out, calls } = run([
|
||||
pr(1, 3),
|
||||
pr(2, 5, { login: 'capy-ai' }),
|
||||
pr(3, 1, { login: 'app/garrytan-agents' }),
|
||||
pr(4, 2, { login: 'capy-ai[bot]', mergeable: 'UNKNOWN' }),
|
||||
pr(10, 9, { isDraft: true }),
|
||||
pr(11, 9, { mergeable: 'CONFLICTING' }),
|
||||
pr(12, 9, { login: 'dependabot' }),
|
||||
pr(13, 9, { login: null }),
|
||||
pr(14, 9, { baseRefName: 'release' }),
|
||||
pr(15, 9, { rollup: 'PENDING' }),
|
||||
pr(16, 9, { rollup: 'FAILURE' }),
|
||||
pr(17, 9, { rollup: null }),
|
||||
]);
|
||||
expect(calls).toEqual([['api', 'graphql', '-F', 'owner={owner}', '-F', 'name={repo}', '-f', `query=${COUNT_QUERY}`]]);
|
||||
expect(out.ok).toBe(true);
|
||||
expect(out.lines).toEqual([
|
||||
'QUEUE_COUNT: finished=4 waited_24h=0 oldest=5h #2 open=12 base=main authors=garrytan,capy-ai,garrytan-agents',
|
||||
'FINISHED: #2 5h Change 2',
|
||||
'FINISHED: #1 3h Change 1',
|
||||
'FINISHED: #4 2h Change 4',
|
||||
'FINISHED: #3 1h Change 3',
|
||||
]);
|
||||
});
|
||||
|
||||
test('more than 6 finished PRs prints DRAIN; exactly 6, none a day old, does not', () => {
|
||||
const six = [1, 2, 3, 4, 5, 6].map(n => pr(n, n));
|
||||
expect(run(six).out.lines.some(l => l.startsWith('DRAIN:'))).toBe(false);
|
||||
const seven = run([...six, pr(7, 7)]).out.lines;
|
||||
expect(seven[0]).toBe('QUEUE_COUNT: finished=7 waited_24h=0 oldest=7h #7 open=7 base=main authors=garrytan,capy-ai,garrytan-agents');
|
||||
expect(seven.at(-1)).toBe('DRAIN: 7 finished PRs are waiting (more than 6); start a drain this turn: land them, bundle them, or send each idle owner its next step (docs/captain.md#drain-the-queue)');
|
||||
});
|
||||
|
||||
test('one PR waiting 24 hours since its last commit prints DRAIN on its own; 23 hours does not', () => {
|
||||
expect(run([pr(1, 23.9)]).out.lines.some(l => l.startsWith('DRAIN:'))).toBe(false);
|
||||
const lines = run([pr(1, 2), pr(4670, 31)]).out.lines;
|
||||
expect(lines[0]).toBe('QUEUE_COUNT: finished=2 waited_24h=1 oldest=31h #4670 open=2 base=main authors=garrytan,capy-ai,garrytan-agents');
|
||||
expect(lines.at(-1)).toMatch(/^DRAIN: 1 has waited 24h or more \(oldest #4670, 31h\); start a drain this turn/);
|
||||
});
|
||||
|
||||
test('both bounds name both reasons; past 10 finished the list folds; over 100 open PRs says the count is partial', () => {
|
||||
const many = Array.from({ length: 12 }, (_, i) => pr(i + 1, 30 + i));
|
||||
const lines = run(many, { totalCount: 140 }).out.lines;
|
||||
expect(lines[1]).toBe('QUEUE_COUNT_PARTIAL: counted the oldest 12 of 140 open PRs');
|
||||
expect(lines.filter(l => l.startsWith('FINISHED: #'))).toHaveLength(10);
|
||||
expect(lines).toContain('FINISHED: and 2 more');
|
||||
expect(lines.at(-1)).toMatch(/^DRAIN: 12 finished PRs are waiting \(more than 6\) and 12 have waited 24h or more \(oldest #12, 41h\); /);
|
||||
});
|
||||
|
||||
test('--authors replaces the default list, and a failed gh call refuses with the fix instead of printing a zero count', () => {
|
||||
expect(run([pr(1, 2), pr(2, 2, { login: 'someone' })], { authors: ['someone'] }).out.lines[0]).toBe('QUEUE_COUNT: finished=1 waited_24h=0 oldest=2h #2 open=2 base=main authors=someone');
|
||||
const failed = run([], { fail: 'HTTP 401: Bad credentials' }).out;
|
||||
expect(failed.ok).toBe(false);
|
||||
expect(failed.lines).toEqual([]);
|
||||
expect(failed.failure).toMatchObject({ code: 'QUEUE_NOT_READY', message: 'gh could not list the open PRs: HTTP 401: Bad credentials' });
|
||||
});
|
||||
});
|
||||
@@ -21,7 +21,7 @@ import { bumpVersion } from '../crew/lib/version-gate-train';
|
||||
import { openRelease } from '../lib/release-stamp';
|
||||
import type { MergedRun } from '../lib/land-merged-checks';
|
||||
import { bunIsolationArgs } from '../lib/bun-isolation';
|
||||
import { readLock, writeLock } from '../crew/lib/ship-queue-land-lock';
|
||||
import { readLock, thisProcess, writeLock, LAND_LOCK_REF } from '../crew/lib/ship-queue-land-lock';
|
||||
import { flakyGit } from './helpers/flaky-git';
|
||||
import { runBackstop } from '../crew/scripts/train-backstop';
|
||||
import { readTrainNotes } from '../crew/scripts/release-cut';
|
||||
@@ -551,6 +551,24 @@ describe('land --pin: direct merge at the PR\'s own green head', () => {
|
||||
expect(dry.out).toContain('DRY-RUN: nothing verified');
|
||||
}, 120_000);
|
||||
|
||||
test.skipIf(process.platform !== 'linux')('the land lock: another PR\'s lock whose land process has exited is taken over without --break-lock, logged, and the land merges; the lock it writes names its process and expiry', () => {
|
||||
const fx = setup();
|
||||
const self = thisProcess()!;
|
||||
const exited = spawnSync('setsid', ['sh', '-c', 'cat /proc/$$/stat'], { encoding: 'utf8', timeout: 10_000 });
|
||||
const f = exited.stdout.slice(exited.stdout.lastIndexOf(')') + 2).split(' ');
|
||||
const pid = Number(exited.stdout.split(' ')[0]);
|
||||
const at = new Date().toISOString();
|
||||
expect(writeLock(fx.repo.work, readLock(fx.repo.work).sha, { pr: '90', holder: `gone:${pid}`, started_at: at, phase_at: at, phase: 'merging', journal: 'land-pin:' + '1'.repeat(40), proc: { ...self, pid, pgid: Number(f[2]), start: Number(f[19]), mark: 'gone' } }).ok).toBe(true);
|
||||
const pin = openPr(fx, '89');
|
||||
const r = land(fx, '89', pin);
|
||||
expect(r.status, r.err).toBe(EXIT.ok);
|
||||
expect(r.out).toContain(`LOCK_TAKEOVER: #90's land lock (holder gone:${pid}, phase merging, since ${at}): its land (process ${pid}) and every process it started have exited`);
|
||||
expect(fx.read().prs['89'].state).toBe('MERGED');
|
||||
expect(readLock(fx.repo.work).state).toBe('released');
|
||||
const took = fx.repo.git('log', '--format=%H %s', LAND_LOCK_REF).split('\n').find(l => l.includes('(took over #90'))!.split(' ')[0]!;
|
||||
expect(JSON.parse(fx.repo.git('show', `${took}:lock.json`))).toMatchObject({ pr: '89', proc: { boot: self.boot }, took_over: { pr: '90', holder: `gone:${pid}` }, expires_at: expect.any(String) });
|
||||
}, 120_000);
|
||||
|
||||
describe('GST-1344: a lock push GitHub applied but answered with an HTTP 502', () => {
|
||||
const lockAt = (fx: Fx) => JSON.parse(fx.repo.git('--git-dir', fx.repo.origin, 'show', 'refs/notes/gstack-land:lock.json'));
|
||||
const flaky = (fx: Fx) => { const g = flakyGit(fx.repo.root); return { g, run: (pr: string, pin: string, extra: string[] = []) => runBin(fx.repo, 'gstack-ship-queue', ['land', '--pr', pr, '--pin', pin, '--base', 'main', ...extra], { ...fx.env, ...g.env, PATH: `${g.dir}:${fx.env.PATH}` }) }; };
|
||||
|
||||
Reference in new issue
Block a user