diff --git a/src/tetra_rp/cli/commands/undeploy.py b/src/tetra_rp/cli/commands/undeploy.py index 0cc0b165..3ed3ab49 100644 --- a/src/tetra_rp/cli/commands/undeploy.py +++ b/src/tetra_rp/cli/commands/undeploy.py @@ -32,6 +32,29 @@ def _get_resource_manager(): return ResourceManager() +def _get_serverless_resources( + resources: Dict[str, DeployableResource], +) -> Dict[str, DeployableResource]: + """Filter resources to only include serverless endpoints. + + Excludes other resource types like NetworkVolume that shouldn't be undeployed + through this command. + + Args: + resources: Dictionary of resource_id -> DeployableResource + + Returns: + Filtered dictionary containing only serverless endpoints + """ + from ...core.resources.serverless import ServerlessResource + + return { + resource_id: resource + for resource_id, resource in resources.items() + if isinstance(resource, ServerlessResource) + } + + def _get_resource_status(resource) -> Tuple[str, str]: """Get resource status with icon and text. @@ -67,7 +90,8 @@ def _get_resource_type(resource) -> str: def list_command(): """List all deployed endpoints tracked in .tetra_resources.pkl.""" manager = _get_resource_manager() - resources = manager.list_all_resources() + all_resources = manager.list_all_resources() + resources = _get_serverless_resources(all_resources) if not resources: console.print( diff --git a/tests/unit/cli/test_undeploy.py b/tests/unit/cli/test_undeploy.py index 7eeaaced..711d92dc 100644 --- a/tests/unit/cli/test_undeploy.py +++ b/tests/unit/cli/test_undeploy.py @@ -75,18 +75,18 @@ def test_list_no_endpoints(self, runner): def test_list_with_endpoints(self, runner): """Test list command with endpoints.""" - # Create mock resources instead of real ones to avoid Pydantic issues - mock_resource1 = MagicMock() + from tetra_rp.core.resources.serverless import ServerlessResource + + # Create mock resources that are instances of ServerlessResource + mock_resource1 = MagicMock(spec=ServerlessResource) mock_resource1.name = "test-api-1" mock_resource1.id = "endpoint-id-1" mock_resource1.is_deployed.return_value = True - mock_resource1.__class__.__name__ = "ServerlessResource" - mock_resource2 = MagicMock() + mock_resource2 = MagicMock(spec=ServerlessResource) mock_resource2.name = "test-api-2" mock_resource2.id = "endpoint-id-2" mock_resource2.is_deployed.return_value = True - mock_resource2.__class__.__name__ = "ServerlessResource" mock_resources = { "resource-id-1": mock_resource1,