Repository navigation
fix(transport): handle missing or unreadable home directories in _find_cli - #1553
Open
adityajai119 wants to merge 1 commit into
Open
adityajai119 wants to merge 1 commit into
adityajai119 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1552
What was wrong
When no bundled CLI binary is present and the
PATHlookup inSubprocessCLITransport._find_cli()misses, fallback CLI discovery fails in headless, service, or restricted environments:Path.home()raisesRuntimeError(such as a rootless container withoutHOMEor/etc/passwdentry, or a Windows service account withoutUSERPROFILE/HOMEDRIVE), POSIX discovery aborts atPath.home() / ".npm-global/bin/claude"before checking/usr/local/bin/claude, and both Windows and POSIX leak rawRuntimeErrorout ofconnect()instead of raisingCLINotFoundError.USERPROFILE=""on Windows (orHOMEis relative),Path.home()returns a non-absolutePath('.'), probing.local/bin/claude.exerelative to the working directory.PermissionErroron Python 3.10/3.11 orOSError),path.exists() and path.is_file()aborts before checking remaining fallback locations (such as/usr/local/bin/claude) and leaksPermissionErrorout ofconnect()instead of raisingCLINotFoundError.Root cause
SubprocessCLITransport._find_cli()evaluatesPath.home()unconditionally when building the fallbacklocationslist and iterateslocationswithout guardingOSError, whileconnect()invokes_find_cli()before itstryblock.Fix
Path.home()via a helper that catches(RuntimeError, OSError)and requireshome.is_absolute(), omitting home-relative fallback candidates when unavailable while still probing/usr/local/bin/claudeon POSIX.if path.exists() and path.is_file():inwith suppress(OSError):so unreadable fallback directories are skipped and discovery either continues to remaining candidates or raisesCLINotFoundError.Testing
.venv\Scripts\python.exe -m pytest tests/test_transport.py -k "CliLookup or PosixCliFallbackLookup"(6 new tests failed before the fix, 13 passed after).venv\Scripts\python.exe -m pytest tests/(1746 passed, 21 skipped).venv\Scripts\python.exe -m ruff check src/ tests/ scripts/.venv\Scripts\python.exe -m ruff format --check src/ tests/ scripts/.venv\Scripts\python.exe -m mypy src/ scripts/AI-assisted: drafted with an AI coding agent; the tests above were run locally.