diff --git a/src/channels/bundled-channel-catalog-read.fail-soft.test.ts b/src/channels/bundled-channel-catalog-read.fail-soft.test.ts new file mode 100644 index 00000000000..6cc95c3ca8d --- /dev/null +++ b/src/channels/bundled-channel-catalog-read.fail-soft.test.ts @@ -0,0 +1,28 @@ +import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures"; +import { afterEach, describe, expect, it, vi } from "vitest"; + +afterEach(() => { + vi.restoreAllMocks(); + vi.resetModules(); +}); + +describe("listBundledChannelCatalogEntries discovery failures", () => { + it("falls back when bundled plugin catalog discovery is unavailable during import", async () => { + vi.doMock("../infra/openclaw-root.js", () => ({ + resolveOpenClawPackageRootSync: () => null, + resolveOpenClawPackageRoot: async () => null, + })); + vi.doMock("../plugins/channel-catalog-registry.js", () => ({ + listChannelCatalogEntries() { + throw new ReferenceError("Cannot access 'discoverOpenClawPlugins' before initialization."); + }, + })); + + const catalog = await importFreshModule( + import.meta.url, + "./bundled-channel-catalog-read.js?scope=discovery-fail-soft", + ); + + expect(catalog.listBundledChannelCatalogEntries()).toEqual([]); + }); +}); diff --git a/src/channels/bundled-channel-catalog-read.ts b/src/channels/bundled-channel-catalog-read.ts index 4e4c2d571aa..2248a405dd5 100644 --- a/src/channels/bundled-channel-catalog-read.ts +++ b/src/channels/bundled-channel-catalog-read.ts @@ -28,7 +28,11 @@ function listPackageRoots(): string[] { } function readBundledExtensionCatalogEntriesSync(): PluginPackageChannel[] { - return listChannelCatalogEntries({ origin: "bundled" }).map((entry) => entry.channel); + try { + return listChannelCatalogEntries({ origin: "bundled" }).map((entry) => entry.channel); + } catch { + return []; + } } function readOfficialCatalogFileSync(): ChannelCatalogEntryLike[] {