Skip to content

Trace logs interfere with output when CI=true environment variable is set #135

@konard

Description

@konard

Problem Description

When the CI environment variable is set to true (as in GitHub Actions and other CI/CD platforms), command-stream emits verbose trace logs to stderr that interfere with command output and break JSON parsing.

Reproduction Steps

  1. Create a simple script using command-stream:
#!/usr/bin/env node
if (typeof use === 'undefined') {
  globalThis.use = (await eval(await (await fetch('https://unpkg.com/use-m/use.js')).text())).use;
}
const { $ } = await use('command-stream');
const $silent = $({ mirror: false, capture: true });

const result = await $silent`echo '{"status":"ok"}'`;
console.log(result.stdout || result);
  1. Run without CI environment:
$ node script.js
{"status":"ok"}
  1. Run with CI environment:
$ CI=true node script.js
[TRACE 2025-09-14T13:25:23.048Z] [Initialization] Registering built-in virtual commands
[TRACE 2025-09-14T13:25:23.048Z] [VirtualCommands] registerBuiltins() called
[TRACE 2025-09-14T13:25:23.050Z] [ProcessRunner] Executing virtual command
{"status":"ok"}
[TRACE 2025-09-14T13:25:23.051Z] [ProcessRunner] Cleanup completed

Impact

  • Breaks JSON parsing: Output contains trace logs mixed with JSON
  • Test failures in CI: Tests that parse command output fail in GitHub Actions
  • Affects all CI platforms: GitHub Actions, GitLab CI, CircleCI, Jenkins

Current Behavior

Even with mirror: false and capture: true, trace logs are emitted to stderr when CI=true.

Expected Behavior

When mirror: false is set, no trace logs should be emitted, regardless of CI environment variable.

Suggested Solutions

  1. Add trace option:
const $silent = $({ mirror: false, capture: true, trace: false });
  1. Respect mirror:false for all output including trace logs

  2. Environment variable override:

// Allow disabling via env var
process.env.COMMAND_STREAM_TRACE = 'false';

Workarounds

Currently we have to:

  • Redirect stderr to /dev/null (loses legitimate errors)
  • Filter trace logs from output (fragile)
  • Modify test frameworks to ignore stderr in CI

Environment

  • Node.js: 20.x
  • command-stream: latest
  • OS: Ubuntu (GitHub Actions), macOS (local)
  • CI platforms: GitHub Actions, GitLab CI

Additional Context

This issue affects production CI/CD pipelines where JSON output from commands is parsed for automation. The trace logs make command-stream difficult to use reliably in CI environments.

Example of trace log components that emit logs:

  • [Initialization]
  • [VirtualCommands]
  • [API]
  • [ProcessRunner]
  • [StreamMonitor]
  • [SignalHandler]
  • [StreamEmitter]
  • [AnsiUtils]
  • [Utils]

Thank you for considering this issue. command-stream is a great library, and fixing this would make it much more CI-friendly!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions