test(plugins): cover registry refresh mutations

This commit is contained in:
Vincent Koc
2026-04-25 10:21:04 -07:00
parent 3ec92dfac0
commit 61b3c04424
4 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
import { beforeEach, describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import {
enablePluginInConfig,
loadConfig,
refreshPluginRegistry,
resetPluginsCliTestState,
runPluginsCommand,
writeConfigFile,
} from "./plugins-cli-test-helpers.js";
describe("plugins cli policy mutations", () => {
beforeEach(() => {
resetPluginsCliTestState();
});
it("refreshes the persisted plugin registry after enabling a plugin", async () => {
const enabledConfig = {
plugins: {
entries: {
alpha: { enabled: true },
},
},
} as OpenClawConfig;
loadConfig.mockReturnValue({} as OpenClawConfig);
enablePluginInConfig.mockReturnValue({
config: enabledConfig,
enabled: true,
});
await runPluginsCommand(["plugins", "enable", "alpha"]);
expect(writeConfigFile).toHaveBeenCalledWith(enabledConfig);
expect(refreshPluginRegistry).toHaveBeenCalledWith({
config: enabledConfig,
reason: "policy-changed",
});
});
it("refreshes the persisted plugin registry after disabling a plugin", async () => {
loadConfig.mockReturnValue({
plugins: {
entries: {
alpha: { enabled: true },
},
},
} as OpenClawConfig);
await runPluginsCommand(["plugins", "disable", "alpha"]);
const nextConfig = writeConfigFile.mock.calls[0]?.[0] as OpenClawConfig;
expect(nextConfig.plugins?.entries?.alpha?.enabled).toBe(false);
expect(refreshPluginRegistry).toHaveBeenCalledWith({
config: nextConfig,
reason: "policy-changed",
});
});
});

View File

@@ -5,6 +5,7 @@ import {
buildPluginDiagnosticsReport,
loadConfig,
promptYesNo,
refreshPluginRegistry,
resetPluginsCliTestState,
runPluginsCommand,
runtimeErrors,
@@ -47,6 +48,7 @@ describe("plugins cli uninstall", () => {
expect(uninstallPlugin).not.toHaveBeenCalled();
expect(writeConfigFile).not.toHaveBeenCalled();
expect(refreshPluginRegistry).not.toHaveBeenCalled();
expect(runtimeLogs.some((line) => line.includes("Dry run, no changes made."))).toBe(true);
});
@@ -101,6 +103,10 @@ describe("plugins cli uninstall", () => {
}),
);
expect(writeConfigFile).toHaveBeenCalledWith(nextConfig);
expect(refreshPluginRegistry).toHaveBeenCalledWith({
config: nextConfig,
reason: "source-changed",
});
});
it("exits when uninstall target is not managed by plugin install records", async () => {

View File

@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import {
loadConfig,
refreshPluginRegistry,
registerPluginsCli,
resetPluginsCliTestState,
runPluginsCommand,
@@ -106,6 +107,7 @@ describe("plugins cli update", () => {
}),
);
expect(writeConfigFile).toHaveBeenCalledWith(nextConfig);
expect(refreshPluginRegistry).not.toHaveBeenCalled();
expect(
runtimeLogs.some((line) => line.includes("Restart the gateway to load plugins and hooks.")),
).toBe(true);
@@ -209,6 +211,10 @@ describe("plugins cli update", () => {
}),
);
expect(writeConfigFile).toHaveBeenCalledWith(nextConfig);
expect(refreshPluginRegistry).toHaveBeenCalledWith({
config: nextConfig,
reason: "source-changed",
});
expect(
runtimeLogs.some((line) => line.includes("Restart the gateway to load plugins and hooks.")),
).toBe(true);

View File

@@ -3,6 +3,7 @@ import type { OpenClawConfig } from "../config/config.js";
import {
enablePluginInConfig,
recordPluginInstall,
refreshPluginRegistry,
resetPluginsCliTestState,
writeConfigFile,
} from "./plugins-cli-test-helpers.js";
@@ -60,5 +61,9 @@ describe("persistPluginInstall", () => {
expect(next).toBe(persistedConfig);
expect(writeConfigFile).toHaveBeenCalledWith(persistedConfig);
expect(refreshPluginRegistry).toHaveBeenCalledWith({
config: persistedConfig,
reason: "source-changed",
});
});
});