From 11498e342fe0b44697394b777d980e30af5d8726 Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Mon, 15 Jun 2026 18:13:08 +0000 Subject: [PATCH] test(lbug): exercise the BufferedCSVWriter FLUSH_EVERY boundary in vitest (#2215 review) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../test/integration/csv-pipeline.test.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gitnexus/test/integration/csv-pipeline.test.ts b/gitnexus/test/integration/csv-pipeline.test.ts index 08c5d7ccb..1d3ee0e7c 100644 --- a/gitnexus/test/integration/csv-pipeline.test.ts +++ b/gitnexus/test/integration/csv-pipeline.test.ts @@ -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 + }); }); /**