Skip to content

fix: keep CLI JSON output parseable#3257

Open
financialvice wants to merge 1 commit into
superdoc-dev:mainfrom
financialvice:cg/cli-json-stdout
Open

fix: keep CLI JSON output parseable#3257
financialvice wants to merge 1 commit into
superdoc-dev:mainfrom
financialvice:cg/cli-json-stdout

Conversation

@financialvice
Copy link
Copy Markdown
Contributor

@financialvice financialvice commented May 12, 2026

Summary

  • add a CLI-level console diagnostic policy for machine/quiet modes
  • suppress global console.debug / console.log / console.info / console.warn / console.error while JSON or quiet commands execute, so lower-level library diagnostics cannot bypass the CLI io abstraction and pollute stdout
  • add a subprocess regression test that runs the CLI with NODE_ENV unset and parses superdoc info --json stdout directly

Why

superdoc <command> --json should produce machine-parseable JSON on stdout. In normal non-test CLI execution, SuperEditor telemetry logs this line with console.debug before the JSON envelope:

[super-editor] Telemetry: enabled

Because Node writes console.debug to stdout, automation that expected JSON.parse(stdout) failed even though the command itself succeeded. --quiet also could not suppress this because the log bypassed the CLI io abstraction.

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 30000
  • NODE_ENV= bun run apps/cli/src/index.ts info demos/nodejs/sample-document.docx --json > stdout 2> stderr followed by JSON.parse(stdout)
  • pre-commit hook: format, lint, and CLI build passed

Note: I also tried the full CLI typecheck, but current main has unrelated typecheck failures in CLI conformance/type-surface files, so I did not treat that as validation for this small CLI-output fix.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@caio-pizzol caio-pizzol self-assigned this May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants