agnes-the-ai-analyst/tests/test_cli_diagnose_system.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

32 lines
1.2 KiB
Python

"""Tests for `agnes diagnose system` (former `agnes status` content)."""
from typer.testing import CliRunner
from cli.commands.diagnose import diagnose_app
# 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)
runner = CliRunner()
def test_diagnose_system_help():
result = runner.invoke(diagnose_app, ["system", "--help"])
assert result.exit_code == 0
def test_diagnose_help_lists_system():
"""Top-level diagnose help should mention the `system` subcommand."""
result = runner.invoke(diagnose_app, ["--help"])
assert result.exit_code == 0
assert "system" in _clean(result.output)
def test_diagnose_default_still_works():
"""`agnes diagnose` (no subcommand) should still produce its existing output —
we only added a sibling subcommand, didn't change the default."""
result = runner.invoke(diagnose_app, [])
# Either runs successfully or fails for unrelated reasons (no server etc).
# We just want to verify no traceback from the addition.
assert "Traceback" not in (_clean(result.output) + _clean(result.stderr or ''))