Skip to content

[Test Improver] fix(tests): strip ANSI codes before plain-text assertions in 3 test files#291

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/fix-ansi-failures-2026-03-14-4cae0cad88219467
Draft

[Test Improver] fix(tests): strip ANSI codes before plain-text assertions in 3 test files#291
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/fix-ansi-failures-2026-03-14-4cae0cad88219467

Conversation

@danielmeppiel
Copy link
Collaborator

🤖 Test Improver — automated AI assistant

Goal

Fix 7 failing unit tests caused by Rich library injecting ANSI escape codes into CLI output captured by Click's CliRunner.

Root Cause

Rich outputs bold/italic ANSI codes (e.g. \x1b[1m2\x1b[0m) even when output is captured by CliRunner. Tests that assert plain-text substrings like "Unpacked 2 file(s)" or "Successfully updated to version 0.7.0" fail because the actual output contains these codes between characters.

Changes

Added a _strip_ansi() helper to 3 test files and applied it before plain-text substring assertions:

File Tests Fixed
tests/unit/test_unpacker.py 4 tests in TestUnpackCmdLogging
tests/unit/test_update_command.py 2 tests in TestUpdateCommand
tests/unit/test_install_command.py 1 test in TestInstallCommandAutoBootstrap

The helper is a one-liner:

def _strip_ansi(text: str) -> str:
    return re.sub(r"\x1b\[[0-9;]*m", "", text)
```

## Test StatusAll 1683 unit tests pass (was 1676 passing + 7 failing before this fix):

```
1683 passed in 12.87s

Reproducibility

uv sync --extra dev
uv run pytest tests/unit/ -q

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

…iles

7 tests were failing because Rich outputs bold/italic ANSI escape codes
even when Click CliRunner captures output. Add _strip_ansi() helper
(re.sub r'\x1b\[[0-9;]*m') to test_unpacker.py, test_update_command.py,
and test_install_command.py, and apply it before assertions that check
plain-text substrings in CLI output.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant