Repository navigation
fix(log): no ANSI colour codes unless stderr is a terminal #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
krassx
wants to merge
2
commits into
main
Choose a base branch
from
fix/no-ansi-when-not-terminal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //! Log output must carry no ANSI escape codes unless stderr is a terminal. | ||
| //! | ||
| //! Xcode, Gradle and CI capture stderr into logs, and the detached daemon writes | ||
| //! it to `bugsee-cli.log`; escape codes there are noise. Under `assert_cmd` stderr | ||
| //! is a pipe, so any ESC byte means the `with_ansi(...)` wiring in `main` regressed. | ||
|
|
||
| mod common; | ||
|
|
||
| /// `sourcemaps inject` on an empty directory needs no network and logs one info line. | ||
| #[test] | ||
| fn piped_stderr_has_no_escape_codes() { | ||
| let dir = tempfile::tempdir().unwrap(); | ||
| let out = common::cli() | ||
| .env("RUST_LOG", "bugsee_cli=info") | ||
| .env_remove("NO_COLOR") | ||
| .args(["sourcemaps", "inject"]) | ||
| .arg(dir.path()) | ||
| .assert() | ||
| .success(); | ||
| let stderr = out.get_output().stderr.clone(); | ||
| let text = String::from_utf8_lossy(&stderr); | ||
| assert!( | ||
| text.contains("sourcemaps inject complete"), | ||
| "expected a log line on stderr, got: {text:?}" | ||
| ); | ||
| assert!( | ||
| !stderr.contains(&0x1b), | ||
| "stderr contains ANSI escapes: {text:?}" | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Severity: P3 Low
Problem: The unit tests only cover the pure predicate
ansi_enabled. Nothing checks that the wiring (.with_ansi(...), and the decision happening afterdaemonizeso the redirected fd 2 is seen) actually produces escape-free output. CLAUDE.md saystests/should pin behaviour through the compiled binary.Scenario: Someone drops
.with_ansi(...)or moves the subscriber setup ahead ofdaemonize. Every test still passes and the escape codes come back in Xcode, Gradle and CI logs.Fix: Add an
assert_cmdtest that runs the binary with stderr piped (so it's not a TTY) and asserts the captured stderr contains no\x1b.tests/elf_upload.rsalready captures stderr and has astrip_ansihelper. That helper is now unnecessary for piped stderr, and an assertion there would pin the fix cheaply.