From 4114995bd9b7198d46df4e96775ad82c47f0aabc Mon Sep 17 00:00:00 2001 From: daniel-lxs Date: Mon, 12 Jan 2026 10:04:28 -0500 Subject: [PATCH] fix(path): return empty string from getReadablePath when path is undefined - ROO-437 More surgical fix: only handle undefined, not empty string, as empty string may have legitimate use cases (per reviewer feedback). --- src/utils/__tests__/path.spec.ts | 9 +++++++-- src/utils/path.ts | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/utils/__tests__/path.spec.ts b/src/utils/__tests__/path.spec.ts index a8cf84b68c9..d0a79c37512 100644 --- a/src/utils/__tests__/path.spec.ts +++ b/src/utils/__tests__/path.spec.ts @@ -153,8 +153,13 @@ describe("Path Utilities", () => { expect(getReadablePath(desktop, filePath)).toBe(filePath.toPosix()) }) - it("should handle undefined relative path", () => { - expect(getReadablePath(cwd)).toBe("project") + it("should return empty string when relative path is undefined", () => { + expect(getReadablePath(cwd)).toBe("") + }) + + it("should return cwd basename when relative path is empty string", () => { + // Empty string resolves to cwd, which returns basename + expect(getReadablePath(cwd, "")).toBe("project") }) it("should handle parent directory traversal", () => { diff --git a/src/utils/path.ts b/src/utils/path.ts index 48e2ce66738..c1f49099959 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -80,7 +80,12 @@ function normalizePath(p: string): string { } export function getReadablePath(cwd: string, relPath?: string): string { - relPath = relPath || "" + // If relPath is undefined, return empty string instead of allowing path.resolve + // to return cwd (which would then show misleading cwd basename in UI) + if (relPath === undefined) { + return "" + } + // path.resolve is flexible in that it will resolve relative paths like '../../' to the cwd and even ignore the cwd if the relPath is actually an absolute path const absolutePath = path.resolve(cwd, relPath) if (arePathsEqual(cwd, path.join(os.homedir(), "Desktop"))) {