| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | cliArchiveFileName, |
| 5 | cliArchivePlatformKey, |
| 6 | cliArchiveTarCommand, |
| 7 | cliReleaseDownloadBaseUrl, |
| 8 | cliReleaseChannelOf, |
| 9 | cliReleaseIndexPageUrl, |
| 10 | newestCliReleaseVersion, |
| 11 | parseChecksums, |
| 12 | } from "./cliRelease.ts"; |
| 13 | |
| 14 | describe("cliRelease", () => { |
| 15 | it("names archives by version and platform, zip only on Windows", () => { |
| 16 | expect(cliArchiveFileName("1.2.3-preview.20260911.4", "linux-x64")).toBe( |
| 17 | "t3-1.2.3-preview.20260911.4-linux-x64.tar.gz", |
| 18 | ); |
| 19 | expect(cliArchiveFileName("1.2.3", "win32-x64")).toBe("t3-1.2.3-win32-x64.zip"); |
| 20 | }); |
| 21 | |
| 22 | it("only maps platforms and architectures that have a release archive", () => { |
| 23 | expect(cliArchivePlatformKey("darwin", "arm64")).toBe("darwin-arm64"); |
| 24 | expect(cliArchivePlatformKey("linux", "x64")).toBe("linux-x64"); |
| 25 | expect(cliArchivePlatformKey("win32", "x64")).toBe("win32-x64"); |
| 26 | // Node single-executables are unsupported on x64 macOS. |
| 27 | expect(cliArchivePlatformKey("darwin", "x64")).toBeUndefined(); |
| 28 | expect(cliArchivePlatformKey("linux", "arm64")).toBe("linux-arm64"); |
| 29 | expect(cliArchivePlatformKey("win32", "arm64")).toBe("win32-arm64"); |
| 30 | expect(cliArchivePlatformKey("freebsd", "x64")).toBeUndefined(); |
| 31 | expect(cliArchivePlatformKey("linux", "ia32")).toBeUndefined(); |
| 32 | }); |
| 33 | |
| 34 | it("resolves download URLs under the tagged release, honoring a mirror", () => { |
| 35 | expect(cliReleaseDownloadBaseUrl("1.2.3")).toBe( |
| 36 | "https://github.com/pingdotgg/t3code/releases/download/v1.2.3", |
| 37 | ); |
| 38 | expect(cliReleaseDownloadBaseUrl("1.2.3", "https://mirror.example/t3/")).toBe( |
| 39 | "https://mirror.example/t3/v1.2.3", |
| 40 | ); |
| 41 | }); |
| 42 | |
| 43 | it("parses sha256sum output including binary-mode markers", () => { |
| 44 | const checksums = parseChecksums( |
| 45 | [ |
| 46 | `${"a".repeat(64)} t3-1.2.3-linux-x64.tar.gz`, |
| 47 | `${"B".repeat(64)} *t3-1.2.3-win32-x64.zip`, |
| 48 | "not a checksum line", |
| 49 | "", |
| 50 | ].join("\n"), |
| 51 | ); |
| 52 | expect(checksums.get("t3-1.2.3-linux-x64.tar.gz")).toBe("a".repeat(64)); |
| 53 | expect(checksums.get("t3-1.2.3-win32-x64.zip")).toBe("b".repeat(64)); |
| 54 | expect(checksums.size).toBe(2); |
| 55 | }); |
| 56 | |
| 57 | it("extracts with the System32 bsdtar on Windows and plain tar elsewhere", () => { |
| 58 | expect(cliArchiveTarCommand("linux", {})).toBe("tar"); |
| 59 | expect(cliArchiveTarCommand("win32", { SystemRoot: "D:\\Win" })).toBe( |
| 60 | "D:\\Win\\System32\\tar.exe", |
| 61 | ); |
| 62 | expect(cliArchiveTarCommand("win32", {})).toBe("C:\\Windows\\System32\\tar.exe"); |
| 63 | }); |
| 64 | |
| 65 | it("derives the release channel from the version alone", () => { |
| 66 | expect(cliReleaseChannelOf("1.2.3")).toBe("stable"); |
| 67 | expect(cliReleaseChannelOf("1.2.3-nightly.20260911.4")).toBe("nightly"); |
| 68 | expect(cliReleaseChannelOf("1.2.3-preview.20260911.4")).toBe("preview"); |
| 69 | // A prerelease that is not one of our trains is not silently a nightly. |
| 70 | expect(cliReleaseChannelOf("1.2.3-rc.1")).toBe("stable"); |
| 71 | }); |
| 72 | |
| 73 | it("picks the newest non-draft release on the requested channel", () => { |
| 74 | const releases = [ |
| 75 | { tag_name: "v1.2.4-preview.20260912.9", draft: true }, |
| 76 | { tag_name: "v1.2.4-preview.20260912.8" }, |
| 77 | { tag_name: "v1.2.4-nightly.20260912.7" }, |
| 78 | { tag_name: "desktop-preview" }, |
| 79 | { tag_name: "v1.2.3" }, |
| 80 | { tag_name: "v1.2.3-nightly.20260911.2" }, |
| 81 | ]; |
| 82 | expect(newestCliReleaseVersion(releases, "preview")).toBe("1.2.4-preview.20260912.8"); |
| 83 | expect(newestCliReleaseVersion(releases, "nightly")).toBe("1.2.4-nightly.20260912.7"); |
| 84 | expect(newestCliReleaseVersion(releases, "stable")).toBe("1.2.3"); |
| 85 | expect(newestCliReleaseVersion([{ tag_name: "v1.2.3" }], "preview")).toBeUndefined(); |
| 86 | }); |
| 87 | |
| 88 | it("pages through the release index at the largest page GitHub allows", () => { |
| 89 | expect(cliReleaseIndexPageUrl(1)).toBe( |
| 90 | "https://api.github.com/repos/pingdotgg/t3code/releases?per_page=100&page=1", |
| 91 | ); |
| 92 | expect(cliReleaseIndexPageUrl(3)).toContain("page=3"); |
| 93 | }); |
| 94 | }); |