train S3: merge #3923 at 5660d09adc v1.94.27.0

This commit is contained in:
garrytan committed 2000-01-01 00:00:00 +00:00
commit 3fb850f433
14 files changed
+271 -17

No files matched your search

+1
View File
@@ -31,6 +31,7 @@ const KEPT: Record<string, string> = {
'restamp-staging.json': 'gstack-restamp files still to stage, read by its noop rerun (bin/gstack-restamp)',
'gate-ahead*': 'gate-ahead record and worktree (lib/restamp.ts)',
'pregate.json': 'pregate result (lib/pregate/index.ts)',
'pregate-guards.json': 'gstack-pregate --stage guards result, the pre-push housekeeping run (lib/pregate/index.ts PREGATE_GUARDS_OUT_REL)',
'ship-queue': 'ship-queue state (lib/ship-queue-gate.ts)',
'ship-receipt.md': '/ship handoff receipt',
'ship-gate.json': '/ship handoff gate record',
+56
View File
@@ -240,3 +240,59 @@ describe('lanes runtime and serial files (CD1)', () => {
expect(r.out).toMatch(/^tests {6}lanes {5}pass .*2 tests ran in 2 file\(s\) \(1 serial\), exit 0/m);
});
});
// ---------------------------------------------------------------------------
// GST-1138 (ship-90-90 L6): the pre-push housekeeping run and gstack's own guard list
// ---------------------------------------------------------------------------
import { matchesAny } from '../lib/ship-policy';
describe('--stage guards: the pre-push housekeeping run (GST-1138)', () => {
// Value: protects=--stage guards runs only regen and guards for the touched files, writes its own record and never replaces the full run's
// pregate.json; fails_when=it runs the secrets, strays or test checks, overwrites .gstack/tmp/pregate.json, or accepts --only/--from-run;
// why_new=gbrain: 64 of 93 red heads were housekeeping (FOUN-64), #3908 went red on the context-budget ratchet; seam=gstack-pregate run; no_claim=CI
test('runs only regen and guards, writes pregate-guards.json, leaves pregate.json alone and refuses --only and --from-run', () => {
const repo = guardedFixture({ ...BASE_PREGATE, guards: [SERIAL_GUARD] });
commit(repo, { 'test/widget-env.serial.test.js': SERIAL_TEST });
const r = pregate(repo, ['--allow-repo-commands', '--stage', 'guards']);
expect(r.status).toBe(EXIT.fail);
expect(r.out).toMatch(/^preflight {2}guards {4}fail .*serial-manifest.*\(PREGATE_GUARD_FAILED\)/m);
expect(fs.existsSync(path.join(repo.work, '.gstack/tmp/pregate.json'))).toBe(false);
const rec = JSON.parse(fs.readFileSync(path.join(repo.work, '.gstack/tmp/pregate-guards.json'), 'utf8'));
expect(rec.checks.map((c: any) => c.id)).toEqual(['regen', 'guards']);
expect(rec.stage2_ms).toBeUndefined();
commit(repo, { 'scripts/serial-files.tsv': 'path\treason\ntest/widget-env.serial.test.js\tglobal-state\n' });
const ok = pregate(repo, ['--allow-repo-commands', '--stage', 'guards']);
expect(ok.status, ok.out + ok.err).toBe(EXIT.ok);
expect(ok.out).toContain('1 guard(s) passed: serial-manifest');
expect(pregate(repo, ['--stage', 'guards', '--only', 'secrets']).status).toBe(EXIT.usage);
expect(pregate(repo, ['--stage', 'guards', '--from-run', '123']).status).toBe(EXIT.usage);
});
});
describe("gstack's own pre-push guards (GST-1138)", () => {
// Value: protects=gstack declares the housekeeping guards that went red after push (typecheck, skill size, parity, context budget,
// module size, goldens, doc caps), each runnable and selected only by its inputs; fails_when=a guard is dropped, names a missing test file,
// fails validation, or fires on a docs-only change; why_new=GST-1138; seam=.gstack/pregate.json; no_claim=the guards' own verdicts
const GSTACK = path.resolve(import.meta.dir, '..');
const policy = JSON.parse(fs.readFileSync(path.join(GSTACK, '.gstack/pregate.json'), 'utf8'));
const guards: { id: string; when: string[]; command: string; fix?: string }[] = policy.guards ?? [];
const selected = (file: string) => guards.filter(g => matchesAny(g.when, file)).map(g => g.id).sort();
test('the list validates, every guard has a fix, and every test file it names exists', () => {
expect(codes(policy)).toEqual([]);
expect(guards.map(g => g.id).sort()).toEqual(['context-budget', 'doc-caps', 'goldens', 'module-size', 'parity-suite', 'skill-size', 'typecheck']);
for (const g of guards) {
expect(g.fix, g.id).toBeTruthy();
for (const f of g.command.match(/test\/[\w./-]+\.test\.ts/g) ?? []) expect(fs.existsSync(path.join(GSTACK, f)), `${g.id}: ${f}`).toBe(true);
}
});
test('each guard fires on its own inputs and none fires on a docs-only change', () => {
expect(selected('ship/SKILL.md.tmpl')).toEqual(['context-budget', 'goldens', 'parity-suite', 'skill-size']);
expect(selected('lib/pregate/index.ts')).toEqual(['module-size', 'typecheck']);
expect(selected('test/fixtures/golden/claude-ship-SKILL.md')).toEqual(['goldens']);
expect(selected('CLAUDE.md')).toEqual(['doc-caps']);
expect(selected('docs/pregate.md')).toEqual([]);
expect(selected('changelog.d/x.md')).toEqual([]);
});
});
+96
View File
@@ -352,3 +352,99 @@ describe('GSTA-167 part 4a: the post-review route stays path-only', () => {
expect(r.stdout).toContain('STOP: behavior, tests or build inputs changed since review (wiki/post/data.json)');
});
});
describe('push: the pre-push housekeeping guards (GST-1138)', () => {
// Value: protects=push runs gstack-pregate --stage guards before every push and stops on a failing guard with its fix, pushing nothing;
// a pass recorded at HEAD's exact tree is reused instead of rerun; fails_when=a housekeeping red reaches CI, a failed guard still pushes,
// or a guard reruns on a tree it already passed; why_new=gbrain 64 of 93 red heads were housekeeping (FOUN-64), #3908's context-budget red;
// seam=gstack-pregate --stage guards; no_claim=CI's own verdict
const policy = (command: string) => JSON.stringify({ guards: [{ id: 'housekeeping', when: ['src/**'], command, fix: 'regenerate the golden' }] }) + '\n';
const ready = (f: ShipFx) => { fs.mkdirSync(f.state, { recursive: true }); fs.writeFileSync(path.join(f.state, '.redact-prepush-prompted'), ''); };
const pushedHead = (f: ShipFx) => f.git('ls-remote', '--heads', 'origin', 'refs/heads/feat').stdout.trim();
test('a failing guard stops the push with its fix and nothing is pushed', () => {
const f = fx({ '.gstack/pregate.json': policy('echo golden is stale; exit 4') });
ready(f);
const r = f.run(RELEASE, ['push', '--branch', 'feat']);
expect(r.status).toBe(3);
expect(lineOf(r.stdout, 'GUARDS')).toMatch(/^GUARDS: fail .*housekeeping/);
expect(r.stdout).toContain('STOP: the pre-push guards did not pass');
expect(r.stdout).toContain('regenerate the golden');
expect(pushedHead(f)).toBe('');
});
test('a passing guard pushes; the next push at the same tree reuses the pass instead of rerunning it', () => {
const f = fx({ '.gstack/pregate.json': policy('echo ran >> ../guard-runs') });
ready(f);
const first = f.run(RELEASE, ['push', '--branch', 'feat']);
expect(first.status, first.stdout + first.stderr).toBe(0);
expect(lineOf(first.stdout, 'GUARDS')).toMatch(/^GUARDS: pass .*1 guard\(s\) passed: housekeeping/);
expect(lineOf(first.stdout, 'PUSH')).toMatch(/^PUSH: pushed /);
const again = f.run(RELEASE, ['push', '--branch', 'feat']);
expect(lineOf(again.stdout, 'GUARDS')).toMatch(/^GUARDS: pass \(reused from pregate-guards\.json at tree [0-9a-f]{12}: /);
expect(fs.readFileSync(path.join(f.root, 'guard-runs'), 'utf8')).toBe('ran\n');
f.write({ 'src/c.ts': 'export const c = 3;\n' }); f.commit('more');
expect(lineOf(f.run(RELEASE, ['push', '--branch', 'feat']).stdout, 'GUARDS')).not.toContain('reused');
expect(fs.readFileSync(path.join(f.root, 'guard-runs'), 'utf8')).toBe('ran\nran\n');
});
test('an uncommitted or untracked file the guards saw stops the push: the verdict must describe the pushed tree', () => {
const f = fx({ '.gstack/pregate.json': policy('test -f src/needed.ts') });
ready(f);
f.write({ 'src/needed.ts': 'export const n = 1;\n' });
const r = f.run(RELEASE, ['push', '--branch', 'feat']);
expect(r.status).toBe(3);
expect(lineOf(r.stdout, 'GUARDS')).toContain('not certified');
expect(r.stdout).toContain('STOP: the working tree differs from HEAD');
expect(pushedHead(f)).toBe('');
});
test('a base that exists on origin but is not fetched, a mistyped --base, a dangling origin/HEAD and an unreadable policy stop the push', () => {
const f = fx({ '.gstack/pregate.json': policy('exit 4') });
ready(f);
f.git('update-ref', '-d', 'refs/remotes/origin/main');
const unfetched = f.run(RELEASE, ['push', '--branch', 'feat']);
expect(unfetched.status).toBe(3);
expect(lineOf(unfetched.stdout, 'GUARDS')).toMatch(/^GUARDS: refused POLICY_SOURCE_UNAVAILABLE/);
expect(unfetched.stdout).toContain('STOP: the pre-push guards could not run');
f.git('fetch', '-q', 'origin', 'main:refs/remotes/origin/main');
const typo = f.run(RELEASE, ['push', '--branch', 'feat', '--base', 'mian']);
expect(typo.status).toBe(3);
expect(lineOf(typo.stdout, 'GUARDS')).toMatch(/^GUARDS: refused /);
f.git('symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/retired-default');
const dangling = f.run(RELEASE, ['push', '--branch', 'feat']);
expect(dangling.status).toBe(3);
expect(lineOf(dangling.stdout, 'GUARDS')).toMatch(/^GUARDS: refused /);
expect(pushedHead(f)).toBe('');
const broken = fx({ '.gstack/pregate.json': '{not json\n' });
ready(broken);
const refused = broken.run(RELEASE, ['push', '--branch', 'feat']);
expect(refused.status).toBe(3);
expect(lineOf(refused.stdout, 'GUARDS')).toMatch(/^GUARDS: refused /);
});
test("finish's preflight record is reused only at HEAD's tree with passing regen and guards rows", () => {
const f = fx({ '.gstack/pregate.json': policy('echo ran >> ../guard-runs') });
ready(f);
const tree = f.git('rev-parse', 'HEAD^{tree}').stdout.trim();
const record = (at: string, guards: string) => JSON.stringify({ tree: at, checks: [{ id: 'regen', status: 'pass' }, { id: 'guards', status: guards }] });
const finishRecord = path.join(f.work, '.git', 'gstack', 'pregate-finish-preflight.json');
fs.mkdirSync(path.dirname(finishRecord), { recursive: true });
const runs = () => (fs.existsSync(path.join(f.root, 'guard-runs')) ? fs.readFileSync(path.join(f.root, 'guard-runs'), 'utf8') : '');
for (const [at, guards] of [[tree, 'fail'], ['0'.repeat(40), 'pass']]) {
fs.rmSync(path.join(f.work, '.git', 'gstack', 'pregate-guards.json'), { force: true });
fs.writeFileSync(finishRecord, record(at, guards));
fs.rmSync(path.join(f.root, 'guard-runs'), { force: true });
expect(lineOf(f.run(RELEASE, ['push', '--branch', 'feat']).stdout, 'GUARDS')).not.toContain('reused');
expect(runs()).toBe('ran\n');
f.git('push', '-q', 'origin', '--delete', 'feat');
}
fs.rmSync(path.join(f.work, '.git', 'gstack', 'pregate-guards.json'), { force: true });
fs.writeFileSync(finishRecord, record(tree, 'pass'));
fs.rmSync(path.join(f.root, 'guard-runs'), { force: true });
const reused = f.run(RELEASE, ['push', '--branch', 'feat']);
expect(lineOf(reused.stdout, 'GUARDS')).toMatch(/^GUARDS: pass \(reused from pregate-finish-preflight\.json at tree /);
expect(runs()).toBe('');
expect(lineOf(reused.stdout, 'PUSH')).toMatch(/^PUSH: pushed /);
});
});