fix: keep CLI JSON output parseable#3257
Open
financialvice wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ad0256f to
367ccc0
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.
Summary
console.debug/console.log/console.info/console.warn/console.errorwhile JSON or quiet commands execute, so lower-level library diagnostics cannot bypass the CLIioabstraction and pollute stdoutNODE_ENVunset and parsessuperdoc info --jsonstdout directlyWhy
superdoc <command> --jsonshould produce machine-parseable JSON on stdout. In normal non-test CLI execution, SuperEditor telemetry logs this line withconsole.debugbefore the JSON envelope:Because Node writes
console.debugto stdout, automation that expectedJSON.parse(stdout)failed even though the command itself succeeded.--quietalso could not suppress this because the log bypassed the CLIioabstraction.The root issue is not telemetry specifically. The root issue is that JSON/quiet CLI execution did not own process-level
console.*output, so any dependency could write directly to stdout outside the CLI response contract. This PR fixes that at the top-level CLI boundary instead of special-casing one telemetry log.Validation
pnpm --filter @superdoc-dev/cli exec bun test src/__tests__/cli.test.ts -t "json output is parseable" --timeout 30000NODE_ENV= bun run apps/cli/src/index.ts info demos/nodejs/sample-document.docx --json > stdout 2> stderrfollowed byJSON.parse(stdout)Note: I also tried the full CLI typecheck, but current
mainhas unrelated typecheck failures in CLI conformance/type-surface files, so I did not treat that as validation for this small CLI-output fix.