Skip to content

Commit b2da7aa

Browse files
authored
fix(plugins): link host declared as direct dependency (#117738)
1 parent 78193de commit b2da7aa

2 files changed

Lines changed: 79 additions & 51 deletions

File tree

‎src/plugins/install-installed-package.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export async function validatePackagePluginInstallSource(params: {
196196
? { setup: ocManifestResult.manifest.setup }
197197
: {}),
198198
hasRuntimeDependencies: hasPackageRuntimeDependencies(manifest),
199-
peerDependencies: manifest.peerDependencies ?? {},
199+
peerDependencies: { ...manifest.dependencies, ...manifest.peerDependencies },
200200
},
201201
};
202202
}

‎src/plugins/install.test.ts‎

Lines changed: 78 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,6 +3820,26 @@ describe("installPluginFromDir", () => {
38203820

38213821
describe("linkOpenClawPeerDependencies (via installPluginFromDir)", () => {
38223822
const resolveRootMock = vi.mocked(resolveOpenClawPackageRootSync);
3823+
const hostDependencyDeclarations: Array<{
3824+
declaration: string;
3825+
peerDependencies: Record<string, string>;
3826+
dependencies?: Record<string, string>;
3827+
}> = [
3828+
{
3829+
declaration: "peerDependencies",
3830+
peerDependencies: { openclaw: "*" },
3831+
},
3832+
{
3833+
declaration: "dependencies",
3834+
peerDependencies: {},
3835+
dependencies: { openclaw: "*" },
3836+
},
3837+
{
3838+
declaration: "dependencies alongside an unrelated peer dependency",
3839+
peerDependencies: { "unrelated-host": "^1.0.0" },
3840+
dependencies: { openclaw: "*" },
3841+
},
3842+
];
38233843

38243844
function writePluginWithPeerDeps(
38253845
pluginDir: string,
@@ -3841,27 +3861,29 @@ describe("linkOpenClawPeerDependencies (via installPluginFromDir)", () => {
38413861
fs.writeFileSync(path.join(pluginDir, "index.js"), "export {};\n", "utf-8");
38423862
}
38433863

3844-
it("creates a node_modules/openclaw symlink when peerDependencies declares openclaw", async () => {
3845-
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
3846-
const fakeHostRoot = suiteTempRootTracker.makeTempDir();
3847-
const run = vi.mocked(runCommandWithTimeout);
3848-
resolveRootMock.mockReturnValue(fakeHostRoot);
3864+
it.each(hostDependencyDeclarations)(
3865+
"creates a host-targeted node_modules/openclaw symlink for $declaration",
3866+
async ({ peerDependencies, dependencies }) => {
3867+
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
3868+
const fakeHostRoot = suiteTempRootTracker.makeTempDir();
3869+
const run = vi.mocked(runCommandWithTimeout);
3870+
resolveRootMock.mockReturnValue(fakeHostRoot);
38493871

3850-
writePluginWithPeerDeps(pluginDir, { openclaw: "*" });
3872+
writePluginWithPeerDeps(pluginDir, peerDependencies, dependencies);
38513873

3852-
const { result } = await installFromDirWithWarnings({ pluginDir, extensionsDir });
3874+
const { result } = await installFromDirWithWarnings({ pluginDir, extensionsDir });
38533875

3854-
expect(result.ok).toBe(true);
3855-
if (!result.ok) {
3856-
return;
3857-
}
3876+
expect(result.ok).toBe(true);
3877+
if (!result.ok) {
3878+
return;
3879+
}
38583880

3859-
const symlinkPath = path.join(result.targetDir, "node_modules", "openclaw");
3860-
const stat = fs.lstatSync(symlinkPath);
3861-
expect(stat.isSymbolicLink()).toBe(true);
3862-
expect(fs.realpathSync(symlinkPath)).toBe(fs.realpathSync(fakeHostRoot));
3863-
expect(run).not.toHaveBeenCalled();
3864-
});
3881+
const symlinkPath = path.join(result.targetDir, "node_modules", "openclaw");
3882+
expect(fs.lstatSync(symlinkPath).isSymbolicLink()).toBe(true);
3883+
expect(fs.realpathSync(symlinkPath)).toBe(fs.realpathSync(fakeHostRoot));
3884+
expect(run).not.toHaveBeenCalled();
3885+
},
3886+
);
38653887

38663888
it("keeps the openclaw peer symlink when a local plugin already has dependencies", async () => {
38673889
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
@@ -3890,33 +3912,36 @@ describe("linkOpenClawPeerDependencies (via installPluginFromDir)", () => {
38903912
expect(vi.mocked(runCommandWithTimeout)).not.toHaveBeenCalled();
38913913
});
38923914

3893-
it("replaces a copied local openclaw package with the host peer symlink", async () => {
3894-
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
3895-
const fakeHostRoot = suiteTempRootTracker.makeTempDir();
3896-
resolveRootMock.mockReturnValue(fakeHostRoot);
3915+
it.each(hostDependencyDeclarations)(
3916+
"replaces a copied local openclaw package with the host symlink for $declaration",
3917+
async ({ peerDependencies, dependencies }) => {
3918+
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
3919+
const fakeHostRoot = suiteTempRootTracker.makeTempDir();
3920+
resolveRootMock.mockReturnValue(fakeHostRoot);
38973921

3898-
writePluginWithPeerDeps(pluginDir, { openclaw: "*" });
3899-
fs.mkdirSync(path.join(pluginDir, "node_modules", "openclaw"), { recursive: true });
3900-
fs.writeFileSync(
3901-
path.join(pluginDir, "node_modules", "openclaw", "package.json"),
3902-
JSON.stringify({ name: "openclaw", version: "2026.5.31" }),
3903-
"utf-8",
3904-
);
3922+
writePluginWithPeerDeps(pluginDir, peerDependencies, dependencies);
3923+
fs.mkdirSync(path.join(pluginDir, "node_modules", "openclaw"), { recursive: true });
3924+
fs.writeFileSync(
3925+
path.join(pluginDir, "node_modules", "openclaw", "package.json"),
3926+
JSON.stringify({ name: "openclaw", version: "2026.5.31" }),
3927+
"utf-8",
3928+
);
39053929

3906-
const { result, warnings } = await installFromDirWithWarnings({ pluginDir, extensionsDir });
3930+
const { result, warnings } = await installFromDirWithWarnings({ pluginDir, extensionsDir });
39073931

3908-
expect(result.ok).toBe(true);
3909-
expect(warnings).toHaveLength(0);
3910-
if (!result.ok) {
3911-
return;
3912-
}
3932+
expect(result.ok).toBe(true);
3933+
expect(warnings).toHaveLength(0);
3934+
if (!result.ok) {
3935+
return;
3936+
}
39133937

3914-
const symlinkPath = path.join(result.targetDir, "node_modules", "openclaw");
3915-
expect(fs.lstatSync(symlinkPath).isSymbolicLink()).toBe(true);
3916-
expect(fs.realpathSync(symlinkPath)).toBe(fs.realpathSync(fakeHostRoot));
3917-
});
3938+
const symlinkPath = path.join(result.targetDir, "node_modules", "openclaw");
3939+
expect(fs.lstatSync(symlinkPath).isSymbolicLink()).toBe(true);
3940+
expect(fs.realpathSync(symlinkPath)).toBe(fs.realpathSync(fakeHostRoot));
3941+
},
3942+
);
39183943

3919-
it("does not create a symlink when peerDependencies is empty", async () => {
3944+
it("does not create a symlink when neither dependency map declares openclaw", async () => {
39203945
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
39213946
resolveRootMock.mockReturnValue(suiteTempRootTracker.makeTempDir());
39223947

@@ -3961,19 +3986,22 @@ describe("linkOpenClawPeerDependencies (via installPluginFromDir)", () => {
39613986
expect(fs.lstatSync(symlinkPath).isSymbolicLink()).toBe(true);
39623987
});
39633988

3964-
it("rejects when resolveOpenClawPackageRootSync returns null", async () => {
3965-
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
3966-
resolveRootMock.mockReturnValue(null);
3989+
it.each(hostDependencyDeclarations)(
3990+
"rejects $declaration when the host package root cannot be resolved",
3991+
async ({ peerDependencies, dependencies }) => {
3992+
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
3993+
resolveRootMock.mockReturnValue(null);
39673994

3968-
writePluginWithPeerDeps(pluginDir, { openclaw: "*" });
3995+
writePluginWithPeerDeps(pluginDir, peerDependencies, dependencies);
39693996

3970-
const { result, warnings } = await installFromDirWithWarnings({ pluginDir, extensionsDir });
3997+
const { result, warnings } = await installFromDirWithWarnings({ pluginDir, extensionsDir });
39713998

3972-
expect(result.ok).toBe(false);
3973-
if (!result.ok) {
3974-
expect(result.error).toContain("plugin-local node_modules/openclaw link");
3975-
}
3976-
expectWarningIncludes(warnings, "Could not locate openclaw package root");
3977-
});
3999+
expect(result.ok).toBe(false);
4000+
if (!result.ok) {
4001+
expect(result.error).toContain("plugin-local node_modules/openclaw link");
4002+
}
4003+
expectWarningIncludes(warnings, "Could not locate openclaw package root");
4004+
},
4005+
);
39784006
});
39794007
/* oxlint-disable max-lines -- TODO: split this grandfathered oversized file. */

0 commit comments

Comments
 (0)