mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-27 10:24:00 +01:00
train S5: merge #3862 at 97595f41ee v1.93.7.0
This commit is contained in:
commit
86bb621fa2
21 files changed
+247
-88
No files matched your search
@@ -218,6 +218,19 @@ describe('carry follow-ups: git floor, named refusal, branch-touched walk, digit
|
||||
expect(stampOnlyText({ before: 'left-pad since: 1.2.3\n', after: 'left-pad since: 1.2.4.0\n', oldVersion: '1.2.3.0', newVersion: '1.2.4.0' })).toBe(false);
|
||||
});
|
||||
|
||||
// GST-963: the carry shares the stage's bound, so a key version the branch added at its fork version (older than the
|
||||
// pin's VERSION after a base merge) is a stamp on the branch's own line and a hand edit on any other.
|
||||
test('stampOnlyText takes the fork-version bound only on a line the branch added', () => {
|
||||
const templates = ["_KEY_VERSION = '{version}'"];
|
||||
const mine = "export const MINE_KEY_VERSION = '1.2.3.0';";
|
||||
const before = `${mine}\nexport const BASE_KEY_VERSION = '1.2.3.0';\n`;
|
||||
const moved = (text: string) => ({ before, after: text, oldVersion: '1.2.4.0', newVersion: '1.2.5.0', templates });
|
||||
const side = { fork: '1.2.3.0', added: new Set([mine]) };
|
||||
expect(stampOnlyText({ ...moved(before.replace(mine, mine.replace('1.2.3.0', '1.2.5.0'))), side })).toBe(true);
|
||||
expect(stampOnlyText(moved(before.replace(mine, mine.replace('1.2.3.0', '1.2.5.0'))))).toBe(false);
|
||||
expect(stampOnlyText({ ...moved(before.replace("BASE_KEY_VERSION = '1.2.3.0'", "BASE_KEY_VERSION = '1.2.5.0'")), side })).toBe(false);
|
||||
});
|
||||
|
||||
test('planCarry names at most CARRY_NAMED_PATHS paths', () => {
|
||||
const many = Array.from({ length: CARRY_NAMED_PATHS + 3 }, (_, i) => `src/f${i}.ts`);
|
||||
const plan = planCarry({ from: 'a'.repeat(40), head: 'b'.repeat(40), changed: many.map(p => ({ path: p, class: 'product' as const })), productPatchId: { from: 'x', head: 'y' }, testPatchId: { from: '', head: '' }, changedProduct: many, mergeCommits: 0, rangeDiff: '' });
|
||||
|
||||
@@ -17,7 +17,8 @@ import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { mergeChangelogs } from '../lib/changelog-check';
|
||||
import { branchAddedLines, stampOnlyLine } from '../lib/restamp';
|
||||
import { branchAddedLines } from '../lib/restamp';
|
||||
import { stampOnlyLine } from '../lib/stamp-only';
|
||||
import { gitArgvIn } from './helpers/scratch-repo';
|
||||
import { BASE_POLICY, cleanup, makeFixtureRepo, makePr, readFile, restamp, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { rewriteStamps, tentativeMentions } from '../lib/restamp';
|
||||
import type { GitFixtureTemplate } from './helpers/git-fixture-template';
|
||||
import { BASE_POLICY, cleanup, cloneFixture, fixtureTemplate, makePr, mergeMain, mergeToMain, readFile, restamp, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
import { BASE_POLICY, cleanup, cloneFixture, fixtureTemplate, makePr, mergeMain, mergeToMain, readFile, restamp, runBin, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
@@ -88,6 +88,11 @@ const notice = (rows: string[]) => ['export const ROWS = [', ...rows, '];', ''].
|
||||
function policy(templates: boolean) {
|
||||
return { ...BASE_POLICY, release_tool: null, stamp_files: ['VERSION', 'package.json', 'CHANGELOG.md', NOTICE], ...(templates ? { stamp_patterns: ["since: '{version}'"] } : {}) };
|
||||
}
|
||||
/** The policy plus the lockfile --next stamps, so the tree receipt's stamp_files allowlist covers the whole stamp commit. */
|
||||
function receiptPolicy(templates: boolean) {
|
||||
const p = policy(templates);
|
||||
return { ...p, stamp_files: [...p.stamp_files, 'package-lock.json'] };
|
||||
}
|
||||
function write(repo: FixtureRepo, rel: string, text: string): void {
|
||||
fs.mkdirSync(path.dirname(path.join(repo.work, rel)), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, rel), text);
|
||||
@@ -157,7 +162,7 @@ describe('a PR whose VERSION already equals the base (gbrain #7640)', () => {
|
||||
expect(r.status).toBe(EXIT.ok);
|
||||
const sp = stageDetail(r.out, 'stamp_paths')!;
|
||||
expect(sp[1]).toBe('skipped');
|
||||
expect(sp[2]).toBe('no tentative mention newer than the fork version 1.2.3.0 and none of base 1.2.3.0 on a line this branch added; VERSION equals base 1.2.3.0, so 1.2.3.0 moved only on lines this branch added and stayed on the base\'s own lines (src/notice.ts: 0 moved, 1 kept)');
|
||||
expect(sp[2]).toBe('no tentative mention at or newer than the fork version 1.2.3.0 and none of base 1.2.3.0 on a line this branch added; VERSION equals base 1.2.3.0, so 1.2.3.0 moved only on lines this branch added and stayed on the base\'s own lines (src/notice.ts: 0 moved, 1 kept)');
|
||||
expect(readFile(repo, NOTICE)).toBe(notice([row('1.2.3.0', 'base_row'), " { since: 'TBD', id: 'mine', text: 'mine' },"]));
|
||||
expect(r.out).not.toMatch(/^[-+] \{ since: '1\.2\.3\.0'/m);
|
||||
});
|
||||
@@ -243,6 +248,18 @@ describe('a PR whose VERSION already equals the base (gbrain #7640)', () => {
|
||||
expect(JSON.parse(readFile(repo, '.gstack/tmp/restamp-journal.json')).status).toBe('complete');
|
||||
});
|
||||
|
||||
// Value: protects=the lost-slot stamp the stage writes is one the train's tree receipt accepts (GST-963 review: one bound
|
||||
// for the writer and the checks); fails_when=the tree receipt reads the moved own row as a product change; seam=stampOnlyLine
|
||||
test('the lost-slot stamp passes the tree receipt', () => {
|
||||
const repo = makeFixtureRepo({ prefix: 'restamp-mentions-receipt-', policy: receiptPolicy(true) }); repos.push(repo);
|
||||
lostSlot(repo);
|
||||
const gated = repo.git('rev-parse', 'HEAD');
|
||||
expect(restamp(repo, ['--next']).status).toBe(EXIT.ok);
|
||||
repo.git('commit', '-qam', 'stamp mine');
|
||||
const receipt = runBin(repo, 'gstack-tree-receipt', ['--gated', gated, '--base', 'main']);
|
||||
expect(receipt.out, receipt.err).toContain('TREE: same-modulo-stamps');
|
||||
});
|
||||
|
||||
test('--was still rewrites every line, the base\'s rows included: it is not the fix for this state', () => {
|
||||
const repo = makeFixtureRepo({ prefix: 'restamp-mentions-was-', policy: policy(true) }); repos.push(repo);
|
||||
lostSlot(repo);
|
||||
@@ -252,3 +269,64 @@ describe('a PR whose VERSION already equals the base (gbrain #7640)', () => {
|
||||
expect(readFile(repo, NOTICE)).toBe(notice([row('1.2.5.0', 'other'), row('1.2.3.0', 'base_row'), '', '', '', row('1.2.5.0', 'mine')]));
|
||||
});
|
||||
});
|
||||
|
||||
describe('a branch-added row left at the fork version after the base moved (GST-963, GBRA-277, gbrain #8425)', () => {
|
||||
// Value: protects=a stamp-form row the branch added at its fork version (not a tentative next version) is its own
|
||||
// stale stamp once the base has moved past the fork, so --next moves it; the base's rows at that version, and a
|
||||
// branch-added row older than the fork, stay; fails_when=the stage skips with "no tentative mention newer than the
|
||||
// fork version" and leaves the row at the fork version (gbrain #8425), or moves a base row or a pre-fork row;
|
||||
// seam=lib/restamp.ts rewriteStampPaths; no_claim=finish's route (test/ship-rereview-triggers.test.ts)
|
||||
test.each([['with the since: template', true], ['built-in quoted form alone', false]])('%s: the fork-version row moves, the base rows and an older branch row stay', (_, templates) => {
|
||||
const repo = makeFixtureRepo({ prefix: 'restamp-fork-row-', policy: receiptPolicy(templates) }); repos.push(repo);
|
||||
write(repo, NOTICE, notice([row('1.2.3.0', 'base_row')]));
|
||||
repo.git('add', '-A'); repo.git('commit', '-qm', 'notice rows'); repo.git('push', '-q', 'origin', 'main');
|
||||
makePr(repo, 'pr-mine');
|
||||
write(repo, NOTICE, notice([row('1.2.3.0', 'base_row'), '', row('1.2.2.0', 'older'), '', row('1.2.3.0', 'mine')]));
|
||||
repo.git('commit', '-qam', 'mine: a row at the fork version');
|
||||
makePr(repo, 'pr-other');
|
||||
write(repo, NOTICE, notice([row('1.2.4.0', 'other'), row('1.2.3.0', 'base_row')]));
|
||||
repo.git('commit', '-qam', 'other row');
|
||||
expect(restamp(repo, ['--next']).status).toBe(EXIT.ok);
|
||||
repo.git('commit', '-qam', 'stamp other');
|
||||
mergeToMain(repo, 'pr-other');
|
||||
repo.git('checkout', '-q', 'pr-mine');
|
||||
mergeMain(repo);
|
||||
expect(readFile(repo, 'VERSION')).toBe('1.2.4.0\n');
|
||||
const gated = repo.git('rev-parse', 'HEAD');
|
||||
const r = restamp(repo, ['--next']);
|
||||
expect(r.status).toBe(EXIT.ok);
|
||||
expect(stageDetail(r.out, 'stamp_paths')![1]).toBe('done');
|
||||
expect(readFile(repo, NOTICE)).toBe(notice([row('1.2.4.0', 'other'), row('1.2.3.0', 'base_row'), '', row('1.2.2.0', 'older'), '', row('1.2.5.0', 'mine')]));
|
||||
repo.git('commit', '-qam', 'stamp mine');
|
||||
const receipt = runBin(repo, 'gstack-tree-receipt', ['--gated', gated, '--base', 'main']);
|
||||
expect(receipt.out, receipt.err).toContain('TREE: same-modulo-stamps');
|
||||
});
|
||||
|
||||
// Value: protects=the four stamp checks share one bound, so a stamp the writer makes is one the train accepts;
|
||||
// fails_when=the tree receipt (stamp, verify, gate-ahead replay) reads a moved fork-version row, or a base row at that
|
||||
// version moved by hand, the same way; seam=lib/stamp-only.ts stampOnlyLine with the branch side
|
||||
test('the tree receipt accepts the moved branch row and refuses the same move on a base row', () => {
|
||||
const repo = makeFixtureRepo({ prefix: 'restamp-fork-row-receipt-', policy: receiptPolicy(true) }); repos.push(repo);
|
||||
write(repo, NOTICE, notice([row('1.2.3.0', 'base_row')]));
|
||||
repo.git('add', '-A'); repo.git('commit', '-qm', 'notice rows'); repo.git('push', '-q', 'origin', 'main');
|
||||
makePr(repo, 'pr-mine');
|
||||
write(repo, NOTICE, notice([row('1.2.3.0', 'base_row'), '', row('1.2.3.0', 'mine')]));
|
||||
repo.git('commit', '-qam', 'mine: a row at the fork version');
|
||||
makePr(repo, 'pr-other');
|
||||
write(repo, 'other.txt', 'other\n');
|
||||
repo.git('add', '-A'); repo.git('commit', '-qm', 'other');
|
||||
expect(restamp(repo, ['--next']).status).toBe(EXIT.ok);
|
||||
repo.git('commit', '-qam', 'stamp other');
|
||||
mergeToMain(repo, 'pr-other');
|
||||
repo.git('checkout', '-q', 'pr-mine');
|
||||
mergeMain(repo);
|
||||
const gated = repo.git('rev-parse', 'HEAD');
|
||||
expect(restamp(repo, ['--next']).status).toBe(EXIT.ok);
|
||||
write(repo, NOTICE, readFile(repo, NOTICE).replace(row('1.2.3.0', 'base_row'), row('1.2.5.0', 'base_row')));
|
||||
repo.git('commit', '-qam', 'stamp mine, and move the base row by hand');
|
||||
const receipt = runBin(repo, 'gstack-tree-receipt', ['--gated', gated, '--base', 'main']);
|
||||
expect(receipt.out).toContain('TREE: changed');
|
||||
expect(receipt.out).toContain("id: 'base_row'");
|
||||
expect(receipt.out).not.toContain("id: 'mine'");
|
||||
});
|
||||
});
|
||||
@@ -136,4 +136,19 @@ describe('stamped train prefixes', () => {
|
||||
const product = tamper('a.txt', () => 'not a\n');
|
||||
expect(stampMismatch(o, merged, product, o.plain[2]!.tree)).toContain('a.txt');
|
||||
}, 60_000);
|
||||
|
||||
// Value: protects=the train's stamp check bounds a branch-added row the same way the train restamp writes it, so a pin
|
||||
// with a row left at the fork version still stamps; fails_when=stampMismatch reads that row against the pin's own
|
||||
// VERSION and refuses the moved row; seam=lib/ship-queue-train-stamp.ts stampMismatch baseRef (GST-963)
|
||||
test('a pin claiming 1.2.4.0 with a stamp_paths row left at the base 1.2.3.0 stamps, and the row moves (GST-963)', () => {
|
||||
const r = makeFixtureRepo({ policy: POLICY, prefix: 'train-stamp-' }); repos.push(r);
|
||||
pin(r, 'f', 'origin/main', '- f change\n');
|
||||
fs.writeFileSync(path.join(r.work, 'VERSION'), '1.2.4.0\n');
|
||||
fs.writeFileSync(path.join(r.work, 'docs', 'f.md'), '// since: 1.2.3.0\n');
|
||||
r.git('add', '-A'); r.git('commit', '-q', '-m', 'f: claims 1.2.4.0, row at the fork version');
|
||||
const out = stampChain(chain(r, [['1', r.git('rev-parse', 'HEAD')]]));
|
||||
if ('code' in out) throw new Error(`${out.code}: ${out.message}`);
|
||||
expect(out.stamped.map(s => s.version)).toEqual(['1.2.4.0']);
|
||||
expect(show(r, out.stamped[0]!.commit + ':docs/f.md')).toBe('// since: 1.2.4.0');
|
||||
}, 60_000);
|
||||
});
|
||||
@@ -206,7 +206,8 @@ describe('a restamp after a lost slot (GST-895, GBRA-218, gbrain #8134)', () =>
|
||||
// Value: protects=after a lost slot and a merge of the base, the restamp moves the branch's own stale stamp (older
|
||||
// than the reviewed tree's VERSION, newer than its fork point) and finish routes that line as a stamp; a row the
|
||||
// base carries (another PR's release at the same version), a merged base row the base later edited, or a branch row
|
||||
// at or older than the fork point, moved the same way still stops;
|
||||
// older than the fork point, moved the same way still stops; a branch row at the fork version is the branch's own
|
||||
// stale stamp and routes as metadata (GST-963, gbrain #8425);
|
||||
// fails_when=stampedFiles floors every moved version at the reviewed tree's VERSION (behavior=1 on gbrain #8134) or
|
||||
// drops the floor for base lines; seam=lib/ship-bin-common.ts stampedFiles; no_claim=the restamp writer
|
||||
const policy = JSON.stringify({ stamp_files: ['VERSION', 'src/notice.ts'], stamp_patterns: ["since: '{version}'"] });
|
||||
@@ -239,7 +240,7 @@ describe('a restamp after a lost slot (GST-895, GBRA-218, gbrain #8134)', () =>
|
||||
const atFork = lostSlot('1.0.0.0');
|
||||
atFork.f.write({ VERSION: '1.0.3.0\n', 'src/notice.ts': notice(['0.9.0.0', 'old'], ['1.0.1.0', 'theirs'], ['1.0.3.0', 'mine']) }); atFork.f.commit('moves a row at the fork version');
|
||||
const a = finish(atFork.f, atFork.reviewed, atFork.post, ['--reviewed-base', atFork.reviewedBase]);
|
||||
expect([a.status, lineOf(a.stdout, 'STOP')]).toEqual([3, behaviorStop]);
|
||||
expect([lineOf(a.stdout, 'ROUTE'), lineOf(a.stdout, 'DOCS')]).toEqual([expect.stringMatching(/ behavior=0 docs=0 metadata=2 tests=0 /), expect.not.stringContaining('src/notice.ts')]);
|
||||
|
||||
const edited = lostSlot('1.0.1.0');
|
||||
edited.f.advanceBase({ VERSION: '1.0.2.0\n', 'src/notice.ts': notice(['0.9.0.0', 'old'], ['1.0.1.0', 'theirs, edited']) }); edited.f.git('fetch', '-q', 'origin');
|
||||
|
||||
@@ -8,7 +8,7 @@ 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 { stampOnlyLine } from '../lib/restamp';
|
||||
import { stampOnlyLine } from '../lib/stamp-only';
|
||||
import { BASE_POLICY, cleanup, ghShim, makeFixtureRepo, makePr, readFile, recordAndBundle, restamp, runBin, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
|
||||
Reference in new issue
Block a user