feat(update): 实现多镜像源自更新机制 (update/upgrade) 并升级版本至 v0.2.1
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled

This commit is contained in:
gitea committed 2026-08-27 11:19:13 +08:00
1 parent 6e73de697b
commit 2dfcf67b00
12 files changed
+1021 -9

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
import { describe, expect, test } from "bun:test";
import { compareSemVer, isNewerVersion, matchAssetForPlatform, type GitHubAsset } from "./update.js";
describe("update version comparator", () => {
test("correctly identifies newer semantic versions", () => {
expect(isNewerVersion("0.2.1", "0.2.0")).toBe(true);
expect(isNewerVersion("1.0.0", "0.2.0")).toBe(true);
expect(isNewerVersion("0.3.0", "0.2.1")).toBe(true);
expect(isNewerVersion("0.2.0", "0.2.0")).toBe(false);
expect(isNewerVersion("0.1.9", "0.2.0")).toBe(false);
expect(isNewerVersion("0.2.0", "0.2.1")).toBe(false);
});
test("compareSemVer handles tags, major, minor, and patch", () => {
expect(compareSemVer("v0.2.1", "0.2.0")).toBe(1);
expect(compareSemVer("0.2.0", "v0.2.1")).toBe(-1);
expect(compareSemVer("v0.2.1", "v0.2.1")).toBe(0);
expect(compareSemVer("1.0.0", "0.9.9")).toBe(1);
expect(compareSemVer("0.1.0", "0.2.1")).toBe(-1);
});
});
describe("matchAssetForPlatform", () => {
const assets: GitHubAsset[] = [
{ name: "hose-use-darwin-arm64", downloadUrl: "https://example.com/darwin-arm64", size: 100 },
{ name: "hose-use-darwin-x64", downloadUrl: "https://example.com/darwin-x64", size: 100 },
{ name: "hose-use-linux-x64.tar.gz", downloadUrl: "https://example.com/linux-x64.tar.gz", size: 100 },
{ name: "hose-use-linux-arm64", downloadUrl: "https://example.com/linux-arm64", size: 100 },
{ name: "hose-use-windows-x64.zip", downloadUrl: "https://example.com/win-x64.zip", size: 100 },
];
test("matches darwin arm64", () => {
const matched = matchAssetForPlatform(assets, "darwin", "arm64");
expect(matched?.name).toBe("hose-use-darwin-arm64");
});
test("matches darwin x64", () => {
const matched = matchAssetForPlatform(assets, "darwin", "x64");
expect(matched?.name).toBe("hose-use-darwin-x64");
});
test("matches linux x64 archive", () => {
const matched = matchAssetForPlatform(assets, "linux", "x64");
expect(matched?.name).toBe("hose-use-linux-x64.tar.gz");
});
test("matches windows x64 archive", () => {
const matched = matchAssetForPlatform(assets, "windows", "x64");
expect(matched?.name).toBe("hose-use-windows-x64.zip");
});
});