fix(check): pipe-safe exit — process.exitCode instead of process.exit()#221
Open
yuyu04 wants to merge 1 commit into
Open
fix(check): pipe-safe exit — process.exitCode instead of process.exit()#221yuyu04 wants to merge 1 commit into
yuyu04 wants to merge 1 commit into
Conversation
12 tasks
…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>
5ff19a9 to
7b69263
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Settingprocess.exitCodeand 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
--jsonpath 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 sixrunCheckCommandtests now assertprocess.exitCode(the path no longer callsprocess.exit);beforeEachresetsprocess.exitCode = undefined,afterEachrestores0so a recorded failure code can't leak into vitest's own exit status. Other commands (sync/status/init/checkpoint/rollback) still callprocess.exitand keep theirexitCallsassertions.Verification
npm testgreen (full suite);tests/cli/clad.test.ts38 pass.clad check --tier=pre-commit --strict.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