// The market offers, against fixtures cut out of the two sources' real answers (29 November 2026): // test/fixtures/offers/runpod-gpu-types.json the whole answer of POST https://api.runpod.io/graphql { gpuTypes {...} } // test/fixtures/offers/vast-offers.json 22 real offers of GET https://console.vast.ai/api/v0/bundles/, // cut down to the fields the file names, in five pages // Where a test needs an offer the real reads did not hold (two GPUs, an AMD card, a machine already rented), // it is made here from a real one and says so. import { test, describe } from "node:test"; import assert from "node:assert/strict"; import { GPUS } from "../lib/rates.mjs"; import { PREFER, SOURCES, TIER_ORDER, VAST_NAMES, VAST_QUERIES, chooseOffer, filterOffers, fromRunpod, fromVast, makeOffers } from "../lib/offers.mjs"; import { RUNPOD_FIXTURE, VAST_FIXTURE, offersFetch } from "./world.mjs"; const AS_OF = "2026-11-29T18:00:00.000Z"; const runpod = () => fromRunpod(RUNPOD_FIXTURE, AS_OF); const vast = () => VAST_FIXTURE.pages.flatMap((p) => fromVast(p, AS_OF)); const all = () => [...runpod(), ...vast().map(({ id, ...o }) => o)]; const SHAPE = ["asOf", "gpu", "kind", "model", "region", "reliability", "secure", "source", "usdPerHour", "vramGb"]; /** A reader over the fixtures with a clock moved by hand. */ function reader(over = {}) { const w = { t: Date.parse(AS_OF), down: {}, offerCalls: { runpod: 0, vast: 0 } }; w.read = makeOffers({ now: () => w.t, fetch: offersFetch(w), ...over }); return w; } describe("Runpod's price list", () => { test("every row becomes an offer per cloud that really carries the type, at the published price", () => { const offers = runpod(); for (const o of offers) { assert.deepEqual(Object.keys(o).sort(), SHAPE); assert.deepEqual([o.source, o.kind, o.region, o.reliability, o.asOf], ["runpod", "list-price", null, null, AS_OF]); assert.ok(o.usdPerHour > 0 && o.vramGb > 0); } const find = (model, secure) => offers.find((o) => o.model === model && o.secure === secure); assert.deepEqual(find("RTX 4090", true), { source: "runpod", kind: "list-price", gpu: "rtx-4090", model: "RTX 4090", vramGb: 24, usdPerHour: 0.89, secure: true, region: null, reliability: null, asOf: AS_OF }); assert.equal(find("RTX 4090", false).usdPerHour, 0.34); // Runpod fills the price column of a cloud that does not carry the type with a placeholder: that is not a price. const raw = RUNPOD_FIXTURE.data.gpuTypes.find((t) => t.displayName === "RTX 3090 Ti"); assert.deepEqual([raw.secureCloud, raw.securePrice], [false, 0.46]); assert.equal(find("RTX 3090 Ti", true), undefined); assert.equal(find("RTX 3090 Ti", false).usdPerHour, 0.27); assert.equal(find("L4", false), undefined, "the L4 is on the secure cloud only"); }); test("Idle's seven GPUs are named by their id; other Nvidia models are kept without one", () => { const offers = runpod(); const mapped = offers.filter((o) => o.gpu); assert.deepEqual([...new Set(mapped.map((o) => o.gpu))].sort(), GPUS.map((g) => g.id).sort()); assert.equal(mapped.length, 14, "seven models, two clouds each"); for (const o of mapped) assert.equal(o.vramGb, GPUS.find((g) => g.id === o.gpu).vram); assert.equal(offers.find((o) => o.model === "A100 PCIe").gpu, null, "Idle's A100 is the SXM one"); assert.equal(offers.find((o) => o.model === "H100 NVL").gpu, null); assert.ok(offers.some((o) => o.model === "V100 SXM2"), "a Tesla is an Nvidia card"); }); test("AMD cards, the unknown row and slices of a GPU are left out", () => { const ids = RUNPOD_FIXTURE.data.gpuTypes.map((t) => t.id); assert.ok(ids.includes("AMD Instinct MI300X OAM") && ids.includes("unknown") && ids.some((id) => /MIG/.test(id)), "the real answer holds all three kinds"); const models = runpod().map((o) => o.model); assert.ok(!models.some((m) => /MI300X|MI350X|unknown|MIG/.test(m))); assert.throws(() => fromRunpod({ errors: [{ message: "nope" }] }, AS_OF), /no gpuTypes/); }); }); describe("Vast's live offers", () => { test("each is one whole GPU, with the source's own price, place and reliability", () => { const offers = vast(); assert.equal(offers.length, 22); for (const { id, ...o } of offers) { assert.deepEqual(Object.keys(o).sort(), SHAPE); assert.deepEqual([o.source, o.kind, o.asOf], ["vast", "live-offer", AS_OF]); assert.ok(o.reliability > 0.9 && o.reliability <= 1); assert.ok(o.region.length >= 2 && !o.region.startsWith(",")); } const first = VAST_FIXTURE.pages[1].offers[0]; assert.deepEqual([first.gpu_name, first.gpu_frac, first.gpu_ram, first.num_gpus], ["RTX 4090", 0.125, 24564, 1]); // gpu_frac 0.125 is one GPU of an eight-GPU host, not an eighth of a GPU: the offer carries the whole 24 GB. assert.equal(first.cpu_cores_effective / first.cpu_cores, first.gpu_frac); assert.deepEqual( (({ id, ...o }) => o)(offers.find((o) => o.id === first.id)), { source: "vast", kind: "live-offer", gpu: "rtx-4090", model: "RTX 4090", vramGb: 24, usdPerHour: Math.round(first.dph_total * 1e6) / 1e6, secure: false, region: first.geolocation, reliability: first.reliability2, asOf: AS_OF }, ); assert.equal(offers.find((o) => o.model === "B200").region, "US", 'Vast sent ", US"'); }); test("a model only gets Idle's id with the memory Idle's GPU has", () => { const offers = vast(); const ids = (model) => offers.filter((o) => o.model === model).map((o) => [o.vramGb, o.gpu]); assert.deepEqual(ids("RTX 4090").sort(), [[24, "rtx-4090"], [24, "rtx-4090"], [24, "rtx-4090"], [24, "rtx-4090"], [48, null]], "a 4090 rebuilt with 48 GB is not Idle's 4090"); assert.deepEqual(ids("A100 SXM4").sort(), [[40, null], [80, "a100"], [80, "a100"]]); assert.deepEqual(ids("L40S").sort(), [[45, "l40s"], [45, "l40s"], [48, "l40s"]], "Vast reports usable memory: 45 of the 48 GB"); assert.deepEqual([ids("H100 SXM")[0], ids("H200")[0], ids("B200")[0]], [[80, "h100"], [140, "h200"], [179, "b200"]]); for (const model of ["Quadro P2000", "GTX 1080 Ti", "Tesla P40", "RTX 3090"]) assert.equal(offers.find((o) => o.model === model).gpu, null); assert.deepEqual(Object.keys(VAST_NAMES), GPUS.map((g) => g.id)); }); test("secure means a datacenter host; being verified is not enough", () => { const raw = VAST_FIXTURE.pages.flatMap((p) => p.offers); assert.ok(raw.every((o) => o.verification === "verified")); const offers = vast(); for (const o of offers) assert.equal(o.secure, raw.find((r) => r.id === o.id).hosting_type === 1); assert.ok(offers.some((o) => o.secure) && offers.some((o) => !o.secure)); }); test("anything that is not one whole, rentable Nvidia GPU with a price is left out", () => { const real = VAST_FIXTURE.pages[1].offers[0]; // Made here from a real offer: none of the real reads held these. const made = [ { ...real, id: 1, num_gpus: 2, gpu_total_ram: real.gpu_ram * 2 }, // two GPUs { ...real, id: 2, num_gpus: 0.5 }, // a share of a GPU, if Vast ever sold one { ...real, id: 3, gpu_total_ram: real.gpu_ram / 2 }, // memory that does not add up to one GPU { ...real, id: 4, gpu_arch: "amd", gpu_name: "RX 7900 XTX" }, { ...real, id: 5, rentable: false }, { ...real, id: 6, rented: true }, { ...real, id: 7, dph_total: 0 }, { ...real, id: 8, dph_total: null }, { ...real, id: 9, gpu_ram: 0 }, { ...real, id: 10, gpu_name: undefined }, ]; assert.deepEqual(fromVast({ offers: [...made, real] }, AS_OF).map((o) => o.id), [real.id]); assert.throws(() => fromVast({ error: "nope" }, AS_OF), /no offers/); }); test("every search asks for one rentable GPU from a verified host, and together they name Idle's seven", () => { for (const q of VAST_QUERIES) { assert.deepEqual([q.rentable, q.num_gpus, q.verified, q.type], [{ eq: true }, { eq: 1 }, { eq: true }, "on-demand"]); assert.deepEqual(q.order, [["dph_total", "asc"]]); assert.ok(q.limit <= 64, "Vast answers 64 offers at most"); } assert.deepEqual(VAST_QUERIES.flatMap((q) => q.gpu_name?.in ?? []).sort(), Object.values(VAST_NAMES).sort()); assert.equal(VAST_QUERIES.length, VAST_FIXTURE.pages.length); }); }); describe("reading both sources", () => { test("merges them, keeps a machine that answered two searches once, and says where it read", async () => { const w = reader(); const r = await w.read(); assert.equal(r.offers.length, runpod().length + 21, "22 Vast offers, one of them twice"); assert.ok(r.offers.every((o) => !("id" in o))); assert.deepEqual(r.errors, []); assert.deepEqual(r.sources.map((s) => [s.name, s.kind, s.ok, s.count, s.asOf]), [["runpod", "list-price", true, runpod().length, AS_OF], ["vast", "live-offer", true, 21, AS_OF]]); assert.equal(r.asOf, AS_OF); assert.deepEqual(SOURCES.map((s) => s.name), ["runpod", "vast"]); }); test("reads each source at most once a minute, and simultaneous callers share one read", async () => { const w = reader(); await Promise.all([w.read(), w.read(), w.read()]); assert.deepEqual(w.offerCalls, { runpod: 1, vast: 5 }); w.t += 59_000; await w.read(); assert.deepEqual(w.offerCalls, { runpod: 1, vast: 5 }); w.t += 2_000; const later = await w.read(); assert.deepEqual(w.offerCalls, { runpod: 2, vast: 10 }); assert.equal(later.asOf, new Date(w.t).toISOString()); }); test("a source that is down is named, the other still answers, and nobody invents its prices", async () => { const w = reader(); w.down.vast = true; const r = await w.read(); assert.equal(r.offers.length, runpod().length); assert.ok(r.offers.every((o) => o.source === "runpod")); assert.deepEqual(r.errors, ["vast: connection refused"]); assert.deepEqual(r.sources.map((s) => [s.name, s.ok, s.count]), [["runpod", true, runpod().length], ["vast", false, 0]]); const w2 = reader(); w2.down.runpod = true; const r2 = await w2.read(); assert.deepEqual([r2.offers.length, r2.errors], [21, ["runpod: answered 503"]]); const w3 = reader(); w3.down = { runpod: true, vast: true }; const r3 = await w3.read(); assert.deepEqual([r3.offers, r3.errors.length], [[], 2]); }); test("a source that failed is not asked again for 15 seconds, and comes back when it answers", async () => { const w = reader(); w.down.vast = true; await w.read(); const calls = w.offerCalls.vast; w.t += 14_000; await w.read(); assert.equal(w.offerCalls.vast, calls, "not hammered"); w.down.vast = false; w.t += 2_000; const r = await w.read(); assert.deepEqual([r.errors, r.sources[1].count], [[], 21]); assert.equal(w.offerCalls.runpod, 1, "the source that was fine was not read again"); }); }); describe("idle/auto: choosing among offers", () => { test("filters by model, memory and cloud, cheapest first", () => { const offers = all(); const big = filterOffers(offers, { minVram: 80 }); assert.ok(big.length > 5 && big.every((o) => o.vramGb >= 80)); assert.deepEqual(big.map((o) => o.usdPerHour), big.map((o) => o.usdPerHour).sort((a, b) => a - b)); assert.ok(filterOffers(offers, { gpu: "h100" }).every((o) => o.gpu === "h100")); assert.ok(filterOffers(offers, { secure: true }).every((o) => o.secure)); assert.ok(filterOffers(offers, { secure: false }).every((o) => !o.secure)); assert.equal(filterOffers(offers).length, offers.length); assert.deepEqual(filterOffers(offers, { minVram: 100_000 }), []); }); test("cheapest: the lowest price that meets the constraints, whatever the model", () => { const c = chooseOffer(all(), { prefer: "cheapest", minVram: 24 }); assert.deepEqual([c.pick.source, c.pick.model, c.pick.vramGb, c.pick.usdPerHour, c.pick.gpu], ["runpod", "RTX A5000", 24, 0.16, null]); assert.equal(c.rule.prefer, "cheapest"); assert.match(c.rule.description, /lowest price/); assert.equal(c.considered, filterOffers(all(), { minVram: 24 }).length); assert.equal(chooseOffer(all(), {}).pick.model, "Quadro P2000", "with no constraint at all it is the cheapest machine on the market"); const h100 = chooseOffer(all(), { gpu: "h100" }); assert.deepEqual([h100.pick.source, h100.pick.usdPerHour], ["vast", 1.735556]); }); test("fastest: the highest tier present, then the lowest price within it", () => { assert.deepEqual(TIER_ORDER.slice().sort(), GPUS.map((g) => g.id).sort(), "the tiers are Idle's seven GPUs, each once"); const c = chooseOffer(all(), { prefer: "fastest", minVram: 24 }); assert.deepEqual([c.pick.gpu, c.pick.source, c.pick.usdPerHour], ["b200", "runpod", 5.98]); assert.deepEqual(c.rule.tierOrder, TIER_ORDER); assert.match(c.rule.description, /b200, h200, h100, a100, rtx-5090, l40s, rtx-4090/); assert.deepEqual(c.alternatives.map((o) => [o.gpu, o.source, o.secure]), [["b200", "runpod", true], ["b200", "vast", true], ["h200", "runpod", false]]); // Models Idle has no id for have no tier, so the rule never picks them. assert.ok(chooseOffer(all(), { prefer: "fastest" }).considered < all().length); // Without the B200 and the H200, the H100 is the fastest. const rest = all().filter((o) => o.gpu !== "b200" && o.gpu !== "h200"); assert.deepEqual([chooseOffer(rest, { prefer: "fastest" }).pick.gpu, chooseOffer(rest, { prefer: "fastest" }).pick.usdPerHour], ["h100", 1.735556]); assert.equal(chooseOffer(all(), { prefer: "fastest", gpu: "l40s" }).pick.usdPerHour, 0.602963); }); test("secure: only secure offers, then the lowest price", () => { const c = chooseOffer(all(), { prefer: "secure", minVram: 24 }); assert.deepEqual([c.pick.source, c.pick.model, c.pick.usdPerHour, c.pick.secure], ["runpod", "RTX A5000", 0.27, true]); assert.ok(c.alternatives.every((o) => o.secure)); assert.deepEqual([c.alternatives[0].source, c.alternatives[0].model, c.alternatives[0].region], ["vast", "RTX 5090", "South Korea, KR"]); assert.ok(c.considered < chooseOffer(all(), { prefer: "cheapest", minVram: 24 }).considered); assert.deepEqual(PREFER, ["cheapest", "fastest", "secure"]); }); test("alternatives are the next three that differ, and nothing fits means no pick", () => { const c = chooseOffer(all(), { gpu: "rtx-4090" }); const key = (o) => [o.source, o.model, o.vramGb, o.secure].join("|"); const keys = [c.pick, ...c.alternatives].map(key); assert.equal(new Set(keys).size, keys.length, "three cheap 4090s from the same kind of host are one alternative, not three"); assert.equal(c.alternatives.length, 3); assert.deepEqual(chooseOffer(all(), { minVram: 1000 }), { rule: { prefer: "cheapest", minVram: 1000, gpu: null, description: c.rule.description }, pick: null, alternatives: [], considered: 0 }); assert.equal(chooseOffer([], { prefer: "fastest" }).pick, null); }); });