mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-25 17:41:35 +01:00
/ship keeps a PR's review when the PR merges main and its stacked parent had already landed before the review. It used to refuse over the parent's files. Why: yc-software/qm#3457 was asked to re-review files it never changed. Nothing for readers to do. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
398 lines
25 KiB
TypeScript
398 lines
25 KiB
TypeScript
/**
|
|
* gstack-ship-receipt carry for a stacked child after its parent squash-merges (#3570,
|
|
* docs/ship-policy.md#receipt-carry): the receipt reviewed the child's own range against the parent
|
|
* branch, and that range must be HEAD's whole product diff against the base the PR now targets.
|
|
* Anything else (the parent not landed, the child changed) fails closed.
|
|
*/
|
|
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 { extractReceipt, landedStackParent, renderReceiptBlock } from '../lib/ship-receipt';
|
|
import { bindShippedReceipt } from '../lib/ship-receipt-depth';
|
|
import { baseMergeOnly } from '../lib/ship-receipt-patch';
|
|
import { cleanup, commit, makeFixtureRepo, runBin, write, type FixtureRepo } from './helpers/pregate-fixture';
|
|
|
|
const repos: FixtureRepo[] = [];
|
|
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
|
const receiptIn = (body: string) => extractReceipt(fs.readFileSync(body, 'utf8')).receipt!;
|
|
const carry = (repo: FixtureRepo, body: string) => runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']);
|
|
const SUB = "exports.add = (a, b) => a + b;\nexports.sub = (a, b) => a - b;\n";
|
|
|
|
const RETRY4 = "exports.MAX_RETRIES = 4;\nexports.TIMEOUT_MS = 5000;\nexports.retry = (fn) => fn();\n";
|
|
|
|
/** main <- parent (lib/util.js) <- feature (lib/retry.js, its /ship receipt written against the parent branch). */
|
|
function stack(repo: FixtureRepo, parentFiles: Record<string, string> = { 'lib/util.js': SUB }, childFiles: Record<string, string> = { 'lib/retry.js': RETRY4 }, base = 'parent'): { parent: string; child: string; body: string } {
|
|
repo.git('checkout', '-q', '-b', 'parent');
|
|
const parent = commit(repo, parentFiles, 'parent: sub');
|
|
repo.git('push', '-q', 'origin', 'parent');
|
|
repo.git('checkout', '-q', 'feature');
|
|
repo.git('reset', '-q', '--hard', parent);
|
|
const child = commit(repo, childFiles, 'child: four retries');
|
|
const body = path.join(repo.root, 'body.md');
|
|
const w = runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '8', '--base', base, '--version', '1.0.0', '--session-kind', 'unattended', '--body', body]);
|
|
expect(w.status).toBe(EXIT.ok);
|
|
return { parent, child, body };
|
|
}
|
|
/** Land `files` on main as one commit (the parent's squash merge; none when the parent never lands), then an unrelated main commit, and merge main into the child. */
|
|
function landOnMain(repo: FixtureRepo, files: Record<string, string>): void {
|
|
repo.git('checkout', '-q', 'main');
|
|
if (Object.keys(files).length) {
|
|
for (const [rel, text] of Object.entries(files)) write(repo.work, rel, text);
|
|
repo.git('add', '-A'); repo.git('commit', '-qm', 'squash: parent (#7)');
|
|
}
|
|
write(repo.work, 'docs/README.md', '# docs after the parent\n');
|
|
repo.git('add', '-A'); repo.git('commit', '-qm', 'main moves on');
|
|
repo.git('push', '-q', 'origin', 'main');
|
|
repo.git('checkout', '-q', 'feature');
|
|
repo.git('merge', '-q', '--no-edit', 'origin/main');
|
|
}
|
|
|
|
describe('carry after a stack parent squash-merges (#3570)', () => {
|
|
// Value: protects=a stacked child keeps its receipt when its parent squash-merges and main is merged in (gstack-evals#19
|
|
// paid a full /ship for it); fails_when=carry compares the child's whole diff from the old fork point; seam=none;
|
|
// no_claim=gh pr edit (--body stands in)
|
|
test('the child carries when the range it was reviewed for is HEAD\'s whole product diff against main', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { child, body } = stack(repo);
|
|
const reviewed = receiptIn(body).product_patch_id;
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
const head = repo.git('rev-parse', 'HEAD');
|
|
const out = carry(repo, body);
|
|
expect(out.status).toBe(EXIT.ok);
|
|
expect(out.out).toContain(`CARRY: carried from ${child.slice(0, 12)} to ${head.slice(0, 12)}`);
|
|
const r = receiptIn(body);
|
|
expect(r.head).toBe(head);
|
|
expect(r.carry!.reason).toBe('stack parent parent landed + base merge');
|
|
expect(r.product_patch_id).toBe(reviewed);
|
|
expect(r.base).toBe('main');
|
|
expect(r.review_depth!.base).toBe(repo.git('rev-parse', 'origin/main'));
|
|
expect(r.review_depth!.gate_scan.head).toBe(head);
|
|
expect(bindShippedReceipt(repo.work, 'origin/main', fs.readFileSync(body, 'utf8'), '8', [head]).ok).toBe(true);
|
|
repo.git('checkout', '-q', 'main');
|
|
commit(repo, { 'docs/CHANGES.md': '# main moves again\n' }, 'main moves again');
|
|
repo.git('push', '-q', 'origin', 'main');
|
|
repo.git('checkout', '-q', 'feature');
|
|
repo.git('merge', '-q', '--no-edit', 'origin/main');
|
|
const again = carry(repo, body);
|
|
expect(again.status).toBe(EXIT.ok);
|
|
expect(receiptIn(body).carry!.reason).toBe('stack parent parent landed + base merge + base merge');
|
|
expect(receiptIn(body).product_patch_id).toBe(reviewed);
|
|
}, 90_000);
|
|
|
|
// Value: protects=a receipt written before product_patch_id still carries while the parent branch resolves, and refuses by
|
|
// name once it is gone; fails_when=the fallback reads another ref or carries with no reviewed diff; seam=none; no_claim=-
|
|
test('without a recorded product patch-id the child range comes from origin/<parent>, and a deleted parent branch refuses', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { parent, child, body } = stack(repo);
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
const { product_patch_id: _dropped, head_tree: _tree, ...legacy } = receiptIn(body);
|
|
fs.writeFileSync(body, renderReceiptBlock(legacy as any));
|
|
expect(receiptIn(body).product_patch_id).toBeUndefined();
|
|
repo.git('push', '-q', 'origin', '--delete', 'parent');
|
|
repo.git('fetch', '-q', '--prune', 'origin');
|
|
const gone = carry(repo, body);
|
|
expect(gone.status).toBe(EXIT.refused);
|
|
expect(gone.out).toContain('CARRY: refused (RECEIPT_CARRY_REFUSED)');
|
|
expect(gone.err).toContain('the receipt was reviewed against parent, not main, and its reviewed product diff is unavailable');
|
|
expect(receiptIn(body).head).toBe(child);
|
|
repo.git('push', '-q', 'origin', `${parent}:refs/heads/parent`);
|
|
repo.git('fetch', '-q', 'origin');
|
|
expect(carry(repo, body).status).toBe(EXIT.ok);
|
|
expect(receiptIn(body).carry!.reason).toBe('stack parent parent landed + base merge');
|
|
}, 90_000);
|
|
|
|
// Value: protects=a child with no product change of its own (product_patch_id none) still carries once the parent lands;
|
|
// fails_when=the recorded 'none' is compared as a literal id; seam=none; no_claim=-
|
|
test('a test-only child carries after its parent lands', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { body } = stack(repo, { 'lib/util.js': SUB }, { 'test/retry.test.js': "const test = require('node:test');\ntest('retries', () => {});\n" });
|
|
expect(receiptIn(body).product_patch_id).toBe('none');
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
const out = carry(repo, body);
|
|
expect(out.status).toBe(EXIT.ok);
|
|
expect(receiptIn(body).carry!.reason).toBe('stack parent parent landed + base merge');
|
|
}, 90_000);
|
|
|
|
// Value: protects=fail closed: a child changed after the parent merged, or a parent that never reached main, takes a fresh
|
|
// /ship; fails_when=the comparison ignores the child's remainder or the parent's absence; seam=none; no_claim=-
|
|
test('a product edit on the child after the merge, or a parent that never landed, refuses with RECEIPT_CARRY_PRODUCT_CHANGED', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { child, body } = stack(repo);
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
commit(repo, { 'lib/retry.js': "exports.MAX_RETRIES = 5;\nexports.TIMEOUT_MS = 5000;\nexports.retry = (fn) => fn();\n" }, 'child: five');
|
|
const edited = carry(repo, body);
|
|
expect(edited.status).toBe(EXIT.refused);
|
|
expect(edited.out).toContain('CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)');
|
|
expect(receiptIn(body).head).toBe(child);
|
|
|
|
const other = makeFixtureRepo(); repos.push(other);
|
|
const s = stack(other);
|
|
landOnMain(other, {});
|
|
const abandoned = carry(other, s.body);
|
|
expect(abandoned.status).toBe(EXIT.refused);
|
|
expect(abandoned.out).toContain('CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)');
|
|
expect(abandoned.err).toContain('is not the one reviewed against parent (the parent has not fully landed on main');
|
|
expect(receiptIn(s.body).head).toBe(s.child);
|
|
}, 120_000);
|
|
|
|
// Value: protects=fail closed on the parent's release-metadata paths: a package.json change (a dependency and a postinstall
|
|
// script) the parent made but main never received is product in HEAD's diff against main, though the child never touched it;
|
|
// fails_when=the comparison takes its pathspec from the reviewed head..HEAD range, where package.json is unchanged; seam=none;
|
|
// no_claim=-
|
|
test('a parent package.json change that never reached main refuses', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const pkg = JSON.stringify({ name: 'fixture', version: '1.0.0', scripts: { test: 'node --test test/*.test.js', generate: 'node gen.js', postinstall: 'node gen.js' }, dependencies: { leftpad: '1.0.0' } }, null, 2) + '\n';
|
|
const { child, body } = stack(repo, { 'lib/util.js': SUB, 'package.json': pkg });
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
const out = carry(repo, body);
|
|
expect(out.status).toBe(EXIT.refused);
|
|
expect(out.out).toContain('CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)');
|
|
expect(receiptIn(body).head).toBe(child);
|
|
}, 90_000);
|
|
|
|
// Value: protects=the docs row "a parent that landed with changes the child never merged" refuses; fails_when=a merge that
|
|
// keeps the child's tree (-s ours) over the landed parent reads as unchanged; seam=none; no_claim=-
|
|
test('a parent that landed with changes the child never merged refuses', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { child, body } = stack(repo);
|
|
repo.git('checkout', '-q', 'main');
|
|
commit(repo, { 'lib/util.js': SUB + "exports.mul = (a, b) => a * b;\n" }, 'squash: parent with a review fix (#7)');
|
|
repo.git('push', '-q', 'origin', 'main');
|
|
repo.git('checkout', '-q', 'feature');
|
|
repo.git('merge', '-q', '--no-edit', '-s', 'ours', 'origin/main');
|
|
const out = carry(repo, body);
|
|
expect(out.status).toBe(EXIT.refused);
|
|
expect(out.out).toContain('CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)');
|
|
expect(receiptIn(body).head).toBe(child);
|
|
}, 90_000);
|
|
});
|
|
|
|
const CONFIG = ['a = 1', 'b = 2', 'c = 3', 'd = 4', 'e = 5', 'f = 6', 'g = 7', 'h = 8', ''].join('\n');
|
|
const configWith = (edits: Record<string, string>) => CONFIG.split('\n').map(l => edits[l] ?? l).join('\n');
|
|
|
|
describe('carry after a stack parent squash-merges, receipt written against main (GST-1199)', () => {
|
|
// Value: protects=a child PR stacked on its parent but targeting main keeps its receipt once the parent squash-merges and
|
|
// main is merged in (gstack-evals#178 faced a 45-60M-token gate re-review for it); fails_when=carry compares the child's
|
|
// whole range from the old fork point, parent hunks included, with HEAD's diff against a base that now holds them;
|
|
// seam=none; no_claim=gh pr edit (--body stands in)
|
|
test('the child carries when its range from the landed parent is HEAD\'s whole product diff against main', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { parent, child, body } = stack(repo, undefined, undefined, 'main');
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
const head = repo.git('rev-parse', 'HEAD');
|
|
const out = carry(repo, body);
|
|
expect(out.err).not.toContain('RECEIPT_CARRY_PRODUCT_CHANGED');
|
|
expect(out.status).toBe(EXIT.ok);
|
|
expect(out.out).toContain(`CARRY: carried from ${child.slice(0, 12)} to ${head.slice(0, 12)}`);
|
|
const r = receiptIn(body);
|
|
expect(r.head).toBe(head);
|
|
expect(r.base).toBe('main');
|
|
expect(r.carry!.reason).toBe(`stack parent ${parent.slice(0, 12)} landed + base merge`);
|
|
expect(bindShippedReceipt(repo.work, 'origin/main', fs.readFileSync(body, 'utf8'), '8', [head]).ok).toBe(true);
|
|
}, 90_000);
|
|
|
|
// Value: protects=fail closed: a product edit after the receipt, or a parent that never landed and whose change the
|
|
// child's merge dropped, takes a fresh /ship; fails_when=any reviewed ancestor counts as a landed parent, or the edit
|
|
// hides behind the shorter range; seam=none; no_claim=-
|
|
test('a product edit after the receipt, or a dropped parent that never landed, refuses with RECEIPT_CARRY_PRODUCT_CHANGED', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { child, body } = stack(repo, undefined, undefined, 'main');
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
commit(repo, { 'lib/retry.js': RETRY4.replace('4', '5') }, 'child: five');
|
|
const edited = carry(repo, body);
|
|
expect(edited.status).toBe(EXIT.refused);
|
|
expect(edited.out).toContain('CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)');
|
|
expect(receiptIn(body).head).toBe(child);
|
|
|
|
const other = makeFixtureRepo(); repos.push(other);
|
|
const s = stack(other, undefined, undefined, 'main');
|
|
landOnMain(other, {});
|
|
commit(other, { 'lib/util.js': other.git('show', 'origin/main:lib/util.js') + '\n' }, 'drop the parent change');
|
|
const dropped = carry(other, s.body);
|
|
expect(dropped.status).toBe(EXIT.refused);
|
|
expect(dropped.out).toContain('CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)');
|
|
expect(receiptIn(s.body).head).toBe(s.child);
|
|
}, 120_000);
|
|
|
|
// Value: protects=a base change next to the child's reviewed hunks gets one fix-check reviewer, not a carry and not a full
|
|
// /ship; fails_when=the landed-parent comparison ignores base context or refuses it outright; seam=none; no_claim=-
|
|
test('a base change next to the child\'s reviewed hunks routes to RECEIPT_CARRY_SCOPED_REVIEW', () => {
|
|
const repo = makeFixtureRepo({ baseFiles: { 'lib/config.js': CONFIG } }); repos.push(repo);
|
|
const { child, body } = stack(repo, undefined, { 'lib/config.js': configWith({ 'd = 4': 'd = 40' }) }, 'main');
|
|
landOnMain(repo, { 'lib/util.js': SUB, 'lib/config.js': configWith({ 'f = 6': 'f = 60' }) });
|
|
const out = carry(repo, body);
|
|
expect(out.status).toBe(EXIT.refused);
|
|
expect(out.out).toContain('CARRY: refused (RECEIPT_CARRY_SCOPED_REVIEW)');
|
|
expect(out.err).toContain('lib/config.js');
|
|
expect(receiptIn(body).head).toBe(child);
|
|
}, 90_000);
|
|
|
|
// Value: protects=the receipt never names a stack parent that does not exist; fails_when=a test-first commit with no
|
|
// product change counts as landed (any base holds it), so the reason claims a parent and the test range shrinks; seam=none;
|
|
// no_claim=-
|
|
test('a test-only commit in a branch that was never stacked is no landed parent', () => {
|
|
const repo = makeFixtureRepo({ baseFiles: { 'lib/config.js': CONFIG } }); repos.push(repo);
|
|
const fork = repo.git('rev-parse', 'HEAD');
|
|
commit(repo, { 'test/config.test.js': "const test = require('node:test');\ntest('d', () => {});\n" }, 'test first');
|
|
const reviewed = commit(repo, { 'lib/config.js': configWith({ 'd = 4': 'd = 40' }) }, 'fix d');
|
|
repo.git('checkout', '-q', 'main');
|
|
const mainTip = commit(repo, { 'docs/README.md': '# main moves on\n' }, 'main moves on');
|
|
expect(landedStackParent(repo.work, { rangeBase: fork, reviewed, currentBase: mainTip }, ['.', ':(exclude,glob)test/**'])).toBeNull();
|
|
}, 60_000);
|
|
});
|
|
|
|
describe('carry after a stack parent lands, the child having merged main before its receipt (GST-1214)', () => {
|
|
/** main <- parent (lib/util.js) <- feature (lib/retry.js), which merges main (wiki/) once before its receipt is written against main. */
|
|
function mergedStack(repo: FixtureRepo, mainFiles: Record<string, string | null> = { 'wiki/a.md': '# a\n', 'wiki/b.md': '# b\n' }): { parent: string; reviewed: string; body: string } {
|
|
repo.git('checkout', '-q', '-b', 'parent');
|
|
const parent = commit(repo, { 'lib/util.js': SUB }, 'parent: sub');
|
|
repo.git('push', '-q', 'origin', 'parent');
|
|
repo.git('checkout', '-q', 'feature');
|
|
repo.git('reset', '-q', '--hard', parent);
|
|
commit(repo, { 'lib/retry.js': RETRY4 }, 'child: four retries');
|
|
repo.git('checkout', '-q', 'main');
|
|
commit(repo, mainFiles, 'main: wiki');
|
|
repo.git('push', '-q', 'origin', 'main');
|
|
repo.git('checkout', '-q', 'feature');
|
|
repo.git('merge', '-q', '--no-edit', 'origin/main');
|
|
const reviewed = repo.git('rev-parse', 'HEAD');
|
|
const body = path.join(repo.root, 'body.md');
|
|
const w = runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '8', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body]);
|
|
expect(w.status).toBe(EXIT.ok);
|
|
return { parent, reviewed, body };
|
|
}
|
|
|
|
// Value: protects=a stacked child that merged main before its receipt keeps it once the parent squash-lands and main is
|
|
// merged again (gstack-evals#178 refused on 20 wiki/ paths its first base merge brought in); fails_when=the range from the
|
|
// landed parent counts paths that hold main's content at the reviewed head; seam=none; no_claim=gh pr edit (--body stands in)
|
|
test('the child carries when only its earlier base merge separates the parent range from HEAD\'s diff against main', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { parent, reviewed, body } = mergedStack(repo);
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
const head = repo.git('rev-parse', 'HEAD');
|
|
const out = carry(repo, body);
|
|
expect(out.err).not.toContain('RECEIPT_CARRY_PRODUCT_CHANGED');
|
|
expect(out.status).toBe(EXIT.ok);
|
|
expect(out.out).toContain(`CARRY: carried from ${reviewed.slice(0, 12)} to ${head.slice(0, 12)}`);
|
|
expect(receiptIn(body).carry!.reason).toBe(`stack parent ${parent.slice(0, 12)} landed + base merge`);
|
|
}, 90_000);
|
|
|
|
// Value: protects=fail closed: an edit to a file the earlier base merge brought in is product and refuses; fails_when=every
|
|
// base-merged path drops out of both sides, the child's own edit included; seam=none; no_claim=-
|
|
test('an edit to a base-merged file after the receipt refuses with RECEIPT_CARRY_PRODUCT_CHANGED', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { reviewed, body } = mergedStack(repo);
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
commit(repo, { 'wiki/a.md': '# a, edited by the child\n' }, 'child: edit wiki');
|
|
const out = carry(repo, body);
|
|
expect(out.status).toBe(EXIT.refused);
|
|
expect(out.out).toContain('CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)');
|
|
expect(out.err).toContain('wiki/a.md');
|
|
expect(receiptIn(body).head).toBe(reviewed);
|
|
}, 90_000);
|
|
|
|
// Value: protects=fail closed when the earlier base merge turned a file into a directory: leaving out the old file must not
|
|
// hide an edit beneath it (a pathspec names a path and everything under it); fails_when=the exclusion covers a changed
|
|
// descendant; seam=none; no_claim=-
|
|
test('a base merge that replaced a file with a directory never hides an edit beneath it', () => {
|
|
const repo = makeFixtureRepo({ baseFiles: { services: 'old\n' } }); repos.push(repo);
|
|
const { reviewed, body } = mergedStack(repo, { services: null, 'services/worker.js': 'exports.allowed = false;\n' });
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
commit(repo, { 'services/worker.js': 'exports.allowed = true;\n' }, 'child: allow');
|
|
const out = carry(repo, body);
|
|
expect(out.status).toBe(EXIT.refused);
|
|
expect(out.out).toContain('CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)');
|
|
expect(receiptIn(body).head).toBe(reviewed);
|
|
}, 90_000);
|
|
});
|
|
|
|
// yc-software/qm#3457 (GST-3315): the parent squash-landed on main and the child merged main before its receipt was
|
|
// written against main. A later main merge moved context next to one of the child's hunks, so the carry looked for a
|
|
// landed parent, found the parent's commits (which the reviewed base already held) and measured from them, refusing
|
|
// RECEIPT_CARRY_PRODUCT_CHANGED on the parent's files.
|
|
/** Main moves, the parent squash-lands, the child merges main, its receipt is written against main, then main moves `files` and the child merges it. */
|
|
function landedFirst(files: Record<string, string>) {
|
|
const repo = makeFixtureRepo({ baseFiles: { 'lib/config.js': CONFIG } }); repos.push(repo);
|
|
repo.git('checkout', '-q', '-b', 'parent');
|
|
const parent = commit(repo, { 'lib/util.js': SUB }, 'parent: sub');
|
|
repo.git('checkout', '-q', 'feature');
|
|
repo.git('reset', '-q', '--hard', parent);
|
|
commit(repo, { 'lib/config.js': configWith({ 'd = 4': 'd = 40' }) }, 'child: d');
|
|
repo.git('checkout', '-q', 'main');
|
|
commit(repo, { 'lib/other.js': 'exports.other = 1;\n' }, 'main moves before the parent lands');
|
|
commit(repo, { 'lib/util.js': SUB }, 'squash: parent (#7)');
|
|
repo.git('push', '-q', 'origin', 'main');
|
|
repo.git('checkout', '-q', 'feature');
|
|
repo.git('merge', '-q', '--no-edit', 'origin/main');
|
|
const reviewed = repo.git('rev-parse', 'HEAD');
|
|
const body = path.join(repo.root, 'body.md');
|
|
expect(runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '8', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body]).status).toBe(EXIT.ok);
|
|
const rangeBase = repo.git('merge-base', 'origin/main', 'HEAD');
|
|
repo.git('checkout', '-q', 'main');
|
|
commit(repo, files, 'main moves on');
|
|
repo.git('push', '-q', 'origin', 'main');
|
|
repo.git('checkout', '-q', 'feature');
|
|
repo.git('merge', '-q', '--no-edit', 'origin/main');
|
|
return { repo, parent, reviewed, rangeBase, body };
|
|
}
|
|
|
|
describe('a stack parent the reviewed base already held is no landed parent (qm#3457, GST-3315)', () => {
|
|
// Value: protects=qm#3457: base context moved beside the child's own hunk takes one scoped review of that file, not a
|
|
// refusal naming the parent's files; fails_when=landedStackParent counts a parent the reviewed base already held and the
|
|
// carry measures from it; seam=gstack-ship-receipt carry; no_claim=the scoped review itself
|
|
test('#3457: context moved next to the child\'s hunk routes to a scoped review of that file alone', () => {
|
|
const { repo, reviewed, rangeBase, body } = landedFirst({ 'lib/config.js': configWith({ 'f = 6': 'f = 60' }) });
|
|
expect(landedStackParent(repo.work, { rangeBase, reviewed, currentBase: repo.git('merge-base', 'origin/main', 'HEAD') }, ['.', ':(exclude,glob)test/**'])).toBeNull();
|
|
const out = carry(repo, body);
|
|
expect([out.status, out.out]).toEqual([EXIT.refused, expect.stringContaining('CARRY: refused (RECEIPT_CARRY_SCOPED_REVIEW)')]);
|
|
expect(out.err).toContain('lib/config.js');
|
|
expect(out.err).not.toContain('lib/util.js');
|
|
expect(receiptIn(body).head).toBe(reviewed);
|
|
}, 90_000);
|
|
|
|
// Value: protects=the patch-id keeps three lines of context whatever the user's git config says; fails_when=diff.context=0
|
|
// drops the moved context from both hashes and the carry passes unread base edits; seam=patchId; no_claim=-
|
|
test('diff.context=0 in the user\'s git config still routes moved context to a scoped review', () => {
|
|
const { repo, body } = landedFirst({ 'lib/config.js': configWith({ 'f = 6': 'f = 60' }) });
|
|
repo.git('config', 'diff.context', '0');
|
|
const out = carry(repo, body);
|
|
expect([out.status, out.out]).toEqual([EXIT.refused, expect.stringContaining('CARRY: refused (RECEIPT_CARRY_SCOPED_REVIEW)')]);
|
|
}, 90_000);
|
|
|
|
test('an unrelated main change carries', () => {
|
|
const { repo, body } = landedFirst({ 'docs/README.md': '# main moves on\n' });
|
|
const out = carry(repo, body);
|
|
expect(out.status, out.err).toBe(EXIT.ok);
|
|
expect(receiptIn(body).carry!.reason).toBe('base merge');
|
|
}, 90_000);
|
|
|
|
// Value: protects=fail closed: an own edit after the merge still refuses, naming the child's file; fails_when=dropping the
|
|
// parent hides an own edit; seam=gstack-ship-receipt carry; no_claim=-
|
|
test('an own edit after the merge refuses with RECEIPT_CARRY_PRODUCT_CHANGED on the child\'s file', () => {
|
|
const { repo, reviewed, body } = landedFirst({ 'docs/README.md': '# main moves on\n' });
|
|
commit(repo, { 'lib/config.js': configWith({ 'd = 4': 'd = 41' }) }, 'child: d again');
|
|
const out = carry(repo, body);
|
|
expect([out.status, out.out]).toEqual([EXIT.refused, expect.stringContaining('CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)')]);
|
|
expect(out.err).toContain('lib/config.js');
|
|
expect(receiptIn(body).head).toBe(reviewed);
|
|
}, 90_000);
|
|
});
|
|
|
|
// Step 11.5 measures a reviewed range the way the carry does (GST-3315): a child reviewed while stacked whose parent then
|
|
// squash-landed is CURRENT after merging main, from that parent; the qm#3457 shape is not.
|
|
describe('Step 11.5\'s base-merge check uses the carry\'s stack-parent rule (GST-3315)', () => {
|
|
const at = (repo: FixtureRepo, ref: string) => repo.git('rev-parse', `${ref}^{tree}`);
|
|
test('a parent that landed after the review is measured from; one the reviewed base held is not', () => {
|
|
const repo = makeFixtureRepo(); repos.push(repo);
|
|
const { parent, child } = stack(repo, undefined, undefined, 'main');
|
|
landOnMain(repo, { 'lib/util.js': SUB });
|
|
const ok = baseMergeOnly(repo.work, 'main', child, at(repo, child), at(repo, 'HEAD'));
|
|
expect(ok).toEqual({ ok: true, note: expect.stringContaining(`, its stack parent ${parent.slice(0, 12)} having landed on origin/main, and the branch's patch is unchanged`) });
|
|
expect(ok.ok && ok.note.endsWith(`save the reviewed base ${parent} for finish's --reviewed-base`)).toBe(true);
|
|
|
|
const { repo: qm, reviewed } = landedFirst({ 'lib/config.js': configWith({ 'f = 6': 'f = 60' }) });
|
|
expect(baseMergeOnly(qm.work, 'main', reviewed, at(qm, reviewed), at(qm, 'HEAD'))).toEqual({ ok: false, why: expect.stringMatching(/^the branch's product patch changed/) });
|
|
}, 120_000);
|
|
});
|