























@@ -1,4 +1,5 @@
11import { spawnSync } from "node:child_process";
2+import { createHash } from "node:crypto";
23import fs from "node:fs";
34import os from "node:os";
45import path from "node:path";
@@ -726,6 +727,56 @@ describe("ensureBundledPluginRuntimeDeps", () => {
726727]);
727728});
728729730+it("does not derive a second-generation stage root from external runtime mirrors", () => {
731+const packageRoot = makeTempDir();
732+const stageDir = makeTempDir();
733+fs.writeFileSync(
734+path.join(packageRoot, "package.json"),
735+JSON.stringify({ name: "openclaw", version: "2026.4.25" }),
736+);
737+const pluginRoot = path.join(packageRoot, "dist", "extensions", "telegram");
738+fs.mkdirSync(pluginRoot, { recursive: true });
739+fs.writeFileSync(
740+path.join(pluginRoot, "package.json"),
741+JSON.stringify({ dependencies: { grammy: "^1.42.0" } }),
742+);
743+const env = { OPENCLAW_PLUGIN_STAGE_DIR: stageDir };
744+const installRoot = resolveBundledRuntimeDependencyInstallRoot(pluginRoot, { env });
745+const mirroredPluginRoot = path.join(installRoot, "dist", "extensions", "telegram");
746+fs.mkdirSync(mirroredPluginRoot, { recursive: true });
747+fs.writeFileSync(
748+path.join(mirroredPluginRoot, "package.json"),
749+JSON.stringify({ dependencies: { grammy: "^1.42.0" } }),
750+);
751+fs.mkdirSync(path.join(installRoot, "node_modules", "grammy"), { recursive: true });
752+fs.writeFileSync(
753+path.join(installRoot, "node_modules", "grammy", "package.json"),
754+JSON.stringify({ name: "grammy", version: "1.42.0" }),
755+);
756+757+const nestedUnknownRoot = path.join(
758+stageDir,
759+`openclaw-unknown-${createHash("sha256").update(path.resolve(installRoot)).digest("hex").slice(0, 12)}`,
760+);
761+762+expect(resolveBundledRuntimeDependencyInstallRoot(mirroredPluginRoot, { env })).toBe(
763+installRoot,
764+);
765+expect(resolveBundledRuntimeDependencyInstallRoot(mirroredPluginRoot, { env })).not.toBe(
766+nestedUnknownRoot,
767+);
768+expect(
769+ensureBundledPluginRuntimeDeps({
770+ env,
771+installDeps: () => {
772+throw new Error("mirrored staged deps should not reinstall into a nested stage root");
773+},
774+pluginId: "telegram",
775+pluginRoot: mirroredPluginRoot,
776+}),
777+).toEqual({ installedSpecs: [], retainSpecs: [] });
778+});
779+729780it("retains existing staged deps without a retained manifest before shared installs", () => {
730781const packageRoot = makeTempDir();
731782const stageDir = makeTempDir();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。