"""Tests for CLI commands.""" import pytest from click.testing import CliRunner from mcp_server_cli.main import main @pytest.fixture def cli_runner(): """Create a CLI runner for testing.""" return CliRunner() class TestCLIVersion: """Tests for CLI version command.""" def test_version(self, cli_runner): """Test --version option.""" result = cli_runner.invoke(main, ["--version"]) assert result.exit_code == 0 assert "0.1.0" in result.output class TestCLIServerCommands: """Tests for server commands.""" def test_server_status_no_config(self, cli_runner): """Test server status without config.""" result = cli_runner.invoke(main, ["server", "status"]) assert result.exit_code == 0 def test_config_show(self, cli_runner): """Test config show command.""" result = cli_runner.invoke(main, ["config", "show"]) assert result.exit_code == 0 class TestCLIToolCommands: """Tests for tool commands.""" def test_tool_list(self, cli_runner): """Test tool list command.""" result = cli_runner.invoke(main, ["tool", "list"]) assert result.exit_code == 0 def test_tool_add_nonexistent_file(self, cli_runner): """Test tool add with nonexistent file.""" result = cli_runner.invoke(main, ["tool", "add", "nonexistent.yaml"]) assert result.exit_code != 0 or "nonexistent" in result.output.lower() class TestCLIConfigCommands: """Tests for config commands.""" def test_config_init(self, cli_runner, tmp_path): """Test config init command.""" output_file = tmp_path / "config.yaml" result = cli_runner.invoke(main, ["config", "init", "-o", str(output_file)]) assert result.exit_code == 0 assert output_file.exists() def test_config_show_with_env(self, cli_runner): """Test config show with environment variables.""" result = cli_runner.invoke(main, ["config", "show"]) assert result.exit_code == 0 class TestCLIHealthCommand: """Tests for health check command.""" def test_health_check_not_running(self, cli_runner): """Test health check when server not running.""" result = cli_runner.invoke(main, ["health"]) assert result.exit_code == 0 or "not running" in result.output.lower() class TestCLIInstallCompletions: """Tests for shell completion installation.""" def test_install_completions(self, cli_runner): """Test install completions command.""" result = cli_runner.invoke(main, ["install"]) assert result.exit_code == 0