mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:10:43 +00:00
test(plugins): cover registry refresh mutations
This commit is contained in:
58
src/cli/plugins-cli.policy.test.ts
Normal file
58
src/cli/plugins-cli.policy.test.ts
Normal 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",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user