Respect the mirror setting when selecting the version manifest (#1164)

Select the manifest source from the action inputs and keep version
resolution separate from archive downloads. Fetch the built-in manifest
directly from GitHub when the Astral mirror is disabled.

Fixes: #1140

Based on the work of @Rudra-G-23 in
https://github.com/astral-sh/setup-uv/pull/1152

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Kevin StillhammerandAmp authored and GitHub committed 2026-12-02 11:40:15 +01:00
1 parent 521745f16c
commit 36300bab3f
19 files changed
+1637 -1647

No files matched your search

+98 -239
View File
@@ -1,6 +1,12 @@
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import * as semver from "semver";
import { VERSIONS_MANIFEST_URL } from "../../src/utils/constants";
import type { ManifestSource } from "../../src/utils/inputs";
const customManifest: ManifestSource = {
custom: true,
newestFirst: false,
url: "https://example.com/custom.ndjson",
};
const mockInfo = jest.fn();
const mockWarning = jest.fn();
@@ -38,14 +44,11 @@ const mockGetLatestVersion = jest.fn<any>();
const mockGetAllVersions = jest.fn<any>();
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
const mockGetFirstMatchingVersion = jest.fn<any>();
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
const mockGetArtifact = jest.fn<any>();
jest.unstable_mockModule("../../src/download/manifest", () => ({
getAllVersions: mockGetAllVersions,
getArtifact: mockGetArtifact,
getFirstMatchingVersion: mockGetFirstMatchingVersion,
getLatestVersion: mockGetLatestVersion,
getFirstVersion: mockGetLatestVersion,
}));
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
@@ -61,9 +64,11 @@ jest.unstable_mockModule("../../src/download/checksum/known-version", () => ({
getLatestKnownVersion: mockGetLatestKnownVersion,
}));
const { downloadVersion, resolveVersion, rewriteToMirror } = await import(
const { downloadVersion, rewriteToMirror } = await import(
"../../src/download/download-version"
);
const { resolveVersion } = await import("../../src/version/resolve");
const { ASTRAL_MANIFEST } = await import("../../src/utils/inputs");
describe("download-version", () => {
beforeEach(() => {
@@ -76,7 +81,6 @@ describe("download-version", () => {
mockGetLatestVersion.mockReset();
mockGetAllVersions.mockReset();
mockGetFirstMatchingVersion.mockReset();
mockGetArtifact.mockReset();
mockValidateChecksum.mockReset();
mockGetLatestKnownVersion.mockClear();
@@ -90,15 +94,15 @@ describe("download-version", () => {
it("uses the default manifest to resolve latest", async () => {
mockGetLatestVersion.mockResolvedValue("0.9.26");
const version = await resolveVersion("latest", undefined);
const version = await resolveVersion("latest", ASTRAL_MANIFEST);
expect(version).toBe("0.9.26");
expect(mockGetLatestVersion).toHaveBeenCalledTimes(1);
expect(mockGetLatestVersion).toHaveBeenCalledWith(undefined);
expect(mockGetLatestVersion).toHaveBeenCalledWith(ASTRAL_MANIFEST);
});
it("resolves latest-known without reading the manifest", async () => {
const version = await resolveVersion("latest-known", undefined);
const version = await resolveVersion("latest-known", ASTRAL_MANIFEST);
expect(version).toBe("0.9.25");
expect(mockGetLatestKnownVersion).toHaveBeenCalledTimes(1);
@@ -113,23 +117,31 @@ describe("download-version", () => {
["0.9.26", "0.9.25"].find(predicate),
);
const version = await resolveVersion("^0.9.0", undefined);
const version = await resolveVersion("^0.9.0", ASTRAL_MANIFEST);
expect(version).toBe("0.9.26");
expect(mockGetFirstMatchingVersion).toHaveBeenCalledTimes(1);
expect(mockGetAllVersions).not.toHaveBeenCalled();
});
it("streams ranges when the default manifest URL is explicit", async () => {
it("uses the ordered search for the direct GitHub manifest", async () => {
mockGetFirstMatchingVersion.mockImplementation(
(predicate: (version: string) => boolean) =>
["0.9.26", "0.9.25"].find(predicate),
);
const source: ManifestSource = {
custom: false,
newestFirst: true,
url: "https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson",
};
const version = await resolveVersion("^0.9.0", VERSIONS_MANIFEST_URL);
const version = await resolveVersion("^0.9.0", source);
expect(version).toBe("0.9.26");
expect(mockGetFirstMatchingVersion).toHaveBeenCalledTimes(1);
expect(mockGetFirstMatchingVersion).toHaveBeenCalledWith(
expect.any(Function),
source,
);
expect(mockGetAllVersions).not.toHaveBeenCalled();
});
@@ -139,7 +151,7 @@ describe("download-version", () => {
["0.9.26", "0.9.25"].find(predicate),
);
const version = await resolveVersion("!=0.9.26", undefined);
const version = await resolveVersion("!=0.9.26", ASTRAL_MANIFEST);
expect(version).toBe("0.9.25");
expect(mockGetFirstMatchingVersion).toHaveBeenCalledTimes(1);
@@ -152,18 +164,15 @@ describe("download-version", () => {
["1.0.0", "0.10.2", "0.9.26"].find(predicate),
);
const version = await resolveVersion("~=0.9", undefined);
const version = await resolveVersion("~=0.9", ASTRAL_MANIFEST);
expect(version).toBe("0.10.2");
});
it("resolves ~= with PEP 440 compatible release semantics from manifest-file", async () => {
mockGetAllVersions.mockResolvedValue(["1.0.0", "0.10.2", "0.9.26"]);
mockGetAllVersions.mockResolvedValue(["0.9.26", "1.0.0", "0.10.2"]);
const version = await resolveVersion(
"~=0.9",
"https://example.com/custom.ndjson",
);
const version = await resolveVersion("~=0.9", customManifest);
expect(version).toBe("0.10.2");
});
@@ -177,7 +186,7 @@ describe("download-version", () => {
["0.10.2", "0.9.26", "0.9.0", "0.8.24"].find(predicate),
);
const version = await resolveVersion(specifier, undefined);
const version = await resolveVersion(specifier, ASTRAL_MANIFEST);
expect(version).toBe(expected);
});
@@ -190,13 +199,13 @@ describe("download-version", () => {
"0.9.0",
]);
const version = await resolveVersion(">0.9", undefined, "lowest");
const version = await resolveVersion(">0.9", ASTRAL_MANIFEST, "lowest");
expect(version).toBe("0.9.1");
});
it("treats == exact pins as explicit versions", async () => {
const version = await resolveVersion("==0.9.26", undefined);
const version = await resolveVersion("==0.9.26", ASTRAL_MANIFEST);
expect(version).toBe("0.9.26");
expect(mockGetAllVersions).not.toHaveBeenCalled();
@@ -206,93 +215,82 @@ describe("download-version", () => {
it("uses latest for minimum-only ranges when using the highest strategy", async () => {
mockGetLatestVersion.mockResolvedValue("0.9.26");
const version = await resolveVersion(">=0.9.0", undefined, "highest");
const version = await resolveVersion(
">=0.9.0",
ASTRAL_MANIFEST,
"highest",
);
expect(version).toBe("0.9.26");
expect(mockGetLatestVersion).toHaveBeenCalledTimes(1);
expect(mockGetLatestVersion).toHaveBeenCalledWith(undefined);
expect(mockGetLatestVersion).toHaveBeenCalledWith(ASTRAL_MANIFEST);
expect(mockGetAllVersions).not.toHaveBeenCalled();
});
it("uses the lowest compatible version when requested", async () => {
mockGetAllVersions.mockResolvedValue(["0.9.26", "0.9.25"]);
const version = await resolveVersion("^0.9.0", undefined, "lowest");
const version = await resolveVersion("^0.9.0", ASTRAL_MANIFEST, "lowest");
expect(version).toBe("0.9.25");
expect(mockGetAllVersions).toHaveBeenCalledTimes(1);
expect(mockGetAllVersions).toHaveBeenCalledWith(undefined);
expect(mockGetAllVersions).toHaveBeenCalledWith(ASTRAL_MANIFEST);
});
it("uses manifest-file when provided", async () => {
mockGetAllVersions.mockResolvedValue(["0.9.26", "0.9.25"]);
it.each(["latest", ">=0.9.0"])(
"uses the first custom manifest record for %s",
async (specifier) => {
mockGetLatestVersion.mockResolvedValue("0.9.7");
mockGetAllVersions.mockResolvedValue(["0.9.7", "0.9.26"]);
const version = await resolveVersion(
"^0.9.0",
"https://example.com/custom.ndjson",
await expect(resolveVersion(specifier, customManifest)).resolves.toBe(
"0.9.7",
);
},
);
it("rejects the first custom manifest record if it does not meet the minimum", async () => {
mockGetLatestVersion.mockResolvedValue("0.9.7");
mockGetAllVersions.mockResolvedValue(["0.9.7", "0.9.26"]);
await expect(resolveVersion(">=0.9.8", customManifest)).rejects.toThrow(
"No version found for >=0.9.8",
);
});
expect(version).toBe("0.9.26");
expect(mockGetAllVersions).toHaveBeenCalledWith(
"https://example.com/custom.ndjson",
it("resolves a range from an unordered custom manifest", async () => {
mockGetAllVersions.mockResolvedValue(["0.9.7", "0.9.26", "0.9.25"]);
await expect(resolveVersion("^0.9.0", customManifest)).resolves.toBe(
"0.9.26",
);
});
});
describe("downloadVersion", () => {
it("fails when manifest lookup fails", async () => {
mockGetArtifact.mockRejectedValue(new Error("manifest unavailable"));
const githubUrl =
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz";
const mirrorUrl =
"https://releases.astral.sh/github/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz";
const customUrl = "https://example.com/uv.tar.gz";
await expect(
downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
"token",
),
).rejects.toThrow("manifest unavailable");
expect(mockDownloadTool).not.toHaveBeenCalled();
expect(mockValidateChecksum).not.toHaveBeenCalled();
});
it("fails when no matching artifact exists in the default manifest", async () => {
mockGetArtifact.mockResolvedValue(undefined);
await expect(
downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
"token",
),
).rejects.toThrow(
"Could not find artifact for version 0.9.26, arch x86_64, platform unknown-linux-gnu in https://releases.astral.sh/github/versions/main/v1/uv.ndjson .",
);
expect(mockDownloadTool).not.toHaveBeenCalled();
expect(mockValidateChecksum).not.toHaveBeenCalled();
});
it("uses the default manifest checksum as a fallback", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "manifest-checksum",
downloadUrl: "https://example.com/uv.tar.gz",
});
await downloadVersion(
function install(downloadUrl: string, checksum?: string, useMirror = true) {
return downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
{ checksum: "manifest-checksum", downloadUrl },
checksum,
"token",
useMirror,
);
}
it("passes the explicit and fallback checksums to verification", async () => {
await install(customUrl, "user-checksum");
expect(mockValidateChecksum).toHaveBeenCalledWith(
undefined,
"user-checksum",
"/tmp/downloaded",
"x86_64",
"unknown-linux-gnu",
@@ -302,102 +300,44 @@ describe("download-version", () => {
});
it("rewrites GitHub Releases URLs to the Astral mirror", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "abc123",
downloadUrl:
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
});
await downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
"token",
);
await install(githubUrl);
expect(mockDownloadTool).toHaveBeenCalledWith(
"https://releases.astral.sh/github/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
mirrorUrl,
undefined,
undefined,
);
});
it("does not send the token to non-GitHub URLs from the default manifest", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "abc123",
downloadUrl: "https://example.com/uv.tar.gz",
});
await downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
"token",
);
expect(mockDownloadTool).toHaveBeenCalledWith(
"https://example.com/uv.tar.gz",
undefined,
undefined,
);
});
it("does not send the token to GitHub lookalike hosts", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "abc123",
downloadUrl: "https://github.com.evil.test/uv.tar.gz",
});
await downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
"token",
);
expect(mockDownloadTool).toHaveBeenCalledWith(
"https://github.com.evil.test/uv.tar.gz",
undefined,
undefined,
);
});
it.each([customUrl, "https://github.com.evil.test/uv.tar.gz"])(
"does not send the token to %s",
async (url) => {
await install(url);
expect(mockDownloadTool).toHaveBeenCalledWith(
url,
undefined,
undefined,
);
},
);
it("falls back to GitHub Releases when the mirror fails", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "abc123",
downloadUrl:
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
});
mockDownloadTool
.mockRejectedValueOnce(new Error("mirror unavailable"))
.mockResolvedValueOnce("/tmp/downloaded");
await downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
"token",
);
await install(githubUrl);
expect(mockDownloadTool).toHaveBeenCalledTimes(2);
expect(mockDownloadTool).toHaveBeenNthCalledWith(
1,
"https://releases.astral.sh/github/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
mirrorUrl,
undefined,
undefined,
);
expect(mockDownloadTool).toHaveBeenNthCalledWith(
2,
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
githubUrl,
undefined,
"token",
);
@@ -407,99 +347,18 @@ describe("download-version", () => {
});
it("does not fall back for non-GitHub URLs", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "abc123",
downloadUrl: "https://example.com/uv.tar.gz",
});
mockDownloadTool.mockRejectedValue(new Error("download failed"));
await expect(
downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
"token",
),
).rejects.toThrow("download failed");
await expect(install(customUrl)).rejects.toThrow("download failed");
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
});
it("uses manifest-file checksum metadata when checksum input is unset", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "manifest-checksum",
downloadUrl: "https://example.com/custom-uv.tar.gz",
});
await downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
"",
"token",
"https://example.com/custom.ndjson",
);
expect(mockValidateChecksum).toHaveBeenCalledWith(
"manifest-checksum",
"/tmp/downloaded",
"x86_64",
"unknown-linux-gnu",
"0.9.26",
"manifest-checksum",
);
});
it("prefers checksum input over manifest-file checksum metadata", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "manifest-checksum",
downloadUrl: "https://example.com/custom-uv.tar.gz",
});
await downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
"user-checksum",
"token",
"https://example.com/custom.ndjson",
);
expect(mockValidateChecksum).toHaveBeenCalledWith(
"user-checksum",
"/tmp/downloaded",
"x86_64",
"unknown-linux-gnu",
"0.9.26",
"manifest-checksum",
);
});
it("skips the Astral mirror when downloadFromAstralMirror is false", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "abc123",
downloadUrl:
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
});
await downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
"token",
undefined,
false,
);
await install(githubUrl, undefined, false);
expect(mockDownloadTool).toHaveBeenCalledWith(
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
githubUrl,
undefined,
"token",
);
@@ -79,7 +79,8 @@ test("enforces intrinsic checksums on downloads and tool-cache hits", async () =
await expect(install(version, true, "0".repeat(64))).rejects.toMatchObject({
stdout: expect.stringContaining("did not match"),
});
// The custom manifest also offers these bytes under a known release version.
// The custom manifest checksum wins unless intrinsic checksums are required.
await install("0.9.26", false);
await expect(install("0.9.26", true)).rejects.toMatchObject({
stdout: expect.stringContaining("did not match"),
});
+108 -60
View File
@@ -6,6 +6,7 @@ import {
it,
jest,
} from "@jest/globals";
import type { ManifestSource } from "../../src/utils/inputs";
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
const mockFetch = jest.fn<any>();
@@ -19,6 +20,7 @@ jest.unstable_mockModule("../../src/utils/fetch", () => ({
fetch: mockFetch,
}));
const { ASTRAL_MANIFEST } = await import("../../src/utils/inputs");
const {
MANIFEST_FETCH_ATTEMPTS,
clearManifestCache,
@@ -26,10 +28,21 @@ const {
getAllVersions,
getArtifact,
getFirstMatchingVersion,
getLatestVersion,
getFirstVersion,
parseManifest,
} = await import("../../src/download/manifest");
const githubManifest: ManifestSource = {
custom: false,
newestFirst: true,
url: "https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson",
};
const customManifest: ManifestSource = {
custom: true,
newestFirst: false,
url: "https://example.com/custom.ndjson",
};
const sampleManifestResponse = `{"version":"0.9.26","artifacts":[{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.tar.gz","archive_format":"tar.gz","sha256":"fcf0a9ea6599c6ae28a4c854ac6da76f2c889354d7c36ce136ef071f7ab9721f"},{"platform":"x86_64-pc-windows-msvc","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-pc-windows-msvc.zip","archive_format":"zip","sha256":"eb02fd95d8e0eed462b4a67ecdd320d865b38c560bffcda9a0b87ec944bdf036"}]}
{"version":"0.9.25","artifacts":[{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/uv/releases/download/0.9.25/uv-aarch64-apple-darwin.tar.gz","archive_format":"tar.gz","sha256":"606b3c6949d971709f2526fa0d9f0fd23ccf60e09f117999b406b424af18a6a6"}]}`;
@@ -91,7 +104,7 @@ describe("manifest", () => {
createMockResponse(true, 200, "OK", sampleManifestResponse),
);
const versions = await fetchManifest();
const versions = await fetchManifest(ASTRAL_MANIFEST);
expect(versions).toHaveLength(2);
expect(versions[0]?.version).toBe("0.9.26");
@@ -111,7 +124,7 @@ describe("manifest", () => {
createMockResponse(true, 200, "OK", sampleManifestResponse),
);
const result = fetchManifest();
const result = fetchManifest(ASTRAL_MANIFEST);
await jest.runAllTimersAsync();
await expect(result).resolves.toEqual([
@@ -125,7 +138,7 @@ describe("manifest", () => {
"https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson",
]);
await expect(getLatestVersion()).resolves.toBe("0.9.26");
await expect(getFirstVersion(ASTRAL_MANIFEST)).resolves.toBe("0.9.26");
expect(mockFetch).toHaveBeenCalledTimes(4);
});
@@ -138,9 +151,9 @@ describe("manifest", () => {
createStreamingMockResponse([`${sampleManifestResponse}\n`]),
);
await expect(getLatestVersion()).resolves.toBe("0.9.26");
await expect(getFirstVersion(ASTRAL_MANIFEST)).resolves.toBe("0.9.26");
await expect(
getArtifact("0.9.26", "aarch64", "apple-darwin"),
getArtifact("0.9.26", "aarch64", "apple-darwin", ASTRAL_MANIFEST),
).resolves.toEqual({
archiveFormat: "tar.gz",
checksum:
@@ -160,9 +173,7 @@ describe("manifest", () => {
createMockResponse(false, 503, "Service Unavailable", ""),
);
await expect(
fetchManifest("https://example.com/custom.ndjson"),
).rejects.toThrow(
await expect(fetchManifest(customManifest)).rejects.toThrow(
"Failed to fetch manifest data: 503 Service Unavailable",
);
expect(mockFetch.mock.calls.map(([url]) => url)).toEqual([
@@ -178,7 +189,7 @@ describe("manifest", () => {
createMockResponse(true, 200, "OK", sampleManifestResponse),
);
const result = fetchManifest();
const result = fetchManifest(ASTRAL_MANIFEST);
await jest.runAllTimersAsync();
await expect(result).resolves.toHaveLength(2);
@@ -189,7 +200,7 @@ describe("manifest", () => {
jest.useFakeTimers();
mockFetch.mockRejectedValue(new Error("request timed out"));
const result = expect(fetchManifest()).rejects.toThrow(
const result = expect(fetchManifest(ASTRAL_MANIFEST)).rejects.toThrow(
"request timed out",
);
await jest.runAllTimersAsync();
@@ -203,20 +214,26 @@ describe("manifest", () => {
createMockResponse(false, 500, "Internal Server Error", ""),
);
await expect(fetchManifest()).rejects.toThrow(
await expect(fetchManifest(ASTRAL_MANIFEST)).rejects.toThrow(
"Failed to fetch manifest data: 500 Internal Server Error",
);
});
it("caches results per URL", async () => {
it("reuses a custom manifest across version and artifact lookups", async () => {
mockFetch.mockResolvedValue(
createMockResponse(true, 200, "OK", sampleManifestResponse),
);
await expect(getAllVersions(customManifest)).resolves.toEqual([
"0.9.26",
"0.9.25",
]);
await expect(
getArtifact("0.9.25", "aarch64", "apple-darwin", customManifest),
).resolves.toBeDefined();
await fetchManifest("https://example.com/custom.ndjson");
await fetchManifest("https://example.com/custom.ndjson");
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch.mock.calls.map(([url]) => url)).toEqual([
"https://example.com/custom.ndjson",
]);
});
});
@@ -226,46 +243,50 @@ describe("manifest", () => {
createMockResponse(true, 200, "OK", sampleManifestResponse),
);
const versions = await getAllVersions(
"https://example.com/custom.ndjson",
);
const versions = await getAllVersions(customManifest);
expect(versions).toEqual(["0.9.26", "0.9.25"]);
});
});
describe("getLatestVersion", () => {
it("returns the first version string", async () => {
describe("getFirstVersion", () => {
it.each([ASTRAL_MANIFEST, githubManifest])(
"stops after the first record from $url",
async (source) => {
const [latestVersion] = sampleManifestResponse.split("\n");
const cancel = jest.fn();
mockFetch.mockResolvedValue(
createStreamingMockResponse(
[
latestVersion.slice(0, 100),
`${latestVersion.slice(100)}\n`,
"invalid trailing data\n",
],
cancel,
),
);
await expect(getFirstVersion(source)).resolves.toBe("0.9.26");
await expect(
getArtifact("0.9.26", "aarch64", "apple-darwin", source),
).resolves.toBeDefined();
expect(cancel).toHaveBeenCalledTimes(1);
expect(mockFetch.mock.calls.map(([url]) => url)).toEqual([source.url]);
},
);
it("does not fall back to Astral when direct GitHub fetching fails", async () => {
mockFetch.mockResolvedValue(
createMockResponse(true, 200, "OK", sampleManifestResponse),
createMockResponse(false, 503, "Service Unavailable", ""),
);
await expect(
getLatestVersion("https://example.com/custom.ndjson"),
).resolves.toBe("0.9.26");
});
it("stops reading the default manifest after the first record", async () => {
const [latestVersion] = sampleManifestResponse.split("\n");
const cancel = jest.fn();
mockFetch.mockResolvedValue(
createStreamingMockResponse(
[
latestVersion.slice(0, 100),
`${latestVersion.slice(100)}\n`,
"invalid trailing data\n",
],
cancel,
),
await expect(getFirstVersion(githubManifest)).rejects.toThrow(
"503 Service Unavailable",
);
await expect(getLatestVersion()).resolves.toBe("0.9.26");
await expect(
getArtifact("0.9.26", "aarch64", "apple-darwin"),
).resolves.toBeDefined();
expect(cancel).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(mockFetch.mock.calls.map(([url]) => url)).toEqual([
"https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson",
]);
});
it("does not fail when canceling the remaining response fails", async () => {
@@ -276,7 +297,7 @@ describe("manifest", () => {
),
);
await expect(getLatestVersion()).resolves.toBe("0.9.26");
await expect(getFirstVersion(ASTRAL_MANIFEST)).resolves.toBe("0.9.26");
});
});
@@ -291,7 +312,10 @@ describe("manifest", () => {
);
await expect(
getFirstMatchingVersion((version) => version === "0.9.25"),
getFirstMatchingVersion(
(version) => version === "0.9.25",
ASTRAL_MANIFEST,
),
).resolves.toBe("0.9.25");
expect(cancel).toHaveBeenCalledTimes(1);
@@ -307,9 +331,12 @@ describe("manifest", () => {
);
await expect(
getFirstMatchingVersion((version) => version === "0.0.1"),
getFirstMatchingVersion(
(version) => version === "0.0.1",
ASTRAL_MANIFEST,
),
).resolves.toBeUndefined();
await expect(getLatestVersion()).resolves.toBe("0.9.26");
await expect(getFirstVersion(ASTRAL_MANIFEST)).resolves.toBe("0.9.26");
expect(mockFetch).toHaveBeenCalledTimes(1);
});
@@ -323,7 +350,12 @@ describe("manifest", () => {
});
it("finds an artifact by version and platform", async () => {
const artifact = await getArtifact("0.9.26", "aarch64", "apple-darwin");
const artifact = await getArtifact(
"0.9.26",
"aarch64",
"apple-darwin",
ASTRAL_MANIFEST,
);
expect(artifact).toEqual({
archiveFormat: "tar.gz",
@@ -335,7 +367,12 @@ describe("manifest", () => {
});
it("finds a windows artifact", async () => {
const artifact = await getArtifact("0.9.26", "x86_64", "pc-windows-msvc");
const artifact = await getArtifact(
"0.9.26",
"x86_64",
"pc-windows-msvc",
ASTRAL_MANIFEST,
);
expect(artifact).toEqual({
archiveFormat: "zip",
@@ -351,7 +388,12 @@ describe("manifest", () => {
createMockResponse(true, 200, "OK", multiVariantManifestResponse),
);
const artifact = await getArtifact("0.9.26", "aarch64", "apple-darwin");
const artifact = await getArtifact(
"0.9.26",
"aarch64",
"apple-darwin",
ASTRAL_MANIFEST,
);
expect(artifact).toEqual({
archiveFormat: "zip",
@@ -362,7 +404,12 @@ describe("manifest", () => {
});
it("returns undefined for an unknown version", async () => {
const artifact = await getArtifact("0.0.1", "aarch64", "apple-darwin");
const artifact = await getArtifact(
"0.0.1",
"aarch64",
"apple-darwin",
ASTRAL_MANIFEST,
);
expect(artifact).toBeUndefined();
});
@@ -372,6 +419,7 @@ describe("manifest", () => {
"0.9.26",
"aarch64",
"unknown-linux-musl",
ASTRAL_MANIFEST,
);
expect(artifact).toBeUndefined();
@@ -391,9 +439,9 @@ describe("manifest", () => {
);
await expect(
getArtifact("0.0.1", "aarch64", "apple-darwin"),
getArtifact("0.0.1", "aarch64", "apple-darwin", ASTRAL_MANIFEST),
).rejects.toThrow("Failed to parse manifest data");
await expect(getLatestVersion()).resolves.toBe("0.9.26");
await expect(getFirstVersion(ASTRAL_MANIFEST)).resolves.toBe("0.9.26");
expect(mockFetch).toHaveBeenCalledTimes(2);
});
@@ -424,9 +472,9 @@ describe("manifest", () => {
);
await expect(
getArtifact("0.0.1", "aarch64", "apple-darwin"),
getArtifact("0.0.1", "aarch64", "apple-darwin", ASTRAL_MANIFEST),
).rejects.toThrow("response stream failed");
await expect(getLatestVersion()).resolves.toBe("0.9.26");
await expect(getFirstVersion(ASTRAL_MANIFEST)).resolves.toBe("0.9.26");
expect(mockFetch).toHaveBeenCalledTimes(2);
});