Files
OpenHands/__tests__
Rohit Malhotraandopenhands 24da834da3 fix: guard against null provider in useUrlSearch hook (#341)
* fix: guard against null provider in useUrlSearch hook

Prevent unnecessary cloud proxy requests when the provider is null/undefined
(e.g., before providers have loaded from settings).

The useUrlSearch hook was calling GitService.searchGitRepositories()
without validating that the provider was truthy first. When the parent
component passed undefined (from providers[0] when array is empty),
the request would be sent to the cloud proxy with an invalid provider.

Changes:
- Update type signature to accept Provider | null | undefined
- Add early return guard when provider is falsy
- Clear results when provider becomes null

* fix: add defensive guards in GitService for invalid providers

Add a second layer of defense at the GitService level to prevent
cloud proxy requests with invalid providers (null, undefined, empty
string, or stringified 'undefined'/'null').

This fixes the installations search API being called with
'provider=undefined' even when hooks have enabled guards.

Changes:
- Add isInvalidProvider() guard function
- Add guards to all GitService methods that take a provider param
- Return empty results instead of making invalid API requests
- Add comprehensive tests for the guards

---------

Co-authored-by: openhands <openhands@all-hands.dev>
2026-05-11 17:14:33 -04:00
..