fix: skip symlink recursion in runtime dep fingerprints

This commit is contained in:
Frank Yang
2026-04-14 15:50:36 +08:00
parent 7ca5c8ee5c
commit bce3e41e36
2 changed files with 40 additions and 3 deletions

View File

@@ -247,16 +247,20 @@ function appendDirectoryFingerprint(hash, rootDir, currentDir = rootDir) {
for (const entry of entries) {
const fullPath = path.join(currentDir, entry.name);
const stat = fs.statSync(fullPath);
const relativePath = path.relative(rootDir, fullPath).replace(/\\/g, "/");
if (stat.isDirectory()) {
if (entry.isSymbolicLink()) {
hash.update(`symlink:${relativePath}->${fs.readlinkSync(fullPath).replace(/\\/g, "/")}\n`);
continue;
}
if (entry.isDirectory()) {
hash.update(`dir:${relativePath}\n`);
appendDirectoryFingerprint(hash, rootDir, fullPath);
continue;
}
if (!stat.isFile()) {
if (!entry.isFile()) {
continue;
}
const stat = fs.statSync(fullPath);
hash.update(`file:${relativePath}:${stat.size}\n`);
hash.update(fs.readFileSync(fullPath));
}

View File

@@ -298,6 +298,39 @@ describe("stageBundledPluginRuntimeDeps", () => {
).toBe("module.exports = 'nested';\n");
});
it("does not change the runtime-deps stamp when only a symlinked directory target changes", () => {
const { pluginDir, repoRoot } = createBundledPluginFixture({
packageJson: {
name: "@openclaw/fixture-plugin",
version: "1.0.0",
dependencies: { direct: "1.0.0" },
openclaw: { bundle: { stageRuntimeDependencies: true } },
},
});
const directDir = path.join(repoRoot, "node_modules", "direct");
const linkedTargetDir = path.join(repoRoot, "linked-target");
const linkedPath = path.join(directDir, "node_modules", "linked");
fs.mkdirSync(path.join(directDir, "node_modules"), { recursive: true });
fs.mkdirSync(linkedTargetDir, { recursive: true });
fs.writeFileSync(
path.join(directDir, "package.json"),
'{ "name": "direct", "version": "1.0.0" }\n',
"utf8",
);
fs.writeFileSync(path.join(directDir, "index.js"), "module.exports = 'direct';\n", "utf8");
fs.writeFileSync(path.join(linkedTargetDir, "marker.txt"), "first\n", "utf8");
fs.symlinkSync(linkedTargetDir, linkedPath);
stageBundledPluginRuntimeDeps({ cwd: repoRoot });
const stampPath = path.join(pluginDir, ".openclaw-runtime-deps-stamp.json");
const firstStamp = fs.readFileSync(stampPath, "utf8");
fs.writeFileSync(path.join(linkedTargetDir, "marker.txt"), "second\n", "utf8");
stageBundledPluginRuntimeDeps({ cwd: repoRoot });
expect(fs.readFileSync(stampPath, "utf8")).toBe(firstStamp);
});
it("falls back to install when the root transitive closure is incomplete", () => {
const { pluginDir, repoRoot } = createBundledPluginFixture({
packageJson: {