|
| 1 | +import { beforeEach, describe, expect, it, mock } from "bun:test"; |
| 2 | + |
| 3 | +import * as actionsHttpClient from "@actions/http-client"; |
| 4 | + |
| 5 | +const mockHttpGet = mock(); |
| 6 | + |
| 7 | +class MockHttpClient { |
| 8 | + public get = mockHttpGet; |
| 9 | +} |
| 10 | + |
| 11 | +mock.module("@actions/http-client", () => ({ |
| 12 | + ...actionsHttpClient, |
| 13 | + HttpClient: MockHttpClient, |
| 14 | +})); |
| 15 | + |
| 16 | +const { buildDownloadUrl, resolveVersion } = await import("../src/installer"); |
| 17 | + |
| 18 | +describe("resolveVersion", () => { |
| 19 | + beforeEach(() => { |
| 20 | + mock.clearAllMocks(); |
| 21 | + }); |
| 22 | + |
| 23 | + it("resolves latest from Cursor endpoint and normalizes v prefix", () => { |
| 24 | + mockHttpGet.mockResolvedValue({ |
| 25 | + readBody: mock(() => Promise.resolve("v2026.03.20-44cb435\n")), |
| 26 | + }); |
| 27 | + |
| 28 | + expect(resolveVersion("latest")).resolves.toBe("2026.03.20-44cb435"); |
| 29 | + expect(mockHttpGet).toHaveBeenCalledWith( |
| 30 | + "https://downloads.cursor.com/lab/latest-version" |
| 31 | + ); |
| 32 | + }); |
| 33 | + |
| 34 | + it("returns pinned version without calling network", () => { |
| 35 | + expect(resolveVersion("v1.2.3")).resolves.toBe("1.2.3"); |
| 36 | + expect(mockHttpGet).not.toHaveBeenCalled(); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +describe("buildDownloadUrl", () => { |
| 41 | + it("uses windows path segment and zip extension for win32", () => { |
| 42 | + expect(buildDownloadUrl("1.2.3", "win32", "x64")).toBe( |
| 43 | + "https://downloads.cursor.com/lab/1.2.3/windows/x64/agent-cli-package.zip" |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + it("uses tar.gz for linux and darwin", () => { |
| 48 | + expect(buildDownloadUrl("1.2.3", "linux", "arm64")).toBe( |
| 49 | + "https://downloads.cursor.com/lab/1.2.3/linux/arm64/agent-cli-package.tar.gz" |
| 50 | + ); |
| 51 | + expect(buildDownloadUrl("1.2.3", "darwin", "x64")).toBe( |
| 52 | + "https://downloads.cursor.com/lab/1.2.3/darwin/x64/agent-cli-package.tar.gz" |
| 53 | + ); |
| 54 | + }); |
| 55 | +}); |
0 commit comments