fix: preserve absolute mention paths (#123)
Co-authored-by: iliya <iliyazelenkog@gmail.com>
This commit is contained in:
parent
f08e228a7d
commit
a6ba6072c0
5 changed files with 27 additions and 0 deletions
|
|
@ -27,6 +27,10 @@ export function resolveFilePath(base: string, relativePath: string): string {
|
||||||
cleanRelative = cleanRelative.slice(1);
|
cleanRelative = cleanRelative.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isAbsolutePath(cleanRelative)) {
|
||||||
|
return cleanRelative;
|
||||||
|
}
|
||||||
|
|
||||||
// Tilde paths (~/) are home-relative absolute paths - pass through as-is
|
// Tilde paths (~/) are home-relative absolute paths - pass through as-is
|
||||||
// The main process will expand ~ to the actual home directory
|
// The main process will expand ~ to the actual home directory
|
||||||
if (cleanRelative.startsWith('~/') || cleanRelative.startsWith('~\\') || cleanRelative === '~') {
|
if (cleanRelative.startsWith('~/') || cleanRelative.startsWith('~\\') || cleanRelative === '~') {
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,9 @@ function joinPaths(base: string, relative: string): string {
|
||||||
if (cleanRelative.startsWith('@')) {
|
if (cleanRelative.startsWith('@')) {
|
||||||
cleanRelative = cleanRelative.slice(1);
|
cleanRelative = cleanRelative.slice(1);
|
||||||
}
|
}
|
||||||
|
if (isAbsolutePath(cleanRelative)) {
|
||||||
|
return cleanRelative;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle ./ prefix (current directory)
|
// Handle ./ prefix (current directory)
|
||||||
if (cleanRelative.startsWith('./') || cleanRelative.startsWith('.\\')) {
|
if (cleanRelative.startsWith('./') || cleanRelative.startsWith('.\\')) {
|
||||||
|
|
|
||||||
|
|
@ -482,6 +482,9 @@ function joinPaths(base: string, relative: string): string {
|
||||||
if (cleanRelative.startsWith('@')) {
|
if (cleanRelative.startsWith('@')) {
|
||||||
cleanRelative = cleanRelative.slice(1);
|
cleanRelative = cleanRelative.slice(1);
|
||||||
}
|
}
|
||||||
|
if (isAbsolutePath(cleanRelative)) {
|
||||||
|
return cleanRelative;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle ./ prefix (current directory)
|
// Handle ./ prefix (current directory)
|
||||||
if (cleanRelative.startsWith('./') || cleanRelative.startsWith('.\\')) {
|
if (cleanRelative.startsWith('./') || cleanRelative.startsWith('.\\')) {
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,14 @@ describe('resolveFilePath', () => {
|
||||||
expect(resolveFilePath('/repo', '@~/some/file.ts')).toBe('~/some/file.ts');
|
expect(resolveFilePath('/repo', '@~/some/file.ts')).toBe('~/some/file.ts');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('passes through @-prefixed absolute paths after stripping the mention marker', () => {
|
||||||
|
expect(resolveFilePath('/repo', '@/outside/file.ts')).toBe('/outside/file.ts');
|
||||||
|
expect(resolveFilePath('C:\\repo', '@C:\\outside\\file.ts')).toBe('C:\\outside\\file.ts');
|
||||||
|
expect(resolveFilePath('C:\\repo', '@\\\\server\\share\\file.ts')).toBe(
|
||||||
|
'\\\\server\\share\\file.ts'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('passes through bare tilde as-is', () => {
|
it('passes through bare tilde as-is', () => {
|
||||||
expect(resolveFilePath('/repo', '~')).toBe('~');
|
expect(resolveFilePath('/repo', '~')).toBe('~');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -195,4 +195,13 @@ describe('extractUserMentionPaths Windows paths', () => {
|
||||||
['~\\.claude\\CLAUDE.md']
|
['~\\.claude\\CLAUDE.md']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('strips mention markers before preserving absolute mention paths', () => {
|
||||||
|
expect(extractUserMentionPaths(userGroupWithPath('@C:\\Other\\file.ts'), 'C:\\Repo')).toEqual([
|
||||||
|
'C:\\Other\\file.ts',
|
||||||
|
]);
|
||||||
|
expect(
|
||||||
|
extractUserMentionPaths(userGroupWithPath('@\\\\server\\share\\file.ts'), 'C:\\Repo')
|
||||||
|
).toEqual(['\\\\server\\share\\file.ts']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue