Skip to content

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

fix(pregate): append lanes provenance without a spread so large diffs get a verdict (GST-1334) (#3988)

Garry Tanc1ace7483b6e
diff --git a/changelog.d/fix-gst-1334-lanes-provenance-spread.md b/changelog.d/fix-gst-1334-lanes-provenance-spread.md
new file mode 100644
index 000000000..bbd4e19fb
--- /dev/null
+++ b/changelog.d/fix-gst-1334-lanes-provenance-spread.md
@@ -0,0 +1 @@
+- **Pregate no longer crashes on large diffs.** When many touched files each reach many tests, the lanes check stopped with `lanes: threw: Maximum call stack size exceeded`, so PREGATE was incomplete and /ship was blocked before any test ran (seen on a 335-file gbrain diff). The lanes check now records every provenance row without hitting the runtime's argument limit, and the secrets check does the same for scanner findings on a very large set of added lines. (GST-1334)
diff --git a/lib/pregate/checks/lanes.ts b/lib/pregate/checks/lanes.ts
index 336077166..c60221c6a 100644
--- a/lib/pregate/checks/lanes.ts
+++ b/lib/pregate/checks/lanes.ts
@@ -619,7 +619,7 @@ function withNoLaneWarning(ctx: PregateContext, sel: Selection, result: CheckRes
async function run(ctx: PregateContext): Promise<CheckResult> {
const sel = selectLanes(ctx);
- ctx.explain.push(...sel.provenance);
+ for (const line of sel.provenance) ctx.explain.push(line);
for (const [lane, set] of Object.entries(sel.laneSets)) ctx.explain.push(`lane ${lane}: ${set === '?' ? 'file set unknown' : `${set.length} files`}`);
const inputs = baseInputs(ctx, { selection: sha256(sel.tests.join('\n')), localTests: sha256(sel.localTests.join('\n')), remote: sha256(sel.remote.map(r => `${r.lane}:${r.tests.join(',')}`).join('\n')) });
const declared = ctx.configKind !== 'none' && ctx.policyDeclaresLanes !== false;
diff --git a/lib/pregate/checks/secrets.ts b/lib/pregate/checks/secrets.ts
index 17572c1f4..5f27b8c8f 100644
--- a/lib/pregate/checks/secrets.ts
+++ b/lib/pregate/checks/secrets.ts
@@ -141,7 +141,7 @@ function run(ctx: PregateContext): CheckResult {
high ||= r.status === 3;
medium ||= r.status === 2;
const lines = part.text.split('\n');
- try { findings.push(...(JSON.parse(r.stdout).findings ?? []).filter((f: Omit<Finding, 'file'>) => !part.keep || f.id?.startsWith('engine.') || (f.line !== undefined && part.keep.includes(f.line))).map((f: Omit<Finding, 'file'>) => ({ ...f, id: f.id ?? 'finding', category: f.category ?? '?', severity: f.severity ?? '?', file: part.file, fileLine: !!part.keep, lineText: f.line ? lines[f.line - 1] : undefined }))); } catch { parsedAll = false; }
+ try { for (const f of (JSON.parse(r.stdout).findings ?? []).filter((f: Omit<Finding, 'file'>) => !part.keep || f.id?.startsWith('engine.') || (f.line !== undefined && part.keep.includes(f.line))).map((f: Omit<Finding, 'file'>) => ({ ...f, id: f.id ?? 'finding', category: f.category ?? '?', severity: f.severity ?? '?', file: part.file, fileLine: !!part.keep, lineText: f.line ? lines[f.line - 1] : undefined }))) findings.push(f); } catch { parsedAll = false; }
}
// The allowlist applies only to findings the scanner reported in full; an unparsed report keeps its exit-code verdict.
const applied = parsedAll && ctx.config.allowlist.length ? applyAllowlist(findings, ctx.config.allowlist) : { kept: findings, allowlisted: [], untested: [], missed: [] };
diff --git a/test/pregate-lanes-large-selection.test.ts b/test/pregate-lanes-large-selection.test.ts
new file mode 100644
index 000000000..6f63e9370
--- /dev/null
+++ b/test/pregate-lanes-large-selection.test.ts
@@ -0,0 +1,39 @@
+/**
+ * GST-1334 (gbrain #8481): a big diff whose touched files each reach many tests gives the lanes check one provenance row
+ * per (touched file, test) pair. The check used to append them with `ctx.explain.push(...sel.provenance)`, and past the
+ * engine's argument limit that throws RangeError, so PREGATE reported `lanes: threw: Maximum call stack size exceeded`
+ * before any lane ran. The fixture declares every test as a dependency of every touched file: SEEDS x TESTS rows.
+ */
+import { afterEach, describe, expect, test } from 'bun:test';
+import { buildContext } from '../lib/pregate/context';
+import { runPregate } from '../lib/pregate/index';
+import { BASE_PREGATE, cleanup, commit, makeFixtureRepo, type FixtureRepo } from './helpers/pregate-fixture';
+
+const repos: FixtureRepo[] = [];
+afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
+
+const SEEDS = 1000;
+const TESTS = 1000;
+const pad = (i: number) => String(i).padStart(4, '0');
+
+describe.skipIf(process.platform === 'win32')('lanes check on a selection with a million provenance rows', () => {
+ // Value: protects=a large diff still gets a lanes verdict instead of PREGATE incomplete; fails_when=the provenance rows go
+ // into ctx.explain through one spread call (RangeError past Bun's argument limit, about 600k on 1.4.4);
+ // why_new=GST-1334, gbrain #8481 (335 touched files) on gstack 1.95.5; seam=runPregate --only lanes on a fixture repo, no tests run
+ test('every provenance row reaches explain and the check reports its selection', async () => {
+ const tests = Array.from({ length: TESTS }, (_, i) => `test/big/t${pad(i)}.test.js`);
+ const repo = makeFixtureRepo({
+ pregate: { ...BASE_PREGATE, dependencies: { ...BASE_PREGATE.dependencies, 'src/big/**': tests } },
+ baseFiles: Object.fromEntries([...tests.map(t => [t, "require('node:test');\n"]), ['src/big/.keep', '']]),
+ });
+ repos.push(repo);
+ commit(repo, Object.fromEntries(Array.from({ length: SEEDS }, (_, i) => [`src/big/f${pad(i)}.js`, `exports.n = ${i};\n`])), 'touch many files');
+ const loaded = buildContext({ repoRoot: repo.work, base: 'main', policyFrom: 'base', allowRepoCommands: false, env: { ...process.env, ...repo.env }, progress: () => {}, cores: 64, testBackend: 'local' });
+ if (!('ctx' in loaded)) throw new Error('fixture context refused');
+ const file = await runPregate(loaded.ctx, { stage: 'tests', only: ['lanes'] });
+ const lanes = file.checks.find(c => c.id === 'lanes')!;
+ expect(lanes.detail).not.toContain('threw');
+ expect(lanes).toMatchObject({ status: 'incomplete', code: 'REPO_COMMANDS_NOT_ALLOWED', detail: `${TESTS} local test file(s) selected but not run (pass --allow-repo-commands)` });
+ expect(loaded.ctx.explain.filter(l => l.endsWith('[touched]')).length).toBe(SEEDS * TESTS);
+ }, 300_000);
+});