From 6ec9db3ca7871cd52f0fd750e14facb0cc4a6557 Mon Sep 17 00:00:00 2001 From: Alpamys Date: Wed, 27 May 2026 23:13:59 +0500 Subject: [PATCH] fix(tests): strip ANSI escapes before --lang substring assertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rich on narrow Windows columns splits `--lang` across colour-cycle ANSI escapes (`\x1b[..m-\x1b[..m-lang`), so the literal substring check fails on CI even though the rendered help renders correctly for humans. CI was red on every commit landing after #234 hit a runner with that exact column width + Python 3.9 + Rich combination. Mirrors the `_ANSI_RE` strip pattern in tests/test_auto_tuning.py — flat regex over the captured output before the `in` check. --- tests/test_brain_rot_multilingual.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_brain_rot_multilingual.py b/tests/test_brain_rot_multilingual.py index e1f19b3..d5b8981 100644 --- a/tests/test_brain_rot_multilingual.py +++ b/tests/test_brain_rot_multilingual.py @@ -11,6 +11,7 @@ from __future__ import annotations import dataclasses import json +import re from pathlib import Path from types import MappingProxyType @@ -20,6 +21,12 @@ from typer.testing import CliRunner from soup_cli.cli import app from soup_cli.utils import brain_rot, brain_rot_lang +# Strip Rich's ANSI escape sequences before substring assertions — on narrow +# Windows columns Rich can split a flag across colour-cycle escapes +# (e.g. `\x1b[..m-\x1b[..m-lang`), so the literal `--lang` substring fails on +# CI even though the rendered help looks correct. Mirrors tests/test_auto_tuning.py. +_ANSI_RE = re.compile(r"\x1b\[[0-9;]*m") + def _write(path: Path, text: str) -> Path: path.write_text(text, encoding="utf-8") @@ -451,7 +458,7 @@ class TestBrainRotCliLang: runner = CliRunner() result = runner.invoke(app, ["data", "brain-rot", "--help"]) assert result.exit_code == 0, result.output - assert "--lang" in result.output + assert "--lang" in _ANSI_RE.sub("", result.output) def test_lang_en_default( self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch