Skip to content

[Code Quality] Add io.Writer parameter to render* functions in pkg/cli/ to eliminate hardcoded os.Stdout #47438

Description

@github-actions

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 ·

  • expires on Jul 23, 2026, 5:19 PM UTC-08:00

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions