Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
/**
* GST-1561 (founderstar#563): a receipt carry whose diff holds both a changed product path and a context path had no
* bounded route. RECEIPT_CARRY_SCOPED_REVIEW opened only when no path changed, and J1's scoped re-check refused whenever
* base context moved, so a base merge that bumped a constant the branch also replaces (SAVE_VERSION := 82 became 83 on
* the base; the branch's own `:= 84` line is byte-identical) next to a moved base block forced a full /ship every time.
* Here: a changed path plus context paths take one composed advisory packet bound to range_base, past the size cap it
* refuses as before, and a branch-side change to an added line still needs review. GST-2706: a hunk whose removed lines
* changed with the base (82 -> 84 reviewed, then the base took 83) is a changed path, not context, so its head gets a full
* review: the PR's own added and removed lines must both be the reviewed bytes for carry to keep the receipt.
*/
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { EXIT } from '../lib/headless-artifacts';
import { comparePath } from '../lib/ship-patch';
import { bindReceipt, CARRY_NAMED_PATHS, extractReceipt, placeReceipt, planCarry } from '../lib/ship-receipt';
import { RECHECK_RANGE_DIFF_CAP } from '../crew/lib/ship-recheck';
import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
setDefaultTimeout(120_000);
const BIN = path.dirname(RELEASE);
const RECEIPT = path.join(BIN, 'gstack-ship-receipt');
const LANE = 'tests=printf " 3 pass\\n 0 fail\\nRan 3 tests across 1 file. [5.00ms]\\n"';
const READER = 'anthropic/claude-opus-5-5';
const ships: ShipFx[] = [];
afterEach(() => { while (ships.length) ships.pop()!.cleanup(); });
const GAME = 'scripts/core/game.gd';
const VESTING = 'scripts/core/vesting.gd';
const SCORE = 'scripts/core/score.gd';
const game = (save: number) => ['extends Node', '', `const SAVE_VERSION := ${save}`, '', 'func _ready():', '\tload_save()', '', 'func load_save():', '\tpass', ''].join('\n') + '\n';
const vesting = (edit: Record<number, string> = {}) => Array.from({ length: 12 }, (_, i) => edit[i + 1] ?? `var v${i + 1} := ${i + 1}`).join('\n') + '\n';
const BRANCH_VESTING = { 6: 'func was_vesting_clear(): return granted and not revoked' };
const BASE_VESTING = { 4: 'var v4 := 40 # moved by the base' };
const UNATTENDED = { GSTACK_SESSION_KIND: 'unattended' };
/** A branch reviewed at its first commit (receipt written by gstack-ship-receipt write, so it records review_depth). */
function reviewedBranch(base: Record<string, string>, feat: Record<string, string>) {
const f = shipFixture(base, feat); ships.push(f);
const from = f.git('rev-parse', 'HEAD').stdout.trim();
const reviewedTree = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
const reviewedBase = f.git('merge-base', 'origin/main', 'HEAD').stdout.trim();
const body = path.join(f.root, 'body.md');
fs.writeFileSync(body, '## Summary\n');
const w = f.run(RECEIPT, ['write', '--pr', '5', '--base', 'main', '--body', body], UNATTENDED);
expect([w.status, w.stderr.slice(0, 400)]).toEqual([EXIT.ok, expect.any(String)]);
expect(extractReceipt(fs.readFileSync(body, 'utf8')).receipt!.review_depth).toBeDefined();
const carry = (extra: string[] = []) => f.run(RECEIPT, ['carry', '--body', body, '--base', 'main', ...extra], UNATTENDED);
return { f, from, reviewedTree, reviewedBase, body, carry };
}
/** Merge origin/main; a conflict takes `resolved` and commits the merge. */
function mergeMain(f: ShipFx, resolved: Record<string, string>) {
f.git('fetch', '-q', 'origin');
if (f.git('merge', '-q', '--no-edit', 'origin/main').status !== 0) { f.write(resolved); f.commit('merge main'); }
}
/** founderstar#563: the base took SAVE_VERSION 83 under the branch's 84, and moved a block next to the branch's vesting hunk. */
function founderstar(resolvedSave = 84, baseBlock = 0) {
const x = reviewedBranch({ [GAME]: game(82), [VESTING]: vesting(), [SCORE]: 'var score := 1\n' }, { [GAME]: game(84), [VESTING]: vesting(BRANCH_VESTING) });
const moved = { 4: [BASE_VESTING[4], ...Array.from({ length: baseBlock }, (_, i) => `var base${i} := ${i}`)].join('\n') };
x.f.advanceBase({ [GAME]: game(83), [VESTING]: vesting(moved) });
mergeMain(x.f, { [GAME]: game(resolvedSave), [VESTING]: vesting({ ...moved, ...BRANCH_VESTING }) });
const head = x.f.git('rev-parse', 'HEAD').stdout.trim();
const sides = { reviewedBase: x.reviewedBase, reviewed: x.from, currentBase: x.f.git('merge-base', 'origin/main', 'HEAD').stdout.trim(), current: head };
return { ...x, head, sides };
}
const scopedPacket = (err: string) => /one scoped reader \(not a review round\) reads (\S+), then rerun carry/.exec(err)?.[1];
const eligible = (err: string) => /^RECHECK: advisory range_diff_lines=(\d+) range_diff_sha256=([0-9a-f]{64}) packet=(\S+);/m.exec(err);
const recordAt = (f: ShipFx, name: string, v: object) => { const file = path.join(f.root, name); fs.writeFileSync(file, JSON.stringify(v)); return file; };
describe('a base-side removed line next to byte-identical added lines (GST-1561 ask 2, GST-2706)', () => {
test('comparePath calls it changed, since the PR now removes other lines than the reviewed ones; moved context alone stays context', () => {
const same = founderstar();
expect(comparePath(same.f.work, same.sides, GAME)).toBe('changed');
expect(comparePath(same.f.work, same.sides, VESTING)).toBe('context');
const moved = founderstar(85);
expect(comparePath(moved.f.work, moved.sides, GAME)).toBe('changed');
});
test('a branch that now also removes a line the base never touched stays changed', () => {
const x = reviewedBranch({ [GAME]: game(82) }, { [GAME]: game(84) });
x.f.advanceBase({ [GAME]: game(83) });
mergeMain(x.f, { [GAME]: game(84).replace('\tload_save()\n', '') });
const head = x.f.git('rev-parse', 'HEAD').stdout.trim();
const sides = { reviewedBase: x.reviewedBase, reviewed: x.from, currentBase: x.f.git('merge-base', 'origin/main', 'HEAD').stdout.trim(), current: head };
expect(comparePath(x.f.work, sides, GAME)).toBe('changed');
});
for (const [where, inserted] of [['before', game(82).replace('const SAVE', 'const BASE_ADD := 1\nconst SAVE')], ['after', game(82).replace(':= 82\n', ':= 82\nconst BASE_ADD := 1\n')], ['beside its own edit of', game(83).replace(':= 83\n', ':= 83\nconst BASE_ADD := 1\n')]] as const) {
test(`a merge that drops a line the base inserted ${where} the replaced line stays changed`, () => {
const x = reviewedBranch({ [GAME]: game(82) }, { [GAME]: game(84) });
x.f.advanceBase({ [GAME]: inserted });
mergeMain(x.f, { [GAME]: game(84) });
if (fs.readFileSync(path.join(x.f.work, GAME), 'utf8') !== game(84)) { x.f.write({ [GAME]: game(84) }); x.f.commit('drop the base line'); }
const head = x.f.git('rev-parse', 'HEAD').stdout.trim();
const sides = { reviewedBase: x.reviewedBase, reviewed: x.from, currentBase: x.f.git('merge-base', 'origin/main', 'HEAD').stdout.trim(), current: head };
expect(comparePath(x.f.work, sides, GAME)).toBe('changed');
});
}
});
describe('carry: the founderstar#563 shape gets a full review (GST-2706)', () => {
test('a removed line the base changed is a product change: no scoped route, and a clean scoped record carries nothing', () => {
const { f, head, carry, body } = founderstar();
const before = fs.readFileSync(body, 'utf8');
const ask = carry();
expect([ask.status, ask.stdout.trim().split('\n')[0]], ask.stderr).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)']);
expect(ask.stderr).toContain(GAME);
expect(scopedPacket(ask.stderr)).toBeUndefined();
const r = carry(['--scoped-review', recordAt(f, 'scoped.json', { head, paths: [GAME, VESTING], reviewer: READER, verdict: 'clean' })]);
expect([r.status, r.stdout.trim().split('\n')[0]]).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)']);
expect(fs.readFileSync(body, 'utf8')).toBe(before);
expect(extractReceipt(before).receipt!.head).not.toBe(head);
});
test('a branch-side change to the added line still forces review (never the scoped context route)', () => {
const { carry } = founderstar(85);
const r = carry();
expect(r.status).toBe(EXIT.refused);
expect(r.stdout).toContain('RECEIPT_CARRY_PRODUCT_CHANGED');
expect(r.stderr).toContain(GAME);
expect(r.stdout).not.toContain('RECEIPT_CARRY_SCOPED_REVIEW');
});
});
describe('carry: a changed path plus context paths compose into one bounded re-check (GST-1561 ask 1)', () => {
const composed = (baseBlock = 0) => {
const x = founderstar(84, baseBlock);
x.f.write({ [SCORE]: 'var score0 := 2\n' }); x.f.commit('fix: score');
return { ...x, head: x.f.git('rev-parse', 'HEAD').stdout.trim() };
};
test('one advisory packet holds the range-diff and the context hunks, bound to range_base; no record carries (GST-2673)', () => {
const { f, from, head, reviewedBase, carry, body } = composed();
const ask = carry();
expect([ask.status, ask.stdout.trim().split('\n')[0]], ask.stderr).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)']);
const m = eligible(ask.stderr);
expect(m, ask.stderr).not.toBeNull();
const text = fs.readFileSync(m![3]!, 'utf8');
for (const s of ['var score0 := 2', 'was_vesting_clear', 'moved by the base', `range_base ${reviewedBase}`]) expect(text).toContain(s);
const before = fs.readFileSync(body, 'utf8');
const record = { from, head, range_base: reviewedBase, range_diff_sha256: m![2], reader: READER, verdict: 'clean' };
const r = carry(['--recheck', recordAt(f, 'recheck.json', record)]);
expect([r.status, r.stderr.includes('--recheck is gone')]).toEqual([EXIT.refused, true]);
expect(fs.readFileSync(body, 'utf8')).toBe(before);
});
test('past the size cap it refuses as before: RECEIPT_CARRY_PRODUCT_CHANGED, re-check not eligible', () => {
const { carry } = composed(RECHECK_RANGE_DIFF_CAP);
const r = carry();
expect([r.status, r.stdout.trim().split('\n')[0]]).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)']);
expect(r.stderr).toMatch(/RECHECK: not eligible \(the packet is \d+ lines, over the scoped re-check cap/);
expect(eligible(r.stderr)).toBeNull();
});
test('changed-only keeps J1 as it is; context-only carries with no reader (GST-3562 G)', () => {
const changed = reviewedBranch({ [SCORE]: 'var score := 1\n' }, { [SCORE]: 'var score := 2\n' });
changed.f.write({ [SCORE]: 'var score := 3\n' }); changed.f.commit('fix: score 3');
const c = changed.carry();
const m = eligible(c.stderr);
expect(m, c.stderr).not.toBeNull();
expect(c.stderr).not.toContain('"range_base"');
expect(fs.readFileSync(m![3]!, 'utf8')).not.toContain('# Scoped review');
const context = reviewedBranch({ [VESTING]: vesting() }, { [VESTING]: vesting(BRANCH_VESTING) });
context.f.advanceBase({ [VESTING]: vesting(BASE_VESTING) });
mergeMain(context.f, { [VESTING]: vesting({ ...BASE_VESTING, ...BRANCH_VESTING }) });
const s = context.carry();
expect(s.status, s.stderr).toBe(EXIT.ok);
expect(s.stderr).not.toContain('RECHECK:');
expect(extractReceipt(fs.readFileSync(context.body, 'utf8')).receipt!.carry!.reason).toContain(`base context moved next to unchanged own lines (${VESTING}; CI at head checks it)`);
});
});
describe('finish: the founderstar#563 shape needs no reader (GST-3562 G)', () => {
test('ROUTE sends nothing to behavior or context: the moved base context next to unchanged own lines counts as reviewed', () => {
const x = founderstar();
const post = path.join(x.f.root, 'post.json');
expect(x.f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'README.md']).status).toBe(0);
const finish = (extra: string[] = []) => x.f.run(RELEASE, ['finish', '--base', 'main', '--reviewed-tree', x.reviewedTree, '--docs-post', post, '--lane', LANE, '--reviewed-base', x.reviewedBase, ...extra]);
const ok = finish();
expect([ok.status, lineOf(ok.stdout, 'ROUTE')], ok.stdout).toEqual([0, expect.stringMatching(/ behavior=0 .* base=[12] context=0$/)]);
expect(ok.stdout).not.toContain('SCOPED_REVIEW');
expect(ok.stdout).not.toContain('STOP:');
});
});
describe('a receipt a scoped re-check carried never carries on or lands (GST-2706)', () => {
/** Reviewed at A, carried to B by a test-only change, then (as old gstack's J1 wrote it) relabelled a re-check hop. */
const lineage = (recheck: boolean) => {
const x = reviewedBranch({ [SCORE]: 'var score := 1\n' }, { [SCORE]: 'var score := 2\n' });
x.f.write({ 'test/score.test.ts': 'test("score", () => {});\n' }); x.f.commit('test: score');
const b = x.f.git('rev-parse', 'HEAD').stdout.trim();
const hop = x.carry();
expect([hop.status, hop.stderr.slice(0, 400)]).toEqual([EXIT.ok, expect.any(String)]);
const text = fs.readFileSync(x.body, 'utf8');
expect(extractReceipt(text).receipt!.carry!.reason).toBe('test-only change');
if (recheck) fs.writeFileSync(x.body, text.replace(/("reason":\s*)"test-only change"/, `$1"scoped re-check by ${READER} (range-diff 12 lines)"`));
expect(extractReceipt(fs.readFileSync(x.body, 'utf8')).receipt!.carry!.reason.startsWith('scoped re-check by ')).toBe(recheck);
return { ...x, b };
};
test('carry refuses it at its own head and after a base merge, and the receipt stays put; an ordinary carry lineage still carries', () => {
for (const recheck of [true, false]) {
const { f, b, body, carry } = lineage(recheck);
const at = carry();
expect(at.stdout.trim().split('\n')[0]).toBe(recheck ? 'CARRY: refused (RECEIPT_CARRY_REFUSED)' : `CARRY: current (the receipt already names ${b.slice(0, 12)})`);
f.advanceBase({ 'README.md': '# Fx moved\n' });
mergeMain(f, {});
const before = fs.readFileSync(body, 'utf8');
const r = carry();
if (!recheck) { expect([r.status, r.stderr.slice(0, 400)]).toEqual([EXIT.ok, expect.any(String)]); continue; }
expect([r.status, r.stdout.trim().split('\n')[0]]).toEqual([EXIT.refused, 'CARRY: refused (RECEIPT_CARRY_REFUSED)']);
expect(r.stderr).toContain('through a scoped re-check');
expect(r.stderr).toContain('never got a full review');
expect(fs.readFileSync(body, 'utf8')).toBe(before);
}
});
test('the queue refuses to bind it at its head, so READY and land need a fresh full review', () => {
for (const recheck of [true, false]) {
const { b, body } = lineage(recheck);
const bound = bindReceipt(fs.readFileSync(body, 'utf8'), '5', [b]);
if (!recheck) { expect(bound.ok).toBe(true); continue; }
expect(bound).toMatchObject({ ok: false, code: 'QUEUE_RECEIPT_STALE', message: expect.stringContaining('through a scoped re-check') });
}
});
});
describe('a receipt that records only what binding needs (GST-3562 H)', () => {
// Value: protects=/ship's receipt no longer needs the docs, review-loop, issue or budget records: a write with none of them
// binds at its head, and a receipt from before H that carries them still binds; fails_when=write or bindReceipt starts
// requiring one of those records again, or rejects an older receipt that has them; seam=gstack-ship-receipt write +
// bindReceipt; no_claim=the queue's other ready checks
test('a slim receipt writes and binds, and an older receipt with every record still binds', () => {
const x = reviewedBranch({ [VESTING]: vesting() }, { [VESTING]: vesting(BRANCH_VESTING) });
const body = fs.readFileSync(x.body, 'utf8');
const slim = extractReceipt(body).receipt!;
expect(['review_loop', 'calls', 'spend_usd', 'docs_audit_read'].filter(k => k in slim)).toEqual([]);
expect(bindReceipt(body, '5', [x.from], { base: 'main' })).toMatchObject({ ok: true, head: x.from });
const older = placeReceipt('## Summary\n', { ...slim, review_loop: { passes: 2, blocking_found: 1, deferred: 1, fixed: 1, rounds: 2 }, calls: 14, spend_usd: 3.25, docs_audit_read: { paths: ['README.md'], reviewer: READER, packet_sha256: 'a'.repeat(64) } } as any);
expect(bindReceipt(older, '5', [x.from], { base: 'main' })).toMatchObject({ ok: true, head: x.from });
});
});
describe('the carry reason names at most CARRY_NAMED_PATHS moved-context paths (GST-3562 G)', () => {
// Value: protects=a PR that merges main often keeps its receipt line bounded: the reason names at most CARRY_NAMED_PATHS
// paths and counts the rest; fails_when=every path is named on every hop and the PR body grows past GitHub's limit;
// seam=planCarry; no_claim=none
test('25 context paths name 20 and count 5', () => {
const paths = Array.from({ length: 25 }, (_, i) => `src/f${String(i).padStart(2, '0')}.ts`);
const plan = planCarry({ from: 'a'.repeat(40), head: 'b'.repeat(40), changed: [], productPatchId: { from: 'p1', head: 'p2' }, testPatchId: { from: '', head: '' }, changedProduct: [], mergeCommits: 1, rangeDiff: '', baseContext: paths });
expect(plan.ok).toBe(true);
const reason = plan.ok ? plan.carry.reason : '';
expect(reason).toContain(`(${paths.slice(0, CARRY_NAMED_PATHS).join(', ')} (+5 more); CI at head checks it)`);
expect(reason).not.toContain(paths[CARRY_NAMED_PATHS]!);
});
});