Fix PATH accumulation when switching between projects with .luca/tools#15
Merged
Merged
Conversation
The cleanup loop in update_path was nested inside the else branch, meaning it only ran when the current directory had no .luca/tools. When navigating from project A to project B (both with .luca/tools), B's entry was appended to PATH while A's was never removed. Navigating back to A found its entry already present and returned early, leaving B's stale entry ahead of A's. Move the cleanup unconditionally to the top of the function so stale .luca/tools entries are always evicted before the current directory's entry is (re-)added. The add step is now a simple append-if-missing that follows the cleaned PATH.
Cover the two missing cases: navigating from project A to project B removes A's entry, and navigating back to A removes B's entry.
update_path previously only checked $(pwd)/.luca/tools, so navigating directly into a project subdirectory from outside would never pick up the project's tools. Walk up from $PWD to / and use the first ancestor that contains .luca/tools. Simplify the PATH cleanup to match against the single resolved tool_bin_dir rather than checking project-root prefixes. Add a test covering direct entry into a subdirectory without first visiting the project root.
The upward search now stops before reaching \$HOME, so \$HOME/.luca/tools (the global Luca installation present on every user's machine) is never treated as a project-specific tools directory. Projects nested inside HOME are still found correctly.
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.
Problem
When navigating between two directories that both contain a
.luca/toolsfolder, thePATHwould accumulate entries for both projects. More critically, switching back to the first project would leave the second project's entry at a higher priority position inPATH, causing the wrong tool version to be resolved.Reproduction steps:
cd /path/to/project-A—project-A/.luca/toolsis added toPATHcd /path/to/project-B—project-B/.luca/toolsis added toPATH(now both are present)cd /path/to/project-A—project-A/.luca/toolsis already inPATH, so the function returns early.project-B/.luca/toolsremains and is still first inPATH.The result is that tools from project B are resolved instead of project A's tools.
Root Cause
In
update_path(), the cleanup loop that removes stale.luca/toolsentries was placed inside anelsebranch — it only ran when the current directory had no.luca/toolsfolder:When navigating from project A to project B (both having
.luca/tools), theifbranch fires, skips cleanup entirely, and simply appends B's entry. The stale A entry is never removed until you navigate to a directory with no.luca/toolsat all.Fix
Move the cleanup loop unconditionally to the top of
update_path(), before the add step. The function now always:PATHfor any*/.luca/toolsentries$PWDtool_bin_dirif it exists and isn't already presentBehaviour After Fix
cd project-Aproject-A/.luca/tools:...cd project-Bproject-B/.luca/tools:...(A's entry removed)cd project-Aproject-A/.luca/tools:...(B's entry removed)cd /no-luca-dir...(all.luca/toolsentries removed)cd project-A/subdirproject-A/.luca/tools:...(parent project entry preserved)All existing idempotency and subdirectory-traversal behaviour is preserved.