mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-07 22:44:16 +00:00
refactor(infra): dedupe update startup test setup
This commit is contained in:
@@ -107,12 +107,20 @@ describe("update-startup", () => {
|
||||
});
|
||||
|
||||
function mockPackageUpdateStatus(tag = "latest", version = "2.0.0") {
|
||||
mockPackageInstallStatus();
|
||||
mockNpmChannelTag(tag, version);
|
||||
}
|
||||
|
||||
function mockPackageInstallStatus() {
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue("/opt/openclaw");
|
||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||
root: "/opt/openclaw",
|
||||
installKind: "package",
|
||||
packageManager: "npm",
|
||||
} satisfies UpdateCheckResult);
|
||||
}
|
||||
|
||||
function mockNpmChannelTag(tag: string, version: string) {
|
||||
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
||||
tag,
|
||||
version,
|
||||
@@ -173,6 +181,20 @@ describe("update-startup", () => {
|
||||
});
|
||||
}
|
||||
|
||||
async function runStableUpdateCheck(params: {
|
||||
onUpdateAvailableChange?: ReturnType<typeof vi.fn>;
|
||||
}) {
|
||||
await runGatewayUpdateCheck({
|
||||
cfg: { update: { channel: "stable" } },
|
||||
log: { info: vi.fn() },
|
||||
isNixMode: false,
|
||||
allowInTests: true,
|
||||
...(params.onUpdateAvailableChange
|
||||
? { onUpdateAvailableChange: params.onUpdateAvailableChange }
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "stable channel",
|
||||
@@ -232,12 +254,7 @@ describe("update-startup", () => {
|
||||
});
|
||||
|
||||
it("emits update change callback when update state clears", async () => {
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue("/opt/openclaw");
|
||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||
root: "/opt/openclaw",
|
||||
installKind: "package",
|
||||
packageManager: "npm",
|
||||
} satisfies UpdateCheckResult);
|
||||
mockPackageInstallStatus();
|
||||
vi.mocked(resolveNpmChannelTag)
|
||||
.mockResolvedValueOnce({
|
||||
tag: "latest",
|
||||
@@ -249,21 +266,9 @@ describe("update-startup", () => {
|
||||
});
|
||||
|
||||
const onUpdateAvailableChange = vi.fn();
|
||||
await runGatewayUpdateCheck({
|
||||
cfg: { update: { channel: "stable" } },
|
||||
log: { info: vi.fn() },
|
||||
isNixMode: false,
|
||||
allowInTests: true,
|
||||
onUpdateAvailableChange,
|
||||
});
|
||||
await runStableUpdateCheck({ onUpdateAvailableChange });
|
||||
vi.setSystemTime(new Date("2026-01-18T11:00:00Z"));
|
||||
await runGatewayUpdateCheck({
|
||||
cfg: { update: { channel: "stable" } },
|
||||
log: { info: vi.fn() },
|
||||
isNixMode: false,
|
||||
allowInTests: true,
|
||||
onUpdateAvailableChange,
|
||||
});
|
||||
await runStableUpdateCheck({ onUpdateAvailableChange });
|
||||
|
||||
expect(onUpdateAvailableChange).toHaveBeenNthCalledWith(1, {
|
||||
currentVersion: "1.0.0",
|
||||
@@ -362,16 +367,8 @@ describe("update-startup", () => {
|
||||
});
|
||||
|
||||
it("uses current runtime + entrypoint for default auto-update command execution", async () => {
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue("/opt/openclaw");
|
||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||
root: "/opt/openclaw",
|
||||
installKind: "package",
|
||||
packageManager: "npm",
|
||||
} satisfies UpdateCheckResult);
|
||||
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
||||
tag: "beta",
|
||||
version: "2.0.0-beta.1",
|
||||
});
|
||||
mockPackageInstallStatus();
|
||||
mockNpmChannelTag("beta", "2.0.0-beta.1");
|
||||
vi.mocked(runCommandWithTimeout).mockResolvedValue({
|
||||
stdout: "{}",
|
||||
stderr: "",
|
||||
|
||||
Reference in New Issue
Block a user