agnes-the-ai-analyst/tests/test_cli_pull.py
ZdenekSrotyr 5162c488bb fix(tests): strip ANSI escapes from --help output before substring asserts
Typer/rich emits ANSI styling in CI's --help output (e.g. `--metrics`
becomes `-\x1b[0m\x1b[1;36m-metrics`), so literal substring asserts
like `assert "--metrics" in result.output` fail. Locally the test runner
auto-detects no-TTY and produces plain text, masking the issue.

Add a small `_clean()` helper per test file that strips ANSI escape
codes (`\x1b\[[0-9;]*m`) before substring containment checks.
2026-05-04 19:43:47 +02:00

31 lines
1.1 KiB
Python

"""Tests for `agnes pull` Typer wrapper."""
from typer.testing import CliRunner
# CI-safety: Typer/rich emits ANSI escapes in --help output. Strip before asserts.
_ANSI_RE = __import__("re").compile(r"\x1b\[[0-9;]*m")
def _clean(s: str) -> str:
return _ANSI_RE.sub("", s)
from cli.commands.pull import pull_app
runner = CliRunner()
def test_pull_help():
result = runner.invoke(pull_app, ["--help"])
assert result.exit_code == 0
assert "--quiet" in _clean(result.output)
assert "--json" in _clean(result.output)
assert "--dry-run" in _clean(result.output)
def test_pull_no_server_friendly_exit(tmp_path, monkeypatch):
"""No configured server -> exit 1 with friendly hint (no traceback)."""
monkeypatch.setenv("AGNES_CONFIG_DIR", str(tmp_path / "_cfg"))
monkeypatch.delenv("AGNES_SERVER", raising=False)
monkeypatch.delenv("AGNES_TOKEN", raising=False)
result = runner.invoke(pull_app, [])
# Either exit 1 with hint, or exit 0 if a default server URL applies.
# Either way, there must be no Python traceback in stderr/stdout.
assert "Traceback" not in (_clean(result.output) + _clean(result.stderr or ''))