mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 20:35:39 -06:00
test: tighten plugin uninstall assertions
This commit is contained in:
@@ -24,6 +24,26 @@ const CLI_STATE_ROOT = "/tmp/openclaw-state";
|
||||
const ALPHA_INSTALL_PATH = installedPluginRoot(CLI_STATE_ROOT, "alpha");
|
||||
const ORIGINAL_OPENCLAW_NIX_MODE = process.env.OPENCLAW_NIX_MODE;
|
||||
|
||||
function expectRuntimeLogIncludes(fragment: string) {
|
||||
expect(runtimeLogs.some((message) => message.includes(fragment))).toBe(true);
|
||||
}
|
||||
|
||||
function expectLatestUninstallPlanParams(expected: {
|
||||
pluginId: string;
|
||||
deleteFiles: boolean;
|
||||
channelIds?: unknown;
|
||||
}) {
|
||||
expect(planPluginUninstall).toHaveBeenCalled();
|
||||
const params = planPluginUninstall.mock.calls.at(-1)?.[0] as
|
||||
| { pluginId?: string; deleteFiles?: boolean; channelIds?: unknown }
|
||||
| undefined;
|
||||
expect(params?.pluginId).toBe(expected.pluginId);
|
||||
expect(params?.deleteFiles).toBe(expected.deleteFiles);
|
||||
if ("channelIds" in expected) {
|
||||
expect(params?.channelIds).toBe(expected.channelIds);
|
||||
}
|
||||
}
|
||||
|
||||
describe("plugins cli uninstall", () => {
|
||||
beforeEach(() => {
|
||||
resetPluginsCliTestState();
|
||||
@@ -104,12 +124,8 @@ describe("plugins cli uninstall", () => {
|
||||
expect(planPluginUninstall).toHaveBeenCalled();
|
||||
expect(writeConfigFile).not.toHaveBeenCalled();
|
||||
expect(refreshPluginRegistry).not.toHaveBeenCalled();
|
||||
expect(runtimeLogs).toEqual(
|
||||
expect.arrayContaining([expect.stringContaining("Dry run, no changes made.")]),
|
||||
);
|
||||
expect(runtimeLogs).toEqual(
|
||||
expect.arrayContaining([expect.stringContaining("context engine slot")]),
|
||||
);
|
||||
expectRuntimeLogIncludes("Dry run, no changes made.");
|
||||
expectRuntimeLogIncludes("context engine slot");
|
||||
});
|
||||
|
||||
it("uninstalls with --force and --keep-files without prompting", async () => {
|
||||
@@ -159,12 +175,7 @@ describe("plugins cli uninstall", () => {
|
||||
await runPluginsCommand(["plugins", "uninstall", "alpha", "--force", "--keep-files"]);
|
||||
|
||||
expect(promptYesNo).not.toHaveBeenCalled();
|
||||
expect(planPluginUninstall).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
pluginId: "alpha",
|
||||
deleteFiles: false,
|
||||
}),
|
||||
);
|
||||
expectLatestUninstallPlanParams({ pluginId: "alpha", deleteFiles: false });
|
||||
expect(writePersistedInstalledPluginIndexInstallRecords).toHaveBeenCalledWith({});
|
||||
expect(writeConfigFile).toHaveBeenCalledWith({
|
||||
plugins: {
|
||||
@@ -393,12 +404,7 @@ describe("plugins cli uninstall", () => {
|
||||
|
||||
await runPluginsCommand(["plugins", "uninstall", "alpha", "--force"]);
|
||||
|
||||
expect(planPluginUninstall).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
pluginId: "alpha",
|
||||
deleteFiles: true,
|
||||
}),
|
||||
);
|
||||
expectLatestUninstallPlanParams({ pluginId: "alpha", deleteFiles: true });
|
||||
expect(writeConfigFile).toHaveBeenCalledWith(nextConfig);
|
||||
expect(runtimeLogs.at(-2)).toContain('Uninstalled plugin "alpha"');
|
||||
});
|
||||
@@ -437,12 +443,7 @@ describe("plugins cli uninstall", () => {
|
||||
|
||||
await runPluginsCommand(["plugins", "uninstall", "alpha", "--force"]);
|
||||
|
||||
expect(planPluginUninstall).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
pluginId: "alpha",
|
||||
deleteFiles: true,
|
||||
}),
|
||||
);
|
||||
expectLatestUninstallPlanParams({ pluginId: "alpha", deleteFiles: true });
|
||||
expect(writeConfigFile).toHaveBeenCalledWith(nextConfig);
|
||||
expect(refreshPluginRegistry).toHaveBeenCalledWith({
|
||||
config: nextConfig,
|
||||
@@ -510,18 +511,14 @@ describe("plugins cli uninstall", () => {
|
||||
|
||||
await runPluginsCommand(["plugins", "uninstall", "alpha", "--force", "--keep-files"]);
|
||||
|
||||
expect(planPluginUninstall).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
pluginId: "alpha",
|
||||
channelIds: undefined,
|
||||
deleteFiles: false,
|
||||
}),
|
||||
);
|
||||
expectLatestUninstallPlanParams({
|
||||
pluginId: "alpha",
|
||||
channelIds: undefined,
|
||||
deleteFiles: false,
|
||||
});
|
||||
expect(writePersistedInstalledPluginIndexInstallRecords).toHaveBeenCalledWith({});
|
||||
expect(writeConfigFile).toHaveBeenCalledWith(nextConfig);
|
||||
expect(runtimeLogs).toEqual(
|
||||
expect.arrayContaining([expect.stringContaining("channel config (channels.alpha)")]),
|
||||
);
|
||||
expectRuntimeLogIncludes("channel config (channels.alpha)");
|
||||
expect(runtimeLogs.at(-2)).toContain('Uninstalled plugin "alpha"');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user