Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions cli/src/utils/__tests__/path-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

Expand All @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/utils/path-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading