fix: validate cached binary version matches requested version (#146) (#169)

* fix: validate cached binary version matches requested version (#146)

* fix: fail closed when cached version cannot be verified
This commit is contained in:
Wai Yan Min Lwin
2026-03-04 22:27:24 +07:00
committed by GitHub
parent 4c32875876
commit 95edc153a3
4 changed files with 89 additions and 50 deletions
+21 -1
View File
@@ -1,7 +1,27 @@
import { afterEach, describe, expect, it, spyOn } from "bun:test";
import { getArchitecture, getAvx2, hasNativeWindowsArm64 } from "../src/utils";
import { extractVersionFromUrl, getArchitecture, getAvx2, hasNativeWindowsArm64 } from "../src/utils";
import * as core from "@actions/core";
describe("extractVersionFromUrl", () => {
it("should extract version from standard download URL", () => {
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/bun-v1.3.1/bun-linux-x64.zip")).toBe("1.3.1");
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/bun-v1.0.0/bun-darwin-aarch64.zip")).toBe("1.0.0");
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/bun-v0.5.0/bun-linux-x64-baseline.zip")).toBe("0.5.0");
});
it("should extract version from URL with profile suffix", () => {
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-linux-x64-profile.zip")).toBe("1.1.0");
});
it("should return undefined for canary URL", () => {
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/canary/bun-linux-x64.zip")).toBeUndefined();
});
it("should return undefined for custom/non-standard URL", () => {
expect(extractVersionFromUrl("https://example.com/bun.zip")).toBeUndefined();
});
});
describe("hasNativeWindowsArm64", () => {
it("should return true for version >= 1.3.10", () => {
expect(hasNativeWindowsArm64("bun-v1.3.10")).toBe(true);