Skip to content

fix(utils): Prevent RangeError from large command output

6155c40
Select commit
Loading
Failed to load commit list.
Sign in for the full log view
Open

fix(utils): Prevent RangeError from large command output #433

fix(utils): Prevent RangeError from large command output
6155c40
Select commit
Loading
Failed to load commit list.
GitHub Actions / warden completed May 29, 2026 in 8m 15s

5 issues

Medium

No tests for the new buffer accumulation, capping, and truncation logic - `src/utils/command.ts:229`

The new appendChunk / finalizeStream functions and the maxOutputBytes cap are entirely untested — src/utils/__tests__/command.test.ts has no test that exercises large output, truncation, the [output truncated after N bytes] message, or the XCODEBUILDMCP_MAX_OUTPUT_BYTES env-var path. Consider adding unit tests that verify: (1) output below the cap is returned verbatim, (2) output at or above the cap is truncated with the expected message, and (3) the env-var override is respected.

Also found at:

  • src/utils/command.ts:76
No tests cover the new output-truncation / maxOutputBytes behaviour

The core fix introduced by this PR (buffer accumulation, truncation cap, appendChunk, finalizeStream, XCODEBUILDMCP_MAX_OUTPUT_BYTES) has no corresponding tests in src/utils/__tests__/command.test.ts, leaving the crash-prevention logic unverified.

Low

Catch block in `finalizeStream` re-throws if `Buffer.concat` itself fails - `src/utils/command.ts:128-130`

In the catch block, Buffer.concat(chunks, totalBytes) is called a second time with identical arguments; if the caught error originated from Buffer.concat rather than .toString('utf8') (e.g. a Node.js internal error or corrupted chunk), the catch block throws the same error, escaping settle() into the childProcess.once('close', …) event handler as an uncaught exception — the exact crash mode this PR aims to prevent.

Redundant `1 *` prefix makes 1 MiB constant less readable - `src/utils/command.ts:128`

Replace 1 * 1024 * 1024 with 1024 * 1024 — multiplying by 1 is a no-op that adds visual noise and is inconsistent with the 64 * 1024 * 1024 pattern used for the same unit on line 77.

Duplicated stdout/stderr chunk handler logic should be consolidated - `src/utils/command.ts:287-330`

The two attachStream callbacks (lines 287–330) are structurally identical — extract a shared helper (e.g. makeChunkHandler) to eliminate the duplication.

7 skills analyzed
Skill Findings Duration Cost
wrdn-pii 0 6.2s $0.05
wrdn-authz 0 5.6s $0.09
wrdn-code-execution 0 7.8s $0.06
wrdn-data-exfil 0 9.6s $0.08
find-bugs 1 7m 27s $1.29
code-review 2 3m 15s $0.73
code-simplifier 2 2m 36s $0.44

⏱ 13m 47s · 789.5k in / 56.2k out · $2.73