Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ requires-poetry = ">=2.0"
version = "0.0.0" # DON'T TOUCH. Placeholder. Will be filled automatically on poetry build from Git Tag

[tool.poetry.dependencies]
click = ">=8.1.0,<8.2.0"
click = ">=8.3.3,<8.4.0"
colorama = ">=0.4.3,<0.5.0"
pyyaml = ">=6.0,<7.0"
marshmallow = ">=4.1.2,<5.0.0"
Expand All @@ -44,7 +44,7 @@ urllib3 = ">=2.8.0,<3.0.0"
pyjwt = ">=2.15.0,<3.0"
rich = ">=15.0.0,<16.0.0"
patch-ng = "1.19.1"
typer = "^0.15.3"
typer = ">=0.25.1,<0.26.0"
tenacity = ">=9.2.1,<9.3.0"
mcp = ">=1.30.0,<2.0.0"
truststore = ">=0.10.4,<0.11.0"
Expand Down
65 changes: 65 additions & 0 deletions tests/cli/test_click_typer_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Guards the seam between Typer and the Click APIs the CLI uses directly.

The CLI raises ``click.ClickException``, mounts a raw ``click.Group`` (``platform``)
into the Typer app, and relies on Typer rendering both. Typer releases that vendor
their own copy of Click (0.26+) silently break these paths, so cover them end to end.
"""

from unittest.mock import patch

import click
from typer.testing import CliRunner

from cycode.cli.app import app
from tests.conftest import CLI_ENV_VARS

_BASE_ARGS = ['--no-update-notifier']


def _invoke(*args: str) -> 'click.testing.Result':
return CliRunner().invoke(app, [*_BASE_ARGS, *args], env=CLI_ENV_VARS)


def test_click_exception_is_rendered_as_error_not_traceback() -> None:
result = _invoke('ignore')

assert result.exit_code == 1
assert 'Ignore by type is missing' in result.output
assert 'Traceback' not in result.output
assert isinstance(result.exception, SystemExit)


def _fake_platform_groups(*_: object) -> list[tuple[click.Group, str]]:
group = click.Group(name='tools', help='Fake tools group')

@group.command(name='ping', help='Fake ping command')
def ping() -> None:
click.echo('pong')

return [(group, 'tools')]


def test_platform_click_group_is_mounted_and_invocable() -> None:
with patch('cycode.cli.apps.api.api_command.build_api_command_groups', side_effect=_fake_platform_groups):
help_result = _invoke('platform', '--help')
run_result = _invoke('platform', 'tools', 'ping')

assert help_result.exit_code == 0, help_result.output
assert 'tools' in help_result.output

assert run_result.exit_code == 0, run_result.output
assert 'pong' in run_result.output


def test_misspelled_command_suggests_once() -> None:
result = _invoke('scna')

assert result.exit_code == 2
assert result.output.count("Did you mean 'scan'?") == 1


def test_group_without_args_shows_help_with_usage_exit_code() -> None:
result = _invoke('scan')

assert result.exit_code == 2
assert 'Usage' in result.output
Loading