Skip to content

Commit 14ce1ef

Browse files
committed
fix: handle large changed coverage diffs
1 parent ae4dbc1 commit 14ce1ef

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎scripts/coverage-changed/run.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ test('passes and prints n/a for a docs-only change without touching coverage', (
7272
assert.match(out, /0\/0 \(n\/a\)/);
7373
});
7474

75+
test('reads a large stacked diff beyond the subprocess default buffer', () => {
76+
write('README.md', '# large stack\n' + 'documentation line\n'.repeat(80_000));
77+
git('add', '-A');
78+
git('commit', '-q', '-m', 'large docs stack');
79+
writeLcov('SF:src/base.ts\nDA:1,1\nend_of_record\n');
80+
81+
const { code, out } = capture(() => run(['--base', 'main'], repo));
82+
83+
assert.equal(code, 0);
84+
assert.match(out, /Changed-line coverage gate: PASS/);
85+
assert.match(out, /0\/0 \(n\/a\)/);
86+
});
87+
7588
test('fails when a changed source line is uncovered and names that line', () => {
7689
write('src/feature.ts', 'export const covered = 1;\nexport const uncovered = 2;\n');
7790
git('add', '-A');

‎scripts/coverage-changed/run.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323

2424
const USAGE = 'Usage: pnpm check:coverage-changed [--base <ref>]\n';
2525
const LCOV_PATH = 'coverage/lcov.info';
26+
const GIT_DIFF_MAX_BUFFER_BYTES = 16 * 1024 * 1024;
2627

2728
function fmtPct(pct: number | null): string {
2829
return pct === null ? 'n/a' : `${pct.toFixed(2)}%`;
@@ -73,6 +74,7 @@ export function run(argv: readonly string[], cwd?: string): number {
7374

7475
const diff = runCmdSync('git', ['diff', '--unified=0', '--no-color', `${base}...HEAD`], {
7576
cwd: root,
77+
maxBuffer: GIT_DIFF_MAX_BUFFER_BYTES,
7678
}).stdout;
7779
const result = computeChangedCoverage({
7880
diffs: parseUnifiedDiff(diff),

0 commit comments

Comments
 (0)