Skip to content

Commit 490a406

Browse files
committed
test(cli): compare on the text, not on rich's colour codes
CI terminals get ANSI sequences from rich; the no-args help assertion failed on every OS. Strip the codes before comparing, and ask for --help explicitly.
1 parent c4db72f commit 490a406

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

‎tests/test_cli.py‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1+
import re
2+
13
from typer.testing import CliRunner
24

35
from openmuse import __version__
46
from openmuse import config as config_module
57
from openmuse.cli import app
68

79
runner = CliRunner()
10+
_ANSI = re.compile(r"\x1b\[[0-9;]*[A-Za-z]")
11+
12+
13+
def plain(output: str) -> str:
14+
"""CI terminals get colour codes from rich; compare on the text."""
15+
return _ANSI.sub("", output)
816

917

1018
def test_version_flag_and_command_agree():
1119
for args in (["--version"], ["-V"], ["version"]):
1220
result = runner.invoke(app, args)
1321
assert result.exit_code == 0, result.output
14-
assert result.output.strip() == f"openmuse {__version__}"
22+
assert plain(result.output).strip() == f"openmuse {__version__}"
1523

1624

17-
def test_no_arguments_prints_help():
18-
result = runner.invoke(app, [])
19-
assert "Usage" in result.output and "--version" in result.output
25+
def test_help_lists_the_version_flag():
26+
result = runner.invoke(app, ["--help"])
27+
assert result.exit_code == 0
28+
assert "--version" in plain(result.output)
2029

2130

2231
def test_doctor_reports_the_setup_without_calling_the_model(tmp_path, monkeypatch):
@@ -32,13 +41,15 @@ def test_doctor_reports_the_setup_without_calling_the_model(tmp_path, monkeypatc
3241

3342
# a local model needs no key: everything checks out
3443
result = runner.invoke(app, ["doctor", "--no-model"])
35-
assert result.exit_code == 0, result.output
36-
assert "qwen3:8b" in result.output and "all good" in result.output
37-
assert "reminders" in result.output and "shell" in result.output # the tool list
38-
assert "skipped" in result.output
44+
out = plain(result.output)
45+
assert result.exit_code == 0, out
46+
assert "qwen3:8b" in out and "all good" in out
47+
assert "reminders" in out and "shell" in out # the tool list
48+
assert "skipped" in out
3949

4050
# a hosted endpoint without a key is a problem worth exit code 1
4151
monkeypatch.setenv("OPENMUSE_LLM_BASE_URL", "https://api.deepseek.com")
4252
result = runner.invoke(app, ["doctor", "--no-model"])
43-
assert result.exit_code == 1, result.output
44-
assert "no usable API key" in result.output
53+
out = plain(result.output)
54+
assert result.exit_code == 1, out
55+
assert "no usable API key" in out

0 commit comments

Comments
 (0)