Skip to content

Commit 344cc44

Browse files
committed
fix(update): repair rebased CI coverage
1 parent d4e49a4 commit 344cc44

5 files changed

Lines changed: 149 additions & 114 deletions

File tree

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18070,21 +18070,25 @@ public struct UpdateStatusParams: Codable, Sendable {}
1807018070
public struct UpdateStatusResult: Codable, Sendable {
1807118071
public let sentinel: AnyCodable
1807218072
public let updateavailable: AnyCodable
18073+
public let effectivechannel: AnyCodable?
1807318074
public let schedule: UpdateScheduleState?
1807418075

1807518076
public init(
1807618077
sentinel: AnyCodable,
1807718078
updateavailable: AnyCodable,
18079+
effectivechannel: AnyCodable? = nil,
1807818080
schedule: UpdateScheduleState? = nil)
1807918081
{
1808018082
self.sentinel = sentinel
1808118083
self.updateavailable = updateavailable
18084+
self.effectivechannel = effectivechannel
1808218085
self.schedule = schedule
1808318086
}
1808418087

1808518088
private enum CodingKeys: String, CodingKey {
1808618089
case sentinel
1808718090
case updateavailable = "updateAvailable"
18091+
case effectivechannel = "effectiveChannel"
1808818092
case schedule
1808918093
}
1809018094
}

‎src/commands/status.update-channel.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ describe("resolveStatusRegistryUpdateChannel", () => {
2020
expect(
2121
resolveStatusRegistryUpdateChannel({
2222
installKind: "git",
23-
git: { branch: "main" },
23+
git: {
24+
root: "/tmp/openclaw",
25+
sha: null,
26+
tag: null,
27+
branch: "main",
28+
upstream: "origin/main",
29+
dirty: false,
30+
ahead: 0,
31+
behind: 0,
32+
fetchOk: true,
33+
},
2434
}),
2535
).toBe("dev");
2636
});

‎src/gateway/server-methods/update-effective-channel.test.ts‎

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
import { beforeEach, describe, expect, it, vi } from "vitest";
22

3+
type TestUpdateAvailable = {
4+
currentVersion: string;
5+
latestVersion: string;
6+
channel: string;
7+
} | null;
8+
type TestUpdateSentinel = {
9+
kind: string;
10+
status: string;
11+
ts: number;
12+
stats: Record<string, unknown>;
13+
} | null;
14+
type TestUpdateSchedule =
15+
| import("../../../packages/gateway-protocol/src/index.js").UpdateScheduleState
16+
| null;
17+
318
const checkUpdateStatusMock = vi.hoisted(() => vi.fn());
419
const versionMock = vi.hoisted(() => ({ value: "1.0.0" }));
20+
const getUpdateAvailableMock = vi.hoisted(() => vi.fn<() => TestUpdateAvailable>(() => null));
21+
const getUpdateScheduleMock = vi.hoisted(() => vi.fn<() => TestUpdateSchedule>(() => null));
22+
const refreshGatewayUpdateStatusMock = vi.hoisted(() => vi.fn(async () => {}));
23+
const getLatestUpdateRestartSentinelMock = vi.hoisted(() =>
24+
vi.fn<() => TestUpdateSentinel>(() => null),
25+
);
26+
const refreshLatestUpdateRestartSentinelMock = vi.hoisted(() =>
27+
vi.fn<() => Promise<TestUpdateSentinel>>(async () => null),
28+
);
529

630
vi.mock("../../infra/openclaw-root.js", async () => {
731
const actual = await vi.importActual<typeof import("../../infra/openclaw-root.js")>(
@@ -15,9 +39,9 @@ vi.mock("../../infra/update-check.js", () => ({
1539
}));
1640

1741
vi.mock("../../infra/update-startup.js", () => ({
18-
getUpdateAvailable: () => null,
19-
getUpdateSchedule: () => null,
20-
refreshGatewayUpdateStatus: async () => {},
42+
getUpdateAvailable: getUpdateAvailableMock,
43+
getUpdateSchedule: getUpdateScheduleMock,
44+
refreshGatewayUpdateStatus: refreshGatewayUpdateStatusMock,
2145
}));
2246

2347
vi.mock("../../version.js", () => ({
@@ -27,8 +51,8 @@ vi.mock("../../version.js", () => ({
2751
}));
2852

2953
vi.mock("../server-restart-sentinel.js", () => ({
30-
getLatestUpdateRestartSentinel: () => null,
31-
refreshLatestUpdateRestartSentinel: async () => null,
54+
getLatestUpdateRestartSentinel: getLatestUpdateRestartSentinelMock,
55+
refreshLatestUpdateRestartSentinel: refreshLatestUpdateRestartSentinelMock,
3256
}));
3357

3458
vi.mock("./validation.js", () => ({
@@ -38,6 +62,16 @@ vi.mock("./validation.js", () => ({
3862
beforeEach(() => {
3963
versionMock.value = "1.0.0";
4064
checkUpdateStatusMock.mockReset();
65+
getUpdateAvailableMock.mockReset();
66+
getUpdateAvailableMock.mockReturnValue(null);
67+
getUpdateScheduleMock.mockReset();
68+
getUpdateScheduleMock.mockReturnValue(null);
69+
refreshGatewayUpdateStatusMock.mockReset();
70+
refreshGatewayUpdateStatusMock.mockResolvedValue(undefined);
71+
getLatestUpdateRestartSentinelMock.mockReset();
72+
getLatestUpdateRestartSentinelMock.mockReturnValue(null);
73+
refreshLatestUpdateRestartSentinelMock.mockReset();
74+
refreshLatestUpdateRestartSentinelMock.mockResolvedValue(null);
4175
});
4276

4377
describe("update.status effective channel", () => {
@@ -66,4 +100,68 @@ describe("update.status effective channel", () => {
66100
expect.objectContaining({ effectiveChannel: "extended-stable" }),
67101
);
68102
});
103+
104+
it("refreshes the latest update sentinel before responding", async () => {
105+
getUpdateAvailableMock.mockReturnValueOnce({
106+
currentVersion: "1.0.0",
107+
latestVersion: "2.0.0",
108+
channel: "latest",
109+
});
110+
getLatestUpdateRestartSentinelMock.mockReturnValueOnce({
111+
kind: "update",
112+
status: "skipped",
113+
ts: 1,
114+
stats: { reason: "restart-health-pending" },
115+
});
116+
refreshLatestUpdateRestartSentinelMock.mockResolvedValueOnce({
117+
kind: "update",
118+
status: "ok",
119+
ts: 2,
120+
stats: { after: { version: "2.0.0" } },
121+
});
122+
getUpdateScheduleMock.mockReturnValueOnce({ channel: "beta", autoEnabled: true });
123+
const { updateHandlers } = await import("./update.js");
124+
const respond = vi.fn();
125+
126+
const handler = updateHandlers["update.status"];
127+
if (!handler) {
128+
throw new Error("update.status handler is unavailable");
129+
}
130+
await handler({ params: {}, respond } as never);
131+
132+
expect(refreshLatestUpdateRestartSentinelMock).toHaveBeenCalledTimes(1);
133+
expect(respond).toHaveBeenCalledWith(
134+
true,
135+
expect.objectContaining({
136+
sentinel: expect.objectContaining({ kind: "update", status: "ok" }),
137+
updateAvailable: expect.objectContaining({ latestVersion: "2.0.0" }),
138+
schedule: expect.objectContaining({ channel: "beta" }),
139+
}),
140+
);
141+
});
142+
143+
it("falls back to the cached update sentinel when refresh fails", async () => {
144+
refreshLatestUpdateRestartSentinelMock.mockRejectedValueOnce(new Error("read failed"));
145+
getLatestUpdateRestartSentinelMock.mockReturnValueOnce({
146+
kind: "update",
147+
status: "skipped",
148+
ts: 1,
149+
stats: { reason: "restart-health-pending" },
150+
});
151+
const warn = vi.fn();
152+
const { updateHandlers } = await import("./update.js");
153+
const respond = vi.fn();
154+
155+
const handler = updateHandlers["update.status"];
156+
if (!handler) {
157+
throw new Error("update.status handler is unavailable");
158+
}
159+
await handler({ params: {}, respond, context: { logGateway: { warn } } } as never);
160+
161+
expect(warn).toHaveBeenCalledWith("update.status sentinel refresh failed: read failed");
162+
expect(respond).toHaveBeenCalledWith(
163+
true,
164+
expect.objectContaining({ sentinel: expect.objectContaining({ status: "skipped" }) }),
165+
);
166+
});
69167
});

‎src/gateway/server-methods/update-run-campaign.test.ts‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { withEnvAsync } from "../../test-utils/env.js";
1212
let currentCampaignId: string | undefined;
1313
let updateSchedule: UpdateScheduleState | null;
1414
let updateChannel: "stable" | "beta" | "dev" | null;
15+
const versionMock = vi.hoisted(() => ({ value: "1.0.0" }));
1516
type UpdateCampaignAdoption = NonNullable<ReturnType<UpdateCampaignController["adopt"]>>;
1617

1718
const adoptCampaignMock = vi.fn<() => UpdateCampaignAdoption | undefined>(() => ({
@@ -103,9 +104,12 @@ vi.mock("../../infra/update-campaign.js", () => ({
103104
},
104105
}));
105106

106-
vi.mock("../../infra/update-channels.js", () => ({
107-
normalizeUpdateChannel: () => updateChannel,
108-
}));
107+
vi.mock("../../infra/update-channels.js", async () => {
108+
const actual = await vi.importActual<typeof import("../../infra/update-channels.js")>(
109+
"../../infra/update-channels.js",
110+
);
111+
return { ...actual, normalizeUpdateChannel: () => updateChannel };
112+
});
109113

110114
vi.mock("../../infra/update-managed-service-handoff.js", () => ({
111115
buildManagedServiceHandoffUnavailableMessage: () => "handoff unavailable",
@@ -131,6 +135,12 @@ vi.mock("../../infra/update-startup.js", () => ({
131135
getUpdateSchedule: () => updateSchedule,
132136
}));
133137

138+
vi.mock("../../version.js", () => ({
139+
get VERSION() {
140+
return versionMock.value;
141+
},
142+
}));
143+
134144
vi.mock("../server-restart-sentinel.js", () => ({
135145
getLatestUpdateRestartSentinel: () => null,
136146
recordLatestUpdateRestartSentinel: () => undefined,
@@ -157,6 +167,7 @@ beforeEach(() => {
157167
currentCampaignId = "campaign-1";
158168
updateSchedule = null;
159169
updateChannel = null;
170+
versionMock.value = "1.0.0";
160171
adoptCampaignMock.mockReset();
161172
adoptCampaignMock.mockReturnValue({
162173
campaignId: "campaign-1",
@@ -269,6 +280,23 @@ describe("update.run campaign ownership", () => {
269280
);
270281
});
271282

283+
it("keeps a configless extended-stable package install on that channel", async () => {
284+
versionMock.value = "2026.6.33";
285+
detectRespawnSupervisorMock.mockReturnValueOnce("launchd");
286+
resolveUpdateInstallSurfaceMock.mockResolvedValueOnce({
287+
kind: "global",
288+
mode: "npm",
289+
root: "/tmp/openclaw",
290+
packageRoot: "/tmp/openclaw",
291+
});
292+
293+
await withEnvAsync({ OPENCLAW_LAUNCHD_LABEL: "ai.openclaw.gateway" }, invokeUpdateRun);
294+
295+
expect(startManagedServiceUpdateHandoffMock).toHaveBeenCalledWith(
296+
expect.objectContaining({ channel: "extended-stable" }),
297+
);
298+
});
299+
272300
it("keeps a plain package update on the moving configured channel", async () => {
273301
updateChannel = "beta";
274302
adoptCampaignMock.mockReturnValueOnce(undefined);

‎src/gateway/server-methods/update.test.ts‎

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -817,20 +817,6 @@ describe("update.run restart scheduling", () => {
817817
);
818818
});
819819

820-
it("keeps a configless extended-stable package install on that channel", async () => {
821-
versionMock.value = "2026.6.33";
822-
detectRespawnSupervisorMock.mockReturnValueOnce("launchd");
823-
mockGlobalInstallSurface();
824-
825-
await withProcessEnv({ OPENCLAW_LAUNCHD_LABEL: "ai.openclaw.gateway" }, () =>
826-
captureUpdateRunPayload(),
827-
);
828-
829-
expect(startManagedServiceUpdateHandoffMock).toHaveBeenCalledWith(
830-
expect.objectContaining({ channel: "extended-stable" }),
831-
);
832-
});
833-
834820
it("keeps unsupervised git/dev updates on the in-process gateway update path", async () => {
835821
runGatewayUpdateMock.mockResolvedValueOnce({
836822
status: "ok",
@@ -1067,94 +1053,3 @@ describe("update.run post-core plugin finalize", () => {
10671053
expect(startManagedServiceUpdateHandoffMock).toHaveBeenCalledTimes(1);
10681054
});
10691055
});
1070-
1071-
describe("update.status", () => {
1072-
it("refreshes the latest update sentinel before responding", async () => {
1073-
getUpdateAvailableMock.mockReturnValueOnce({
1074-
currentVersion: "1.0.0",
1075-
latestVersion: "2.0.0",
1076-
channel: "latest",
1077-
});
1078-
getLatestUpdateRestartSentinelMock.mockReturnValueOnce({
1079-
kind: "update",
1080-
status: "skipped",
1081-
ts: 1,
1082-
stats: {
1083-
reason: "restart-health-pending",
1084-
},
1085-
});
1086-
refreshLatestUpdateRestartSentinelMock.mockResolvedValueOnce({
1087-
kind: "update",
1088-
status: "ok",
1089-
ts: 2,
1090-
stats: {
1091-
after: { version: "2.0.0" },
1092-
},
1093-
});
1094-
getUpdateScheduleMock.mockReturnValueOnce({
1095-
channel: "beta",
1096-
autoEnabled: true,
1097-
});
1098-
const { updateHandlers } = await import("./update.js");
1099-
const respond = vi.fn();
1100-
1101-
await expectDefined(
1102-
updateHandlers["update.status"],
1103-
'updateHandlers["update.status"] test invariant',
1104-
)({
1105-
params: {},
1106-
respond,
1107-
} as never);
1108-
1109-
expect(respond).toHaveBeenCalledTimes(1);
1110-
const [ok, response] = firstMockCall(respond, "update status response") as [
1111-
boolean,
1112-
(
1113-
| {
1114-
sentinel?: { kind?: string; status?: string };
1115-
updateAvailable?: { latestVersion?: string } | null;
1116-
schedule?: { channel?: string };
1117-
}
1118-
| undefined
1119-
),
1120-
];
1121-
expect(ok).toBe(true);
1122-
expect(refreshLatestUpdateRestartSentinelMock).toHaveBeenCalledTimes(1);
1123-
expect(response?.sentinel?.kind).toBe("update");
1124-
expect(response?.sentinel?.status).toBe("ok");
1125-
expect(response?.updateAvailable?.latestVersion).toBe("2.0.0");
1126-
expect(response?.schedule?.channel).toBe("beta");
1127-
});
1128-
1129-
it("falls back to the cached update sentinel when refresh fails", async () => {
1130-
refreshLatestUpdateRestartSentinelMock.mockRejectedValueOnce(new Error("read failed"));
1131-
getLatestUpdateRestartSentinelMock.mockReturnValueOnce({
1132-
kind: "update",
1133-
status: "skipped",
1134-
ts: 1,
1135-
stats: {
1136-
reason: "restart-health-pending",
1137-
},
1138-
});
1139-
const warn = vi.fn();
1140-
const { updateHandlers } = await import("./update.js");
1141-
const respond = vi.fn();
1142-
1143-
await expectDefined(
1144-
updateHandlers["update.status"],
1145-
'updateHandlers["update.status"] test invariant',
1146-
)({
1147-
params: {},
1148-
respond,
1149-
context: { logGateway: { warn } },
1150-
} as never);
1151-
1152-
expect(warn).toHaveBeenCalledWith("update.status sentinel refresh failed: read failed");
1153-
const [, response] = firstMockCall(respond, "update status response") as [
1154-
boolean,
1155-
{ sentinel?: { kind?: string; status?: string } } | undefined,
1156-
];
1157-
expect(response?.sentinel?.kind).toBe("update");
1158-
expect(response?.sentinel?.status).toBe("skipped");
1159-
});
1160-
});

0 commit comments

Comments
 (0)