Skip to content

Commit 07e0f0d

Browse files
Fix: _strip_ansi regex covers only a subset of CSI escape sequences (#52) (#55)
* Fix: _strip_ansi regex covers only a subset of CSI escape sequences (#52) The test helper only stripped a narrow set of CSI final bytes, which made the suite fragile if Rich emitted other valid escape sequences. Changes: - Broadened `_strip_ansi` to strip the full CSI range - Added a regression test for cursor-movement CSI sequences Fixes #52 * Archive investigation for issue #52 --------- Co-authored-by: OpenCode <opencode@users.noreply.github.com>
1 parent 74a561a commit 07e0f0d

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Issue 52 Archive
2+
3+
**Issue**: #52 - `test: _strip_ansi regex covers only a subset of CSI escape sequences`
4+
5+
**Type**: BUG
6+
7+
**Investigation Summary**
8+
9+
The `_strip_ansi` helper in `tests/test_workflow_to_harness.py` used a narrow regex that only stripped a small set of CSI escape-sequence final bytes. That made the test suite fragile if Rich emitted other valid ANSI sequences.
10+
11+
**Implementation Plan**
12+
13+
1. Broaden `_strip_ansi` in `tests/test_workflow_to_harness.py` to match the full CSI range.
14+
2. Add a regression test for a cursor-movement CSI sequence.
15+
3. Keep the existing help-output contract assertions unchanged.
16+
17+
**Validation**
18+
19+
```bash
20+
make qa
21+
uv run --locked pytest tests/test_workflow_to_harness.py -k strip_ansi
22+
```
23+
24+
**Result**
25+
26+
Implemented on branch `fix/issue-52-strip-ansi-regex` and verified with `make qa` and the targeted pytest invocation.

tests/test_workflow_to_harness.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ def _strip_ansi(text: str) -> str:
3838
causing Rich to emit ANSI codes even in non-TTY subprocesses. Stripping
3939
sequences here keeps assertions deterministic regardless of the host env.
4040
"""
41-
return re.sub(r"\x1b\[[0-9;]*[mGKHFJ]", "", text)
41+
return re.sub(r"\x1b\[[0-?]*[ -/]*[@-~]", "", text)
42+
43+
44+
def test_strip_ansi_removes_common_csi_sequences() -> None:
45+
assert _strip_ansi("before\x1b[2Cafter") == "beforeafter"
46+
assert _strip_ansi("before\x1b[1Aafter") == "beforeafter"
47+
assert _strip_ansi("before\x1b[?25lafter") == "beforeafter"
4248

4349

4450
EXPECTED_HELP = """\

0 commit comments

Comments
 (0)