From 716d9e09657eb4e156c4cb35560e8372253de243 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Wed, 17 Jun 2026 10:44:46 -0400 Subject: [PATCH] test: cap corpus L0 test to an 8MB per-file prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The real-corpus reflow check read whole transcript files; on a large ~/.claude/projects (multi-hundred-MB files) that blew the 30s timeout and aborted 'pnpm test' (hence prepublishOnly). Read only the first 8MB per file — enough for the per-file sample; a truncated trailing line just fails JSON.parse and is skipped. Corpus test now runs in ~5s. --- tests/reflow.test.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/reflow.test.ts b/tests/reflow.test.ts index d9fc1e6..c98f1b1 100644 --- a/tests/reflow.test.ts +++ b/tests/reflow.test.ts @@ -14,7 +14,7 @@ */ import { describe, expect, it } from 'vitest'; -import { readdirSync, readFileSync, statSync, existsSync } from 'node:fs'; +import { readdirSync, readFileSync, statSync, existsSync, openSync, readSync, closeSync } from 'node:fs'; import { join, resolve } from 'node:path'; import { homedir } from 'node:os'; import { @@ -536,7 +536,21 @@ describe('reflow L0 contract – real corpus', () => { if (textsChecked >= MAX_TOTAL) break; let rawContent: string; try { - rawContent = readFileSync(filePath, 'utf-8'); + // Read only a prefix, not the whole file: this corpus can contain + // multi-hundred-MB transcripts and we only need MAX_TEXTS_PER_FILE + // blocks per file. Whole-file reads here blew the 30s budget on large + // ~/.claude dirs. 8 MB is plenty for the per-file sample; a truncated + // trailing line just fails JSON.parse below and is skipped. + const CAP_BYTES = 8 * 1024 * 1024; + const toRead = Math.min(statSync(filePath).size, CAP_BYTES); + const fd = openSync(filePath, 'r'); + try { + const buf = Buffer.allocUnsafe(toRead); + const n = readSync(fd, buf, 0, toRead, 0); + rawContent = buf.toString('utf-8', 0, n); + } finally { + closeSync(fd); + } } catch { continue; // unreadable — skip }