test(lbug): exercise the BufferedCSVWriter FLUSH_EVERY boundary in vitest (#2215 review)

The U3 addRow change (returns a flush promise only on flush; undefined when
buffered) and the loop's `if (pending) await pending` were only crossed by the
bench, never vitest (all fixtures are <500 nodes). Add a 600-node graph through
streamAllCSVsToDisk asserting all rows land exactly once across the 500-row
flush boundary — no drops, dups, or corruption.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gergo Magyar 2026-06-15 18:13:08 +00:00
parent 3823586fa8
commit 11498e342f

View file

@ -253,6 +253,27 @@ describe('streamAllCSVsToDisk', () => {
expect(fileCsv).toBeDefined();
expect(fileCsv!.rows).toBe(1);
});
it('crosses the BufferedCSVWriter FLUSH_EVERY boundary without losing rows', async () => {
// FLUSH_EVERY=500; a >500-node graph forces ≥1 mid-stream flush, exercising
// addRow's flush-promise return + the loop's `if (pending) await pending`
// path that the small fixtures above never reach (only the bench did).
const N = 600;
const nodes = Array.from({ length: N }, (_, i) => ({
id: `File:src/f${i}.ts`,
label: 'File' as const,
name: `f${i}.ts`,
filePath: `src/f${i}.ts`,
}));
const result = await streamAllCSVsToDisk(buildTestGraph(nodes), repoDir, csvDir);
const fileCsv = result.nodeFiles.get('File');
expect(fileCsv).toBeDefined();
expect(fileCsv!.rows).toBe(N); // no rows dropped/duplicated at the flush boundary
const dataRows = dataRowsOf(await fs.readFile(fileCsv!.csvPath, 'utf-8'));
expect(dataRows).toHaveLength(N);
expect(new Set(dataRows).size).toBe(N); // all distinct — no flush-boundary corruption
});
});
/**