Keep worktree session dir when pane cwd is outside#49
Open
iam-vipin wants to merge 1 commit into
Open
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-019eb074-d17e-743c-a833-2519cfed77a9 Co-authored-by: Amp <amp@ampcode.com>
There was a problem hiding this comment.
inspect review
Triage: 7 entities analyzed | 0 critical, 0 high, 3 medium, 4 low
Verdict: standard_review
Findings (4)
- [low] Logic error in
is_home_dir: The function returnsfalsewhen HOME environment variable is not set, but should handle the case where HOME exists but comparison fails. The current implementation usingis_ok_andwill returnfalseboth when HOME is unset AND when HOME is set but doesn't match, making it impossible to distinguish between these cases. More critically, if HOME is not set, the function silently returns false, which could cause incorrect behavior inchoose_session_dirwhere it might incorrectly prefer active_dir over session_dir. - [low] Path comparison bug in
choose_session_dir: UsingPath::new(active_dir).starts_with(Path::new(session_dir))for path prefix checking is incorrect becausestarts_withdoes component-wise comparison, not string prefix. For example,/repo-wt/workspace-1does NOT start with/repo-wt/workspace(different components), but/repo-wt/workspace-1/subDOES start with/repo-wt/workspace-1. However, the test case expects/repo/packages/appto NOT be considered as starting with/repo-wt/workspace-1, which works correctly. But edge cases like/repo-wt/workspace-1xvs/repo-wt/workspace-1would incorrectly return false when they should (string-wise they share a prefix but component-wise they don't). This is actually correct behavior for the intended use case, so this may not be a bug. Retracting this. - [low] Logic error in is_home_dir: The function checks is_ok_and() but doesn't handle the case where HOME is not set. If HOME is not set, is_ok_and returns false, which means a directory won't be considered a home directory even if it should be. More critically, the function will return false for any directory when HOME is unset, which could lead to incorrect behavior in choose_session_dir where session_dir might actually be a home directory but isn't detected as such.
- [low] Path comparison logic error in choose_session_dir: The function uses Path::new(active_dir).starts_with(Path::new(session_dir)) which has a known footgun in Rust - starts_with() does component-wise comparison, not string prefix matching. For example, Path::new('/repo-wt/workspace-1').starts_with('/repo-wt/workspace') would return false even though the string starts with that prefix. This could cause the function to incorrectly return session_dir when it should return active_dir for paths that are actually subdirectories.
Reviewed by inspect | Entity-level triage found 0 high-risk changes
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.
Summary
Why
Worktree sessions can contain panes whose current directory points at a sibling/root checkout. Previously that active pane cwd could override the session's worktree path, causing branch/worktree metadata to be computed from the wrong directory.
Test