Fix stray ^M characters in subprocess output when redirected to file
Metadata
Current evaluation
Normalizes carriage returns in subprocess output when redirected to files, preventing stray ^M characters. Adds tests for bare \r and Windows \r\n line endings. Awaiting maintainer review with minor CI failures on lint and conventional commit title.
Suggested action: needs review
Reason: This is a legitimate bug fix for stray ^M characters in redirected subprocess output, but it has been open 51 days with zero human comments and zero reviewers. The PR has 2 unresolved review comments (unspecified) and fails CI on fixable lint/conventional-commit-title checks. A maintainer review is needed to assess the approach and address the unresolved comments.
Impact:
45
Quick Win:
38.25
Staleness:
65
Complexity:
15
Confidence:
65
Issue body
Subprocesses using bare `\r` for in-place terminal progress updates (e.g. `Downloading 50%\rDownloading 100%\n`) pass those carriage returns through `_PipeReaderThread._write()` unchanged. When the output stream is not a terminal (file redirect, pipe), the `\r` chars survive into the written text, producing `^M`-riddled output.
## Changes
- **`craft_cli/messages.py`** — Normalize carriage returns in `_PipeReaderThread._write()` before line-splitting via a single `re.sub` pass:
- `\r\n` / `\r+\n` (Windows endings, `\r\r\n`) → `\n` (no extra blank lines)
- bare `\r` (in-place overwrites) → `\n`, so each update becomes its own line
- `b"\r" in data` guard skips regex entirely for the common CR-free case
- **`tests/unit/test_messages_stream_cm.py`** — Two new tests as reproducers:
- `test_pipereader_carriage_returns`: `b"Step 1\rStep 2\rStep 3\n"` → three clean lines, no `\r`
- `test_pipereader_windows_line_endings`: `b"line1\r\nline2\r\n"` → two clean lines, no `\r`
```python
# Before: \r passed through to the captured message
# text == ':: Initializing\rDone!' ← stray ^M in file
# After: bare \r treated as line separator
# text[0] == ':: Initializing'
# text[1] == ':: Done!'
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen3.6-35b-a3b-mtp-q6 |
Impact:
45
Quick Win:
38.25
Staleness:
65
Complexity:
15
Confidence:
65
|
needs review | Normalizes carriage returns in subprocess output when redirected to files, preventing stray ^M characters. Adds tests for bare \r and Windows \r\n line endings. Awaiting maintainer review with minor CI failures on lint and conventional commit title. | |
| qwen/qwen3.6-35b-a3b |
Staleness:
15
Complexity:
15
Confidence:
85
|
needs review | Fixes stray carriage return characters in redirected subprocess output by normalizing \r sequences in _PipeReaderThread._write(). Adds regression tests. Currently awaiting maintainer review with passing CI. | |
| qwen3.6-35b-a3b-mtp-q6 |
Staleness:
5
Complexity:
15
Confidence:
90
|
needs review | Normalizes carriage returns in subprocess output to prevent stray ^M characters when redirected to files. Adds regex-based normalization in _PipeReaderThread._write() and includes unit tests. Currently awaiting maintainer review. |
Update history
| Date | Change |
|---|---|
| updated |
Related issues
No related issues found above the similarity threshold.