mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-12-04 02:16:06 +00:00
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:
1 parent
521745f16c
commit
36300bab3f
19 files changed
+1637
-1647
No files matched your search
@@ -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",
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user