Skip to content
Draft
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
20 changes: 14 additions & 6 deletions openhands_cli/auth/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,22 @@ async def fetch_user_data_after_oauth(

# Fetch user settings
console_print("• Getting user settings...", style=OPENHANDS_THEME.secondary)
settings = await client.get_user_settings()

if settings:
_print_settings_summary(settings)
else:
settings: dict[str, Any] | None
try:
settings = await client.get_user_settings()
except ApiClientError as e:
settings = None
console_print(
" ! No user settings available", style=OPENHANDS_THEME.warning
f" ! Could not fetch user settings: {e}",
style=OPENHANDS_THEME.warning,
)
else:
if settings:
_print_settings_summary(settings)
else:
console_print(
" ! No user settings available", style=OPENHANDS_THEME.warning
)

user_data = {
"llm_api_key": llm_api_key,
Expand Down
27 changes: 27 additions & 0 deletions tests/auth/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,33 @@ async def test_fetch_user_data_after_oauth_no_settings(self):
expected_result = {"llm_api_key": "llm-key-123", "settings": None}
assert result == expected_result

@pytest.mark.asyncio
async def test_fetch_user_data_after_oauth_settings_api_error_is_nonfatal(self):
"""Settings sync failures should not fail the completed login flow."""
server_url = "https://api.example.com"
api_key = "test-api-key"

with patch(
"openhands_cli.auth.api_client.OpenHandsApiClient"
) as mock_client_class:
with patch(
"openhands_cli.auth.api_client.create_and_save_agent_configuration"
) as mock_create_and_save:
with patch("openhands_cli.auth.api_client.console_print"):
mock_client = AsyncMock()
mock_client_class.return_value = mock_client

mock_client.get_llm_api_key.return_value = "llm-key-123"
mock_client.get_user_settings.side_effect = ApiClientError(
"Request to '/api/v1/settings' returned a non-JSON response"
)

result = await fetch_user_data_after_oauth(server_url, api_key)

expected_result = {"llm_api_key": "llm-key-123", "settings": None}
assert result == expected_result
mock_create_and_save.assert_not_called()

@pytest.mark.asyncio
async def test_fetch_user_data_after_oauth_agent_creation_error(self):
"""Test user data fetching when agent creation fails."""
Expand Down
Loading