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
/**
* The four no-stop defaults (GSTA-258 K1, lib/no-stop.ts, bin/gstack-no-stop): each routine stop that qualifies is
* recorded as {class, reason, evidence} and the run goes on; anything that does not qualify, and any stop outside
* the four, still stops for the owner. The autoplan re-gate is covered in test/autoplan-carry.test.ts.
*/
import { afterAll, describe, expect, test } from 'bun:test';
import { spawnSync } from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { bunIsolationArgs } from '../lib/bun-isolation';
import { validateReceipt } from '../lib/ship-receipt';
import { lineDiff } from '../lib/autoplan-confirm';
import { checkNoStop, notEli5Only, parseDiff, type NoStopRecord } from '../lib/no-stop';
const ROOT = path.resolve(import.meta.dir, '..');
const BIN = path.join(ROOT, 'bin', 'gstack-no-stop');
const ID = { GIT_AUTHOR_NAME: 'fixture', GIT_AUTHOR_EMAIL: '[email protected]', GIT_COMMITTER_NAME: 'fixture', GIT_COMMITTER_EMAIL: '[email protected]' };
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'no-stop-'));
afterAll(() => fs.rmSync(tmp, { recursive: true, force: true }));
const diff = (file: string, was: string[], now: string[]) =>
[`diff --git a/${file} b/${file}`, `--- a/${file}`, `+++ b/${file}`, '@@ -1,3 +1,3 @@', ' context', ...was.map(l => '-' + l), ...now.map(l => '+' + l), ' context', ''].join('\n');
const TIMEOUT = diff('test/worker.test.ts', [" test('drains', async () => { await drain(); }, 5_000);"], [" test('drains', async () => { await drain(); }, 30_000);"]);
const check = (cls: string, d?: string, prior: NoStopRecord[] = []) => checkNoStop({ cls, reason: 'r', evidence: 'run 41715705702', prior, diff: d, root: ROOT });
describe('lib/no-stop: what qualifies', () => {
// Value: protects=the retired scoped-fix-check (fix-checks and their grants, GST-3562 part 4) never records a no-stop, so a
// stop after round 2 goes to the lane's Captain; fails_when=checkNoStop still accepts a docs-only or timeout-only round-2
// fix as scoped-fix-check while gstack-no-stop refuses it (#4826 final review); seam=lib/no-stop checkNoStop
test('scoped-fix-check is retired: no diff qualifies, not even a docs-only or timeout-only one', () => {
for (const d of [diff('docs/review-policy-notes.md', ['old wording'], ['new wording']), TIMEOUT, diff('lib/worker.ts', ['return a;'], ['return b;'])]) {
expect(check('scoped-fix-check', d)).toMatchObject({ ok: false, reason: expect.stringContaining('removed with fix-check grants (GST-3562 part 4)') });
}
});
test('test-timeout-fix: only a raised timeout in a test file qualifies', () => {
expect(check('test-timeout-fix', TIMEOUT)).toMatchObject({ ok: true });
expect(check('test-timeout-fix', diff('test/worker.test.ts', [" test('drains', async () => { await drain(); }, 30_000);"], [" test('drains', async () => { await drain(); }, 5_000);"]))).toMatchObject({ ok: false, reason: expect.stringContaining('does not raise') });
expect(check('test-timeout-fix', diff('test/worker.test.ts', ['expect(n).toBe(3);'], ['expect(n).toBe(4);']))).toMatchObject({ ok: false, reason: expect.stringContaining('more than a timeout') });
expect(check('test-timeout-fix', diff('lib/worker.ts', ['const timeoutMs = 5000;'], ['const timeoutMs = 9000;']))).toMatchObject({ ok: false, reason: expect.stringContaining('not a test file') });
expect(check('test-timeout-fix', diff('test/worker.test.ts', [], [' // a new line, timeout 30_000']))).toMatchObject({ ok: false });
});
test('review pass 1 holes: an assertion bound, a name that only contains "timeout", and a "-- " line inside a hunk are not timeout-only', () => {
expect(check('test-timeout-fix', diff('test/perf.test.ts', [' expect(elapsedMs).toBeLessThan(timeoutMs + 100);'], [' expect(elapsedMs).toBeLessThan(timeoutMs + 5000);']))).toMatchObject({ ok: false });
expect(check('test-timeout-fix', diff('test/retry.test.ts', ['const MAX_ATTEMPTS_BEFORE_TIMEOUT = 3;'], ['const MAX_ATTEMPTS_BEFORE_TIMEOUT = 30;']))).toMatchObject({ ok: false });
expect(check('test-timeout-fix', diff('test/x.test.ts', [' setDefaultTimeout(5_000);'], [' setDefaultTimeout(30_000);']))).toMatchObject({ ok: true });
const hidden = 'diff --git a/test/x.test.ts b/test/x.test.ts\n--- a/test/x.test.ts\n+++ b/test/x.test.ts\n@@ -1,2 +1,1 @@\n--- guard\n- }, 5000);\n+ }, 50000);\n';
expect(check('test-timeout-fix', hidden)).toMatchObject({ ok: false });
});
test('pregate-flake-rerun: one rerun per branch; a second stops', () => {
expect(check('pregate-flake-rerun')).toMatchObject({ ok: true });
expect(check('pregate-flake-rerun', undefined, [{ class: 'pregate-flake-rerun', reason: 'x', evidence: 'y' }])).toMatchObject({ ok: false });
});
test('stamp-only-carry is gone (GST-2706): a refused carry already goes on to Steps 2-16, so there is no stop to record past', () => {
const stamp = diff('package.json', [' "version": "1.94.41.0",'], [' "version": "1.94.42.0",']) + diff('VERSION', ['1.94.41.0'], ['1.94.42.0']);
expect(check('stamp-only-carry', stamp)).toMatchObject({ ok: false, reason: expect.stringContaining('not one of the four no-stop classes') });
});
test('anything outside the four, a missing reason or evidence, or a hand-recorded re-gate still stops', () => {
expect(check('merge-anyway')).toMatchObject({ ok: false, reason: expect.stringContaining('not one of the four') });
expect(checkNoStop({ cls: 'pregate-flake-rerun', reason: ' ', evidence: 'run 1', prior: [] })).toMatchObject({ ok: false });
expect(check('autoplan-regate')).toMatchObject({ ok: false, reason: expect.stringContaining('gstack-autoplan decides') });
});
test('notEli5Only: only added lines inside ## ELI5 that name no number, spend, cap, arm, model or verdict carry', () => {
const PLAN = '# Plan\n\nRetry the webhook worker, cap 30 s.\n\n## ELI5\n\nRetries wait longer each time.\n';
const edit = (after: string) => notEli5Only(lineDiff(PLAN, after));
expect(edit(PLAN + 'They stop hammering the service.\n')).toBeNull();
expect(edit('# Plan\n\nRetry the webhook worker, cap 30 s.\n\n## ELI5\n\nRetries wait longer each time.\nNothing else changes.\n\n## Notes\n')).toContain('adds a heading');
expect(notEli5Only(lineDiff('# Plan\n\nDo it.\n', '# Plan\n\nDo it.\n\n## ELI5\n\nIt waits longer.\n'))).toBeNull();
expect(edit(PLAN.replace('Retry the webhook worker', 'Retry the webhook worker and the queue'))).toContain('removes or rewrites');
expect(edit(PLAN.replace('cap 30 s.\n', 'cap 30 s.\nAlso delete the users table.\n'))).toContain('outside ## ELI5');
expect(edit(PLAN + 'It runs (30 times) per case.\n')).toContain('names a number');
expect(edit(PLAN + 'Run it on **Opus** instead.\n')).toContain('names a number');
expect(edit(PLAN + 'The budget grows.\n')).toContain('names a number');
expect(edit(PLAN)).toBe('the edit adds no ELI5 line');
});
test('review pass 2 holes: a retry count, or a brace that closes any multi-line call, is not a timeout', () => {
expect(check('test-timeout-fix', diff('test/a.test.ts', [' retry({ fn }, 3);'], [' retry({ fn }, 10);']))).toMatchObject({ ok: false });
expect(check('test-timeout-fix', diff('test/a.test.ts', [' }, 3);'], [' }, 30);']))).toMatchObject({ ok: false });
});
});
describe('gstack-no-stop record: the ledger, the grant and the receipt', () => {
const work = path.join(tmp, 'repo');
const state = path.join(tmp, 'state');
const env = { ...process.env, ...ID, GSTACK_STATE_ROOT: state, GSTACK_APPROVALS_DIR: path.join(tmp, 'approvals') };
const git = (...args: string[]) => {
const r = spawnSync('git', args, { cwd: work, encoding: 'utf8', timeout: 30_000, env });
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
return r.stdout.trim();
};
const run = (...args: string[]) => spawnSync('bun', [...bunIsolationArgs(), BIN, ...args], { cwd: work, encoding: 'utf8', timeout: 60_000, env });
fs.mkdirSync(path.join(work, 'docs'), { recursive: true });
git('init', '-q', '-b', 'feat');
fs.writeFileSync(path.join(work, 'docs', 'guide.md'), 'old wording\n');
fs.writeFileSync(path.join(work, 'lib.ts'), 'export const a = 1;\n');
git('add', '-A'); git('commit', '-qm', 'base');
const base = git('rev-parse', 'HEAD');
const slug = Object.fromEntries(spawnSync(path.join(ROOT, 'bin', 'gstack-slug'), [], { cwd: work, encoding: 'utf8', timeout: 30_000, env }).stdout.trim().split('\n').map(l => l.split('=') as [string, string]));
const reviewLog = path.join(state, 'projects', slug.SLUG!, `${slug.BRANCH}-reviews.jsonl`);
fs.mkdirSync(path.dirname(reviewLog), { recursive: true });
fs.writeFileSync(reviewLog, JSON.stringify({ skill: 'review', commit_full: base }) + '\n');
test('a scoped fix-check (removed in GST-3562 part 4) and a code fix both stop (exit 3) and leave the ledger alone', () => {
const before = run('list', '--json');
const second = run('record', '--class', 'scoped-fix-check', '--range-base', base, '--reason', 'again', '--evidence', 'commit x');
expect(second.status).toBe(3);
expect(second.stderr).toMatch(/^NO_STOP: refused scoped-fix-check \(removed with fix-check grants, GST-3562 part 4/m);
fs.writeFileSync(path.join(work, 'lib.ts'), 'export const a = 2;\n');
git('commit', '-qam', 'code fix');
const code = run('record', '--class', 'test-timeout-fix', '--range-base', 'HEAD~1', '--reason', 'r', '--evidence', 'e');
expect(code.status).toBe(3);
expect(code.stderr).toContain('NO_STOP: refused test-timeout-fix (not a test file: lib.ts)');
expect(run('list', '--json').stdout).toBe(before.stdout);
});
test('a class outside the four stops, and the range-based classes need --range-base', () => {
expect(run('record', '--class', 'merge-anyway', '--reason', 'r', '--evidence', 'e').status).toBe(3);
expect(run('record', '--class', 'test-timeout-fix', '--reason', 'r', '--evidence', 'e').status).toBe(2);
});
});
describe('gstack-no-stop record after a base merge and a restamp, and import', () => {
const work = path.join(tmp, 'stamp');
const env = { ...process.env, ...ID, GSTACK_STATE_ROOT: path.join(tmp, 'state2'), GSTACK_APPROVALS_DIR: path.join(tmp, 'approvals2') };
const git = (...args: string[]) => {
const r = spawnSync('git', args, { cwd: work, encoding: 'utf8', timeout: 30_000, env });
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
return r.stdout.trim();
};
const write = (rel: string, text: string) => fs.writeFileSync(path.join(work, rel), text);
const run = (...args: string[]) => spawnSync('bun', [...bunIsolationArgs(), BIN, ...args], { cwd: work, encoding: 'utf8', timeout: 60_000, env });
fs.mkdirSync(work, { recursive: true });
git('init', '-q', '-b', 'main');
write('VERSION', '1.0.0.0\n'); write('app.ts', 'export const a = 1;\n'); write('other.ts', 'export const b = 1;\n');
git('add', '-A'); git('commit', '-qm', 'base');
git('checkout', '-q', '-b', 'feat');
write('app.ts', 'export const a = 2;\n'); write('VERSION', '1.0.1.0\n'); git('commit', '-qam', 'feature');
const receiptHead = git('rev-parse', 'HEAD');
git('checkout', '-q', 'main');
write('other.ts', 'export const b = 2;\n'); write('VERSION', '1.0.2.0\n'); git('commit', '-qam', 'main moves');
git('checkout', '-q', 'feat');
spawnSync('git', ['merge', '-q', 'main', '-m', 'merge main'], { cwd: work, encoding: 'utf8', timeout: 30_000, env });
write('VERSION', '1.0.3.0\n'); git('add', '-A'); git('commit', '-qm', 'merge main + stamp');
test('a base merge plus a version stamp records nothing: the refused carry runs Steps 2-16 with no stop to skip (GST-2706)', () => {
const r = run('record', '--class', 'stamp-only-carry', '--range-base', receiptHead, '--reason', 'restamp after the base moved', '--evidence', `commit ${git('rev-parse', 'HEAD').slice(0, 12)}`);
expect(r.status).toBe(3);
expect(r.stderr).toContain('stamp-only-carry is not one of the four no-stop classes');
expect(JSON.parse(run('list', '--json').stdout).records).toEqual([]);
});
test('import adds an autoplan run\'s re-gate records once and skips every other class', () => {
const src = path.join(tmp, 'run-no-stop.json');
fs.writeFileSync(src, JSON.stringify([{ class: 'autoplan-regate', reason: 'plan edit, no spend', evidence: 'autoplan:run-1@gate_rev=2' }, { class: 'merge-anyway', reason: 'x', evidence: 'y' }, { class: 'stamp-only-carry', reason: 'x', evidence: 'y' }, { class: 'autoplan-regate', reason: 'x', evidence: 'hand-written' }]));
const first = run('import', '--from', src).stdout;
expect(first).toMatch(/^NO_STOP: imported 1 record\(s\)/m);
expect(first).toMatch(/^NO_STOP: skipped 3 record\(s\): import takes only autoplan-regate records/m);
expect(run('import', '--from', src).stdout).toMatch(/^NO_STOP: imported 0 record\(s\)/m);
expect(JSON.parse(run('list', '--json').stdout).records.map((r: NoStopRecord) => r.class)).toEqual(['autoplan-regate']);
});
});
describe('the no-stop defaults in the /ship and /autoplan sources', () => {
const read = (rel: string) => fs.readFileSync(path.join(ROOT, rel), 'utf8');
const ship = read('ship/sections/tests.md.tmpl');
const help = spawnSync('bun', [...bunIsolationArgs(), BIN, '--help'], { encoding: 'utf8', timeout: 60_000 }).stdout;
test.each(['scoped-fix-check', 'test-timeout-fix', 'pregate-flake-rerun', 'autoplan-regate'])('the bin help and the policy say what to do on %s', cls => {
expect(help).toMatch(new RegExp('^ ' + cls + ' +\\S', 'm'));
expect(read('docs/review-policy.md')).toContain('| `' + cls + '` |');
});
test('neither the bin help nor the policy offers stamp-only-carry any more', () => {
expect(help).not.toContain('stamp-only-carry');
expect(read('docs/review-policy.md')).not.toContain('| `stamp-only-carry` |');
});
test('a refused case and any other stop still stop; the receipt write carries the ledger', () => {
expect(ship).toContain('two other routine stops go through `gstack-no-stop record` (`--help`); `recorded` goes on,\n`refused` stops.');
expect(help).toContain('NO_STOP: refused (exit 3): the stop stands. Anything else still stops.');
expect(read('ship/sections/pr-body.md.tmpl')).toContain('${NS:+--no-stop "@$NS"}');
expect(read('ship/DRIVER.md.tmpl')).toContain('end the run, except `gstack-no-stop`');
expect(read('autoplan/DRIVER.md.tmpl')).toContain("K1's `autoplan-regate` no-stop");
});
});