Skip to content

[Test Improver] Fix 7 failing tests: strip ANSI codes in _ascii_only helper#1029

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/fix-policy-status-ansi-v3-81d63ca111a6237b
Draft

[Test Improver] Fix 7 failing tests: strip ANSI codes in _ascii_only helper#1029
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/fix-policy-status-ansi-v3-81d63ca111a6237b

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver — automated AI assistant

Problem

TestStatusAsciiOnly::test_renderings_are_ascii_safe had 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 \x1b byte (0x1B = 27) is below 0x20 and has Unicode category Cc (control), so _ascii_only() returned False — a false negative.

Fix

Added a compiled regex helper _strip_ansi() that removes ANSI CSI sequences (\x1b[...m and 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

Metric Before After
Tests passing 6668 6675
Tests failing 7 0

Test status

uv run pytest tests/unit tests/test_console.py -q
6675 passed, 1 warning, 26 subtests passed

How to test

uv run pytest tests/unit/commands/test_policy_status.py -v
# All 40 tests pass, including TestStatusAsciiOnly

Generated by Daily Test Improver · ● 1.5M ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/daily-test-improver.md@b87234850bf9664d198f28a02df0f937d0447295

_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>
@danielmeppiel danielmeppiel added automation Deprecated: use type/automation. Kept for issue history; will be removed in milestone 0.10.0. testing Deprecated: use area/testing. Kept for issue history; will be removed in milestone 0.10.0. labels Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Deprecated: use type/automation. Kept for issue history; will be removed in milestone 0.10.0. testing Deprecated: use area/testing. Kept for issue history; will be removed in milestone 0.10.0.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant