From 782a35705da0b518cbe815742f5d01cb3e6b3293 Mon Sep 17 00:00:00 2001 From: Muhammad Abdulrehman Date: Sat, 14 Nov 2026 18:17:24 -0500 Subject: [PATCH] Fix relative file paths on Windows --- cli/src/utils/__tests__/path-helpers.test.ts | 13 ++++++------- cli/src/utils/path-helpers.ts | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cli/src/utils/__tests__/path-helpers.test.ts b/cli/src/utils/__tests__/path-helpers.test.ts index daa2a5f131..a27d86f12f 100644 --- a/cli/src/utils/__tests__/path-helpers.test.ts +++ b/cli/src/utils/__tests__/path-helpers.test.ts @@ -23,9 +23,7 @@ describe('formatCwd', () => { test('falls back to USERPROFILE when HOME is unset', () => { const env = { USERPROFILE: 'C:\\Users\\foo' } as CliEnv - expect(formatCwd('C:\\Users\\foo\\project', env)).toBe( - '~\\project', - ) + expect(formatCwd('C:\\Users\\foo\\project', env)).toBe('~\\project') }) }) @@ -47,10 +45,11 @@ describe('getRelativePath', () => { }) test('resolves an absolute path relative to the project root when one is set', () => { - setProjectRoot('/Users/foo/project') - expect(getRelativePath('/Users/foo/project/src/utils/helper.ts')).toBe( - path.join('src', 'utils', 'helper.ts'), - ) + const projectRoot = path.resolve('/Users/foo/project') + setProjectRoot(projectRoot) + expect( + getRelativePath(path.join(projectRoot, 'src', 'utils', 'helper.ts')), + ).toBe(path.join('src', 'utils', 'helper.ts')) }) test('falls back to returning the absolute path as-is when the project root is unavailable', () => { diff --git a/cli/src/utils/path-helpers.ts b/cli/src/utils/path-helpers.ts index d83a2acb52..4c5e5c5af7 100644 --- a/cli/src/utils/path-helpers.ts +++ b/cli/src/utils/path-helpers.ts @@ -28,7 +28,7 @@ export function formatCwd(cwd: string | undefined, env?: CliEnv): string { */ export function getRelativePath(filePath: string): string { // If it's already a relative path, return as-is - if (!filePath.startsWith('/')) return filePath + if (!path.isAbsolute(filePath)) return filePath // Use the non-throwing accessor: the project root may legitimately be // unset (e.g. during early startup or in tests), and the fallback below