diff --git a/tests/test_cli.py b/tests/test_cli.py index a3c73d7..a00e005 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,7 @@ """CLI integration tests.""" import json +import re from pathlib import Path from typer.testing import CliRunner @@ -9,6 +10,14 @@ runner = CliRunner() REPO_ROOT = Path(__file__).resolve().parents[1] +_ANSI = re.compile(r"\x1b\[[0-9;]*[A-Za-z]") + + +def _plain(result) -> str: + raw = "".join( + part for part in (result.output, getattr(result, "stdout", ""), getattr(result, "stderr", "") or "") if part + ) + return _ANSI.sub("", raw) def test_demo_exits_zero_and_writes_json(tmp_path: Path, monkeypatch) -> None: @@ -52,12 +61,12 @@ def test_run_requires_api_key_for_gemini(tmp_path: Path, monkeypatch) -> None: assert "GEMINI_API_KEY" in result.output -def test_run_help_lists_provider_flags() -> None: - result = runner.invoke(app, ["run", "--help"]) - assert result.exit_code == 0 - assert "--provider" in result.output - assert "--model" in result.output - assert "--ollama-host" in result.output - assert "--exit-on-loss" in result.output - assert "--min-win-rate" in result.output - assert "--swap-order" in result.output +def test_run_help_lists_provider_flags(monkeypatch) -> None: + monkeypatch.setenv("COLUMNS", "200") + monkeypatch.setenv("NO_COLOR", "1") + monkeypatch.setenv("TERM", "dumb") + result = runner.invoke(app, ["run", "--help"], env={"COLUMNS": "200", "NO_COLOR": "1", "TERM": "dumb"}) + assert result.exit_code == 0, result.output + text = re.sub(r"\s+", "", _plain(result)) + for flag in ("--provider", "--model", "--ollama-host", "--exit-on-loss", "--min-win-rate", "--swap-order"): + assert flag in text, _plain(result)