[Test Improver] Fix 7 failing tests: strip ANSI codes in _ascii_only helper#1029
Draft
danielmeppiel wants to merge 1 commit intomainfrom
Draft
[Test Improver] Fix 7 failing tests: strip ANSI codes in _ascii_only helper#1029danielmeppiel wants to merge 1 commit intomainfrom
danielmeppiel wants to merge 1 commit intomainfrom
Conversation
_ascii_only() failed on Rich's ANSI escape sequences (bold/italic markers like \x1b[1m, \x1b[3m, \x1b[0m). These are control codes added by the Rich library, not content we author. Add _strip_ansi() helper using a compiled regex and apply it at the top of _ascii_only() so only visible characters are inspected. Fixes 7 pre-existing test failures: TestStatusAsciiOnly::test_renderings_are_ascii_safe[found-*] TestStatusAsciiOnly::test_renderings_are_ascii_safe[absent-*] TestStatusAsciiOnly::test_renderings_are_ascii_safe[cached_stale-*] TestStatusAsciiOnly::test_renderings_are_ascii_safe[disabled-*] Before: 6668 passed, 7 failed After: 6675 passed, 0 failed Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤖 Test Improver — automated AI assistant
Problem
TestStatusAsciiOnly::test_renderings_are_ascii_safehad 7 pre-existing failures. The_ascii_only()helper checks that CLI output stays within printable ASCII, but it did not strip ANSI escape sequences before inspecting characters.Rich emits terminal control codes like
\x1b[1m(bold),\x1b[3m(italic),\x1b[0m(reset) even when the CLI runner captures output. The\x1bbyte (0x1B = 27) is below 0x20 and has Unicode categoryCc(control), so_ascii_only()returnedFalse— a false negative.Fix
Added a compiled regex helper
_strip_ansi()that removes ANSI CSI sequences (\x1b[...mand variants) from text before character-level inspection. Applied it at the start of_ascii_only().This is the correct fix: ANSI escape sequences are terminal control codes emitted by Rich, not content that APM source strings author. The encoding rule ("keep output within printable ASCII") targets authored strings, not Rich's colour markup.
Coverage impact
Test status
How to test
uv run pytest tests/unit/commands/test_policy_status.py -v # All 40 tests pass, including TestStatusAsciiOnly