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
/**
* A ruled edit after the final review (GST-3775, GBRA-795 on garrytan/gbrain#10256): the read-only final review ran, a
* one-line edit followed, finish stopped and gstack-review-plan --post-review stopped for the owner. The owner's "ship it
* with the note" is recorded as one ruling per changed path, `gstack-approvals rule --finding edit:<path> --head <stop head>`,
* and finish routes exactly those paths, at exactly the ruled bytes, as RULED_EDIT instead of stopping again.
*/
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { ruledEdits, type RuledNote } from '../lib/ruled-notes';
import { spawnSync } from '../lib/spawn-sync';
import { DOCS_CAPS_KEY_VERSION } from '../lib/ship-policy';
import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
setDefaultTimeout(90_000);
const BIN = path.dirname(RELEASE);
const LANE = 'tests=printf " 3 pass\\n 0 fail\\nRan 3 tests across 1 file. [5.00ms]\\n"';
const ships: ShipFx[] = [];
const dirs: string[] = [];
afterEach(() => { while (ships.length) ships.pop()!.cleanup(); while (dirs.length) fs.rmSync(dirs.pop()!, { recursive: true, force: true }); });
const TEST_V1 = "import { expect, test } from 'bun:test';\ntest('a', () => { expect(2).toBe(2); });\n";
const TEST_V2 = "import { expect, test } from 'bun:test';\ntest('a', () => { expect(2).toBe(2); }, 1_000);\n";
const TEST_V3 = "import { expect, test } from 'bun:test';\ntest('a', () => { expect(2).toBe(2); }, 2_000);\n";
const STOPPED = 'STOP: behavior, tests or build inputs changed since review';
const run = (f: ShipFx, bin: string, args: string[]) => f.run(path.join(BIN, '..', bin), args, { GSTACK_APPROVALS_MIRROR: '0' });
const finish = (f: ShipFx, reviewed: string, post: string, more: string[] = []) => f.run(RELEASE, ['finish', '--base', 'main', '--reviewed-tree', reviewed, '--docs-post', post, ...more, '--lane', LANE]);
const rule = (f: ShipFx, file: string, head: string) => run(f, 'bin/gstack-approvals', ['rule', '--finding', `edit:${file}`, '--head', head, '--reason', 'the one-line timeout edit after the final review ships as a disclosed note', '--words', 'ship it with the note', '--by', 'GStack Minder (GSTA-36)']);
/** GBRA-795's sequence: the read-only final review read passHead, then a one-line edit to a test landed after it. */
function editedAfterFinalReview() {
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n', 'test/x.test.ts': TEST_V1 });
ships.push(f);
const passHead = f.git('rev-parse', 'HEAD').stdout.trim();
const reviewed = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
const post = path.join(f.root, 'post.json');
expect(f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'README.md']).status).toBe(0);
f.write({ 'test/x.test.ts': TEST_V2 }); f.commit('raise the test timeout');
return { f, passHead, stopHead: f.git('rev-parse', 'HEAD').stdout.trim(), reviewed, post };
}
// Value: protects=the owner's ship-with-the-note ruling on an edit after the final review is honoured: finish routes the ruled
// path as RULED_EDIT and goes on; fails_when=finish stops on the same edit after the ruling is recorded (GBRA-795, a
// gstack-approvals add row a-4f45c3661ca2 that nothing read); seam=finish's route reading the approval record
describe('finish honours an edit ruling after the final review (GST-3775)', () => {
test('GBRA-795: finish stops, the owner rules the edit a note at the stop head, and finish goes on', () => {
const { f, stopHead, reviewed, post } = editedAfterFinalReview();
const before = finish(f, reviewed, post);
expect([before.status, before.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (test/x.test.ts)`)]);
expect(rule(f, 'test/x.test.ts', stopHead).status).toBe(0);
const r = finish(f, reviewed, post);
expect(r.stdout).not.toContain(STOPPED);
expect(lineOf(r.stdout, 'RULED_EDIT')).toMatch(new RegExp(`^RULED_EDIT: test/x\\.test\\.ts \\(ruled at ${stopHead.slice(0, 12)} by GStack Minder \\(GSTA-36\\), approval a-[0-9a-f]{12}\\)$`));
expect(lineOf(r.stdout, 'RULED_NOTE')).toMatch(/^RULED_NOTE: edit:test\/x\.test\.ts at /);
expect([r.status, lineOf(r.stdout, 'EVIDENCE')]).toEqual([0, expect.stringMatching(/^EVIDENCE: FRESH label=tests /)]);
});
// Value: protects=a ruling covers only the path it names, at the bytes it was made on; fails_when=one ruling accepts every
// edit after review, or a path edited again after the ruling ships unread; seam=finish's route matching edit:<path> rulings
test('a ruling covers only its own path at the ruled bytes', () => {
const other = editedAfterFinalReview();
expect(rule(other.f, 'src/x.ts', other.stopHead).status).toBe(0);
expect(finish(other.f, other.reviewed, other.post).stdout).toContain(`${STOPPED} (test/x.test.ts)`);
const later = editedAfterFinalReview();
expect(rule(later.f, 'test/x.test.ts', later.stopHead).status).toBe(0);
later.f.write({ 'test/x.test.ts': TEST_V3 }); later.f.commit('edit it again after the ruling');
const r = finish(later.f, later.reviewed, later.post);
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (test/x.test.ts)`)]);
expect(r.stdout).not.toContain('RULED_EDIT:');
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toStartWith(`RULED_EDIT_REFUSED: test/x.test.ts (its mode or bytes differ from the ruled head ${later.stopHead.slice(0, 12)};`);
expect(lineOf(r.stdout, 'RULED_NOTE')).toEndWith('(no RULED_EDIT at this head; not applied)');
later.f.write({ 'test/x.test.ts': TEST_V2 }); later.f.commit('restore the ruled bytes');
const restored = finish(later.f, later.reviewed, later.post);
expect([restored.status, restored.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (test/x.test.ts)`)]);
const early = editedAfterFinalReview();
expect(rule(early.f, 'test/x.test.ts', early.passHead).status).toBe(0);
expect(finish(early.f, early.reviewed, early.post).stdout).toContain(`${STOPPED} (test/x.test.ts)`);
});
// Value: protects=finish fails closed when git cannot hold the ruled path under the spelling it routes: a filename with
// invalid UTF-8 reaches finish with a replacement character, both ls-tree lookups find nothing, and that must not read as
// equal bytes; fails_when=a ruling on a path neither tree holds clears the stop; seam=finish's route reading each ls-tree
test('a ruled path neither tree holds under its routed spelling stops finish (no file, not equal bytes)', () => {
const { f, reviewed, post } = editedAfterFinalReview();
const raw = Buffer.concat([Buffer.from(path.join(f.work, 'test') + path.sep), Buffer.from([0xff]), Buffer.from('y.test.ts')]);
fs.writeFileSync(raw, TEST_V1); f.commit('add a test whose name is not UTF-8');
const stopHead = f.git('rev-parse', 'HEAD').stdout.trim();
const routed = 'test/\uFFFDy.test.ts';
for (const p of ['test/x.test.ts', routed]) expect(rule(f, p, stopHead).status).toBe(0);
const r = finish(f, reviewed, post);
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (${routed})`)]);
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toBe(`RULED_EDIT_REFUSED: ${routed} (no file at ${stopHead.slice(0, 12)} or in the tree finish routes, and no commit up to ${stopHead.slice(0, 12)} deleted a file git held under this spelling: a ruling covers a file git holds or deleted under exactly this spelling; keep the edit and run /gstack-ship again, docs/ship-policy.md#ruled-edits)`);
expect(r.stdout).toContain('RULED_EDIT: test/x.test.ts (');
expect(r.stdout).toMatch(new RegExp(`^RULED_NOTE: edit:test/\\uFFFDy\\.test\\.ts at .* \\(no RULED_EDIT at this head; not applied\\)$`, 'm'));
});
// Value: protects=a ruling on a replacement-character spelling never clears an edit to a different file: a filename with
// invalid UTF-8 changed after review reaches finish as the spelling of an unchanged file that holds a literal U+FFFD;
// fails_when=finish prints RULED_EDIT for the unchanged file and the unreviewed edit ships; seam=finish's route refusal
test('a ruled spelling with a replacement character stops finish even when a file of that name exists', () => {
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n', 'test/\uFFFDy.test.ts': TEST_V1 }, { 'src/x.ts': 'export const x = 2;\n' });
ships.push(f);
const raw = Buffer.concat([Buffer.from(path.join(f.work, 'test') + path.sep), Buffer.from([0xff]), Buffer.from('y.test.ts')]);
fs.writeFileSync(raw, TEST_V1); f.commit('add a test whose name is not UTF-8');
const reviewed = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
const post = path.join(f.root, 'post.json');
expect(f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'README.md']).status).toBe(0);
fs.writeFileSync(raw, TEST_V2); f.commit('edit it after the final review');
const routed = 'test/\uFFFDy.test.ts';
expect(rule(f, routed, f.git('rev-parse', 'HEAD').stdout.trim()).status).toBe(0);
const r = finish(f, reviewed, post);
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (${routed})`)]);
expect(r.stdout).not.toContain('RULED_EDIT:');
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toStartWith(`RULED_EDIT_REFUSED: ${routed} (its spelling holds a replacement character (U+FFFD)`);
});
});
/** GBRA-108 (gbrain #10492, #10494): Step 14.5's audit hashed `file`, an edit to it followed the final review, and the owner ruled it. */
function docEditedAfterAudit(file: string, base: Record<string, string> = {}) {
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n', [file]: '# Notes\n\nOne line.\n', ...base }, { 'src/x.ts': 'export const x = 2;\n' });
ships.push(f);
const reviewed = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
const post = path.join(f.root, 'post.json');
expect(f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', file]).status).toBe(0);
f.write({ [file]: '# Notes\n\nOne line.\nA second line the audit asked for.\n' }); f.commit('docs audit edit after the final review');
return { f, stopHead: f.git('rev-parse', 'HEAD').stdout.trim(), reviewed, post };
}
const finishRechecked = (f: ShipFx, reviewed: string, post: string) => f.run(RELEASE, ['finish', '--base', 'main', '--reviewed-tree', reviewed, '--docs-post', post, '--docs-rechecked', '--lane', LANE]);
// Value: protects=a ruled edit to a doc the docs audit hashed carries finish's freshness check, at the ruled bytes only;
// fails_when=finish prints DOCS: stale (<path>) after RULED_EDIT (GBRA-108), or an unruled doc edit, or one edited again after
// its ruling, passes as fresh; seam=lib/ship-release.ts route's ruled paths into docsFresh
describe('a ruled edit to an audited doc keeps the docs audit fresh (GBRA-108)', () => {
test('agent-prose policy doc (behavior) and a plain doc: ruled, each carries as ruled=1', () => {
for (const file of ['docs/ship-policy.md', 'README.md']) {
const { f, stopHead, reviewed, post } = docEditedAfterAudit(file);
const before = finishRechecked(f, reviewed, post);
expect([file, before.status]).toEqual([file, 3]);
expect(rule(f, file, stopHead).status).toBe(0);
const r = finishRechecked(f, reviewed, post);
expect([file, lineOf(r.stdout, 'RULED_EDIT')]).toEqual([file, expect.stringContaining(`RULED_EDIT: ${file} (ruled at ${stopHead.slice(0, 12)}`)]);
expect([file, lineOf(r.stdout, 'DOCS')]).toEqual([file, 'DOCS: fresh against the Step 14.5 post-audit snapshot (carried: tests=0 base=0 requested=0 ruled=1)']);
}
});
test('an unruled doc edit, or a doc edited again after its ruling, is still stale', () => {
const plain = docEditedAfterAudit('README.md');
expect(lineOf(finishRechecked(plain.f, plain.reviewed, plain.post).stdout, 'DOCS')).toBe('DOCS: stale (README.md)');
const later = docEditedAfterAudit('README.md');
expect(rule(later.f, 'README.md', later.stopHead).status).toBe(0);
later.f.write({ 'README.md': '# Notes\n\nOne line.\nA different line.\n' }); later.f.commit('edit it again');
const r = finishRechecked(later.f, later.reviewed, later.post);
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toStartWith('RULED_EDIT_REFUSED: README.md (');
expect(lineOf(r.stdout, 'DOCS')).toBe('DOCS: stale (README.md)');
});
test('a ruled doc edit that breaks a doc cap the base declares stops finish', () => {
const policy = JSON.stringify({ docs: { caps: [{ path: 'README.md', max_bytes: 30 }] }, min_gstack_version: DOCS_CAPS_KEY_VERSION });
const { f, stopHead, reviewed, post } = docEditedAfterAudit('README.md', { '.gstack/ship-policy.json': policy });
expect(rule(f, 'README.md', stopHead).status).toBe(0);
const r = finishRechecked(f, reviewed, post);
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining('a ruled doc edit breaks a doc cap')]);
});
});
/** A file the final review read is deleted (or renamed: git's --no-renames diff is a deletion plus an addition) after it. */
function deletedAfterFinalReview(rename: boolean, mergeBase = false) {
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n', 'src/old.ts': 'export const o = 1;\n' });
ships.push(f);
const reviewed = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
const reviewedBase = f.git('merge-base', 'origin/main', 'HEAD').stdout.trim();
const post = path.join(f.root, 'post.json');
expect(f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'README.md']).status).toBe(0);
if (mergeBase) { f.advanceBase({ 'src/base.ts': 'export const base = 1;\n' }); expect(f.git('fetch', '-q', 'origin').status).toBe(0); expect(f.git('merge', '-q', '--no-edit', 'origin/main').status).toBe(0); }
if (rename) fs.renameSync(path.join(f.work, 'src/old.ts'), path.join(f.work, 'src/new.ts')); else fs.rmSync(path.join(f.work, 'src/old.ts'));
f.commit(rename ? 'rename a file after the final review' : 'delete a file after the final review');
return { f, stopHead: f.git('rev-parse', 'HEAD').stdout.trim(), reviewed, reviewedBase, post };
}
// Value: protects=the owner can rule a deletion after the final review, and a rename as its two paths, so folding or renaming a
// file (a changelog.d fragment, gbrain#10623) ships as a disclosed note; fails_when=finish refuses every deleted path
// (`RULED_EDIT_REFUSED: … never a deletion`), or one ruling on a rename's new path clears its old one; seam=finish's route
// reading edit:<path> rulings through ruledEdits
describe('finish honours a ruled deletion or rename after the final review (GST-4139)', () => {
test('a deleted file: finish stops, the owner rules it at the stop head, and finish routes it as RULED_EDIT', () => {
const { f, stopHead, reviewed, post } = deletedAfterFinalReview(false);
expect(finish(f, reviewed, post).stdout).toContain(`${STOPPED} (src/old.ts)`);
expect(rule(f, 'src/old.ts', stopHead).status).toBe(0);
const r = finish(f, reviewed, post);
expect(r.stdout).not.toContain(STOPPED);
expect(r.stdout).not.toContain('RULED_EDIT_REFUSED');
expect(lineOf(r.stdout, 'RULED_EDIT')).toStartWith(`RULED_EDIT: src/old.ts (ruled at ${stopHead.slice(0, 12)} by GStack Minder (GSTA-36), approval a-`);
expect(r.status).toBe(0);
});
test('a rename needs both rulings: the new path alone still stops on the old one', () => {
const { f, stopHead, reviewed, post } = deletedAfterFinalReview(true);
expect(rule(f, 'src/new.ts', stopHead).status).toBe(0);
const one = finish(f, reviewed, post);
expect([one.status, one.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (src/old.ts)`)]);
expect(rule(f, 'src/old.ts', stopHead).status).toBe(0);
const r = finish(f, reviewed, post);
expect(r.stdout).not.toContain(STOPPED);
expect(r.stdout.split('\n').filter(l => l.startsWith('RULED_EDIT: ')).map(l => l.split(' (')[0])).toEqual(['RULED_EDIT: src/new.ts', 'RULED_EDIT: src/old.ts']);
expect(r.status).toBe(0);
});
test('a base merge after the review, then the deletion: the ruling clears only the PR\'s own deletion', () => {
const { f, stopHead, reviewed, reviewedBase, post } = deletedAfterFinalReview(false, true);
expect(rule(f, 'src/old.ts', stopHead).status).toBe(0);
const r = finish(f, reviewed, post, ['--reviewed-base', reviewedBase]);
expect(r.stdout).not.toContain(STOPPED);
expect(r.stdout.split('\n').filter(l => l.startsWith('RULED_EDIT: ')).map(l => l.split(' (')[0])).toEqual(['RULED_EDIT: src/old.ts']);
expect(r.status).toBe(0);
});
test('a file deleted after its edit was ruled stops finish', () => {
const { f, stopHead, reviewed, post } = editedAfterFinalReview();
expect(rule(f, 'test/x.test.ts', stopHead).status).toBe(0);
fs.rmSync(path.join(f.work, 'test/x.test.ts')); f.commit('delete the ruled file');
const r = finish(f, reviewed, post);
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (test/x.test.ts)`)]);
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toStartWith('RULED_EDIT_REFUSED: test/x.test.ts (no file in the tree finish routes: a ruling on an edit never covers deleting the file');
});
});
/** A doc the Step 14.5 audit hashed is deleted after the final review. */
function docDeletedAfterAudit(file: string) {
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n', [file]: '# Notes\n\nOne line.\n' }, { 'src/x.ts': 'export const x = 2;\n' });
ships.push(f);
const reviewed = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
const post = path.join(f.root, 'post.json');
expect(f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', file]).status).toBe(0);
fs.rmSync(path.join(f.work, file)); f.commit('fold the doc away after the final review');
return { f, stopHead: f.git('rev-parse', 'HEAD').stdout.trim(), reviewed, post };
}
// Value: protects=a ruled deletion of a doc the docs audit hashed keeps stage 3 fresh, and an unruled one stays stale;
// fails_when=stage 3 reads the deleted file (ENOENT) or calls the ruled deletion stale; seam=lib/ship-release.ts docsFresh
describe('a ruled deletion of an audited doc keeps the docs audit fresh (GST-4139)', () => {
test('ruled: DOCS fresh with ruled=1; unruled: DOCS stale', () => {
const ruled = docDeletedAfterAudit('guide/notes.md');
expect(rule(ruled.f, 'guide/notes.md', ruled.stopHead).status).toBe(0);
const r = finishRechecked(ruled.f, ruled.reviewed, ruled.post);
expect(lineOf(r.stdout, 'RULED_EDIT')).toStartWith('RULED_EDIT: guide/notes.md (');
expect(lineOf(r.stdout, 'DOCS')).toBe('DOCS: fresh against the Step 14.5 post-audit snapshot (carried: tests=0 base=0 requested=0 ruled=1)');
const plain = docDeletedAfterAudit('guide/notes.md');
expect(lineOf(finishRechecked(plain.f, plain.reviewed, plain.post).stdout, 'DOCS')).toBe('DOCS: stale (guide/notes.md)');
});
});
/** A plain git repository outside this checkout for ruledEdits itself; `commit` takes null to delete a file. */
function gitRepo() {
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'ruled-deletion-')));
dirs.push(dir);
const git = (...args: string[]) => {
const r = spawnSync('git', ['-c', '[email protected]', '-c', 'user.name=Fixture', '-c', 'commit.gpgsign=false', ...args], { cwd: dir, encoding: 'utf8', timeout: 30_000 });
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
return String(r.stdout).trim();
};
const commit = (files: Record<string, string | null>, msg: string) => {
for (const [p, t] of Object.entries(files)) {
const at = path.join(dir, p);
if (t === null) fs.rmSync(at); else { fs.mkdirSync(path.dirname(at), { recursive: true }); fs.writeFileSync(at, t); }
}
git('add', '-A'); git('commit', '-qm', msg);
return git('rev-parse', 'HEAD');
};
git('init', '-q', '-b', 'main');
commit({ 'src/a.ts': 'export const a = 1;\n', 'src/gone.ts': 'export const g = 1;\n', 'dir/inner.ts': 'export const i = 1;\n' }, 'base');
return { dir, git, commit };
}
const note = (p: string, head: string): RuledNote => ({ finding: `edit:${p}`, head, by: 'GStack Minder (GSTA-36)', reason: 'ships as a note', at: '2026-11-28T00:00:00Z', approval: 'a-000000000001' });
const ruledAt = (dir: string, paths: string[], notes: RuledNote[], now = 'HEAD') => { const r = ruledEdits(dir, paths, now, notes); return { ruled: [...r.ruled.keys()].sort(), refused: r.refused }; };
// Value: protects=ruledEdits clears a deletion only when git proves it: the ruled head and the routed tree both lack the path, a
// commit up to the ruled head deleted a file under exactly that spelling, and nothing after the ruling touched it; every other
// case still refuses; fails_when=a typo, a directory, a re-created or re-deleted file, a non-ancestor head or an unreadable tree
// clears; seam=lib/ruled-notes.ts ruledEdits
describe('ruledEdits on deleted paths (GST-4139)', () => {
test('a deletion and both paths of a rename clear; a rename ruled on one path clears only that path', () => {
const r = gitRepo();
const head = r.commit({ 'src/gone.ts': null, 'src/a.ts': null, 'src/b.ts': 'export const a = 1;\n' }, 'delete gone, rename a to b');
expect(ruledAt(r.dir, ['src/a.ts', 'src/b.ts', 'src/gone.ts'], [note('src/gone.ts', head), note('src/a.ts', head), note('src/b.ts', head)])).toEqual({ ruled: ['src/a.ts', 'src/b.ts', 'src/gone.ts'], refused: [] });
expect(ruledAt(r.dir, ['src/a.ts', 'src/b.ts'], [note('src/b.ts', head)])).toEqual({ ruled: ['src/b.ts'], refused: [] });
});
test('a path no commit deleted (a typo, or a directory whose files were deleted) refuses', () => {
const r = gitRepo();
const head = r.commit({ 'dir/inner.ts': null, 'src/gone.ts': null }, 'delete');
const out = ruledAt(r.dir, ['src/gonee.ts', 'dir'], [note('src/gonee.ts', head), note('dir', head)]);
expect(out.ruled).toEqual([]);
expect(out.refused).toEqual(['src/gonee.ts', 'dir'].map(p => `${p} (no file at ${head.slice(0, 12)} or in the tree finish routes, and no commit up to ${head.slice(0, 12)} deleted a file git held under this spelling: a ruling covers a file git holds or deleted under exactly this spelling; keep the edit and run /gstack-ship again, docs/ship-policy.md#ruled-edits)`));
});
test('deleting after an edit ruling, re-creating after a deletion ruling, and re-creating then re-deleting all refuse', () => {
const del = gitRepo();
const edited = del.commit({ 'src/a.ts': 'export const a = 2;\n' }, 'edit');
del.commit({ 'src/a.ts': null }, 'delete after the ruling');
expect(ruledAt(del.dir, ['src/a.ts'], [note('src/a.ts', edited)]).refused[0]).toStartWith('src/a.ts (no file in the tree finish routes: a ruling on an edit never covers deleting the file');
const back = gitRepo();
const gone = back.commit({ 'src/gone.ts': null }, 'delete');
back.commit({ 'src/gone.ts': 'export const g = 1;\n' }, 're-create it after the ruling');
expect(ruledAt(back.dir, ['src/gone.ts'], [note('src/gone.ts', gone)]).refused[0]).toStartWith(`src/gone.ts (no file at ${gone.slice(0, 12)}, but the tree finish routes holds one: a ruling on a deletion never covers re-creating the file`);
back.commit({ 'src/gone.ts': null }, 'and delete it again');
expect(ruledAt(back.dir, ['src/gone.ts'], [note('src/gone.ts', gone)]).refused[0]).toStartWith(`src/gone.ts (a commit after ${gone.slice(0, 12)} touches it`);
});
test('a replacement character, a head off this branch, or an unreadable tree refuses a deletion', () => {
const r = gitRepo();
const odd = 'src/x\uFFFDy.ts';
r.commit({ [odd]: 'export const x = 1;\n' }, 'a file whose name holds U+FFFD');
r.git('checkout', '-q', '-b', 'side');
const side = r.commit({ 'src/gone.ts': null }, 'delete on a side branch');
r.git('checkout', '-q', 'main');
const head = r.commit({ [odd]: null, 'src/gone.ts': null }, 'delete');
expect(ruledAt(r.dir, [odd], [note(odd, head)]).refused[0]).toStartWith(`${odd} (its spelling holds a replacement character (U+FFFD)`);
expect(ruledAt(r.dir, ['src/gone.ts'], [note('src/gone.ts', side)]).refused[0]).toStartWith(`src/gone.ts (ruled at ${side.slice(0, 12)}, which is not HEAD or an ancestor of it`);
expect(ruledAt(r.dir, ['src/gone.ts'], [note('src/gone.ts', head)], '0'.repeat(40)).refused[0]).toStartWith('src/gone.ts (git ls-tree could not read it at the tree finish routes');
});
test('a deleted submodule clears like a file, even with log.showSignature on', () => {
const r = gitRepo();
r.git('config', 'log.showSignature', 'true');
r.git('update-index', '--add', '--cacheinfo', `160000,${r.git('rev-parse', 'HEAD')},vendor/sub`);
r.git('commit', '-qm', 'add a submodule');
r.git('rm', '-q', '--cached', 'vendor/sub');
r.git('commit', '-qm', 'remove the submodule');
const head = r.git('rev-parse', 'HEAD');
expect(ruledAt(r.dir, ['vendor/sub'], [note('vendor/sub', head)])).toEqual({ ruled: ['vendor/sub'], refused: [] });
});
test('a base merge between the review and the deletion: the deletion still clears', () => {
const r = gitRepo();
r.git('checkout', '-q', '-b', 'feat');
r.commit({ 'src/a.ts': 'export const a = 2;\n' }, 'feat');
r.git('checkout', '-q', 'main');
r.commit({ 'src/base.ts': 'export const b = 1;\n' }, 'base moves');
r.git('checkout', '-q', 'feat');
r.git('merge', '-q', '--no-edit', 'main');
const head = r.commit({ 'src/gone.ts': null }, 'delete after the review');
expect(ruledAt(r.dir, ['src/gone.ts'], [note('src/gone.ts', head)])).toEqual({ ruled: ['src/gone.ts'], refused: [] });
});
});