Coverage for src/chuck_data/commands/status.py: 0%

22 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-06-05 22:56 -0700

1""" 

2Command handler for displaying system status. 

3 

4This module contains the handler for showing the current status 

5of workspace, catalog, schema, model, and API permissions. 

6""" 

7 

8import logging 

9from typing import Optional 

10 

11from ..clients.databricks import DatabricksAPIClient 

12from ..command_registry import CommandDefinition 

13from ..config import ( 

14 get_workspace_url, 

15 get_active_catalog, 

16 get_active_schema, 

17 get_active_model, 

18 get_warehouse_id, 

19) 

20from ..databricks.permission_validator import validate_all_permissions 

21from .base import CommandResult 

22 

23 

24def handle_command(client: Optional[DatabricksAPIClient], **kwargs) -> CommandResult: 

25 """ 

26 Show current status of workspace, catalog, schema, model, and API permissions. 

27 

28 Args: 

29 client: API client instance 

30 **kwargs: No parameters required 

31 """ 

32 try: 

33 data = { 

34 "workspace_url": get_workspace_url(), 

35 "active_catalog": get_active_catalog(), 

36 "active_schema": get_active_schema(), 

37 "active_model": get_active_model(), 

38 "warehouse_id": get_warehouse_id(), 

39 "connection_status": "Client not available or not initialized.", 

40 "permissions": {}, 

41 } 

42 if client: 

43 try: 

44 # Add client.validate_token() if such method exists and is desired here 

45 # For now, just assume if client exists, basic connection might be possible. 

46 data["connection_status"] = "Connected (client present)." 

47 # Note: validate_all_permissions requires an active, valid client. 

48 # It might fail if token is bad, which is fine for status. 

49 data["permissions"] = validate_all_permissions(client) 

50 # To be more precise on token validity, client.validate_token() would be good. 

51 except Exception as e_client: 

52 data["connection_status"] = ( 

53 f"Client connection/permission error: {str(e_client)}" 

54 ) 

55 logging.warning(f"Status check client error: {e_client}") 

56 return CommandResult(True, data=data) 

57 except Exception as e: 

58 logging.error(f"Failed to get status: {e}", exc_info=True) 

59 return CommandResult(False, error=e, message=str(e)) 

60 

61 

62DEFINITION = CommandDefinition( 

63 name="status", 

64 description="Show current status of the configured workspace, catalog, schema, model, and API permissions. Used to verify connection and permissions.", 

65 handler=handle_command, 

66 parameters={}, 

67 required_params=[], 

68 tui_aliases=[ 

69 "/status", 

70 ], 

71 visible_to_user=True, 

72 visible_to_agent=True, 

73 agent_display="full", # Show full status details to agents 

74)