Download src/plugins/runtime/metadata-registry-loader.test.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 7.22 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/plugins/runtime/metadata-registry-loader.test.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/plugins/runtime/metadata-registry-loader.test.ts
-
curl -L -o metadata-registry-loader.test.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/plugins/runtime/metadata-registry-loader.test.ts
7.22 kB
| // Metadata registry loader tests cover metadata-only plugin registry assembly. | |
| import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; | |
| import { createInfoWarnErrorLogger } from "../../../test/helpers/mock-logger.js"; | |
| import type { PluginLoadOptions } from "../loader.js"; | |
| const loadConfigMock = vi.fn(); | |
| const applyPluginAutoEnableMock = vi.fn(); | |
| const loadOpenClawPluginsMock = vi.fn(); | |
| let loadPluginMetadataRegistrySnapshot: typeof import("./metadata-registry-loader.js").loadPluginMetadataRegistrySnapshot; | |
| vi.mock("../../config/config.js", () => ({ | |
| getRuntimeConfig: () => loadConfigMock(), | |
| loadConfig: () => loadConfigMock(), | |
| })); | |
| vi.mock("../../config/plugin-auto-enable.js", () => ({ | |
| applyPluginAutoEnable: (...args: unknown[]) => applyPluginAutoEnableMock(...args), | |
| })); | |
| vi.mock("../loader.js", () => ({ | |
| loadOpenClawPlugins: (...args: unknown[]) => loadOpenClawPluginsMock(...args), | |
| loadPluginRegistryHandle: (options: Record<string, unknown> = {}) => | |
| loadOpenClawPluginsMock({ ...options, activate: false }), | |
| })); | |
| vi.mock("../../agents/agent-scope.js", () => ({ | |
| listAgentEntries: vi.fn<typeof import("../../agents/agent-scope.js").listAgentEntries>(() => []), | |
| resolveAgentWorkspaceDir: () => "/resolved-workspace", | |
| tryResolveConfiguredAgentWorkspaceDir: vi.fn< | |
| typeof import("../../agents/agent-scope.js").tryResolveConfiguredAgentWorkspaceDir | |
| >(() => "/resolved-workspace"), | |
| resolveDefaultAgentId: () => "default", | |
| })); | |
| vi.mock("../control-plane-workspace.js", () => ({ | |
| resolvePluginControlPlaneWorkspace: (params: { workspaceDir?: string }) => ({ | |
| workspaceDir: params.workspaceDir ?? "/resolved-workspace", | |
| workspaceScope: "selected", | |
| }), | |
| })); | |
| function getOnlyLoadOpenClawPluginsOptions(): PluginLoadOptions { | |
| expect(loadOpenClawPluginsMock).toHaveBeenCalledTimes(1); | |
| const options = loadOpenClawPluginsMock.mock.calls[0]?.[0]; | |
| if (!options || typeof options !== "object") { | |
| throw new Error("expected loadOpenClawPlugins to receive plugin load options"); | |
| } | |
| return options as PluginLoadOptions; | |
| } | |
| describe("loadPluginMetadataRegistrySnapshot", () => { | |
| beforeAll(async () => { | |
| ({ loadPluginMetadataRegistrySnapshot } = await import("./metadata-registry-loader.js")); | |
| }); | |
| beforeEach(() => { | |
| loadConfigMock.mockReset(); | |
| applyPluginAutoEnableMock.mockReset(); | |
| loadOpenClawPluginsMock.mockReset(); | |
| loadConfigMock.mockReturnValue({ plugins: {} }); | |
| applyPluginAutoEnableMock.mockImplementation((params: { config: unknown }) => ({ | |
| config: params.config, | |
| changes: [], | |
| autoEnabledReasons: {}, | |
| })); | |
| loadOpenClawPluginsMock.mockReturnValue({ plugins: [], diagnostics: [] }); | |
| }); | |
| it("defaults to a non-activating validate snapshot", () => { | |
| loadPluginMetadataRegistrySnapshot({ | |
| config: { plugins: {} }, | |
| activationSourceConfig: { plugins: { allow: ["demo"] } }, | |
| env: { HOME: "/tmp/openclaw-home" } as NodeJS.ProcessEnv, | |
| workspaceDir: "/workspace", | |
| onlyPluginIds: ["demo"], | |
| }); | |
| const loadOptions = getOnlyLoadOpenClawPluginsOptions(); | |
| expect(loadOptions).toMatchObject({ | |
| config: { plugins: {} }, | |
| activationSourceConfig: { plugins: { allow: ["demo"] } }, | |
| autoEnabledReasons: {}, | |
| workspaceDir: "/workspace", | |
| env: { HOME: "/tmp/openclaw-home" }, | |
| throwOnLoadError: true, | |
| cache: false, | |
| activate: false, | |
| mode: "validate", | |
| loadModules: undefined, | |
| onlyPluginIds: ["demo"], | |
| }); | |
| expect(loadOptions.logger).toBeDefined(); | |
| }); | |
| it("forwards explicit manifest-only requests", () => { | |
| loadPluginMetadataRegistrySnapshot({ | |
| config: { plugins: {} }, | |
| loadModules: false, | |
| }); | |
| const loadOptions = getOnlyLoadOpenClawPluginsOptions(); | |
| expect(loadOptions).toMatchObject({ | |
| config: { plugins: {} }, | |
| activationSourceConfig: { plugins: {} }, | |
| autoEnabledReasons: {}, | |
| workspaceDir: "/resolved-workspace", | |
| throwOnLoadError: true, | |
| cache: false, | |
| activate: false, | |
| mode: "validate", | |
| loadModules: false, | |
| }); | |
| expect(loadOptions.env === process.env).toBe(true); | |
| expect(loadOptions.logger).toBeDefined(); | |
| }); | |
| it("forwards an explicit logger through metadata snapshots", () => { | |
| const logger = createInfoWarnErrorLogger(); | |
| loadPluginMetadataRegistrySnapshot({ | |
| config: { plugins: {} }, | |
| logger, | |
| workspaceDir: "/workspace", | |
| }); | |
| const { env, ...loadOptions } = getOnlyLoadOpenClawPluginsOptions(); | |
| expect(loadOptions).toMatchObject({ | |
| config: { plugins: {} }, | |
| activationSourceConfig: { plugins: {} }, | |
| autoEnabledReasons: {}, | |
| workspaceDir: "/workspace", | |
| logger, | |
| throwOnLoadError: true, | |
| cache: false, | |
| activate: false, | |
| mode: "validate", | |
| loadModules: undefined, | |
| }); | |
| // Preserve the env subset check without handing its values to the matcher. | |
| expect( | |
| env !== undefined && Object.entries(process.env).every(([key, value]) => env[key] === value), | |
| ).toBe(true); | |
| }); | |
| it("honors explicit load options when reusing a resolved runtime context", () => { | |
| const logger = createInfoWarnErrorLogger(); | |
| const env = { HOME: "/tmp/context-home" } as NodeJS.ProcessEnv; | |
| const manifestRegistry = { plugins: [], diagnostics: [] }; | |
| loadPluginMetadataRegistrySnapshot({ | |
| config: { plugins: { allow: ["compat-provider"] } }, | |
| activationSourceConfig: { plugins: { allow: ["raw-plugin"] } }, | |
| workspaceDir: "/compat-workspace", | |
| env, | |
| logger, | |
| manifestRegistry, | |
| runtimeContext: { | |
| rawConfig: { plugins: { allow: ["raw-plugin"] } }, | |
| config: { plugins: { allow: ["raw-plugin"] } }, | |
| activationSourceConfig: { plugins: { allow: ["raw-plugin"] } }, | |
| autoEnabledReasons: {}, | |
| workspaceDir: "/context-workspace", | |
| env, | |
| logger, | |
| }, | |
| }); | |
| expect(applyPluginAutoEnableMock).not.toHaveBeenCalled(); | |
| expect(getOnlyLoadOpenClawPluginsOptions()).toEqual({ | |
| config: { plugins: { allow: ["compat-provider"] } }, | |
| activationSourceConfig: { plugins: { allow: ["raw-plugin"] } }, | |
| autoEnabledReasons: {}, | |
| workspaceDir: "/compat-workspace", | |
| env, | |
| logger, | |
| throwOnLoadError: true, | |
| cache: false, | |
| activate: false, | |
| mode: "validate", | |
| loadModules: undefined, | |
| manifestRegistry, | |
| installRecords: undefined, | |
| }); | |
| }); | |
| it("preserves explicit empty plugin scopes on metadata snapshots", () => { | |
| loadPluginMetadataRegistrySnapshot({ | |
| config: { plugins: {} }, | |
| onlyPluginIds: [], | |
| }); | |
| const loadOptions = getOnlyLoadOpenClawPluginsOptions(); | |
| expect(loadOptions).toMatchObject({ | |
| config: { plugins: {} }, | |
| activationSourceConfig: { plugins: {} }, | |
| autoEnabledReasons: {}, | |
| workspaceDir: "/resolved-workspace", | |
| throwOnLoadError: true, | |
| cache: false, | |
| activate: false, | |
| mode: "validate", | |
| loadModules: undefined, | |
| onlyPluginIds: [], | |
| }); | |
| expect(loadOptions.env === process.env).toBe(true); | |
| expect(loadOptions.logger).toBeDefined(); | |
| }); | |
| }); | |