mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-21 15:43:24 +01:00
fix(ship-queue): train land takes the shared land lock (train-scoped, freeze-owned), verify --train proves the stamp and needs GitHub MERGED, restamp stages its writes (#3599, #3531)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
93fc5dc9e8
commit
60a6ecb85e
21 files changed
+1055
-150
No files matched your search
+1
@@ -171,6 +171,7 @@
|
||||
{ "file": "lib/ship-queue-train-verify.ts", "movedFrom": "(new: verify --train, the queue freeze and its backstop, plan GSTA-49 T1)" },
|
||||
{ "file": "lib/ship-queue-train-ready.ts", "movedFrom": "(new: ready --screen|--no-screen and the READY receipt, plan GSTA-49 T1)" },
|
||||
{ "file": "lib/ship-queue-train-cli.ts", "movedFrom": "(new: merge-train argument parsing and output, plan GSTA-49 T1)" },
|
||||
{ "file": "lib/ship-queue-land-lock.ts", "movedFrom": "lib/ship-queue-land.ts (the land lock, shared with train land, #3599)" },
|
||||
{ "file": "lib/gate-cost.ts", "movedFrom": "(new: paid gate cost by model and token class, per-case costs, selection replays and the merge-train model, GSTA-49 T0)" },
|
||||
{ "file": "scripts/gate-cost-replay.ts", "movedFrom": "(new: CLI behind lib/gate-cost.ts: cached report artifacts, merged-PR replay and the train model table, GSTA-49 T0)" },
|
||||
{ "file": "lib/gate-cost-history.ts", "movedFrom": "(new: red attribution, red-head screen replay, READY times and the READY-arrival train replay, GSTA-49 T0b)" },
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* version-source shapes (package-manifest pin, monorepo pin, absent source).
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
@@ -163,7 +164,7 @@ describe('three PRs, reordered twice, zero manual edits', () => {
|
||||
expect(changed.status).toBe(EXIT.fail);
|
||||
expect(changed.out).toMatch(/^TREE: changed \(pr-b\.txt\)$/m);
|
||||
expect(changed.out).toMatch(/^gate-reuse: not-eligible \(tree changed: pr-b\.txt\) — fix: .* \(GATE_REUSE_NOT_ELIGIBLE\)$/m);
|
||||
});
|
||||
}, 30_000);
|
||||
|
||||
test('--dry-run prints the full diff and writes nothing; --was overrides the mention source', () => {
|
||||
const repo = fixture();
|
||||
@@ -191,7 +192,7 @@ describe('three PRs, reordered twice, zero manual edits', () => {
|
||||
const stamped = restamp(repo, ['--next']);
|
||||
expect(stamped.status).toBe(EXIT.ok);
|
||||
expect(stamped.out).toMatch(/^next: NEW_VERSION=1\.2\.4\.0; record the release decision, then write the CHANGELOG entry text only/m);
|
||||
});
|
||||
}, 30_000);
|
||||
|
||||
// Value: protects=a bump never repo's --next never invents a MICRO stamp: without --bump or --version it refuses and writes nothing, and an explicit level stamps as before; fails_when=restamp falls back to micro for a repo whose policy names no level;
|
||||
// why_new=GST-380 added bump never; seam=gstack-ship-policy, gstack-version-bump write; no_claim=the claim queue read
|
||||
@@ -454,7 +455,7 @@ describe('gate-ahead (--after), predecessor movement and queue staleness', () =>
|
||||
const viaGh = runBin(repo, 'gstack-tree-receipt', ['--from', path.join(repo.work, '.gstack/tmp/gate-ahead.json'), '--predecessor-pr', '1', '--bundle', bundle, '--base', 'main', '--json'], ghShim(repo, { '1': { headRefOid: repo.git('rev-parse', 'pr-a') } }));
|
||||
expect(JSON.parse(viaGh.out).predecessor.moved).toBe(true);
|
||||
expect(JSON.parse(viaGh.out).code).toBe('RESTAMP_PREDECESSOR_MOVED');
|
||||
});
|
||||
}, 30_000);
|
||||
|
||||
test('a gate-ahead merge that conflicts outside the stamp files is RESTAMP_MERGE_CONFLICT with nothing written', () => {
|
||||
const repo = fixture();
|
||||
@@ -587,3 +588,75 @@ describe('version-source shapes', () => {
|
||||
expect(fs.existsSync(path.join(repo.work, 'VERSION'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gstack-restamp stages what it writes (#3531)', () => {
|
||||
/** Branch b forks from main; branch a stamps and merges first, so b's base merge conflicts only on the CHANGELOG. */
|
||||
function behindMain(): FixtureRepo {
|
||||
const repo = fixture();
|
||||
makePr(repo, 'pr-b');
|
||||
makePr(repo, 'pr-a');
|
||||
expect(restamp(repo, ['--next']).status).toBe(EXIT.ok);
|
||||
repo.git('add', '-A');
|
||||
repo.git('commit', '-q', '-m', 'stamp pr-a');
|
||||
mergeToMain(repo, 'pr-a');
|
||||
repo.git('fetch', '-q', 'origin');
|
||||
repo.git('checkout', '-q', 'pr-b');
|
||||
return repo;
|
||||
}
|
||||
const cached = (repo: FixtureRepo) => repo.git('diff', '--cached', '--name-only').split('\n').filter(Boolean);
|
||||
const unstaged = (repo: FixtureRepo) => repo.git('diff', '--name-only').split('\n').filter(Boolean);
|
||||
const filesOf = (out: string) => (/^FILES: (.*)$/m.exec(out)?.[1] ?? '').split(' ').filter(Boolean);
|
||||
|
||||
test('after --next on a staged no-commit base merge, every FILES entry is staged, STAGED: names them, and a bare commit carries the stamp', () => {
|
||||
const repo = behindMain();
|
||||
const merge = spawnSync('git', ['merge', '--no-ff', '--no-commit', '-q', 'origin/main'], { cwd: repo.work, encoding: 'utf8', timeout: 30_000, env: { ...process.env, ...repo.env } });
|
||||
if (merge.status !== 0) {
|
||||
fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), mergeChangelogs(repo.git('show', ':2:CHANGELOG.md') + '\n', repo.git('show', ':3:CHANGELOG.md') + '\n')!);
|
||||
repo.git('add', 'CHANGELOG.md');
|
||||
}
|
||||
const r = restamp(repo, ['--next']);
|
||||
expect(r.status, r.err).toBe(EXIT.ok);
|
||||
const files = filesOf(r.out);
|
||||
expect(files).toEqual(expect.arrayContaining(['VERSION', 'CHANGELOG.md']));
|
||||
expect(cached(repo)).toEqual(expect.arrayContaining(files));
|
||||
expect(unstaged(repo).filter(f => files.includes(f))).toEqual([]);
|
||||
const staged = /^STAGED: (.*)$/m.exec(r.out)?.[1]?.split(' ') ?? [];
|
||||
expect(staged).toEqual(expect.arrayContaining(files));
|
||||
repo.git('commit', '-q', '--no-edit');
|
||||
expect(repo.git('show', 'HEAD:VERSION')).toBe('1.2.5.0');
|
||||
expect(repo.git('show', 'HEAD:CHANGELOG.md')).toMatch(/^# Changelog\n\n## \[1\.2\.5\.0\]/);
|
||||
expect(fs.existsSync(path.join(repo.work, '.gstack/tmp/restamp-staging.json'))).toBe(false);
|
||||
});
|
||||
|
||||
test('a stamp file with unstaged edits of its own refuses before writing (RESTAMP_UNSTAGED_EDITS); nothing written or staged', () => {
|
||||
const repo = fixture();
|
||||
makePr(repo, 'pr-c');
|
||||
fs.appendFileSync(path.join(repo.work, 'CHANGELOG.md'), '\n- an edit the caller has not staged\n');
|
||||
const r = restamp(repo, ['--next']);
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
expect(r.err).toMatch(/CHANGELOG\.md holds? unstaged edits of your own.*nothing written.*\(RESTAMP_UNSTAGED_EDITS\)/);
|
||||
expect(readFile(repo, 'VERSION')).toBe('1.2.3.0\n');
|
||||
expect(cached(repo)).toEqual([]);
|
||||
});
|
||||
|
||||
test('a staging failure prints RESTAMP_NOT_STAGED with the files written and a marker; the noop rerun stages them', () => {
|
||||
const repo = fixture();
|
||||
makePr(repo, 'pr-d');
|
||||
const lock = path.join(repo.work, '.git', 'index.lock');
|
||||
fs.writeFileSync(lock, '');
|
||||
const r = restamp(repo, ['--next']);
|
||||
expect(r.status).toBe(EXIT.fail);
|
||||
expect(r.err).toContain('(RESTAMP_NOT_STAGED)');
|
||||
expect(r.out).not.toMatch(/^STAGED:/m);
|
||||
expect(readFile(repo, 'VERSION')).toBe('1.2.4.0\n');
|
||||
expect(cached(repo)).toEqual([]);
|
||||
expect(fs.existsSync(path.join(repo.work, '.gstack/tmp/restamp-staging.json'))).toBe(true);
|
||||
fs.rmSync(lock, { force: true });
|
||||
const again = restamp(repo, ['--next']);
|
||||
expect(again.status, again.err).toBe(EXIT.ok);
|
||||
expect(again.out).toMatch(/^RESTAMP: .*\(noop;/m);
|
||||
expect(cached(repo)).toEqual(expect.arrayContaining(['VERSION', 'CHANGELOG.md']));
|
||||
expect(again.out).toMatch(/^STAGED: .*VERSION/m);
|
||||
expect(fs.existsSync(path.join(repo.work, '.gstack/tmp/restamp-staging.json'))).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -147,6 +147,41 @@ export function trainJson(fx: TrainFixture, nonce: string, state = fx.state): an
|
||||
}
|
||||
export const dispatches = (fx: TrainFixture, workflow?: string) => fx.read().log.filter(l => l.cmd === 'workflow run' && (!workflow || l.workflow === workflow));
|
||||
|
||||
/** For train land and land: pr view reads the head from origin's branch; pr edit and pr merge act on origin; any commit without recorded CI reads green. */
|
||||
export function wrapLand(fx: TrainFixture): void {
|
||||
const dir = path.join(fx.repo.root, 'gh-land-wrap');
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
const shim = path.join(fx.repo.root, 'gh-train-shim', 'shim.js');
|
||||
fs.writeFileSync(path.join(dir, 'gh'), [
|
||||
'#!/usr/bin/env node',
|
||||
"const fs=require('fs');const cp=require('child_process');const D=process.env.LAND_WRAP_DATA;const a=process.argv.slice(2);",
|
||||
"const d=JSON.parse(fs.readFileSync(D,'utf8'));const save=()=>fs.writeFileSync(D,JSON.stringify(d));",
|
||||
"const g=(...x)=>cp.execFileSync('git',['--git-dir',d.origin,...x],{encoding:'utf8',timeout:30000}).trim();",
|
||||
"const rev=r=>{try{return g('rev-parse','--verify','--quiet',r)}catch{return ''}};",
|
||||
"if(a[0]==='pr'&&a[1]==='view'&&d.prs[a[2]]){const p=d.prs[a[2]];const h=rev('refs/heads/'+p.headRefName);if(h)p.headRefOid=h;save();console.log(JSON.stringify(p));process.exit(0)}",
|
||||
"if(a[0]==='pr'&&a[1]==='edit'){(d.labels=d.labels||{})[a[2]]=a[a.indexOf('--add-label')+1];save();process.exit(0)}",
|
||||
"if(a[0]==='pr'&&a[1]==='merge'){const p=d.prs[a[2]];const want=a[a.indexOf('--match-head-commit')+1];if(rev('refs/heads/'+p.headRefName)!==want){console.error('Head branch was modified');process.exit(1)}",
|
||||
" const before=rev('main');let tree=rev(want+'^{tree}');",
|
||||
" if(d.outsideOnMerge){const blob=cp.execFileSync('git',['--git-dir',d.origin,'hash-object','-w','--stdin'],{input:'outside\\n',encoding:'utf8',timeout:30000}).trim();",
|
||||
" const ls=g('ls-tree',before+'^{tree}')+'\\n100644 blob '+blob+'\\toutside.txt';const ot=cp.execFileSync('git',['--git-dir',d.origin,'mktree'],{input:ls+'\\n',encoding:'utf8',timeout:30000}).trim();",
|
||||
" g('update-ref','refs/heads/main',g('commit-tree',ot,'-p',before,'-m','outside'));tree=g('merge-tree','--write-tree','--merge-base='+before,rev('main'),want).split('\\n')[0];d.outsideOnMerge=false}",
|
||||
" g('update-ref','refs/heads/main',g('commit-tree',tree,'-p',rev('main'),'-m','squash #'+a[2]));p.state='MERGED';save();process.exit(0)}",
|
||||
"const paged=/commits\\/([0-9a-f]+)\\/(check-runs|status)\\?.*page=(\\d+)/.exec(a[1]||'');",
|
||||
"if(a[0]==='api'&&paged&&!(d.ci||{})[paged[1]]&&!((d.statuses||{})[paged[1]])){const list=paged[2]==='check-runs'?[{name:'free-tests',status:'completed',conclusion:'success',id:1,completed_at:'2026-10-26T00:00:00Z'}]:[];const key=paged[2]==='check-runs'?'check_runs':'statuses';console.log(JSON.stringify(paged[3]==='1'?{total_count:list.length,state:'success',[key]:list}:{total_count:list.length,[key]:[]}));process.exit(0)}",
|
||||
`const r=cp.spawnSync('node',[${JSON.stringify(shim)},D,...a],{stdio:'inherit',timeout:120000});process.exit(r.status??1);`,
|
||||
'',
|
||||
].join('\n'), { mode: 0o755 });
|
||||
fx.env.PATH = `${dir}:${fx.env.PATH}`;
|
||||
(fx.env as Record<string, string>).LAND_WRAP_DATA = fx.dataFile;
|
||||
}
|
||||
|
||||
/** A changelog_fragments PR: a fragment under changelog.d/, pushed as pr-<n>, with a READY receipt. */
|
||||
export function fragmentPr(fx: TrainFixture, pr: string, fragment = `- #${pr} change\n`): string {
|
||||
const head = openPr(fx, pr, { file: `changelog.d/pr-${pr}.md`, text: fragment, changelog: false });
|
||||
fx.repo.git('push', '-q', 'origin', `${head}:refs/heads/pr-${pr}`);
|
||||
readyReceipt(fx, pr, head);
|
||||
return head;
|
||||
}
|
||||
function shimSource(): string {
|
||||
return [
|
||||
"const fs = require('fs'); const path = require('path'); const cp = require('child_process');",
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
/**
|
||||
* The shared land lock (lib/ship-queue-land-lock.ts, #3599): `land` and `train land` take the same
|
||||
* refs/notes/gstack-land lock, so a standalone land and a train slot can never both publish onto one main.
|
||||
* Module cases run against a bare origin and two clones (the race, the read states, owner kinds, the
|
||||
* --break-lock rules); command cases drive bin/gstack-ship-queue against the train fixture and its gh
|
||||
* shims (both directions, the train-scoped between phase, refusal and resume, the freeze-owned lock and the
|
||||
* repair train's takeover).
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { acquireLandLock, LAND_LOCK_REF, readLock, writeLock, type LandLock, type LockOwner } from '../lib/ship-queue-land-lock';
|
||||
import { BASE_POLICY, cleanup, makeFixtureRepo, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
import { coordinatorClone } from './helpers/ship-queue-fixture';
|
||||
import {
|
||||
GREEN_GATE, TRAIN_POLICY, fragmentPr, nonceOf, queue, trainFixture, trainJson, wrapLand, type TrainFixture,
|
||||
} from './helpers/ship-queue-train-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
const fixtures: TrainFixture[] = [];
|
||||
afterEach(() => {
|
||||
while (repos.length) cleanup(repos.pop()!);
|
||||
while (fixtures.length) cleanup(fixtures.pop()!.repo);
|
||||
});
|
||||
|
||||
const T0 = Date.parse('2026-10-31T12:00:00Z');
|
||||
const at = (min: number) => () => new Date(T0 + min * 60_000);
|
||||
|
||||
/** Run fn with the fixture's git identity in process.env (the lock writes commits in-process). */
|
||||
function withRepoEnv<T>(repo: FixtureRepo, fn: () => T): T {
|
||||
const saved = Object.fromEntries(Object.keys(repo.env).map(k => [k, process.env[k]]));
|
||||
Object.assign(process.env, repo.env);
|
||||
try { return fn(); } finally {
|
||||
for (const [k, v] of Object.entries(saved)) { if (v === undefined) delete process.env[k]; else process.env[k] = v; }
|
||||
}
|
||||
}
|
||||
function bareRepo(): FixtureRepo { const r = makeFixtureRepo({ policy: BASE_POLICY, prefix: 'gstack-land-lock-' }); repos.push(r); return r; }
|
||||
const standalone = (pr: string): LockOwner => ({ pr });
|
||||
const slotOf = (train: string, slot: number, pr: string): LockOwner => ({ train, slot, pr });
|
||||
function take(root: string, owner: LockOwner, o: { journal?: string; now?: () => Date; breakLock?: boolean; breakTrainLock?: boolean; liveTrain?: (nonce: string) => boolean; phase?: LandLock['phase'] } = {}) {
|
||||
return acquireLandLock({
|
||||
root, holder: 'test:1', owner, journal: o.journal ?? ('train' in owner && owner.train ? `train/${owner.train}/slot-${owner.slot}` : `land/${owner.pr}`),
|
||||
phase: () => o.phase ?? 'stamping', now: o.now ?? at(0), breakLock: o.breakLock, breakTrainLock: o.breakTrainLock, liveTrain: o.liveTrain,
|
||||
});
|
||||
}
|
||||
const failureOf = (r: ReturnType<typeof take>) => ('failure' in r ? r.failure : null);
|
||||
|
||||
describe('the lock module', () => {
|
||||
test('two writers racing the same lock sha leave one winner', () => {
|
||||
const repo = bareRepo();
|
||||
const other = coordinatorClone(repo);
|
||||
withRepoEnv(repo, () => {
|
||||
const lock = (pr: string): LandLock => ({ pr, holder: `h${pr}`, started_at: new Date(T0).toISOString(), phase: 'stamping', journal: `land/${pr}` });
|
||||
expect(readLock(repo.work).state).toBe('absent');
|
||||
const first = writeLock(repo.work, '', lock('1'));
|
||||
const second = writeLock(other, '', lock('2'));
|
||||
expect([first.ok, second.ok]).toEqual([true, false]);
|
||||
const seen = readLock(other);
|
||||
expect(seen.state === 'held' && seen.lock.pr).toBe('1');
|
||||
const a = writeLock(repo.work, seen.sha, lock('3'));
|
||||
const b = writeLock(other, seen.sha, lock('4'));
|
||||
expect([a.ok, b.ok]).toEqual([true, false]);
|
||||
const final = readLock(other);
|
||||
expect(final.state === 'held' && final.lock.pr).toBe('3');
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
test('absent, released, held and unreadable are distinct; an unreadable lock refuses, and --break-lock replaces it', () => {
|
||||
const repo = bareRepo();
|
||||
withRepoEnv(repo, () => {
|
||||
const root = repo.work;
|
||||
expect(readLock(root)).toMatchObject({ state: 'absent' });
|
||||
const got = take(root, standalone('5'));
|
||||
expect(failureOf(got)).toBeNull();
|
||||
expect(readLock(root)).toMatchObject({ state: 'held', lock: { pr: '5', phase: 'stamping' } });
|
||||
if ('held' in got) expect(got.held.release()).toBe(true);
|
||||
expect(readLock(root)).toMatchObject({ state: 'released' });
|
||||
const junk = repo.git('commit-tree', '4b825dc642cb6eb9a060e54bf8d69288fbee4904', '-m', 'not a lock');
|
||||
repo.git('push', '-q', '-f', 'origin', `${junk}:${LAND_LOCK_REF}`);
|
||||
expect(readLock(root)).toMatchObject({ state: 'unreadable' });
|
||||
const refused = take(root, standalone('6'));
|
||||
expect(failureOf(refused)).toMatchObject({ code: 'QUEUE_LAND_LOCKED' });
|
||||
expect(failureOf(refused)!.message).toContain('cannot be read');
|
||||
const broke = take(root, standalone('6'), { breakLock: true });
|
||||
expect(failureOf(broke)).toBeNull();
|
||||
expect(broke.lines.join('\n')).toContain(`LOCK: broke an unreadable lock at ${junk.slice(0, 12)}`);
|
||||
expect(readLock(root)).toMatchObject({ state: 'held', lock: { pr: '6' } });
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
test('ownership compares the owner kind and journal: the same PR across commands and across trains refuses; a resume of the same journal and a sequential acquisition succeed', () => {
|
||||
const repo = bareRepo();
|
||||
withRepoEnv(repo, () => {
|
||||
const root = repo.work;
|
||||
const mine = take(root, standalone('7'), { phase: 'waiting' });
|
||||
expect(failureOf(mine)).toBeNull();
|
||||
const asSlot = take(root, slotOf('trainA', 1, '7'));
|
||||
expect(failureOf(asSlot)).toMatchObject({ code: 'QUEUE_LAND_LOCKED' });
|
||||
expect(failureOf(asSlot)!.message).toMatch(/^#7 holds the land lock \(test:1, phase waiting, since /);
|
||||
const resumed = take(root, standalone('7'), { now: at(3) });
|
||||
expect(failureOf(resumed)).toBeNull();
|
||||
expect(readLock(root)).toMatchObject({ state: 'held', lock: { pr: '7', started_at: new Date(T0).toISOString() } });
|
||||
if ('held' in resumed) resumed.held.release();
|
||||
|
||||
const trainA = take(root, slotOf('trainA', 1, '7'), { phase: 'pushing' });
|
||||
expect(failureOf(trainA)).toBeNull();
|
||||
expect(readLock(root)).toMatchObject({ state: 'held', lock: { train: 'trainA', slot: 1, pr: '7' } });
|
||||
const trainB = take(root, slotOf('trainB', 1, '7'));
|
||||
expect(failureOf(trainB)!.message).toMatch(/^train trainA slot 1 \(#7\) holds the land lock/);
|
||||
expect(failureOf(take(root, standalone('7')))!.message).toMatch(/^train trainA slot 1 \(#7\) holds the land lock/);
|
||||
expect(failureOf(take(root, slotOf('trainA', 2, '8')))!.message).toMatch(/^train trainA slot 1 \(#7\) holds the land lock/);
|
||||
const same = take(root, slotOf('trainA', 1, '7'));
|
||||
expect(failureOf(same)).toBeNull();
|
||||
if ('held' in same) same.held.release();
|
||||
expect(failureOf(take(root, standalone('8')))).toBeNull();
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
test('--break-lock prints the holder, refuses a live train run\'s lock without --break-train-lock, and keeps the staleness, mid-push, between and freeze rules', () => {
|
||||
const repo = bareRepo();
|
||||
withRepoEnv(repo, () => {
|
||||
const root = repo.work;
|
||||
const hold = (owner: LockOwner, phase: LandLock['phase']) => {
|
||||
const r = readLock(root);
|
||||
if (r.state === 'held') writeLock(root, r.sha, { released: true, by: 'test', at: new Date(T0).toISOString() });
|
||||
expect(failureOf(take(root, owner, { phase }))).toBeNull();
|
||||
};
|
||||
hold(slotOf('trainA', 2, '9'), 'waiting');
|
||||
const live = take(root, standalone('3'), { breakLock: true, now: at(1) });
|
||||
expect(failureOf(live)).toMatchObject({ code: 'QUEUE_LAND_LOCKED' });
|
||||
expect(failureOf(live)!.message).toContain('--break-train-lock');
|
||||
expect(live.lines).toContain(`LOCK_HOLDER: train trainA slot 2 (#9) holder=test:1 phase=waiting since=${new Date(T0).toISOString()}`);
|
||||
const ended = take(root, standalone('3'), { breakLock: true, now: at(1), liveTrain: () => false });
|
||||
expect(failureOf(ended)).toBeNull();
|
||||
expect(ended.lines).toContain("LOCK: broke train trainA slot 2 (#9)'s lock (test:1, phase waiting)");
|
||||
|
||||
hold(slotOf('trainA', 2, '9'), 'waiting');
|
||||
const forced = take(root, standalone('3'), { breakLock: true, breakTrainLock: true, now: at(1) });
|
||||
expect(failureOf(forced)).toBeNull();
|
||||
|
||||
hold(slotOf('trainA', 1, '9'), 'between');
|
||||
const young = take(root, standalone('3'), { breakLock: true, breakTrainLock: true, now: at(1) });
|
||||
expect(failureOf(young)!.message).toMatch(/train trainA slot 1 \(#9\) is between slots \(60 s ago\); --break-lock refused/);
|
||||
expect(failureOf(take(root, standalone('3'), { breakLock: true, breakTrainLock: true, now: at(11) }))).toBeNull();
|
||||
|
||||
hold(slotOf('trainA', 1, '9'), 'pushing');
|
||||
expect(failureOf(take(root, standalone('3'), { breakLock: true, breakTrainLock: true, now: at(1) }))!.message).toMatch(/train trainA slot 1 \(#9\)'s holder is mid-push \(60 s ago\); --break-lock refused/);
|
||||
|
||||
hold(slotOf('trainA', 1, '9'), 'freeze');
|
||||
const frozen = take(root, standalone('3'), { breakLock: true, breakTrainLock: true, now: at(60) });
|
||||
expect(failureOf(frozen)).toMatchObject({ code: 'QUEUE_TRAIN_FROZEN' });
|
||||
expect(failureOf(take(root, slotOf('trainB', 1, '4'), { breakLock: true, breakTrainLock: true, now: at(60) }))).toMatchObject({ code: 'QUEUE_TRAIN_FROZEN' });
|
||||
|
||||
hold(standalone('5'), 'waiting');
|
||||
const plain = take(root, standalone('3'), { breakLock: true, now: at(1) });
|
||||
expect(plain.lines).toContain(`LOCK_HOLDER: #5 holder=test:1 phase=waiting since=${new Date(T0).toISOString()}`);
|
||||
expect(plain.lines).toContain("LOCK: broke #5's lock (test:1, phase waiting)");
|
||||
});
|
||||
}, 60_000);
|
||||
});
|
||||
|
||||
const POLICY = { ...TRAIN_POLICY, release_tool: null, release_outputs: [], changelog_fragments: { dir: 'changelog.d' }, min_gstack_version: '1.91.336.0' };
|
||||
function stampedTrain(prs = ['1', '2']) {
|
||||
const fx = trainFixture(POLICY, 'gstack-land-lock-'); fixtures.push(fx); wrapLand(fx);
|
||||
const heads = prs.map(pr => fragmentPr(fx, pr));
|
||||
fx.write(d => { d.rules['evals.yml'] = GREEN_GATE; });
|
||||
const nonce = nonceOf(queue(fx, ['train', 'build', '--prs', prs.map((pr, i) => `${pr}@${heads[i]}`).join(',')]).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
return { fx, heads, nonce };
|
||||
}
|
||||
const trainLand = (fx: TrainFixture, nonce: string, pr: string, extra: string[] = []) => queue(fx, ['train', 'land', '--train', nonce, '--pr', pr, '--no-wait', ...extra]);
|
||||
const land = (fx: TrainFixture, pr: string, extra: string[] = []) => queue(fx, ['land', '--pr', pr, '--no-wait', '--allow-repo-commands', ...extra]);
|
||||
const originRev = (fx: TrainFixture, ref: string) => fx.repo.git('--git-dir', fx.repo.origin, 'rev-parse', '--verify', '-q', ref);
|
||||
/** The lock as origin holds it: the parsed lock.json, or null when origin has no lock ref. */
|
||||
function originLock(fx: TrainFixture): any {
|
||||
const sha = (() => { try { return originRev(fx, LAND_LOCK_REF); } catch { return ''; } })();
|
||||
return sha ? JSON.parse(fx.repo.git('--git-dir', fx.repo.origin, 'show', `${sha}:lock.json`)) : null;
|
||||
}
|
||||
const freezeFile = (fx: TrainFixture) => path.join(fx.state, 'ship-queue', 'freeze');
|
||||
|
||||
describe('land and train land share the lock', () => {
|
||||
test('a train slot holding the lock refuses a standalone land (no takeover, no freeze; --break-lock names the train and wants --break-train-lock); the train keeps it between slots and releases it after the last', () => {
|
||||
const { fx, heads, nonce } = stampedTrain();
|
||||
const pin3 = fragmentPr(fx, '3');
|
||||
const pushed = trainLand(fx, nonce, '1');
|
||||
expect(pushed.out, pushed.err).toMatch(/^PUSHED: [0-9a-f]{40}/m);
|
||||
expect(originLock(fx)).toMatchObject({ train: nonce, slot: 1, pr: '1', phase: 'waiting' });
|
||||
const lockSha = originRev(fx, LAND_LOCK_REF);
|
||||
|
||||
const blocked = land(fx, '3');
|
||||
expect(blocked.status).toBe(EXIT.refused);
|
||||
expect(blocked.err).toMatch(new RegExp(`train ${nonce} slot 1 \\(#1\\) holds the land lock .*phase waiting.*\\(QUEUE_LAND_LOCKED\\)`));
|
||||
const broke = land(fx, '3', ['--break-lock']);
|
||||
expect(broke.status).toBe(EXIT.refused);
|
||||
expect(broke.err).toContain('--break-train-lock');
|
||||
expect(broke.out).toMatch(new RegExp(`^LOCK_HOLDER: train ${nonce} slot 1 \\(#1\\) holder=\\S+ phase=waiting since=`, 'm'));
|
||||
expect(originRev(fx, LAND_LOCK_REF)).toBe(lockSha);
|
||||
expect(originRev(fx, 'refs/heads/pr-3')).toBe(pin3);
|
||||
expect(fs.existsSync(freezeFile(fx))).toBe(false);
|
||||
|
||||
const merged = trainLand(fx, nonce, '1');
|
||||
expect(merged.status, merged.err).toBe(EXIT.ok);
|
||||
expect(originLock(fx)).toMatchObject({ train: nonce, slot: 1, pr: '1', phase: 'between' });
|
||||
expect(land(fx, '3').err).toMatch(new RegExp(`train ${nonce} slot 1 \\(#1\\) holds the land lock .*phase between.*\\(QUEUE_LAND_LOCKED\\)`));
|
||||
expect(originRev(fx, 'refs/heads/pr-3')).toBe(pin3);
|
||||
|
||||
const second = trainLand(fx, nonce, '2');
|
||||
expect(second.out, second.err).toMatch(/^LOCK: train \S+ slot 2 takes over its train's between-slots lock/m);
|
||||
expect(originLock(fx)).toMatchObject({ train: nonce, slot: 2, pr: '2', phase: 'waiting' });
|
||||
expect(trainLand(fx, nonce, '2').status).toBe(EXIT.ok);
|
||||
expect(originLock(fx)).toMatchObject({ released: true });
|
||||
expect(trainJson(fx, nonce).state).toBe('merged');
|
||||
expect(land(fx, '3').out).toMatch(/^PUSHED: [0-9a-f]{40}/m);
|
||||
void heads;
|
||||
}, 300_000);
|
||||
|
||||
test('a standalone land holding the lock refuses train land; a refusal before any push releases the train\'s lock', () => {
|
||||
const { fx, heads, nonce } = stampedTrain();
|
||||
fragmentPr(fx, '3');
|
||||
expect(land(fx, '3').out).toMatch(/^PUSHED: /m);
|
||||
const blocked = trainLand(fx, nonce, '1');
|
||||
expect(blocked.status).toBe(EXIT.refused);
|
||||
expect(blocked.err).toMatch(/#3 holds the land lock .*phase waiting.*\(QUEUE_LAND_LOCKED\)/);
|
||||
expect(blocked.out).not.toMatch(/^PUSHED:/m);
|
||||
expect(originRev(fx, 'refs/heads/pr-1')).toBe(heads[0]);
|
||||
|
||||
expect(land(fx, '3').out).toContain('LOCK: released');
|
||||
const stale = trainLand(fx, nonce, '1');
|
||||
expect(stale.err).toMatch(/nothing of train \S+ merged, so the queue is not frozen.*\(QUEUE_TRAIN_TREE_MISMATCH\)/);
|
||||
expect(originLock(fx)).toMatchObject({ released: true });
|
||||
}, 300_000);
|
||||
|
||||
test('after a push the train keeps its lock through a failed wait and a resume takes it back', () => {
|
||||
const { fx, nonce } = stampedTrain(['1']);
|
||||
const stamp = /^PUSHED: ([0-9a-f]{40})/m.exec(trainLand(fx, nonce, '1').out)![1]!;
|
||||
fx.write(d => { d.ci[stamp] = [{ name: 'free-tests', status: 'completed', conclusion: 'failure' }] as any; });
|
||||
const red = trainLand(fx, nonce, '1');
|
||||
expect(red.status).not.toBe(EXIT.ok);
|
||||
expect(originLock(fx)).toMatchObject({ train: nonce, slot: 1, pr: '1', phase: 'waiting' });
|
||||
fx.write(d => { delete d.ci[stamp]; });
|
||||
const resumed = trainLand(fx, nonce, '1');
|
||||
expect(resumed.status, resumed.err).toBe(EXIT.ok);
|
||||
expect(originLock(fx)).toMatchObject({ released: true });
|
||||
}, 300_000);
|
||||
|
||||
test('a stop that freezes leaves the lock in a freeze phase that --break-lock never breaks; only the admitted repair train takes it over, and it is released once the freeze clears', () => {
|
||||
const { fx, nonce } = stampedTrain();
|
||||
trainLand(fx, nonce, '1');
|
||||
expect(trainLand(fx, nonce, '1').status).toBe(EXIT.ok);
|
||||
trainLand(fx, nonce, '2');
|
||||
fx.write(d => { (d as any).outsideOnMerge = true; });
|
||||
const drift = trainLand(fx, nonce, '2');
|
||||
expect(drift.err).toContain('(QUEUE_TRAIN_TREE_MISMATCH)');
|
||||
expect(drift.out).toMatch(/^QUEUE_TRAIN_FROZEN: /m);
|
||||
expect(originLock(fx)).toMatchObject({ train: nonce, phase: 'freeze' });
|
||||
const lockSha = originRev(fx, LAND_LOCK_REF);
|
||||
|
||||
fragmentPr(fx, '3');
|
||||
const refused = land(fx, '3', ['--break-lock', '--break-train-lock']);
|
||||
expect(refused.status).toBe(EXIT.refused);
|
||||
expect(refused.err).toContain('(QUEUE_TRAIN_FROZEN)');
|
||||
expect(originRev(fx, LAND_LOCK_REF)).toBe(lockSha);
|
||||
|
||||
const h4 = fragmentPr(fx, '4');
|
||||
const repair = queue(fx, ['train', 'build', '--repair', '--prs', `4@${h4}`]);
|
||||
expect(repair.status, repair.err).toBe(EXIT.ok);
|
||||
const rn = nonceOf(repair.out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', rn]).status).toBe(EXIT.ok);
|
||||
const taken = trainLand(fx, rn, '4');
|
||||
expect(taken.out, taken.err).toMatch(new RegExp(`^LOCK: repair train ${rn} takes over the freeze lock of train ${nonce}`, 'm'));
|
||||
expect(originLock(fx)).toMatchObject({ train: rn, slot: 1, pr: '4', phase: 'freeze' });
|
||||
expect(land(fx, '3', ['--break-lock', '--break-train-lock']).err).toContain('(QUEUE_TRAIN_FROZEN)');
|
||||
const cleared = trainLand(fx, rn, '4');
|
||||
expect(cleared.status, cleared.err).toBe(EXIT.ok);
|
||||
expect(cleared.out).toMatch(/^FREEZE: cleared /m);
|
||||
expect(originLock(fx)).toMatchObject({ released: true });
|
||||
}, 600_000);
|
||||
});
|
||||
@@ -10,47 +10,13 @@ import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { cleanup } from './helpers/restamp-fixture';
|
||||
import {
|
||||
GREEN_GATE, RED_GATE, TRAIN_POLICY, line, nonceOf, openPr, queue, readyReceipt, shippedBody, trainFixture, trainJson, type TrainFixture,
|
||||
GREEN_GATE, RED_GATE, TRAIN_POLICY, fragmentPr, line, nonceOf, openPr, queue, readyReceipt, shippedBody, trainFixture, trainJson, wrapLand as wrap, type TrainFixture,
|
||||
} from './helpers/ship-queue-train-fixture';
|
||||
|
||||
const POLICY = { ...TRAIN_POLICY, release_tool: null, release_outputs: [], changelog_fragments: { dir: 'changelog.d' }, min_gstack_version: '1.91.336.0' };
|
||||
const fixtures: TrainFixture[] = [];
|
||||
afterEach(() => { while (fixtures.length) cleanup(fixtures.pop()!.repo); });
|
||||
|
||||
/** pr view reads the head from origin's branch; pr edit and pr merge act on origin; any commit without recorded CI reads green. */
|
||||
function wrap(fx: TrainFixture): void {
|
||||
const dir = path.join(fx.repo.root, 'gh-land-wrap');
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
const shim = path.join(fx.repo.root, 'gh-train-shim', 'shim.js');
|
||||
fs.writeFileSync(path.join(dir, 'gh'), [
|
||||
'#!/usr/bin/env node',
|
||||
"const fs=require('fs');const cp=require('child_process');const D=process.env.LAND_WRAP_DATA;const a=process.argv.slice(2);",
|
||||
"const d=JSON.parse(fs.readFileSync(D,'utf8'));const save=()=>fs.writeFileSync(D,JSON.stringify(d));",
|
||||
"const g=(...x)=>cp.execFileSync('git',['--git-dir',d.origin,...x],{encoding:'utf8',timeout:30000}).trim();",
|
||||
"const rev=r=>{try{return g('rev-parse','--verify','--quiet',r)}catch{return ''}};",
|
||||
"if(a[0]==='pr'&&a[1]==='view'&&d.prs[a[2]]){const p=d.prs[a[2]];const h=rev('refs/heads/'+p.headRefName);if(h)p.headRefOid=h;save();console.log(JSON.stringify(p));process.exit(0)}",
|
||||
"if(a[0]==='pr'&&a[1]==='edit'){(d.labels=d.labels||{})[a[2]]=a[a.indexOf('--add-label')+1];save();process.exit(0)}",
|
||||
"if(a[0]==='pr'&&a[1]==='merge'){const p=d.prs[a[2]];const want=a[a.indexOf('--match-head-commit')+1];if(rev('refs/heads/'+p.headRefName)!==want){console.error('Head branch was modified');process.exit(1)}",
|
||||
" const before=rev('main');let tree=rev(want+'^{tree}');",
|
||||
" if(d.outsideOnMerge){const blob=cp.execFileSync('git',['--git-dir',d.origin,'hash-object','-w','--stdin'],{input:'outside\\n',encoding:'utf8',timeout:30000}).trim();",
|
||||
" const ls=g('ls-tree',before+'^{tree}')+'\\n100644 blob '+blob+'\\toutside.txt';const ot=cp.execFileSync('git',['--git-dir',d.origin,'mktree'],{input:ls+'\\n',encoding:'utf8',timeout:30000}).trim();",
|
||||
" g('update-ref','refs/heads/main',g('commit-tree',ot,'-p',before,'-m','outside'));tree=g('merge-tree','--write-tree','--merge-base='+before,rev('main'),want).split('\\n')[0];d.outsideOnMerge=false}",
|
||||
" g('update-ref','refs/heads/main',g('commit-tree',tree,'-p',rev('main'),'-m','squash #'+a[2]));p.state='MERGED';save();process.exit(0)}",
|
||||
"const paged=/commits\\/([0-9a-f]+)\\/(check-runs|status)\\?.*page=(\\d+)/.exec(a[1]||'');",
|
||||
"if(a[0]==='api'&&paged&&!(d.ci||{})[paged[1]]&&!((d.statuses||{})[paged[1]])){const list=paged[2]==='check-runs'?[{name:'free-tests',status:'completed',conclusion:'success',id:1,completed_at:'2026-10-26T00:00:00Z'}]:[];const key=paged[2]==='check-runs'?'check_runs':'statuses';console.log(JSON.stringify(paged[3]==='1'?{total_count:list.length,state:'success',[key]:list}:{total_count:list.length,[key]:[]}));process.exit(0)}",
|
||||
`const r=cp.spawnSync('node',[${JSON.stringify(shim)},D,...a],{stdio:'inherit',timeout:120000});process.exit(r.status??1);`,
|
||||
'',
|
||||
].join('\n'), { mode: 0o755 });
|
||||
fx.env.PATH = `${dir}:${fx.env.PATH}`;
|
||||
(fx.env as Record<string, string>).LAND_WRAP_DATA = fx.dataFile;
|
||||
}
|
||||
|
||||
function fragmentPr(fx: TrainFixture, pr: string, fragment = `- #${pr} change\n`): string {
|
||||
const head = openPr(fx, pr, { file: `changelog.d/pr-${pr}.md`, text: fragment, changelog: false });
|
||||
fx.repo.git('push', '-q', 'origin', `${head}:refs/heads/pr-${pr}`);
|
||||
readyReceipt(fx, pr, head);
|
||||
return head;
|
||||
}
|
||||
function stampedTrain(gate = GREEN_GATE, policy: Record<string, unknown> = POLICY) {
|
||||
const fx = trainFixture(policy, 'gstack-train-land-'); fixtures.push(fx); wrap(fx);
|
||||
const h1 = fragmentPr(fx, '1');
|
||||
@@ -193,7 +159,7 @@ describe('stamped trains: build and land', () => {
|
||||
const { fx, nonce } = stampedTrain();
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const hook = path.join(fx.repo.origin, 'hooks', 'pre-receive');
|
||||
fs.writeFileSync(hook, '#!/bin/sh\nexit 1\n', { mode: 0o755 });
|
||||
fs.writeFileSync(hook, '#!/bin/sh\nwhile read old new ref; do [ "$ref" = refs/heads/pr-1 ] && exit 1; done\nexit 0\n', { mode: 0o755 });
|
||||
const failed = land(fx, nonce, '1');
|
||||
expect(failed.err).toMatch(/the stamp push failed and pr-1 still reads.*\(QUEUE_NOT_READY\)/);
|
||||
expect(failed.err).not.toContain('QUEUE_TRAIN_MOVED');
|
||||
|
||||
+185
-13
@@ -59,6 +59,34 @@ function publishMain(fx: TrainFixture, prefixCommit: string, version: string, ex
|
||||
return repo.git('rev-parse', 'HEAD');
|
||||
}
|
||||
|
||||
/** The lane's slot stamp on its pin (main merged in first from slot 2 on): gstack-restamp --next, then the stamp files committed and pushed as the PR head. */
|
||||
function laneStamp(fx: TrainFixture, pr: string, pin: string, o: { mergeMain?: boolean; dropStamp?: boolean } = {}): string {
|
||||
const { repo } = fx;
|
||||
repo.git('reset', '-q', '--hard');
|
||||
repo.git('fetch', '-q', 'origin');
|
||||
repo.git('checkout', '-q', '-B', `lane${pr}`, pin);
|
||||
if (o.mergeMain) {
|
||||
const m = spawnSync('git', ['merge', '--no-ff', '--no-commit', '-q', 'origin/main'], { cwd: repo.work, encoding: 'utf8', timeout: 30_000, env: { ...process.env, ...repo.env } });
|
||||
if (m.status !== 0) {
|
||||
const side = (n: number) => repo.git('show', `:${n}:CHANGELOG.md`) + '\n';
|
||||
fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), mergeChangelogs(side(2), side(3), side(1))!);
|
||||
repo.git('add', 'CHANGELOG.md');
|
||||
}
|
||||
}
|
||||
const index = repo.git('write-tree');
|
||||
const stamp = runBin(repo, 'gstack-restamp', ['--next', '--base', 'main', '--allow-repo-commands'], fx.env);
|
||||
expect(stamp.status, stamp.err).toBe(EXIT.ok);
|
||||
const files = line(stamp.out, 'FILES:').slice('FILES: '.length).split(' ').filter(Boolean);
|
||||
if (o.dropStamp) repo.git('read-tree', index);
|
||||
else repo.git('add', '-A', '--', ...files);
|
||||
repo.git('commit', '-q', '--no-edit', '-m', `slot stamp #${pr}`);
|
||||
if (o.dropStamp) repo.git('checkout', '-q', '--', '.');
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
repo.git('push', '-q', '-f', 'origin', `${head}:refs/pull/${pr}/head`);
|
||||
return head;
|
||||
}
|
||||
const markMerged = (fx: TrainFixture, pr: string) => fx.write(d => { (d.prs[pr] as any).state = 'MERGED'; });
|
||||
|
||||
// fails_when=coordinatorClone copies origin.git/objects file by file again, so an entry that appears or vanishes there mid-copy (the detached maintenance.lock every push into the fixture origin leaves) fails the clone, as in two Free Tests reds on 2026-10-28 (GSTA-139 ledger); why_new=no other test clones while origin's objects directory changes; seam=a dangling symlink planted under objects/, which a local copy refuses on every run; no_claim=which process removed the loose object those runs named
|
||||
test('the coordinator clone reads origin through git, never by copying its objects directory (GSTA-139)', () => {
|
||||
const fx = make();
|
||||
@@ -794,21 +822,24 @@ describe('verify, freeze, repair and clear', () => {
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string, train = nonce) => queue(fx, ['verify', '--pr', pr, '--train', train], {}, coord);
|
||||
|
||||
const s1 = laneStamp(fx, '1', h1);
|
||||
const pre1 = v('1');
|
||||
expect(pre1.status).toBe(EXIT.ok);
|
||||
expect(pre1.out).toContain(`VERIFY_TRAIN: #1 may merge as slot 1 of train ${nonce}`);
|
||||
expect(line(pre1.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h1}`);
|
||||
expect(line(pre1.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${s1}`);
|
||||
const early = v('2');
|
||||
expect(early.status).toBe(EXIT.fail);
|
||||
expect(early.err).toMatch(/is neither T1 nor T2 modulo stamps.*nothing of train \S+ merged, so the queue is not frozen.*\(QUEUE_TRAIN_TREE_MISMATCH\)/);
|
||||
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: fx.repo.git('show', `${s1}:CHANGELOG.md`) + '\n' });
|
||||
markMerged(fx, '1');
|
||||
const post1 = v('1');
|
||||
expect(post1.status).toBe(EXIT.ok);
|
||||
expect(post1.out).toMatch(/^main: [0-9a-f]{40} = T1 \(same modulo stamps \(1 stamp file\(s\)\)\)$/m);
|
||||
expect(post1.out).toMatch(/^main: [0-9a-f]{40} = T1 \(same modulo stamps \(2 stamp file\(s\)\)\)$/m);
|
||||
expect(post1.out).toContain(`VERIFY_TRAIN: #1 merged; main's tree is T1 of train ${nonce} (1/2 merged)`);
|
||||
expect(next(post1.out)).toBe(`NEXT: gstack-ship-queue verify --pr 2 --train ${nonce}`);
|
||||
expect(line(v('2').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h2}`);
|
||||
const s2 = laneStamp(fx, '2', h2, { mergeMain: true });
|
||||
expect(line(v('2').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${s2}`);
|
||||
|
||||
const broken = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'stray.txt', text: 'not in the train\n' });
|
||||
const mismatch = v('2');
|
||||
@@ -836,8 +867,16 @@ describe('verify, freeze, repair and clear', () => {
|
||||
expect(queue(fx, ['train', 'verdict', '--train', rn]).status).toBe(EXIT.ok);
|
||||
expect(v('2').err).toContain('(QUEUE_TRAIN_FROZEN)');
|
||||
expect(dispatches(fx, 'evals.yml').filter(d => d.ref === 'main').length).toBe(1);
|
||||
expect(line(v('3', rn).out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h3}`);
|
||||
// The broken main still carries T2's [Unreleased] section, so #3's lane stamps its own entry by hand.
|
||||
fx.repo.git('checkout', '-q', '-B', 'lane3', h3);
|
||||
fs.writeFileSync(path.join(fx.repo.work, 'VERSION'), '1.2.6.0\n');
|
||||
fs.writeFileSync(path.join(fx.repo.work, 'CHANGELOG.md'), fx.repo.git('show', `${h3}:CHANGELOG.md`).replace('## [Unreleased]', '## [1.2.6.0] - 2026-10-18') + '\n');
|
||||
fx.repo.git('commit', '-qam', 'slot stamp #3');
|
||||
const s3 = fx.repo.git('rev-parse', 'HEAD');
|
||||
fx.repo.git('push', '-q', '-f', 'origin', `${s3}:refs/pull/3/head`);
|
||||
expect(line(v('3', rn).out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${s3}`);
|
||||
publishMain(fx, trainJson(fx, rn).prefixes[1].commit, '1.2.6.0');
|
||||
markMerged(fx, '3');
|
||||
const cleared = v('3', rn);
|
||||
expect(cleared.status).toBe(EXIT.ok);
|
||||
expect(cleared.out).toMatch(/^FREEZE: cleared \(repair #3 via train \S+; main [0-9a-f]{12} carries a green record\)$/m);
|
||||
@@ -852,14 +891,10 @@ describe('verify, freeze, repair and clear', () => {
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = () => queue(fx, ['verify', '--pr', '1', '--train', nonce], {}, coord);
|
||||
const { repo } = fx;
|
||||
repo.git('checkout', '-q', '-B', 'lane1', h1);
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.4.0\n');
|
||||
repo.git('commit', '-qam', 'v1.2.4.0 stamp');
|
||||
const stamped = repo.git('rev-parse', 'HEAD');
|
||||
repo.git('push', '-q', '-f', 'origin', `${stamped}:refs/pull/1/head`);
|
||||
const stamped = laneStamp(fx, '1', h1);
|
||||
const ok = v();
|
||||
expect(ok.status).toBe(EXIT.ok);
|
||||
expect(ok.out).toContain(`head: ${stamped} (same modulo stamps (1 stamp file(s)))`);
|
||||
expect(ok.out).toContain(`head: ${stamped} (same modulo stamps (5 stamp file(s)))`);
|
||||
expect(ok.out).toContain(`SHIP_RECEIPT: pr=1 head=${h1.slice(0, 12)} version=- base=main (binds the pinned head)`);
|
||||
expect(line(ok.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${stamped}`);
|
||||
setPrBody(fx, '1', shippedBody('1', 'b'.repeat(40)));
|
||||
@@ -900,6 +935,7 @@ describe('verify, freeze, repair and clear', () => {
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
markMerged(fx, '1');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
|
||||
const { repo } = fx;
|
||||
@@ -909,6 +945,7 @@ describe('verify, freeze, repair and clear', () => {
|
||||
repo.git('rm', '-rq', '.');
|
||||
repo.git('checkout', t.prefixes[2].commit, '--', '.');
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.5.0\n');
|
||||
fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), repo.git('show', `${t.prefixes[2].commit}:CHANGELOG.md`).replace('## [Unreleased]', '## [1.2.5.0] - 2026-10-18') + '\n');
|
||||
if (extra) fs.writeFileSync(path.join(repo.work, extra.file), extra.text);
|
||||
repo.git('add', '-A');
|
||||
const tree = repo.git('write-tree');
|
||||
@@ -991,8 +1028,10 @@ describe('verify, freeze, repair and clear', () => {
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
|
||||
// Slot 1: #1 squash-merges and is released as 1.2.4.0 (its [Unreleased] re-headed).
|
||||
expect(line(v('1').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h1}`);
|
||||
const s1 = laneStamp(fx, '1', h1);
|
||||
expect(line(v('1').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${s1}`);
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: repo.git('show', `${t.prefixes[1].commit}:CHANGELOG.md`).replace('## [Unreleased]', '## [1.2.4.0] - 2026-10-18') + '\n' });
|
||||
markMerged(fx, '1');
|
||||
expect(v('1').out).toContain(`VERIFY_TRAIN: #1 merged; main's tree is T1 of train ${nonce} (1/2 merged)`);
|
||||
|
||||
// Slot 2: the lane merges main into its pin; mergeChangelogs carries the child past its released parent.
|
||||
@@ -1016,6 +1055,7 @@ describe('verify, freeze, repair and clear', () => {
|
||||
// The squash merge publishes exactly that tree; the post-merge verify confirms it instead of freezing the queue.
|
||||
const main2 = publishMain(fx, laneHead, '1.2.5.0');
|
||||
expect(repo.git('rev-parse', `${main2}^{tree}`)).toBe(repo.git('rev-parse', `${laneHead}^{tree}`));
|
||||
markMerged(fx, '2');
|
||||
const post = v('2');
|
||||
expect([post.status, post.err]).toEqual([EXIT.ok, '']);
|
||||
expect(line(post.out, 'main:')).toBe(`main: ${main2} = T2 (same modulo stamps (1 stamp file(s)) except CHANGELOG.md, main ${main1.slice(0, 12)}'s CHANGELOG.md plus #2's own entry)`);
|
||||
@@ -1033,8 +1073,10 @@ describe('verify, freeze, repair and clear', () => {
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const released = (prefix: string, version: string) => fx.repo.git('show', `${prefix}:CHANGELOG.md`).replace('## [Unreleased]', `## [${version}] - 2026-10-18`) + '\n';
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: released(t.prefixes[1].commit, '1.2.4.0') });
|
||||
markMerged(fx, '1');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
expect(line(v('2').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h2}`);
|
||||
const s2 = laneStamp(fx, '2', h2, { mergeMain: true });
|
||||
expect(line(v('2').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${s2}`);
|
||||
// Main's CHANGELOG plus #2's stamped entry, with one line the pin never wrote.
|
||||
const smuggled = fx.repo.git('show', `${main1}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.5.0] - 2026-10-18\n\n- #2 change\n- added after the gate\n') + '\n';
|
||||
const broken = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'CHANGELOG.md', text: smuggled });
|
||||
@@ -1116,6 +1158,7 @@ describe('verify, freeze, repair and clear', () => {
|
||||
const rn = nonceOf(queue(fx, ['train', 'build', '--repair', '--prs', `3@${h3}`]).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', rn]).status).toBe(EXIT.ok);
|
||||
publishMain(fx, trainJson(fx, rn).prefixes[1].commit, '1.2.6.0');
|
||||
markMerged(fx, '3');
|
||||
const cleared = queue(fx, ['verify', '--pr', '3', '--train', rn], {}, coord);
|
||||
expect(cleared.out).toMatch(/^FREEZE: cleared /m);
|
||||
expect(next(cleared.out)).toBe(`NEXT: gh pr view 2 --json state,headRefOid (unreadable at the freeze: #2@${h2.slice(0, 12)}); seat each that is OPEN in a train`);
|
||||
@@ -1130,6 +1173,7 @@ describe('verify, freeze, repair and clear', () => {
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
markMerged(fx, '1');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
const later = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'stray.txt', text: 'a later train\n' });
|
||||
fx.write(d => { (d.prs['2'] as any).state = 'MERGED'; });
|
||||
@@ -1162,6 +1206,7 @@ describe('verify, freeze, repair and clear', () => {
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
markMerged(fx, '1');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
const later = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'stray.txt', text: 'a later train\n' });
|
||||
const tree = fx.repo.git('rev-parse', `${later}^{tree}`);
|
||||
@@ -1186,6 +1231,7 @@ describe('verify, freeze, repair and clear', () => {
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const released = fx.repo.git('show', `${t.prefixes[1].commit}:CHANGELOG.md`).replace('## [Unreleased]', '## [1.2.4.0] - 2026-10-18') + '\n';
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: released });
|
||||
markMerged(fx, '1');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
const foreign = publishMain(fx, t.prefixes[1].commit, '1.2.4.1', { file: 'stray.txt', text: 'landed between the two slots\n' });
|
||||
const text = fx.repo.git('show', `${main1}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.5.0] - 2026-10-18\n\n- #2 change\n- added after the gate\n') + '\n';
|
||||
@@ -1198,3 +1244,129 @@ describe('verify, freeze, repair and clear', () => {
|
||||
expect(line(frozen.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1; main /);
|
||||
}, 300_000);
|
||||
});
|
||||
|
||||
describe('verify --train proves the slot stamp and a GitHub merge (#3531)', () => {
|
||||
/** A main commit that carries an unstamped [Unreleased] entry, the way a bare commit after a no-commit merge shipped #3527. */
|
||||
function unstampedMain(fx: TrainFixture, entry: string): string {
|
||||
const { repo } = fx;
|
||||
repo.git('fetch', '-q', 'origin');
|
||||
repo.git('checkout', '-q', '-B', 'mainsim', 'origin/main');
|
||||
fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), fs.readFileSync(path.join(repo.work, 'CHANGELOG.md'), 'utf8').replace('# Changelog\n', `# Changelog\n\n## [Unreleased]\n\n${entry}\n`));
|
||||
repo.git('commit', '-qam', 'merged without its stamp');
|
||||
repo.git('push', '-q', 'origin', 'HEAD:refs/heads/main');
|
||||
repo.git('fetch', '-q', 'origin');
|
||||
return repo.git('rev-parse', 'HEAD');
|
||||
}
|
||||
const freezeFile = (fx: TrainFixture) => path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`);
|
||||
|
||||
test('#3527: an unstamped slot head (the bare pin, or a no-commit base merge committed without the restamp it wrote) refuses QUEUE_TRAIN_UNSTAMPED naming both versions; the stamped head passes with STAMP_VERSION from the head', () => {
|
||||
const fx = make();
|
||||
const { h1, h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
|
||||
const bare = v('1');
|
||||
expect(bare.status).toBe(EXIT.refused);
|
||||
expect(bare.err).toMatch(/#1's head [0-9a-f]{12} is not stamped above main: version: the head's VERSION 1\.2\.3\.0 is not above main's 1\.2\.3\.0.*\(QUEUE_TRAIN_UNSTAMPED\)/);
|
||||
expect(bare.out).not.toContain('MERGE_CONDITION:');
|
||||
expect(next(bare.out)).toMatch(/^NEXT: #1's lane runs gstack-restamp --next on its head, commits what restamp staged/);
|
||||
|
||||
const s1 = laneStamp(fx, '1', h1);
|
||||
const ok = v('1');
|
||||
expect(ok.status, ok.err).toBe(EXIT.ok);
|
||||
expect(ok.out).toContain('STAMP_VERSION: 1.2.4.0');
|
||||
expect(line(ok.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${s1}`);
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: fx.repo.git('show', `${s1}:CHANGELOG.md`) + '\n' });
|
||||
markMerged(fx, '1');
|
||||
expect(v('1').out).toContain(`VERIFY_TRAIN: #1 merged; main's tree is T1 of train ${nonce} (1/2 merged)`);
|
||||
|
||||
laneStamp(fx, '2', h2, { mergeMain: true, dropStamp: true });
|
||||
const dropped = v('2');
|
||||
expect(dropped.status, dropped.err).toBe(EXIT.refused);
|
||||
expect(dropped.err).toMatch(/#2's head [0-9a-f]{12} is not stamped above main: version: the head's VERSION 1\.2\.4\.0 is not above main's 1\.2\.4\.0.*\(QUEUE_TRAIN_UNSTAMPED\)/);
|
||||
expect(dropped.out).not.toContain('MERGE_CONDITION:');
|
||||
expect(fs.existsSync(freezeFile(fx))).toBe(false);
|
||||
const s2 = laneStamp(fx, '2', h2, { mergeMain: true });
|
||||
const stamped = v('2');
|
||||
expect(stamped.status, stamped.err).toBe(EXIT.ok);
|
||||
expect(stamped.out).toContain('STAMP_VERSION: 1.2.5.0');
|
||||
expect(line(stamped.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${s2}`);
|
||||
}, 300_000);
|
||||
|
||||
test('the CHANGELOG rule is named: a head whose VERSION moved but whose entry is still [Unreleased] refuses', () => {
|
||||
const fx = make();
|
||||
const { h1, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const { repo } = fx;
|
||||
repo.git('checkout', '-q', '-B', 'lane1', h1);
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.4.0\n');
|
||||
repo.git('commit', '-qam', 'VERSION only');
|
||||
repo.git('push', '-q', '-f', 'origin', `${repo.git('rev-parse', 'HEAD')}:refs/pull/1/head`);
|
||||
const r = queue(fx, ['verify', '--pr', '1', '--train', nonce], {}, coordinatorClone(fx.repo));
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
expect(r.err).toMatch(/is not stamped above main: changelog: CHANGELOG\.md's top section at the head is \[Unreleased\], not \[1\.2\.4\.0\].*\(QUEUE_TRAIN_UNSTAMPED\)/);
|
||||
}, 300_000);
|
||||
|
||||
test('claim-at-open: a pin that carries its own stamp verifies at head == pin', () => {
|
||||
const fx = make({ ...TRAIN_POLICY, queue_mode: 'claim-at-open' });
|
||||
const h1 = openPr(fx, '1', { file: 'VERSION', text: '1.2.4.0\n', changelog: cl => cl.replace('# Changelog\n', '# Changelog\n\n## [1.2.4.0] - 2026-10-18\n\n- #1 change\n') });
|
||||
readyReceipt(fx, '1', h1);
|
||||
fx.write(d => { d.rules['evals.yml'] = GREEN_GATE; });
|
||||
const nonce = nonceOf(queue(fx, ['train', 'build', '--prs', `1@${h1}`, '--urgent']).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const r = queue(fx, ['verify', '--pr', '1', '--train', nonce], {}, coordinatorClone(fx.repo));
|
||||
expect(r.status, r.err).toBe(EXIT.ok);
|
||||
expect(r.out).toContain('STAMP_VERSION: 1.2.4.0');
|
||||
expect(line(r.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h1}`);
|
||||
}, 300_000);
|
||||
|
||||
test('#3530: an open release-only PR whose stamp-only diff makes main equal its prefix modulo stamps is not reported merged; it takes the pre-merge path', () => {
|
||||
const fx = make();
|
||||
unstampedMain(fx, '- #3527 change');
|
||||
const h5 = openPr(fx, '5', { file: 'VERSION', text: '1.2.4.0\n', changelog: cl => cl.replace('## [Unreleased]', '## [1.2.4.0] - 2026-10-18') });
|
||||
readyReceipt(fx, '5', h5);
|
||||
fx.write(d => { d.rules['evals.yml'] = GREEN_GATE; });
|
||||
const nonce = nonceOf(queue(fx, ['train', 'build', '--prs', `5@${h5}`, '--urgent']).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const r = queue(fx, ['verify', '--pr', '5', '--train', nonce], {}, coordinatorClone(fx.repo));
|
||||
expect(r.out).not.toMatch(/^VERIFY_TRAIN: #5 merged/m);
|
||||
expect(r.status, r.err).toBe(EXIT.ok);
|
||||
expect(r.out).toContain(`VERIFY_TRAIN: #5 may merge as slot 1 of train ${nonce}`);
|
||||
expect(line(r.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h5}`);
|
||||
expect(trainJson(fx, nonce).merged).toEqual([]);
|
||||
}, 300_000);
|
||||
|
||||
test('no false freeze: main at the next prefix while GitHub reports the PR OPEN, or cannot be read, refuses QUEUE_PROOF_MISSING and never freezes; MERGED confirms', () => {
|
||||
const fx = make();
|
||||
const { h1, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
laneStamp(fx, '1', h1);
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
markMerged(fx, '1');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
publishMain(fx, t.prefixes[2].commit, '1.2.5.0');
|
||||
|
||||
const open = v('2');
|
||||
expect(open.status).toBe(EXIT.refused);
|
||||
expect(open.err).toMatch(/GitHub reports #2 as OPEN, not MERGED.*\(QUEUE_PROOF_MISSING\)/);
|
||||
expect(open.out).not.toMatch(/^VERIFY_TRAIN: #2 merged/m);
|
||||
expect(open.out).not.toMatch(/^QUEUE_TRAIN_FROZEN:/m);
|
||||
expect(next(open.out)).toContain('rerun once GitHub reports #2 MERGED');
|
||||
const saved = fx.read().prs['2'];
|
||||
fx.write(d => { delete d.prs['2']; });
|
||||
const unread = v('2');
|
||||
expect(unread.err).toContain('(QUEUE_PROOF_MISSING)');
|
||||
expect(unread.out).not.toMatch(/^QUEUE_TRAIN_FROZEN:/m);
|
||||
expect(fs.existsSync(freezeFile(fx))).toBe(false);
|
||||
fx.write(d => { d.prs['2'] = { ...(saved as object), state: 'MERGED' }; });
|
||||
const done = v('2');
|
||||
expect(done.status, done.err).toBe(EXIT.ok);
|
||||
expect(done.out).toContain(`VERIFY_TRAIN: #2 merged; main's tree is T2 of train ${nonce} (2/2 merged)`);
|
||||
}, 300_000);
|
||||
});
|
||||
Reference in new issue
Block a user