Skip to content

Commit f8248f5

Browse files
committed
Strip ANSI color in dub CLI-output asserts (CI forced-color failure)
CI renders CliRunner output with color, so style codes interleave inside flag names ("--lang") and the human summary line, breaking substring asserts that pass locally without color. Strip SGR sequences first via a shared plain() helper, the same convention test_help_rendering and the clip suite use. https://claude.ai/code/session_01Mcran5xqMHcrt4RUxSHrkX
1 parent 8ade812 commit f8248f5

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

tests/_dub_helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from __future__ import annotations
1010

11+
import re
1112
import subprocess
1213
import wave
1314
from pathlib import Path
@@ -33,6 +34,14 @@
3334

3435
SAMPLE_RATE = 100 # tiny rate keeps the timeline byte math exact and readable
3536

37+
_ANSI_SGR = re.compile(r"\x1b\[[0-9;]*m")
38+
39+
40+
def plain(text: str) -> str:
41+
"""Strip SGR color codes (CI forces color on, splitting flags like --lang
42+
with style sequences) for substring assertions."""
43+
return _ANSI_SGR.sub("", text)
44+
3645

3746
def utterance(start, speaker, text):
3847
return SimpleNamespace(start=start, end=None, speaker=speaker, text=text)

tests/test_dub_command.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from aai_cli import dub_exec, llm
1414
from aai_cli.main import app
15+
from tests._dub_helpers import plain
1516

1617
runner = CliRunner()
1718

@@ -32,16 +33,17 @@ def fake_run(opts, state, *, json_mode):
3233
def test_lang_is_required():
3334
result = runner.invoke(app, ["dub", "talk.mp4"])
3435
assert result.exit_code == 2
35-
assert "--lang" in result.output
36+
assert "--lang" in plain(result.output)
3637

3738

3839
def test_production_env_is_rejected_with_sandbox_hint():
3940
result = runner.invoke(app, ["dub", "talk.mp4", "--lang", "de"]) # default = production
4041
assert result.exit_code == 2
41-
assert "only available in the sandbox" in result.output
42+
output = plain(result.output)
43+
assert "only available in the sandbox" in output
4244
# The suggestion spells out the exact corrected invocation: --sandbox is a root
4345
# flag, so it must go before the command, not after it.
44-
assert "Re-run as: assembly --sandbox dub" in result.output
46+
assert "Re-run as: assembly --sandbox dub" in output
4547

4648

4749
def test_defaults_map_to_options(captured_run):

tests/test_dub_pipeline.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
enable_sandbox,
2828
fake_transcript,
2929
patch_api_key,
30+
plain,
3031
record_ffmpeg,
3132
record_synthesize,
3233
record_transcribe,
@@ -150,7 +151,9 @@ def test_run_dub_human_summary(
150151
# mid-word and these substring asserts would depend on where the break lands.
151152
opts = dataclasses.replace(DEFAULTS, media=str(media), out=Path("dub.de.mp4"))
152153
_run(opts, json_mode=False)
153-
out = capsys.readouterr().out
154+
# plain(): under FORCE_COLOR (CI) Rich's repr highlighter interleaves style
155+
# codes inside the line ("(2 utterances" renders with the 2 colored).
156+
out = plain(capsys.readouterr().out)
154157
assert "dub.de.mp4" in out
155158
assert "dubbed to German" in out
156159
assert "2 utterances" in out

0 commit comments

Comments
 (0)