Skip to content

Commit 4224f5b

Browse files
fix: normalize detached update swap failures
1 parent c0f2110 commit 4224f5b

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/gateway/server-restart-sentinel.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ describe("scheduleRestartSentinelWake", () => {
500500
message: "continue",
501501
},
502502
},
503-
} as unknown as Awaited<ReturnType<typeof mocks.readRestartSentinel>>);
503+
});
504504

505505
const wakePromise = scheduleRestartSentinelWake({ deps: {} as never });
506506
await Promise.resolve();
@@ -535,7 +535,7 @@ describe("scheduleRestartSentinelWake", () => {
535535
} as never,
536536
threadId: "fresh-thread",
537537
},
538-
} as unknown as Awaited<ReturnType<typeof mocks.readRestartSentinel>>);
538+
});
539539

540540
await scheduleRestartSentinelWake({ deps: {} as never });
541541

@@ -796,7 +796,7 @@ describe("scheduleRestartSentinelWake", () => {
796796
message: "continue",
797797
},
798798
},
799-
} as unknown as Awaited<ReturnType<typeof mocks.readRestartSentinel>>);
799+
});
800800
mocks.deliveryContextFromSession.mockReturnValue({
801801
channel: "telegram",
802802
to: "telegram:200482621",
@@ -1048,9 +1048,7 @@ describe("scheduleRestartSentinelWake", () => {
10481048
},
10491049
},
10501050
} as Awaited<ReturnType<typeof mocks.readRestartSentinel>>)
1051-
.mockResolvedValueOnce(
1052-
null as unknown as Awaited<ReturnType<typeof mocks.readRestartSentinel>>,
1053-
);
1051+
.mockResolvedValueOnce(null);
10541052

10551053
await scheduleRestartSentinelWake({ deps: {} as never });
10561054
await scheduleRestartSentinelWake({ deps: {} as never });
@@ -1063,7 +1061,7 @@ describe("scheduleRestartSentinelWake", () => {
10631061
payload: {
10641062
message: "restart message",
10651063
},
1066-
} as unknown as Awaited<ReturnType<typeof mocks.readRestartSentinel>>);
1064+
});
10671065

10681066
await scheduleRestartSentinelWake({ deps: {} as never });
10691067

@@ -1083,7 +1081,7 @@ describe("scheduleRestartSentinelWake", () => {
10831081
message: "continue",
10841082
},
10851083
},
1086-
} as unknown as Awaited<ReturnType<typeof mocks.readRestartSentinel>>);
1084+
});
10871085

10881086
await scheduleRestartSentinelWake({ deps: {} as never });
10891087

src/infra/update-runner.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { withEnvAsync } from "../test-utils/env.js";
88
import { pathExists } from "../utils.js";
99
import { writePackageDistInventory } from "./package-dist-inventory.js";
1010
import { resolveStableNodePath } from "./stable-node-path.js";
11-
import { runGatewayUpdate } from "./update-runner.js";
11+
import { normalizeFallbackFailureReason, runGatewayUpdate } from "./update-runner.js";
1212

1313
type CommandResponse = { stdout?: string; stderr?: string; code?: number | null };
1414
type CommandResult = { stdout: string; stderr: string; code: number | null };
@@ -1783,3 +1783,11 @@ describe("runGatewayUpdate", () => {
17831783
expect(result.reason).toBe("ui-assets-missing");
17841784
});
17851785
});
1786+
1787+
describe("normalizeFallbackFailureReason", () => {
1788+
it("reports detached staged npm swap failures as global install failures", () => {
1789+
expect(normalizeFallbackFailureReason("global install swap (detached win32)")).toBe(
1790+
"global-install-failed",
1791+
);
1792+
});
1793+
});

src/infra/update-runner.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,18 @@ function shouldRunDevPreflightLint(): boolean {
571571
return process.platform !== "win32";
572572
}
573573

574-
function normalizeFallbackFailureReason(stepName: string): NonNullable<UpdateRunResult["reason"]> {
574+
export function normalizeFallbackFailureReason(
575+
stepName: string,
576+
): NonNullable<UpdateRunResult["reason"]> {
577+
if (stepName === "global install swap" || stepName.startsWith("global install swap ")) {
578+
return "global-install-failed";
579+
}
580+
575581
switch (stepName) {
576582
case "global update":
577583
case "global update (omit optional)":
578584
case "global install stage":
579585
case "global install verify":
580-
case "global install swap":
581586
return "global-install-failed";
582587
case "openclaw doctor":
583588
return "doctor-failed";

0 commit comments

Comments
 (0)