From bc0b02b2a675808f38e7c0493fa7291b2418cc69 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 27 Apr 2026 11:15:37 +0100 Subject: [PATCH] fix(channels): avoid bundled plugin load paths --- CHANGELOG.md | 1 + .../channel-setup/plugin-install.test.ts | 6 +-- .../onboarding-plugin-install.test.ts | 49 ++++++++++++++++++- src/commands/onboarding-plugin-install.ts | 28 +++++++++++ 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9dec264bc1..5880db9da44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Docs: https://docs.openclaw.ai ### Fixes +- Channels/setup: treat bundled channel plugins as already bundled during `channels add` and onboarding, enabling them without writing redundant `plugins.load.paths` entries or path install records. Fixes #72740. Thanks @iCodePoet. - Git hooks: skip ignored staged paths when formatting and restaging pre-commit files, so merge commits no longer abort when `.gitignore` newly ignores staged merged content. Fixes #72744. Thanks @100yenadmin. - Memory-core/dreaming: add a supported `dreaming.model` knob for Dream Diary narrative subagents, wired through phase config and the existing plugin subagent model-override trust gate. Refs #65963. Thanks @esqandil and @mjamiv. - Memory-core/dreaming: treat request-scoped narrative fallback as expected, skip session cleanup when no subagent run was created, and remove duplicate phase-level cleanup so fallback no longer emits warning noise. Fixes #67152. Thanks @jsompis. diff --git a/src/commands/channel-setup/plugin-install.test.ts b/src/commands/channel-setup/plugin-install.test.ts index 3984a980089..656298a5002 100644 --- a/src/commands/channel-setup/plugin-install.test.ts +++ b/src/commands/channel-setup/plugin-install.test.ts @@ -446,9 +446,9 @@ describe("ensureChannelSetupPluginInstalled", () => { expect(select).not.toHaveBeenCalled(); expect(result.installed).toBe(true); - expect(result.cfg.plugins?.load?.paths).toContain( - bundledPluginRootAt("/opt/openclaw", "bundled-chat"), - ); + expect(result.cfg.plugins?.entries?.["bundled-chat"]?.enabled).toBe(true); + expect(result.cfg.plugins?.load?.paths).toBeUndefined(); + expect(result.cfg.plugins?.installs).toBeUndefined(); }); it("does not default to bundled local path when an external catalog overrides the npm spec", async () => { diff --git a/src/commands/onboarding-plugin-install.test.ts b/src/commands/onboarding-plugin-install.test.ts index 8df2d4a2a28..dadd4a824dd 100644 --- a/src/commands/onboarding-plugin-install.test.ts +++ b/src/commands/onboarding-plugin-install.test.ts @@ -5,7 +5,9 @@ import type { OpenClawConfig } from "../config/types.openclaw.js"; import type { PluginEnableResult } from "../plugins/enable.js"; import { withTempDir } from "../test-helpers/temp-dir.js"; -const resolveBundledInstallPlanForCatalogEntry = vi.hoisted(() => vi.fn(() => undefined)); +const resolveBundledInstallPlanForCatalogEntry = vi.hoisted(() => + vi.fn<(...args: unknown[]) => unknown>(() => undefined), +); vi.mock("../cli/plugin-install-plan.js", () => ({ resolveBundledInstallPlanForCatalogEntry, })); @@ -479,6 +481,51 @@ describe("ensureOnboardingPluginInstalled", () => { }); }); + it("enables bundled plugins without adding their bundled directory as a local install", async () => { + await withTempDir({ prefix: "openclaw-onboarding-install-bundled-record-" }, async (temp) => { + const bundledDir = path.join(temp, "dist", "extensions", "discord"); + await fs.mkdir(bundledDir, { recursive: true }); + const realBundledDir = await fs.realpath(bundledDir); + resolveBundledInstallPlanForCatalogEntry.mockReturnValueOnce({ + bundledSource: { + localPath: realBundledDir, + }, + }); + enablePluginInConfig.mockReturnValueOnce({ + config: { + plugins: { + entries: { + discord: { enabled: true }, + }, + }, + }, + enabled: true, + }); + + const result = await ensureOnboardingPluginInstalled({ + cfg: {}, + entry: { + pluginId: "discord", + label: "Discord", + install: { + npmSpec: "@openclaw/discord", + }, + }, + prompter: { + select: vi.fn(async () => "local"), + } as never, + runtime: {} as never, + promptInstall: false, + }); + + expect(result.installed).toBe(true); + expect(result.cfg.plugins?.entries?.discord?.enabled).toBe(true); + expect(result.cfg.plugins?.load?.paths).toBeUndefined(); + expect(result.cfg.plugins?.installs).toBeUndefined(); + expect(recordPluginInstall).not.toHaveBeenCalled(); + }); + }); + it("records local install source metadata when npm install falls back to local", async () => { await withTempDir( { prefix: "openclaw-onboarding-install-npm-fallback-record-" }, diff --git a/src/commands/onboarding-plugin-install.ts b/src/commands/onboarding-plugin-install.ts index 52e107c8891..4c61f48b061 100644 --- a/src/commands/onboarding-plugin-install.ts +++ b/src/commands/onboarding-plugin-install.ts @@ -116,6 +116,18 @@ function addPluginLoadPath(cfg: OpenClawConfig, pluginPath: string): OpenClawCon }; } +function pathsReferToSameDirectory( + left: string | null | undefined, + right: string | null | undefined, +): boolean { + if (!left || !right) { + return false; + } + const realLeft = resolveRealDirectory(left); + const realRight = resolveRealDirectory(right); + return Boolean(realLeft && realRight && realLeft === realRight); +} + function formatPortableLocalPath(localPath: string, workspaceDir?: string): string | undefined { const bases = [workspaceDir, process.cwd()].filter((entry): entry is string => Boolean(entry)); for (const base of bases) { @@ -478,6 +490,14 @@ export async function ensureOnboardingPluginInstalled(params: { status: "failed", }; } + if (pathsReferToSameDirectory(localPath, bundledLocalPath)) { + return { + cfg: enableResult.config, + installed: true, + pluginId: entry.pluginId, + status: "installed", + }; + } next = addPluginLoadPath(enableResult.config, localPath); next = await recordLocalPluginInstall({ cfg: next, entry, localPath, npmSpec, workspaceDir }); return { @@ -595,6 +615,14 @@ export async function ensureOnboardingPluginInstalled(params: { status: "failed", }; } + if (pathsReferToSameDirectory(localPath, bundledLocalPath)) { + return { + cfg: enableResult.config, + installed: true, + pluginId: entry.pluginId, + status: "installed", + }; + } next = addPluginLoadPath(enableResult.config, localPath); next = await recordLocalPluginInstall({ cfg: next, entry, localPath, npmSpec, workspaceDir }); return {