openclaw/scripts/lib/format-command-batches.mts
Peter Steinberger 4d79288452
refactor(testing): deslop test-only production seams (#164320)
* refactor(testing): remove test-only production seams

Use native module boundaries, fake clocks, and temporary filesystem fixtures instead of production dependency bags and test setters. Remove retired agent-exec repair options while retaining public SDK and real lifecycle contracts.

* test: classify browser fixtures and prune retired assertions

* test: finish module-boundary fixture migration

* refactor(testing): remove CLI and readiness injection tables

* test: complete native process fixture contracts

* test: preserve the logger write gate and strengthen queue proof

* test(browser): exercise delegated Windows installation fixtures

* test: bind mock cleanup callbacks to their owners

* refactor(testing): preserve required fixture lifecycle boundaries

* refactor(testing): preserve asynchronous writer typing

* refactor(scripts): keep formatter batch budget private

* test: preserve native worker ownership in fixtures
2026-10-03 16:46:36 -07:00

33 lines
897 B
TypeScript

// Keep formatter arguments bounded even when pnpm joins them into one shell command.
const FORMAT_MAX_COMMAND_LINE_BYTES = 24 * 1024;
function commandLineBytes(args: string[]) {
return args.reduce((total, arg) => total + Buffer.byteLength(arg, "utf8") + 3, 0);
}
export function chunkFormatFilesForCommand(
files: string[],
prefixArgs: string[],
maxBytes = FORMAT_MAX_COMMAND_LINE_BYTES,
) {
const chunks: string[][] = [];
let chunk: string[] = [];
let chunkBytes = commandLineBytes(prefixArgs);
for (const file of files) {
const fileBytes = Buffer.byteLength(file, "utf8") + 3;
if (chunk.length > 0 && chunkBytes + fileBytes > maxBytes) {
chunks.push(chunk);
chunk = [];
chunkBytes = commandLineBytes(prefixArgs);
}
chunk.push(file);
chunkBytes += fileBytes;
}
if (chunk.length > 0) {
chunks.push(chunk);
}
return chunks;
}