fix(update): honor update.channel for update.run

This commit is contained in:
Peter Steinberger
2026-02-03 17:57:44 -08:00
parent 61a7fc5e0e
commit bbe9cb3022
5 changed files with 98 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import type { GatewayRequestHandlers } from "./types.js";
import { loadConfig } from "../../config/config.js";
import { resolveOpenClawPackageRoot } from "../../infra/openclaw-root.js";
import {
formatDoctorNonInteractiveHint,
@@ -6,6 +7,7 @@ import {
writeRestartSentinel,
} from "../../infra/restart-sentinel.js";
import { scheduleGatewaySigusr1Restart } from "../../infra/restart.js";
import { normalizeUpdateChannel } from "../../infra/update-channels.js";
import { runGatewayUpdate } from "../../infra/update-runner.js";
import {
ErrorCodes,
@@ -48,6 +50,8 @@ export const updateHandlers: GatewayRequestHandlers = {
let result: Awaited<ReturnType<typeof runGatewayUpdate>>;
try {
const config = loadConfig();
const configChannel = normalizeUpdateChannel(config.update?.channel);
const root =
(await resolveOpenClawPackageRoot({
moduleUrl: import.meta.url,
@@ -58,6 +62,7 @@ export const updateHandlers: GatewayRequestHandlers = {
timeoutMs,
cwd: root,
argv1: process.argv[1],
channel: configChannel ?? undefined,
});
} catch (err) {
result = {

View File

@@ -16,6 +16,8 @@ vi.mock("../infra/update-runner.js", () => ({
})),
}));
import { writeConfigFile } from "../config/config.js";
import { runGatewayUpdate } from "../infra/update-runner.js";
import { sleep } from "../utils.js";
import {
connectOk,
@@ -193,6 +195,37 @@ describe("gateway update.run", () => {
process.off("SIGUSR1", sigusr1);
}
});
test("uses configured update channel", async () => {
const sigusr1 = vi.fn();
process.on("SIGUSR1", sigusr1);
try {
await writeConfigFile({ update: { channel: "beta" } });
const updateMock = vi.mocked(runGatewayUpdate);
updateMock.mockClear();
const id = "req-update-channel";
ws.send(
JSON.stringify({
type: "req",
id,
method: "update.run",
params: {
restartDelayMs: 0,
},
}),
);
const res = await onceMessage<{ ok: boolean; payload?: unknown }>(
ws,
(o) => o.type === "res" && o.id === id,
);
expect(res.ok).toBe(true);
expect(updateMock.mock.calls[0]?.[0]?.channel).toBe("beta");
} finally {
process.off("SIGUSR1", sigusr1);
}
});
});
describe("gateway node command allowlist", () => {