Fix #144: Check FOUNDRY_TOKEN/FOUNDRY_HOST env vars before keyring access - #146
Fix #144: Check FOUNDRY_TOKEN/FOUNDRY_HOST env vars before keyring access#146anjor wants to merge 2 commits into
Conversation
…cess - Add environment variable check at the start of AuthManager.get_client() - Create TokenAuthProvider directly when env vars are set (bypasses keyring) - Update validate_profile() to handle env vars similarly - Implement lazy initialization of CredentialStorage to avoid keyring import - Add comprehensive tests for env var authentication flow - All existing tests continue to pass Resolves keyring hanging in headless/agent environments by prioritizing environment variables over stored credentials.
Code ReviewGood fix for a real pain point - keyring hanging in headless environments is a common problem. The lazy initialization approach is clean. A few things worth discussing: Medium: Explicit
|
- Remove unused mock_profile_class variables in tests - Fix trailing whitespace in auth manager - Reformat long lines for better readability Applied ruff check --fix --unsafe-fixes and ruff format
PR Review: Fix #144 - Check env vars before keyring accessThis is a clean, well-motivated fix. The lazy initialization approach and env-var-first logic directly solve the headless environment hang. Overall structure is good - a few issues worth addressing before merging. Issues1. test_get_client_with_partial_env_vars is not hermetic (potential CI flakiness) The @patch.dict at line 291 is missing clear=True: If FOUNDRY_HOST happens to be set in the CI environment or a developer shell, both env vars are present and the env-var fast-path fires instead of falling back to profile. Assertions break silently. Fix: 2. Duplicate test test_validate_profile_without_env_vars (new) and test_validate_profile (existing, line 429) are functionally identical - same patch, same assertions, same profile name. The only difference is the new one explicitly clears env vars. The old test adds no incremental coverage and having two near-identical tests creates confusion. Recommend removing test_validate_profile or repurposing it to cover a distinct edge case. 3. test_validate_profile_with_env_vars creates a real ProfileManager AuthManager.init always calls ProfileManager() eagerly. Unlike all the other new env-var tests, this one does not patch ProfileManager, so a real instance is created that may read from the filesystem. For consistency and isolation, it should be patched: 4. Silent profile override - UX concern When env vars are set, an explicit --profile staging passed by the user is silently discarded. A user who has FOUNDRY_TOKEN/FOUNDRY_HOST set globally but wants to test a specific profile will get the wrong credentials with no feedback. A logging.debug message would help: Minor observations
Summary
The critical fix before merging is issue 1 (missing clear=True) - it can cause non-deterministic CI failures. Issues 2 and 3 are cleanup that improve test quality. |
Problem
pltrstores credentials in macOS keyring. In headless environments, keyring access hangs and the process gets killed. The CLI supportsFOUNDRY_TOKENandFOUNDRY_HOSTenv vars intoken.py, butAuthManager.__init__()always createsCredentialStorage()which imports keyring before env vars are checked.Solution
This PR modifies
src/pltr/auth/manager.pyto:get_client()before accessing keyringFOUNDRY_TOKENandFOUNDRY_HOSTare setCredentialStorageto avoid keyring import duringAuthManagerinitializationvalidate_profile()to handle env vars similarlyChanges
AuthManager.get_client(): Added env var check at the beginningAuthManager.validate_profile(): Added env var validation pathTesting
Result
When
FOUNDRY_TOKENandFOUNDRY_HOSTare set, the CLI will now authenticate without ever touching the keyring, resolving the hanging issue in headless environments.Fixes #144