Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(process): keep observed symlink targets in filesystem snapshots (#3418)

Wade7a83af3cbaa7
diff --git a/src/process/capture/FilesystemCoverage.test.ts b/src/process/capture/FilesystemCoverage.test.ts
index 4d77ebfaa..a2ea11079 100644
--- a/src/process/capture/FilesystemCoverage.test.ts
+++ b/src/process/capture/FilesystemCoverage.test.ts
@@ -339,6 +339,38 @@ it.skipIf(process.platform === "win32")(
},
);
+it.skipIf(process.platform === "win32")(
+ "keeps the observed symlink target when dot segments resolve to the same path",
+ async () => {
+ const root = await createTestTempDirectory("rea-fs-symlink-spelling-");
+ await mkdir(join(root, "aaa"));
+ await writeFile(join(root, "target"), "content");
+ // Equal length, so only the target spelling distinguishes the links;
+ // "bbb" does not exist, so the replacement link is broken.
+ await symlink("aaa/../target", join(root, "link"));
+ const scenario = parseProcessScenario({
+ executable: process.execPath,
+ working_directory: root,
+ filesystem_observation_paths: [root],
+ limits: { file_bytes: 1 },
+ });
+ const before = await snapshotRoots(scenario);
+ await rm(join(root, "link"));
+ await symlink("bbb/../target", join(root, "link"));
+ const after = await snapshotRoots(scenario);
+
+ const link = (snapshot: typeof before) =>
+ snapshot.files.find(({ path }) => path === "root_0:link");
+ expect(link(before)?.symlink_target).toBe("aaa/../target");
+ expect(link(after)?.symlink_target).toBe("bbb/../target");
+ expect(
+ classifyFilesystemEffects(before, after).find(
+ ({ path }) => path === "root_0:link",
+ )?.status,
+ ).toBe("modified");
+ },
+);
+
it("preserves creation when the selected root was observed missing before capture", async () => {
const root = await createTestTempDirectory("rea-fs-missing-root-");
const file = join(root, "created.txt");
diff --git a/src/process/capture/FilesystemSnapshot.ts b/src/process/capture/FilesystemSnapshot.ts
index 5defd2574..60bee8fd5 100644
--- a/src/process/capture/FilesystemSnapshot.ts
+++ b/src/process/capture/FilesystemSnapshot.ts
@@ -1,7 +1,7 @@
import { createHash } from "node:crypto";
import { constants as fsConstants } from "node:fs";
import { lstat, open, opendir, readlink } from "node:fs/promises";
-import { dirname, join, relative, resolve } from "node:path";
+import { join, relative } from "node:path";
import type { FileHandle } from "node:fs/promises";
import type { ProcessScenario } from "../../domain/process/processScenario.js";
import type { FilesystemCoverage } from "../../domain/process/processCaptureCoverage.js";
@@ -224,7 +224,8 @@ export const snapshotRoots = async (
if (stats === undefined) return true;
const relativePath = relative(root, path) || ".";
if (stats.isSymbolicLink()) {
- const target = resolve(dirname(path), await readlink(path));
+ // Keep the target as stored: lexical resolution can merge distinct targets.
+ const target = await readlink(path);
const afterRead = await lstat(path);
if (!hasSameIdentity(stats, afterRead, "symlink")) {
truncated = true;