Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/apm_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def cli(ctx):

warnings.filterwarnings("ignore", category=AgentsTargetDeprecationWarning)

# Check for updates non-blockingly (only if not already showing version)
if not ctx.resilient_parsing:
# Check for updates only for known commands; skip on invalid input to fail fast.
if not ctx.resilient_parsing and ctx.invoked_subcommand in cli.commands:
_check_and_notify_updates()
Comment on lines +67 to 69


Expand Down
37 changes: 37 additions & 0 deletions tests/integration/test_version_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,43 @@ def test_notification_does_not_block_command(self, mock_check):
self.assertIn("initialized successfully", result.output)


class TestUpdateCheckSkippedOnInvalidCommand(unittest.TestCase):
"""Test that update check is skipped for unknown/invalid commands."""

def setUp(self):
self.runner = CliRunner()

@patch("apm_cli.cli._check_and_notify_updates")
def test_no_update_check_on_unknown_command(self, mock_check):
"""Update check must not run when an unknown command is invoked."""
from apm_cli.cli import cli

result = self.runner.invoke(cli, ["invalid"])

mock_check.assert_not_called()
self.assertNotEqual(result.exit_code, 0)
self.assertIn("invalid", result.output)

@patch("apm_cli.cli._check_and_notify_updates")
def test_update_check_runs_on_valid_command(self, mock_check):
"""Update check must still run when a known command is invoked."""
from apm_cli.cli import cli

with self.runner.isolated_filesystem():
self.runner.invoke(cli, ["init", "test-project", "--yes"])

mock_check.assert_called_once()

@patch("apm_cli.cli._check_and_notify_updates")
def test_no_update_check_without_subcommand(self, mock_check):
"""Update check must not run when no subcommand is given (help display)."""
from apm_cli.cli import cli

self.runner.invoke(cli, [])

mock_check.assert_not_called()


class TestUpdateCommand(unittest.TestCase):
"""Test the update command."""

Expand Down