Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Nov 30, 2025

Summary

Fixes #135 - Trace logs no longer interfere with command output when CI=true environment variable is set.

Problem

When the CI environment variable was set to true (as in GitHub Actions and other CI/CD platforms), command-stream automatically enabled verbose trace logging to stderr. This caused:

  • 🔴 Broken JSON parsing (trace logs mixed with JSON output)
  • 🔴 Test failures in CI environments
  • 🔴 Unreliable command output in CI/CD pipelines

Example of the issue:

$ 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
{"status":"ok"}    # <- JSON mixed with trace logs
[TRACE 2025-09-14T13:25:23.051Z] [ProcessRunner] Cleanup completed

Solution

1. Removed CI Auto-Enable for Trace Logs

  • CI environment variable no longer automatically enables tracing
  • Trace logs only appear when explicitly requested

2. Added Explicit Trace Control

New COMMAND_STREAM_TRACE environment variable:

  • COMMAND_STREAM_TRACE=true - Explicitly enable tracing (even in CI)
  • COMMAND_STREAM_TRACE=false - Explicitly disable tracing (overrides VERBOSE)
  • Not set - Use COMMAND_STREAM_VERBOSE setting (default: disabled)

3. Dynamic Trace Evaluation

  • Trace settings are now evaluated at runtime
  • Allows runtime control of trace logging

Changes

Modified Files:

  • src/$.mjs - Updated trace function and removed CI auto-enable
  • src/$.utils.mjs - Consistent trace logic

Test Files:

  • tests/issue-135-final.test.mjs - 4 tests covering the fix
  • examples/ - Reproduction and test scripts

Testing

✅ All new tests passing (4/4):

  • CI=true no longer produces trace logs
  • JSON parsing works in CI environment
  • Default behavior is clean (no env vars)
  • mirror:false works correctly in CI

✅ Existing tests: 619 pass, 2 pre-existing failures unrelated to this change

Migration Guide

Before (Broken in CI)

// CI=true caused trace logs to pollute output
const result = await $({ mirror: false, capture: true })`echo '{"status":"ok"}'`;
console.log(result.stdout); // Mixed with trace logs in CI

After (Fixed)

// Clean output in CI
const result = await $({ mirror: false, capture: true })`echo '{"status":"ok"}'`;
console.log(result.stdout); // Pure JSON, even in CI

// To enable tracing in CI (if needed):
process.env.COMMAND_STREAM_TRACE = 'true';
// or set environment variable: COMMAND_STREAM_TRACE=true

Environment Variable Reference

Variable Effect
CI=true ✅ No longer enables trace logs
COMMAND_STREAM_VERBOSE=true ✅ Enables trace logs
COMMAND_STREAM_TRACE=true ✅ Explicitly enable (overrides default)
COMMAND_STREAM_TRACE=false ✅ Explicitly disable (overrides VERBOSE)

Impact

  • ✅ CI/CD pipelines work reliably
  • ✅ JSON parsing works in GitHub Actions, GitLab CI, etc.
  • ✅ Backward compatible (trace logs still available via explicit env vars)
  • ✅ No breaking changes to existing functionality

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #135
@konard konard self-assigned this Nov 30, 2025
## Problem
When the CI environment variable was set to 'true' (as in GitHub Actions
and other CI/CD platforms), command-stream automatically enabled verbose
trace logging to stderr. This interfered with command output and broke
JSON parsing in CI environments.

## Root Cause
In src/$.mjs line 15, the VERBOSE constant was set to:
`const VERBOSE = process.env.COMMAND_STREAM_VERBOSE === 'true' || process.env.CI === 'true'`

This caused trace logs to be emitted whenever CI=true, regardless of
the mirror:false or capture:true options.

## Solution
1. Removed automatic trace log activation when CI=true
2. Added COMMAND_STREAM_TRACE environment variable for explicit control:
   - COMMAND_STREAM_TRACE=true: Explicitly enable tracing
   - COMMAND_STREAM_TRACE=false: Explicitly disable tracing (overrides VERBOSE)
   - Not set: Use COMMAND_STREAM_VERBOSE setting
3. Made trace evaluation dynamic to support runtime env var changes
4. Applied consistent trace logic in both src/$.mjs and src/$.utils.mjs

## Benefits
- CI environments no longer get polluted with trace logs by default
- JSON parsing works reliably in CI/CD pipelines
- Users can still enable tracing in CI by setting COMMAND_STREAM_TRACE=true
- Explicit control via environment variables

## Testing
- Added tests/issue-135-final.test.mjs with 4 tests covering:
  - CI=true no longer produces trace logs
  - JSON parsing works in CI environment
  - Default behavior (no env vars) is clean
  - mirror:false works correctly in CI
- All 4 new tests pass
- Existing test suite: 619 pass, 2 pre-existing failures unrelated to this change

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Trace logs interfere with output when CI=true environment variable is set Fix #135: Remove CI auto-enable for trace logs Nov 30, 2025
@konard konard marked this pull request as ready for review November 30, 2025 18:29
@konard
Copy link
Member Author

konard commented Dec 28, 2025

Resolve conflicts, and double checks all original requirements are met.

@konard konard marked this pull request as draft December 28, 2025 02:35
@konard
Copy link
Member Author

konard commented Dec 28, 2025

🤖 AI Work Session Started

Starting automated work session at 2025-12-28T02:35:40.900Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

konard and others added 3 commits December 28, 2025 03:37
Conflicts resolved in src/$.mjs and src/$.utils.mjs:
- Kept our fix that removes CI=true auto-enabling of trace logs
- Maintained COMMAND_STREAM_TRACE and COMMAND_STREAM_VERBOSE support
- Preserved dynamic trace evaluation for runtime control

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Documents the fix for CI=true trace logs interfering with output.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Apply automatic formatting fixes from 'bun run lint --fix'.
All errors fixed; remaining warnings are pre-existing in codebase.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard marked this pull request as ready for review December 28, 2025 02:48
@konard
Copy link
Member Author

konard commented Dec 28, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $4.773127 USD
  • Calculated by Anthropic: $2.852013 USD
  • Difference: $-1.921115 (-40.25%)
    📎 Log file uploaded as GitHub Gist (691KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 826bcc3 into main Dec 28, 2025
11 checks passed
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.

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

2 participants