Skip to content

@W-24232594 refactor(mrt): centralize --json log suppression in MrtCommand - #693

Merged
kieran-sf merged 1 commit into
mainfrom
mrt-json-logging-cleanup
Sep 18, 2026
Merged

kieran-sf merged 1 commit into
mainfrom
mrt-json-logging-cleanup

Conversation

@kieran-sf

Copy link
Copy Markdown
Contributor

Summary

MRT commands previously guarded every human-readable log line with if (!this.jsonEnabled()) so progress/status text wouldn't corrupt --json output. That was repetitive (~40 call sites) and easy to forget — mrt env var push missed the guards entirely and leaked progress text onto stdout in --json mode.

This centralizes the behavior:

  • MrtCommand.log() override (SDK): returns early when jsonEnabled(), so this.log() is a no-op in --json mode. this.log() routes to the pino logger (stderr); warn()/error() are untouched and still surface.
  • ~30 command files: removed the now-redundant if (!this.jsonEnabled()) wrappers around pure this.log() calls.
  • Deliberately kept: confirmation-prompt guards (!force && !jsonEnabled()), ux.stdout table/detail blocks (the real stdout data payloads), positive if (this.jsonEnabled()) branches, and the tail-logs useColor logic guard.
  • mrt env var push: fixed the --json stdout-pollution bug, and converted its human-only progress/summary lines from ux.stdout to this.log (its real output is the returned {pushed, failed, skipped} object, matching sibling deploy).

Test plan

  • pnpm --filter @salesforce/b2c-tooling-sdk run test:agent — new log() - suppressed in --json mode block passes (suppressed under --json; emits without --json; warn() still surfaces under --json)
  • pnpm --filter @salesforce/b2c-cli run test:agent — full CLI suite green (1525 passing)
  • pnpm run typecheck:agent (SDK + CLI) clean
  • pnpm run lint:agent clean; prettier clean on all mrt command files
  • Manual: b2c mrt env var push -p <project> -e <env> --json — stdout is valid JSON only, no progress text interleaved
  • Manual: same command without --json — progress lines, per-var output, and summary still render
  • Manual: a destructive command with --json (e.g. mrt project delete <slug> --json) — confirmation prompt is still skipped and JSON result is clean

Notes

  • User-facing behavior change is covered by a changeset (@salesforce/b2c-cli + @salesforce/b2c-tooling-sdk, patch).
  • No API/flag changes; --json output payloads are unchanged, only interleaved stderr/stdout noise is removed.

Override MrtCommand.log() to no-op when --json is set, replacing the
~40 per-call-site `if (!this.jsonEnabled())` guards that wrapped pure
this.log() progress/status output across the mrt commands. Guards that
gate confirmation prompts, table/detail stdout payloads, and positive
`if (this.jsonEnabled())` branches are kept.

Also fixes `mrt env var push --json`, which leaked progress text onto
stdout alongside the JSON result, and converts its human-only progress
lines from ux.stdout to this.log to match sibling commands.

Adds tests asserting log() is suppressed under --json while warn() and
error diagnostics still surface.
@kieran-sf kieran-sf changed the title refactor(mrt): centralize --json log suppression in MrtCommand @W-24232594 refactor(mrt): centralize --json log suppression in MrtCommand Sep 18, 2026
@kieran-sf
kieran-sf marked this pull request as ready for review September 18, 2026 15:38
@kieran-sf
kieran-sf requested a review from clavery as a code owner September 18, 2026 15:38
@kieran-sf
kieran-sf merged commit 09e5a0a into main Sep 18, 2026
8 checks passed
@kieran-sf
kieran-sf deleted the mrt-json-logging-cleanup branch September 18, 2026 17:09
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.

2 participants