Description
The pkg/cli/ log rendering subsystem hardcodes os.Stdout in all six primary render functions (renderLogsTSV, renderLogsTSVVerbose, renderLogsCompact, renderLogsCompactVerbose, renderLogsJSON, renderLogsConsole), making unit testing awkward (requires OS-pipe surgery via captureOutput) and preventing output redirection.
Suggested Changes
- Add an
io.Writer parameter to each of the six renderLogs* functions
- Update callers to pass
cmd.OutOrStdout() or os.Stdout as appropriate
- Replace
captureOutput OS-swap pattern in tests with bytes.Buffer
- Apply same pattern to
audit_cross_run_render.go top-level JSON/Pretty functions
Files Affected
pkg/cli/logs_format_tsv.go (12 os.Stdout refs)
pkg/cli/logs_format_compact.go (39 os.Stdout refs)
pkg/cli/audit_cross_run_render.go (22 os.Stdout refs)
pkg/cli/checks_command_test.go and 4 other test files using captureOutput
Success Criteria
- All 6
renderLogs* functions accept io.Writer instead of hardcoding os.Stdout
captureOutput mutex helper removed; tests use bytes.Buffer directly
t.Parallel() can be used in formatter tests
- All existing tests pass
Source
Extracted from [repository-quality] Output Stream Abstraction Gap #47310
Priority
Medium — improves testability and aligns with the existing audit_cross_run_render.go convention
🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent · sonnet46 38.9 AIC · ⌖ 8.11 AIC · ⊞ 7.1K · ◷
Description
The
pkg/cli/log rendering subsystem hardcodesos.Stdoutin all six primary render functions (renderLogsTSV,renderLogsTSVVerbose,renderLogsCompact,renderLogsCompactVerbose,renderLogsJSON,renderLogsConsole), making unit testing awkward (requires OS-pipe surgery viacaptureOutput) and preventing output redirection.Suggested Changes
io.Writerparameter to each of the sixrenderLogs*functionscmd.OutOrStdout()oros.Stdoutas appropriatecaptureOutputOS-swap pattern in tests withbytes.Bufferaudit_cross_run_render.gotop-level JSON/Pretty functionsFiles Affected
pkg/cli/logs_format_tsv.go(12os.Stdoutrefs)pkg/cli/logs_format_compact.go(39os.Stdoutrefs)pkg/cli/audit_cross_run_render.go(22os.Stdoutrefs)pkg/cli/checks_command_test.goand 4 other test files usingcaptureOutputSuccess Criteria
renderLogs*functions acceptio.Writerinstead of hardcodingos.StdoutcaptureOutputmutex helper removed; tests usebytes.Bufferdirectlyt.Parallel()can be used in formatter testsSource
Extracted from [repository-quality] Output Stream Abstraction Gap #47310
Priority
Medium — improves testability and aligns with the existing
audit_cross_run_render.goconvention