Skip to content

fix(check): pipe-safe exit — process.exitCode instead of process.exit()#221

Open
yuyu04 wants to merge 1 commit into
qwerfunch:developfrom
yuyu04:feature/check-pipe-safe-exit
Open

fix(check): pipe-safe exit — process.exitCode instead of process.exit()#221
yuyu04 wants to merge 1 commit into
qwerfunch:developfrom
yuyu04:feature/check-pipe-safe-exit

Conversation

@yuyu04

@yuyu04 yuyu04 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

What

clad check's machine-output mode (--json) can write >64KB to stdout. process.exit(worst) terminates Node before a buffered stdout PIPE flushes, so a consumer that pipes the output (clad check --json | cat, as opposed to redirecting to a file) receives a truncated document. Setting process.exitCode and letting the event loop drain guarantees the full payload is emitted, then Node exits with the worst stage code.

Why a separate PR

This is the pipe-safety fix extracted from #201 (SARIF export) on its own. It has value independent of SARIF — it fixes the existing --json path today. The SARIF body remains in #201 for if/when GitHub code-scanning adoption is decided; this small fix shouldn't wait on that.

Changes

  • src/cli/clad.ts · runCheckCommand: process.exit(runCheckStages(...).worst)process.exitCode = runCheckStages(...).worst.
  • tests/cli/clad.test.ts: the six runCheckCommand tests now assert process.exitCode (the path no longer calls process.exit); beforeEach resets process.exitCode = undefined, afterEach restores 0 so a recorded failure code can't leak into vitest's own exit status. Other commands (sync/status/init/checkpoint/rollback) still call process.exit and keep their exitCalls assertions.

Verification

  • npm test green (full suite); tests/cli/clad.test.ts 38 pass.
  • Local CI mirror green: build+diff, typecheck, lint, clad check --tier=pre-commit --strict.
  • Committed bundle (plugins/claude-code/dist/clad.js) rebuilt; attestation re-stamped.

Base note

Branched off develop. Independent of #217#220. (#201 keeps the SARIF body + this same exit change; if both land, the overlap is the one-line exit edit — trivial.)

🤖 Generated with Claude Code

…exit()

`clad check`'s machine-output mode (--json) can write >64KB to stdout. Calling
process.exit(worst) terminates Node before a buffered stdout PIPE flushes, so a
consumer that pipes the output (`clad check --json | cat`, vs. redirecting to a
file) gets a TRUNCATED document. Setting process.exitCode and letting the event
loop drain guarantees the full payload is emitted, then Node exits with the
worst stage code.

This is the pipe-safety fix extracted from qwerfunch#201 (SARIF) on its own — it has
value independent of SARIF: it fixes the existing --json path. The SARIF body
stays in qwerfunch#201 for when GitHub code-scanning adoption is decided.

- runCheckCommand: process.exit(...).worst → process.exitCode = ...worst
- tests/cli/clad.test.ts: the six runCheckCommand tests now assert
  process.exitCode (process.exit is no longer called for that path); beforeEach
  resets process.exitCode, afterEach restores 0 so a recorded failure code
  can't leak into vitest's own exit status. Other commands (sync/status/init/
  checkpoint/rollback) still use process.exit and keep their exitCalls asserts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yuyu04 yuyu04 force-pushed the feature/check-pipe-safe-exit branch from 5ff19a9 to 7b69263 Compare July 2, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant