Repository navigation
fix(cli): Support Windows-style tilde paths #6029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c7f5081
839df00
16ccc97
fde1509
a4a38d1
28ee32d
060227c
7e0392e
591c8e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -419,6 +419,12 @@ describe('resolvePath', () => { | |||||
| expect(result).toBe(path.join(homeDir, 'documents/file.txt')); | ||||||
| }); | ||||||
|
|
||||||
| it('expands Windows-style tilde-prefixed paths to home directory', () => { | ||||||
| const homeDir = os.homedir(); | ||||||
| const result = resolvePath('/some/base', '~\\documents\\file.txt'); | ||||||
| expect(result).toBe(path.join(homeDir, 'documents\\file.txt')); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Critical] Test validates broken behavior on POSIX. Both the implementation and A correct assertion would expose the bug by expecting proper path joining:
Suggested change
This assertion will FAIL on POSIX with the current implementation (exposing the bug) and PASS after applying the — qwen3.7-max via Qwen Code /review
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] This test encodes a POSIX-incorrect result. On macOS/Linux, The codebase already has a more robust pattern in path.join(homeDir, ...relativePath.slice(2).split(/[/\\]+/).filter(Boolean))This normalizes separators correctly on all platforms. Consider adopting this pattern in both — qwen3.7-max via Qwen Code /review |
||||||
| }); | ||||||
|
|
||||||
| it('uses baseDir when provided for relative paths', () => { | ||||||
| const baseDir = '/custom/base'; | ||||||
| const result = resolvePath(baseDir, './relative/path'); | ||||||
|
|
@@ -619,6 +625,9 @@ describe('resolveAndValidatePath', () => { | |||||
| expect(resolveAndValidatePath(configWithHome, '~/project')).toBe( | ||||||
| homeSubdir, | ||||||
| ); | ||||||
| expect(resolveAndValidatePath(configWithHome, '~\\project')).toBe( | ||||||
| homeSubdir, | ||||||
| ); | ||||||
| expect(resolveAndValidatePath(configWithHome, '~')).toBe(fakeHome); | ||||||
| } finally { | ||||||
| homedirSpy.mockRestore(); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -329,7 +329,7 @@ export function resolvePath( | |||||||
|
|
||||||||
| if (relativePath === '~') { | ||||||||
| return homeDir; | ||||||||
| } else if (relativePath.startsWith('~/')) { | ||||||||
| } else if (relativePath.startsWith('~/') || relativePath.startsWith('~\\')) { | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Critical] POSIX backslash normalization bug. On macOS/Linux, The codebase already has 6+ correct implementations using
Suggested change
Apply the same fix in if (input.startsWith('~/') || input.startsWith('~\\')) {
const segments = input.slice(2).split(/[\/\\]+/).filter(Boolean);
return path.normalize(path.join(os.homedir(), ...segments));
}— qwen3.7-max via Qwen Code /review |
||||||||
| return path.join(homeDir, relativePath.slice(2)); | ||||||||
| } else if (path.isAbsolute(relativePath)) { | ||||||||
| return relativePath; | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] This test only covers the error path (directory not found). No success test verifies that
cd ~\existingDiractually callsrelocateWorkingDirectory. Consider adding a success-path test mirroring the existing../nexttest pattern:— qwen3.7-max via Qwen Code /review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. This is covered now by the success-path Windows-style home-relative /cd test, and the targeted
cdCommand.test.ts -t "Windows-style home-relative"run passed: 2 passed, 18 skipped.