Files
rea/tests/boundary/filesystem/callerPath.test.ts
T
Oke Iyanuoluwa Enoch f85a932d71 test(paths): pin Windows separator normalization before native admission (#4733)
rea-agents 6.5.0 passed an absolute caller path to Windows native
snapshot admission verbatim, so a spelling with forward slashes or
repeated separators reached the native component walker, which rejects
empty components as "Ambiguous Windows path component is unsupported"
(Win32 50). Current main already resolves every Windows caller path with
win32.resolve (fc791bb60), which collapses those spellings.

Pin that boundary: absoluteCallerPath normalizes four separator spellings
of one absolute Windows path, and on Windows parseBinaryTarget returns the
same canonical sourcePath for each of them. The Windows test fails when
the 6.5.0 verbatim-absolute-path rule is restored.

Fixes #4707

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 17:14:16 +08:00

53 lines
2.1 KiB
TypeScript

import { expect, it } from "vitest";
import { absoluteCallerPath } from "../../../src/filesystem/callerPath.js";
it("keeps POSIX parent components for the filesystem to resolve", () => {
const posix = { cwd: "/work", platform: "linux" } as const;
expect(absoluteCallerPath("link/../sample", posix)).toBe(
"/work/link/../sample",
);
expect(absoluteCallerPath("/abs/link/../sample", posix)).toBe(
"/abs/link/../sample",
);
expect(absoluteCallerPath("../sample", posix)).toBe("/work/../sample");
});
it("removes only POSIX spellings that cannot change the named file", () => {
const posix = { cwd: "/work/", platform: "darwin" } as const;
expect(absoluteCallerPath("./module.wasm", posix)).toBe("/work/module.wasm");
expect(absoluteCallerPath("a//./b", posix)).toBe("/work/a/b");
expect(absoluteCallerPath("/x/./y", posix)).toBe("/x/y");
expect(absoluteCallerPath("sample", { ...posix, cwd: "/" })).toBe("/sample");
expect(absoluteCallerPath("/", posix)).toBe("/");
// A trailing separator or `.` still requires a directory.
expect(absoluteCallerPath("sample/", posix)).toBe("/work/sample/");
expect(absoluteCallerPath("sample/.", posix)).toBe("/work/sample/");
expect(absoluteCallerPath("a//b//", posix)).toBe("/work/a/b/");
});
it("makes a relative POSIX cwd absolute before appending the path", () => {
expect(
absoluteCallerPath("sample", { cwd: "fixtures/../x", platform: "linux" }),
).toBe(`${process.cwd()}/fixtures/../x/sample`);
});
it("uses lexical resolution on Windows, where it is exact", () => {
const win32 = { cwd: "C:\\work", platform: "win32" } as const;
expect(absoluteCallerPath("link\\..\\sample", win32)).toBe(
"C:\\work\\sample",
);
expect(absoluteCallerPath("D:\\x\\..\\y", win32)).toBe("D:\\y");
});
it("normalizes separator spellings of absolute Windows paths (#4707)", () => {
const win32 = { cwd: "C:\\work", platform: "win32" } as const;
for (const spelling of [
"C:\\Users\\u\\h.exe",
"C:/Users/u/h.exe",
"C:\\\\Users\\\\u\\\\h.exe",
"C://Users//u//h.exe",
])
expect(absoluteCallerPath(spelling, win32)).toBe("C:\\Users\\u\\h.exe");
});