Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

test(paths): pin Windows separator normalization before native admission (#4733)

Oke Iyanuoluwa Enochf85a932d7127
diff --git a/tests/boundary/filesystem/callerPath.test.ts b/tests/boundary/filesystem/callerPath.test.ts
index 98d8f5a5e..57593c3ac 100644
--- a/tests/boundary/filesystem/callerPath.test.ts
+++ b/tests/boundary/filesystem/callerPath.test.ts
@@ -39,3 +39,14 @@ it("uses lexical resolution on Windows, where it is exact", () => {
);
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");
+});
diff --git a/tests/boundary/filesystem/windowsTargetSeparators.test.ts b/tests/boundary/filesystem/windowsTargetSeparators.test.ts
new file mode 100644
index 000000000..8ebdc700c
--- /dev/null
+++ b/tests/boundary/filesystem/windowsTargetSeparators.test.ts
@@ -0,0 +1,31 @@
+import { writeFile } from "node:fs/promises";
+import { join } from "node:path";
+
+import { expect, it } from "vitest";
+
+import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
+import { pe } from "../../../src/domain/binaryTarget.fixture.js";
+import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
+
+// Windows native snapshot admission rejects empty and forward-slash path
+// components, so the caller path it receives must already be one canonical
+// drive path whatever separator spelling the caller used (#4707).
+it.runIf(process.platform === "win32")(
+ "hands native admission one drive path for every separator spelling",
+ async () => {
+ const directory = await createTestTempDirectory("rea-win-separators-");
+ const path = join(directory, "image.exe");
+ await writeFile(path, pe(0x8664));
+ const spellings = [
+ path,
+ path.replaceAll("\\", "/"),
+ path.replaceAll("\\", "\\\\"),
+ path.replaceAll("\\", "//"),
+ ];
+ for (const spelling of spellings) {
+ const target = await parseBinaryTarget(spelling);
+ expect(target.ok, spelling).toBe(true);
+ if (target.ok) expect(target.value.sourcePath, spelling).toBe(path);
+ }
+ },
+);