mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:38:28 +00:00
test: cover beta fallback update logic
This commit is contained in:
47
src/infra/update-check.test.ts
Normal file
47
src/infra/update-check.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { resolveNpmChannelTag } from "./update-check.js";
|
||||
|
||||
describe("resolveNpmChannelTag", () => {
|
||||
let versionByTag: Record<string, string | null>;
|
||||
|
||||
beforeEach(() => {
|
||||
versionByTag = {};
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url =
|
||||
typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
const tag = decodeURIComponent(url.split("/").pop() ?? "");
|
||||
const version = versionByTag[tag] ?? null;
|
||||
return {
|
||||
ok: version != null,
|
||||
status: version != null ? 200 : 404,
|
||||
json: async () => ({ version }),
|
||||
} as Response;
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("falls back to latest when beta is older", async () => {
|
||||
versionByTag.beta = "2026.1.19-beta.1";
|
||||
versionByTag.latest = "2026.1.20-1";
|
||||
|
||||
const resolved = await resolveNpmChannelTag({ channel: "beta", timeoutMs: 1000 });
|
||||
|
||||
expect(resolved).toEqual({ tag: "latest", version: "2026.1.20-1" });
|
||||
});
|
||||
|
||||
it("keeps beta when beta is not older", async () => {
|
||||
versionByTag.beta = "2026.1.20-beta.1";
|
||||
versionByTag.latest = "2026.1.20-1";
|
||||
|
||||
const resolved = await resolveNpmChannelTag({ channel: "beta", timeoutMs: 1000 });
|
||||
|
||||
expect(resolved).toEqual({ tag: "beta", version: "2026.1.20-beta.1" });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user