mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:00:43 +00:00
fix: roll back plugin index on config write conflicts
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
loadConfig,
|
||||
promptYesNo,
|
||||
refreshPluginRegistry,
|
||||
replaceConfigFile,
|
||||
resetPluginsCliTestState,
|
||||
runPluginsCommand,
|
||||
runtimeErrors,
|
||||
@@ -122,6 +123,62 @@ describe("plugins cli uninstall", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("restores install records when the config write rejects during uninstall", async () => {
|
||||
const installRecords = {
|
||||
alpha: {
|
||||
source: "path",
|
||||
sourcePath: ALPHA_INSTALL_PATH,
|
||||
installPath: ALPHA_INSTALL_PATH,
|
||||
},
|
||||
} as const;
|
||||
const baseConfig = {
|
||||
plugins: {
|
||||
entries: {
|
||||
alpha: { enabled: true },
|
||||
},
|
||||
installs: installRecords,
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const nextConfig = {
|
||||
plugins: {
|
||||
entries: {},
|
||||
installs: {},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
|
||||
loadConfig.mockReturnValue(baseConfig);
|
||||
setInstalledPluginIndexInstallRecords(installRecords);
|
||||
buildPluginDiagnosticsReport.mockReturnValue({
|
||||
plugins: [{ id: "alpha", name: "alpha" }],
|
||||
diagnostics: [],
|
||||
});
|
||||
uninstallPlugin.mockResolvedValue({
|
||||
ok: true,
|
||||
config: nextConfig,
|
||||
warnings: [],
|
||||
actions: {
|
||||
entry: true,
|
||||
install: true,
|
||||
allowlist: false,
|
||||
loadPath: false,
|
||||
memorySlot: false,
|
||||
directory: false,
|
||||
},
|
||||
});
|
||||
replaceConfigFile.mockRejectedValueOnce(new Error("config changed"));
|
||||
|
||||
await expect(
|
||||
runPluginsCommand(["plugins", "uninstall", "alpha", "--force", "--keep-files"]),
|
||||
).rejects.toThrow("config changed");
|
||||
|
||||
expect(writePersistedInstalledPluginIndexInstallRecords).toHaveBeenNthCalledWith(1, {});
|
||||
expect(writePersistedInstalledPluginIndexInstallRecords).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
installRecords,
|
||||
);
|
||||
expect(refreshPluginRegistry).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("exits when uninstall target is not managed by plugin install records", async () => {
|
||||
loadConfig.mockReturnValue({
|
||||
plugins: {
|
||||
|
||||
Reference in New Issue
Block a user