fix: defer plugin sync after git switch

This commit is contained in:
Peter Steinberger
2026-04-06 00:46:38 +01:00
parent 3bc17fc823
commit be16cf2f0d
2 changed files with 49 additions and 6 deletions

View File

@@ -132,6 +132,7 @@ vi.mock("../utils.js", () => ({
isRecord: (value: unknown) =>
typeof value === "object" && value !== null && !Array.isArray(value),
pathExists: (...args: unknown[]) => pathExists(...args),
resolveConfigDir: () => "/tmp/openclaw-config",
}));
vi.mock("../plugins/update.js", () => ({
@@ -1006,6 +1007,34 @@ describe("update-cli", () => {
expect(lastWrite?.nextConfig?.update?.channel).toBe("beta");
});
it("skips plugin sync in the old process after switching from package to git", async () => {
const tempDir = createCaseDir("openclaw-update");
mockPackageInstallStatus(tempDir);
vi.mocked(runGatewayUpdate).mockResolvedValue(
makeOkUpdateResult({
mode: "git",
root: path.join(tempDir, "..", "openclaw"),
after: { version: "2026.4.5" },
}),
);
syncPluginsForUpdateChannel.mockRejectedValue(
new Error("Config validation failed: old host version"),
);
await updateCommand({ channel: "dev", yes: true });
expect(syncPluginsForUpdateChannel).not.toHaveBeenCalled();
expect(defaultRuntime.exit).not.toHaveBeenCalledWith(1);
expect(
vi
.mocked(defaultRuntime.log)
.mock.calls.map((call) => String(call[0]))
.join("\n"),
).toContain(
"Skipped plugin update sync in the pre-update CLI process after switching to a git install.",
);
});
it.each([
{
name: "refreshes service env when already installed",

View File

@@ -1061,12 +1061,26 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
}
}
await updatePluginsAfterCoreUpdate({
root,
channel,
configSnapshot: postUpdateConfigSnapshot,
opts,
});
// A package -> git switch still runs inside the pre-update CLI process.
// Plugin sync/validation can then compare new bundled plugin minima against
// the old host version and fail even though the install itself succeeded.
const deferPluginSync = switchToGit && result.mode === "git";
if (deferPluginSync) {
if (!opts.json) {
defaultRuntime.log(
theme.muted(
"Skipped plugin update sync in the pre-update CLI process after switching to a git install.",
),
);
}
} else {
await updatePluginsAfterCoreUpdate({
root,
channel,
configSnapshot: postUpdateConfigSnapshot,
opts,
});
}
await tryWriteCompletionCache(root, Boolean(opts.json));
await tryInstallShellCompletion({