68 lines
2.8 KiB
TypeScript
68 lines
2.8 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { afterEach, test, vi } from "vitest";
|
|
import { buildAgentDownloadCatalog, downloadLinksFor, fetchAgentDownloadCatalog, formatSize } from "./agentRegistry";
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
test("offline download catalog includes the JDBC plugin ZIP", () => {
|
|
const catalog = buildAgentDownloadCatalog([]);
|
|
|
|
assert.deepEqual(catalog.jdbcPlugin, {
|
|
label: "DBX JDBC Plugin",
|
|
filename: "dbx-jdbc-plugin-latest.zip",
|
|
url: "https://dl.dbxio.com/releases/latest/dbx-jdbc-plugin-latest.zip",
|
|
});
|
|
});
|
|
|
|
test("release assets expose GitHub, CNB, and AtomGit download links", () => {
|
|
assert.deepEqual(downloadLinksFor("https://github.com/t8y2/dbx/releases/download/agents-latest/dbx-agents-offline-macos-aarch64.zip"), [
|
|
{ source: "github", url: "https://github.com/t8y2/dbx/releases/download/agents-latest/dbx-agents-offline-macos-aarch64.zip" },
|
|
{ source: "cnb", url: "https://cnb.cool/dbxio.com/dbx/-/releases/download/agents-latest/dbx-agents-offline-macos-aarch64.zip" },
|
|
{ source: "atomgit", url: "https://atomgit.com/t8y2/dbx/releases/download/agents-latest/dbx-agents-offline-macos-aarch64.zip" },
|
|
]);
|
|
});
|
|
|
|
test("non-release assets retain their official download link", () => {
|
|
assert.deepEqual(downloadLinksFor("https://dl.dbxio.com/releases/latest/dbx-jdbc-plugin-latest.zip"), [
|
|
{ source: "official", url: "https://dl.dbxio.com/releases/latest/dbx-jdbc-plugin-latest.zip" },
|
|
]);
|
|
});
|
|
|
|
test("catalog falls back from GitHub to CNB and then AtomGit", async () => {
|
|
const requestedUrls: string[] = [];
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn(async (input: string | URL | Request) => {
|
|
const url = String(input);
|
|
requestedUrls.push(url);
|
|
if (url.includes("api.github.com")) return new Response("rate limited", { status: 403 });
|
|
if (url.includes("cnb.cool")) throw new TypeError("CORS blocked");
|
|
return Response.json({
|
|
tag_name: "agents-latest",
|
|
assets: [
|
|
{ name: "dbx-agent-access.jar", type: "attach" },
|
|
{ name: "dbx-jre-21-macos-aarch64.tar.gz", type: "attach" },
|
|
{ name: "dbx-agents-offline-macos-aarch64.zip", type: "attach" },
|
|
],
|
|
});
|
|
}),
|
|
);
|
|
|
|
const catalog = await fetchAgentDownloadCatalog();
|
|
|
|
assert.deepEqual(requestedUrls, [
|
|
"https://api.github.com/repos/t8y2/dbx/releases/tags/agents-latest",
|
|
"https://cnb.cool/dbxio.com/dbx/-/releases/download/agents-latest/agent-registry.json",
|
|
"https://api.atomgit.com/api/v5/repos/t8y2/dbx/releases/agents-latest",
|
|
]);
|
|
assert.equal(catalog?.drivers[0]?.key, "access");
|
|
assert.equal(catalog?.jres[0]?.platformKey, "macos-aarch64");
|
|
assert.equal(catalog?.bundles[0]?.platformKey, "macos-aarch64");
|
|
});
|
|
|
|
test("unknown fallback asset sizes render as unavailable", () => {
|
|
assert.equal(formatSize(0), "—");
|
|
});
|