|
| 1 | +import { beforeEach, describe, expect, it } from "vitest"; |
| 2 | +import type { OpenClawConfig } from "../config/config.js"; |
| 3 | +import { |
| 4 | + enablePluginInConfig, |
| 5 | + recordPluginInstall, |
| 6 | + resetPluginsCliTestState, |
| 7 | + writeConfigFile, |
| 8 | +} from "./plugins-cli-test-helpers.js"; |
| 9 | + |
| 10 | +describe("persistPluginInstall", () => { |
| 11 | + beforeEach(() => { |
| 12 | + resetPluginsCliTestState(); |
| 13 | + }); |
| 14 | + |
| 15 | + it("adds installed plugins to restrictive allowlists before enabling", async () => { |
| 16 | + const { persistPluginInstall } = await import("./plugins-install-persist.js"); |
| 17 | + const baseConfig = { |
| 18 | + plugins: { |
| 19 | + allow: ["memory-core"], |
| 20 | + }, |
| 21 | + } as OpenClawConfig; |
| 22 | + const enabledConfig = { |
| 23 | + plugins: { |
| 24 | + allow: ["alpha", "memory-core"], |
| 25 | + entries: { |
| 26 | + alpha: { enabled: true }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + } as OpenClawConfig; |
| 30 | + const persistedConfig = { |
| 31 | + plugins: { |
| 32 | + ...enabledConfig.plugins, |
| 33 | + installs: { |
| 34 | + alpha: { |
| 35 | + source: "npm", |
| 36 | + |
| 37 | + installPath: "/tmp/alpha", |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + } as OpenClawConfig; |
| 42 | + |
| 43 | + enablePluginInConfig.mockImplementation((...args: unknown[]) => { |
| 44 | + const [cfg, pluginId] = args as [OpenClawConfig, string]; |
| 45 | + expect(pluginId).toBe("alpha"); |
| 46 | + expect(cfg.plugins?.allow).toEqual(["alpha", "memory-core"]); |
| 47 | + return { config: enabledConfig }; |
| 48 | + }); |
| 49 | + recordPluginInstall.mockReturnValue(persistedConfig); |
| 50 | + |
| 51 | + const next = await persistPluginInstall({ |
| 52 | + config: baseConfig, |
| 53 | + pluginId: "alpha", |
| 54 | + install: { |
| 55 | + source: "npm", |
| 56 | + |
| 57 | + installPath: "/tmp/alpha", |
| 58 | + }, |
| 59 | + }); |
| 60 | + |
| 61 | + expect(next).toBe(persistedConfig); |
| 62 | + expect(writeConfigFile).toHaveBeenCalledWith(persistedConfig); |
| 63 | + }); |
| 64 | +}); |
0 commit comments