mirror of
https://github.com/teamchong/pxpipe.git
synced 2026-07-22 02:02:51 +02:00
test: cap corpus L0 test to an 8MB per-file prefix
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.
This commit is contained in:
+16
-2
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user