diff --git a/src/plugins/loader.ts b/src/plugins/loader.ts index ab127678da1..48a485d6325 100644 --- a/src/plugins/loader.ts +++ b/src/plugins/loader.ts @@ -1225,6 +1225,12 @@ export function resolveRuntimePluginRegistry( return loadOpenClawPlugins(options); } +export function getRuntimePluginRegistryForLoadOptions( + options?: PluginLoadOptions, +): PluginRegistry | undefined { + return resolveRuntimePluginRegistry(options); +} + export function resolvePluginRegistryLoadCacheKey(options: PluginLoadOptions = {}): string { return resolvePluginLoadCacheContext(options).cacheKey; } diff --git a/src/plugins/providers.runtime.ts b/src/plugins/providers.runtime.ts index 6423653b7a7..36c5c4f9c2d 100644 --- a/src/plugins/providers.runtime.ts +++ b/src/plugins/providers.runtime.ts @@ -3,9 +3,9 @@ import { resolveBundledPluginCompatibleActivationInputs } from "./activation-con import { resolveManifestActivationPluginIds } from "./activation-planner.js"; import { getLoadedRuntimePluginRegistry } from "./active-runtime-registry.js"; import { + getRuntimePluginRegistryForLoadOptions, isPluginRegistryLoadInFlight, loadOpenClawPlugins, - resolveRuntimePluginRegistry, type PluginLoadOptions, } from "./loader.js"; import { hasExplicitPluginIdScope } from "./plugin-scope.js"; @@ -312,13 +312,13 @@ export function resolvePluginProviders(params: { const loadState = resolveRuntimeProviderPluginLoadState(params, base); const registry = loadState.loadOptions.onlyPluginIds?.length === 0 - ? resolveRuntimePluginRegistry(loadState.loadOptions) + ? undefined : (getLoadedRuntimePluginRegistry({ env: base.env, loadOptions: loadState.loadOptions, workspaceDir: base.workspaceDir, requiredPluginIds: loadState.loadOptions.onlyPluginIds, - }) ?? resolveRuntimePluginRegistry(loadState.loadOptions)); + }) ?? getRuntimePluginRegistryForLoadOptions(loadState.loadOptions)); if (!registry) { return []; } diff --git a/src/plugins/providers.test.ts b/src/plugins/providers.test.ts index f3f114cd62c..d561399bf7e 100644 --- a/src/plugins/providers.test.ts +++ b/src/plugins/providers.test.ts @@ -9,6 +9,8 @@ import type { ProviderPlugin } from "./types.js"; type ResolveRuntimePluginRegistry = typeof import("./loader.js").resolveRuntimePluginRegistry; type ResolveCompatibleRuntimePluginRegistry = typeof import("./loader.js").resolveCompatibleRuntimePluginRegistry; +type GetRuntimePluginRegistryForLoadOptions = + typeof import("./loader.js").getRuntimePluginRegistryForLoadOptions; type LoadOpenClawPlugins = typeof import("./loader.js").loadOpenClawPlugins; type IsPluginRegistryLoadInFlight = typeof import("./loader.js").isPluginRegistryLoadInFlight; type LoadPluginManifestRegistry = @@ -17,6 +19,7 @@ type ApplyPluginAutoEnable = typeof import("../config/plugin-auto-enable.js").ap type SetActivePluginRegistry = typeof import("./runtime.js").setActivePluginRegistry; const resolveRuntimePluginRegistryMock = vi.fn(); +const getRuntimePluginRegistryForLoadOptionsMock = vi.fn(); const resolveCompatibleRuntimePluginRegistryMock = vi.fn(); const loadOpenClawPluginsMock = vi.fn(); const isPluginRegistryLoadInFlightMock = vi.fn((_) => false); @@ -375,6 +378,9 @@ describe("resolvePluginProviders", () => { resolveCompatibleRuntimePluginRegistry: ( ...args: Parameters ) => resolveCompatibleRuntimePluginRegistryMock(...args), + getRuntimePluginRegistryForLoadOptions: ( + ...args: Parameters + ) => getRuntimePluginRegistryForLoadOptionsMock(...args), resolveRuntimePluginRegistry: (...args: Parameters) => resolveRuntimePluginRegistryMock(...args), })); @@ -446,6 +452,7 @@ describe("resolvePluginProviders", () => { beforeEach(() => { setActivePluginRegistry(createEmptyPluginRegistry()); resolveRuntimePluginRegistryMock.mockReset(); + getRuntimePluginRegistryForLoadOptionsMock.mockReset(); resolveCompatibleRuntimePluginRegistryMock.mockReset(); loadOpenClawPluginsMock.mockReset(); isPluginRegistryLoadInFlightMock.mockReset(); @@ -458,6 +465,9 @@ describe("resolvePluginProviders", () => { const registry = createEmptyPluginRegistry(); registry.providers.push({ pluginId: "google", provider, source: "bundled" }); resolveRuntimePluginRegistryMock.mockReturnValue(registry); + getRuntimePluginRegistryForLoadOptionsMock.mockImplementation((...args) => + resolveRuntimePluginRegistryMock(...args), + ); loadOpenClawPluginsMock.mockReturnValue(registry); loadPluginManifestRegistryMock.mockReset(); applyPluginAutoEnableMock.mockReset(); @@ -1226,12 +1236,8 @@ describe("resolvePluginProviders", () => { }); expect(providers).toEqual([]); - expect(resolveRuntimePluginRegistryMock).toHaveBeenCalledWith( - expect.objectContaining({ - config: {}, - onlyPluginIds: [], - }), - ); + expect(resolveRuntimePluginRegistryMock).not.toHaveBeenCalled(); + expect(getRuntimePluginRegistryForLoadOptionsMock).not.toHaveBeenCalled(); }); it("does not auto-activate workspace runtime owners by default", () => { @@ -1254,12 +1260,8 @@ describe("resolvePluginProviders", () => { }); expect(providers).toEqual([]); - expect(resolveRuntimePluginRegistryMock).toHaveBeenCalledWith( - expect.objectContaining({ - config: {}, - onlyPluginIds: [], - }), - ); + expect(resolveRuntimePluginRegistryMock).not.toHaveBeenCalled(); + expect(getRuntimePluginRegistryForLoadOptionsMock).not.toHaveBeenCalled(); }); it("keeps explicit provider requests scoped when runtime owner activation resolves nothing", () => { @@ -1285,16 +1287,8 @@ describe("resolvePluginProviders", () => { }); expect(providers).toEqual([]); - expect(resolveRuntimePluginRegistryMock).toHaveBeenCalledWith( - expect.objectContaining({ - config: { - plugins: { - allow: ["other-plugin"], - }, - }, - onlyPluginIds: [], - }), - ); + expect(resolveRuntimePluginRegistryMock).not.toHaveBeenCalled(); + expect(getRuntimePluginRegistryForLoadOptionsMock).not.toHaveBeenCalled(); }); it("does not keep explicitly trusted disabled workspace setup owners discoverable", () => {