|
| 1 | +import { beforeEach, describe, expect, it } from "vitest"; |
| 2 | +import type { OpenClawConfig } from "../config/config.js"; |
| 3 | +import { |
| 4 | +enablePluginInConfig, |
| 5 | +loadConfig, |
| 6 | +refreshPluginRegistry, |
| 7 | +resetPluginsCliTestState, |
| 8 | +runPluginsCommand, |
| 9 | +writeConfigFile, |
| 10 | +} from "./plugins-cli-test-helpers.js"; |
| 11 | + |
| 12 | +describe("plugins cli policy mutations", () => { |
| 13 | +beforeEach(() => { |
| 14 | +resetPluginsCliTestState(); |
| 15 | +}); |
| 16 | + |
| 17 | +it("refreshes the persisted plugin registry after enabling a plugin", async () => { |
| 18 | +const enabledConfig = { |
| 19 | +plugins: { |
| 20 | +entries: { |
| 21 | +alpha: { enabled: true }, |
| 22 | +}, |
| 23 | +}, |
| 24 | +} as OpenClawConfig; |
| 25 | +loadConfig.mockReturnValue({} as OpenClawConfig); |
| 26 | +enablePluginInConfig.mockReturnValue({ |
| 27 | +config: enabledConfig, |
| 28 | +enabled: true, |
| 29 | +}); |
| 30 | + |
| 31 | +await runPluginsCommand(["plugins", "enable", "alpha"]); |
| 32 | + |
| 33 | +expect(writeConfigFile).toHaveBeenCalledWith(enabledConfig); |
| 34 | +expect(refreshPluginRegistry).toHaveBeenCalledWith({ |
| 35 | +config: enabledConfig, |
| 36 | +reason: "policy-changed", |
| 37 | +}); |
| 38 | +}); |
| 39 | + |
| 40 | +it("refreshes the persisted plugin registry after disabling a plugin", async () => { |
| 41 | +loadConfig.mockReturnValue({ |
| 42 | +plugins: { |
| 43 | +entries: { |
| 44 | +alpha: { enabled: true }, |
| 45 | +}, |
| 46 | +}, |
| 47 | +} as OpenClawConfig); |
| 48 | + |
| 49 | +await runPluginsCommand(["plugins", "disable", "alpha"]); |
| 50 | + |
| 51 | +const nextConfig = writeConfigFile.mock.calls[0]?.[0] as OpenClawConfig; |
| 52 | +expect(nextConfig.plugins?.entries?.alpha?.enabled).toBe(false); |
| 53 | +expect(refreshPluginRegistry).toHaveBeenCalledWith({ |
| 54 | +config: nextConfig, |
| 55 | +reason: "policy-changed", |
| 56 | +}); |
| 57 | +}); |
| 58 | +}); |