From 5b2e71463181aaec99fc4d97f15eb7d2e214dc12 Mon Sep 17 00:00:00 2001 From: Nate Marmorstein Date: Mon, 30 Nov 2026 09:36:06 -0800 Subject: [PATCH 1/2] feat: Vast.ai skips machines that failed to start, takes a max price and asks for faster networks A Vast.ai machine whose container fails to start, or whose sshd refuses VM Bridge's key, is often the cheapest offer, so the next VM rented it again and lost minutes before moving on. Such a machine is now left out of searches for a day (`machine_id notin`). A new optional "Max price per hour" setting caps the search, and the search asks for 500 Mbps down instead of 200, since every new VM downloads its image, Node, T3 and the agents. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/providers/vast.ts | 59 +++++++++++++++++++++++++++++-- apps/server/test/vast.test.ts | 53 ++++++++++++++++++++++++++- docs/PROVIDERS.md | 2 +- 3 files changed, 109 insertions(+), 5 deletions(-) diff --git a/apps/server/src/providers/vast.ts b/apps/server/src/providers/vast.ts index b076359..865d891 100644 --- a/apps/server/src/providers/vast.ts +++ b/apps/server/src/providers/vast.ts @@ -78,6 +78,38 @@ setsid nohup bash /root/vmbridge-idle.sh >/dev/null 2>&1 < /dev/null &`; /** Hosts set an end date on each offer, when they may take the machine back. VM Bridge skips offers ending sooner. */ const leastDurationS = 14 * 86_400; +/** + * Machines whose rented container failed to start or never let VM Bridge in over SSH, by Vast.ai machine ID, with + * when to try them again. The cheapest offer is often the same broken machine, so without this every new VM would + * rent it first and lose minutes to it. Kept for this process only, across drivers, so changing a setting keeps it. + */ +const failedMachines = new Map(); +const failedMachineMs = 24 * 60 * 60_000; +const failedMachineLimit = 200; + +/** Machines to leave out of the search now. */ +export function skippedMachines(now = Date.now()) { + for (const [machine, until] of failedMachines) if (until <= now) failedMachines.delete(machine); + return [...failedMachines.keys()]; +} + +/** Leaves `machine` out of searches for a day. */ +export function skipMachine(machine: number, now = Date.now()) { + failedMachines.delete(machine); + failedMachines.set(machine, now + failedMachineMs); + // The oldest go first: a Map keeps insertion order. + while (failedMachines.size > failedMachineLimit) failedMachines.delete(failedMachines.keys().next().value!); +} + +/** The highest price per hour a setting allows, or undefined for none. Throws a readable error for a value that is not a price. */ +export function maxPrice(value: string | undefined) { + const text = value?.trim().replace(/^\$/, ""); + if (!text) return undefined; + const price = Number(text); + if (!Number.isFinite(price) || price <= 0) throw fail(`The Vast.ai max price per hour must be a number of dollars, such as 0.50, not "${value}".`, "invalid_argument"); + return price; +} + interface Instance { id: number; label: string | null; @@ -94,6 +126,7 @@ interface Instance { interface Offer { id: number; + machine_id?: number; gpu_name: string; dph_total: number; } @@ -102,6 +135,8 @@ export interface VastOptions { apiKey: string; /** A choice from the GPU field, or empty for the cheapest. */ gpu?: string; + /** The max price per hour field, in dollars. Empty: no limit. */ + maxPrice?: string; /** For tests. Default: the global `fetch`. */ fetch?: Fetch; /** For tests. Default: SSH (vast-ssh.ts). */ @@ -331,6 +366,8 @@ export function vast(options: VastOptions): VastProvider { async function offers(size: VmSize) { const { cores, ramMb, diskGb } = vastSizes[size]; + const highest = maxPrice(options.maxPrice); + const skipped = skippedMachines(); const { offers: found } = await json<{ offers: Offer[] }>("POST", "/v0/bundles/", undefined, { verified: { eq: true }, external: { eq: false }, @@ -340,18 +377,24 @@ export function vast(options: VastOptions): VastProvider { // SSH straight to the host, which Vast.ai calls faster and more reliable than its proxy. direct_port_count: { gte: 1 }, disk_space: { gte: diskGb }, - inet_down: { gte: 200 }, + // Each new VM downloads its image, Node, T3 and the agents, so a slow line makes it slow to start. + inet_down: { gte: 500 }, reliability2: { gte: 0.97 }, cpu_cores_effective: { gte: cores }, cpu_ram: { gte: ramMb }, duration: { gte: leastDurationS }, ...(gpuNames.length ? { gpu_name: { in: gpuNames } } : {}), + ...(highest !== undefined ? { dph_total: { lte: highest } } : {}), + ...(skipped.length ? { machine_id: { notin: skipped } } : {}), order: [["dph_total", "asc"]], type: "on-demand", allocated_storage: diskGb, limit: 5, }); - if (!found.length) throw fail("Vast.ai has no machine for this size right now. Try another size or GPU, or try again later.", "quota"); + if (!found.length) { + const price = highest !== undefined ? ` under $${highest} an hour` : ""; + throw fail(`Vast.ai has no machine for this size${price} right now. Try another size or GPU${price ? ", a higher max price" : ""}, or try again later.`, "quota"); + } return found; } @@ -407,6 +450,8 @@ export function vast(options: VastOptions): VastProvider { return info(ready, labels); } catch (error) { lastError = error; + // The machine rented but would not start or let VM Bridge in: the next VM should not rent it again. + if (offer.machine_id !== undefined) skipMachine(offer.machine_id); await destroy(id).catch(() => {}); } } @@ -573,6 +618,14 @@ export const vastProvider: ProviderDefinition = { required: false, options: Object.keys(gpuModels).map((value) => ({ value, label: value || "Cheapest available" })), }, + { + key: "maxPrice", + label: "Max price per hour", + kind: "text", + required: false, + placeholder: "0.50", + help: "In dollars, for the whole machine. VM Bridge rents nothing that costs more. Empty: no limit.", + }, ], features: { // A stopped container keeps its disk. Memory and processes go, and T3 starts again on wake. @@ -588,7 +641,7 @@ export const vastProvider: ProviderDefinition = { defaultSize: "small", open(config) { - const provider = vast({ apiKey: required(config, "apiKey", "Vast.ai API key"), gpu: config.values.gpu }); + const provider = vast({ apiKey: required(config, "apiKey", "Vast.ai API key"), gpu: config.values.gpu, maxPrice: config.values.maxPrice }); return { ...sdkDriver({ id: "vast", provider, sleep: "pause" }), verify: provider.verify }; }, }; diff --git a/apps/server/test/vast.test.ts b/apps/server/test/vast.test.ts index 005b025..e4312e2 100644 --- a/apps/server/test/vast.test.ts +++ b/apps/server/test/vast.test.ts @@ -3,7 +3,7 @@ import { mkdtempSync, rmSync, statSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { SandboxError } from "@opencoredev/sandbox-sdk"; -import { parseLabel, sshTarget, vast } from "../src/providers/vast.ts"; +import { maxPrice, parseLabel, skipMachine, skippedMachines, sshTarget, vast } from "../src/providers/vast.ts"; import type { RunOptions, RunResult, Transport } from "../src/providers/vast-ssh.ts"; interface Call { @@ -222,6 +222,57 @@ describe("Vast.ai instances", () => { }); }); +describe("Vast.ai offer search", () => { + test("a machine that failed to start is left out of the next VM's search", async () => { + let rented = 0; + const searches: Record[] = []; + const { fetch } = fakeApi((call) => { + if (call.path === "/v0/ssh/" && call.method === "GET") return { json: [{ id: 1, public_key: "ssh-ed25519 AAAAvmbridge vmbridge" }] }; + if (call.path === "/v0/bundles/") { + searches.push(call.body as Record); + return { json: { offers: [{ id: 201, machine_id: 9001, gpu_name: "GTX 1070", dph_total: 0.058 }, { id: 202, machine_id: 9002, gpu_name: "GTX 1660 S", dph_total: 0.067 }] } }; + } + if (call.path.startsWith("/v0/asks/")) return { json: { success: true, new_contract: 7 + rented++ } }; + // The first machine's container stops while starting; every later one runs. + if (call.path === "/v0/instances/7/" && call.method === "GET") return { json: { instances: instance("exited") } }; + const id = Number(call.path.split("/")[3]); + if (call.method === "GET" && id > 7) return { json: { instances: { ...instance("running"), id } } }; + return undefined; + }); + const provider = vast({ apiKey: "vast_secret", fetch, transport: recordingTransport().transport, publicKey, timing }); + + await provider.create({ key: "vm-1", size: "small", labels: { vmbridge: "b1" } }); + await provider.create({ key: "vm-2", size: "small", labels: { vmbridge: "b1" } }); + + expect((searches[1]!.machine_id as { notin: number[] }).notin).toContain(9001); + expect((searches[1]!.machine_id as { notin: number[] }).notin).not.toContain(9002); + }); + + test("a skipped machine is searched again after a day", () => { + skipMachine(424242, 0); + expect(skippedMachines(1_000)).toContain(424242); + expect(skippedMachines(24 * 60 * 60_000 + 1)).not.toContain(424242); + }); + + test("the max price setting caps the search, and asks for faster networks", async () => { + const { calls, fetch } = fakeApi((call) => (call.path === "/v0/bundles/" ? { json: { offers: [] } } : call.path === "/v0/ssh/" ? { json: [] } : undefined)); + const provider = vast({ apiKey: "vast_secret", maxPrice: "$0.50", fetch, transport: recordingTransport().transport, publicKey, timing }); + + const error = (await provider.create({ key: "vm-1", size: "small", labels: { vmbridge: "b1" } }).catch((caught: unknown) => caught)) as SandboxError; + + expect(calls.find((call) => call.path === "/v0/bundles/")!.body).toMatchObject({ dph_total: { lte: 0.5 }, inet_down: { gte: 500 } }); + expect(error.code).toBe("quota"); + expect(error.message).toContain("under $0.5 an hour"); + }); + + test("a max price that is not a price is refused with a reason, and an empty one sets no limit", () => { + expect(maxPrice("")).toBeUndefined(); + expect(maxPrice(" 1.25 ")).toBe(1.25); + expect(() => maxPrice("cheap")).toThrow("must be a number of dollars"); + expect(() => maxPrice("0")).toThrow("must be a number of dollars"); + }); +}); + describe("Vast.ai commands and files", () => { const dir = mkdtempSync(join(tmpdir(), "vast-test-")); afterAll(() => rmSync(dir, { recursive: true, force: true })); diff --git a/docs/PROVIDERS.md b/docs/PROVIDERS.md index 373e811..054e010 100644 --- a/docs/PROVIDERS.md +++ b/docs/PROVIDERS.md @@ -29,7 +29,7 @@ The default size is what new VMs get unless **Settings**, **VMs** or a repositor - **Instabox**: the default template is `agent-browser`. Ports must be 1024 or higher (T3 uses 3773). The free plan allows one machine in any state (a paused one counts) and only 4 vCPU, 8 GB (`400 spec_not_allowed` for 2 vCPU, 4 GB, checked live), so medium is the default. With one machine there is no room to build a base snapshot, and those builds fail with `429 quota_exceeded`, which the SDK retries for up to a minute first. A snapshot fixes the size of VMs made from it to its source's (`sizeLocked`), so VM Bridge names no size there. A snapshot of a running machine is like a power cut, so the base setup runs `sync` first. Deleting a snapshot leaves the machines made from it working. - **Superserve**: every template has 2 vCPU, 4 GB and 8 GB of disk, so all three sizes are the same VM. The SDK needs Python in the VM and the default `superserve/node-22` template has none, so VM Bridge uses `superserve/python-3.11` and installs Node itself. Superserve has no idle timer, only a cap on time awake that resets on every resume, so the safety net is a pause after 12 hours awake. Superserve's docs only say pause keeps "VM state". A check confirmed it keeps memory: a process started before a pause was still running after resume, and uptime carried on instead of restarting. - **Kubi**: one machine for every size: 4 vCPU, 8 GB and 50 GB of disk, Debian 13 with Node 20.19, in `eu-1`. VM Bridge calls Kubi's API with `fetch` (the `@trykubi/sdk` package has no ports). A VM is a Kubi screen labelled with VM Bridge's labels and its key. Sleep is a stop (disk kept) and wake is a start, which reboots the VM, so T3 starts again on every wake like on Daytona. Processes do not survive a stop. T3 is reached through a token port (`PUT /screens/{id}/ports/3773`), whose token goes in a `Kubi-Port-Token` header; Kubi closes idle HTTP connections after 5 minutes and WebSockets after 1 hour, and VM Bridge's 5 s ping keeps the socket busy. Exec takes at most 10000 characters of command and 64 KiB of stdin, so longer commands and all stdin go up as files only the VM's user can read, removed as the command starts. A persistent screen ($20 a month, kept until deleted) is the default. Kubi settings can pick disposable instead ($0.035 an hour running, $0.003 an hour stopped), which Kubi deletes 7 days after it stops. The API key needs `read`, `exec`, `power` and `network`; adding the provider checks the key with `GET /me` and names any that are missing. A full account (`402 QUOTA_EXCEEDED`) names its screen limit. Kubi has no idle timer, so there is no safety net. -- **Vast.ai**: every VM gets one NVIDIA GPU. VM Bridge rents the cheapest verified, on-demand machine from Vast.ai's marketplace that fits the size (small: 4+ vCPU, 8+ GB, 40 GB disk; medium: 8+ vCPU, 16+ GB, 60 GB; large: 16+ vCPU, 32+ GB, 100 GB), and only machines its host offers for at least 14 days. The optional GPU model setting narrows the search and costs more than "Cheapest available". The API key comes from https://cloud.vast.ai/manage-keys/. VM Bridge reaches each VM with the `ssh` command from the computer it runs on, so Vast.ai cannot run on Cloudflare Workers. It makes its own SSH key and adds it to the Vast.ai account. T3 and OpenCode are reached through SSH tunnels, so no ports are open to the internet. Sleep is a stop (disk kept, memory gone) and wake is a start, which reboots the VM. Asleep it pays only for its disk. Vast.ai bills per second from prepaid credit and stops instances at zero credit. Limits: a sleeping VM wakes only if its host's GPU is still free, so if someone else rented it meanwhile the wake fails and the VM has to wait or be deleted. Each host sets an end date on its machines (usually weeks to months), and a VM can be lost when it passes. Hosts are independent and can go offline. There are no snapshots, so base snapshots are not available. Containers have no systemd or Docker. Safety net: a small script in each VM stops it after 60 minutes with no SSH connection, using the key Vast.ai gives each container for itself, so a VM left awake while VM Bridge is down stops paying for its GPU within the hour. +- **Vast.ai**: every VM gets one NVIDIA GPU. VM Bridge rents the cheapest verified, on-demand machine from Vast.ai's marketplace that fits the size (small: 4+ vCPU, 8+ GB, 40 GB disk; medium: 8+ vCPU, 16+ GB, 60 GB; large: 16+ vCPU, 32+ GB, 100 GB), and only machines its host offers for at least 14 days. The optional GPU model setting narrows the search and costs more than "Cheapest available". The optional max price per hour, in dollars, leaves out every offer that costs more. The search asks for hosts with at least 500 Mbps down, since every new VM downloads its image, Node, T3 and the agents. A machine whose container fails to start, or that never lets VM Bridge in over SSH, is left out of searches for a day, so the next VM does not rent the same broken machine first. VM Bridge remembers those machines until it restarts. The API key comes from https://cloud.vast.ai/manage-keys/. VM Bridge reaches each VM with the `ssh` command from the computer it runs on, so Vast.ai cannot run on Cloudflare Workers. It makes its own SSH key and adds it to the Vast.ai account. T3 and OpenCode are reached through SSH tunnels, so no ports are open to the internet. Sleep is a stop (disk kept, memory gone) and wake is a start, which reboots the VM. Asleep it pays only for its disk. Vast.ai bills per second from prepaid credit and stops instances at zero credit. Limits: a sleeping VM wakes only if its host's GPU is still free, so if someone else rented it meanwhile the wake fails and the VM has to wait or be deleted. Each host sets an end date on its machines (usually weeks to months), and a VM can be lost when it passes. Hosts are independent and can go offline. There are no snapshots, so base snapshots are not available. Containers have no systemd or Docker. Safety net: a small script in each VM stops it after 60 minutes with no SSH connection, using the key Vast.ai gives each container for itself, so a VM left awake while VM Bridge is down stops paying for its GPU within the hour. - **Kubi watch links**: every Kubi VM gets a link, `/watch/` on VM Bridge's address, that shows its screen live and view-only in any browser, with no dashboard login. The VM's details in the dashboard copy it, make a new one (the old one stops working at once) or turn it off. The token is 32 random bytes, looked up by its SHA-256 hash and stored encrypted, and a wrong or old token gets the same 404 as any unknown path. The page's stream goes through VM Bridge, which asks Kubi for a fresh view-only ticket (`POST /screens/{id}/viewer`) on every connect, so the browser never sees the Kubi key, ticket or address. VM Bridge only passes on the bytes a viewer sends to ask for frames; anything else, such as keys or the mouse, ends the stream. Opening the link never wakes the VM: while it sleeps the page says so and connects when it wakes. VM Bridge also keeps the link in `/workspace/.vmbridge/watch-url` on the VM (readable only by its user), written on every wake and whenever the link or VM Bridge's address changes, and removed while the link is off. On Cloudflare Workers the link uses the Worker's address. - **Railway**: no pause, and Railway's own idle timeout destroys the VM, so VM Bridge sets none. CPU and memory are fixed per client, so VM Bridge opens one client per size. Railway keeps checkpoints until they are deleted and the SDK has no delete, so VM Bridge deletes them with Railway's own SDK (`Sandbox.checkpoints` to find one by key, then `Sandbox.deleteCheckpoint`): after a wake from the checkpoint, and when a VM asleep as a checkpoint is deleted. From 99891b48805b7da9847ee9e62ec65b311c66a42e Mon Sep 17 00:00:00 2001 From: Nate Marmorstein Date: Mon, 30 Nov 2026 09:50:31 -0800 Subject: [PATCH 2/2] fix: Vast.ai skips a machine only for its own startup or SSH failures, and refuses a max price of "$" Only the errors that show the machine itself is broken (its container stopped or never started, or SSH never let VM Bridge in) leave it out of searches. An API error, or setup failing after SSH worked, no longer does. A max price of "$" alone was read as no limit; it is now refused with a reason. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/providers/vast.ts | 27 +++++++++++++++++++-------- apps/server/test/vast.test.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/apps/server/src/providers/vast.ts b/apps/server/src/providers/vast.ts index 865d891..02c6e32 100644 --- a/apps/server/src/providers/vast.ts +++ b/apps/server/src/providers/vast.ts @@ -103,10 +103,12 @@ export function skipMachine(machine: number, now = Date.now()) { /** The highest price per hour a setting allows, or undefined for none. Throws a readable error for a value that is not a price. */ export function maxPrice(value: string | undefined) { - const text = value?.trim().replace(/^\$/, ""); - if (!text) return undefined; + const trimmed = value?.trim(); + if (!trimmed) return undefined; + const text = trimmed.replace(/^\$/, "").trim(); const price = Number(text); - if (!Number.isFinite(price) || price <= 0) throw fail(`The Vast.ai max price per hour must be a number of dollars, such as 0.50, not "${value}".`, "invalid_argument"); + // Number("") is 0, so a lone "$" is refused here too. + if (!text || !Number.isFinite(price) || price <= 0) throw fail(`The Vast.ai max price per hour must be a number of dollars, such as 0.50, not "${value}".`, "invalid_argument"); return price; } @@ -165,6 +167,14 @@ export type VastProvider = Provider, "pause" | "size"> & { const fail = (message: string, code: ErrorCode, sandboxId?: string) => new SandboxError(message, { code, provider: "vast", sandboxId }); +/** Errors that show the rented machine itself is broken: its container stopped or never started, or SSH never let VM Bridge in. */ +const machineFaults = new WeakSet(); +function machineFault(message: string, code: ErrorCode, sandboxId: string) { + const error = fail(message, code, sandboxId); + machineFaults.add(error); + return error; +} + /** ssh's own last line on a failed connection, as ": reason", with any IPv4 address left out. */ function sshReason(stderr: string) { const line = stderr.trim().split("\n").at(-1)?.trim().replace(/\b\d{1,3}(?:\.\d{1,3}){3}\b/g, "the host"); @@ -331,7 +341,7 @@ export function vast(options: VastOptions): VastProvider { const status = current.actual_status ?? ""; if (status !== "exited" && status !== "stopped") left = true; if ((status === "exited" && left) || status === "offline") { - throw fail(`The Vast.ai machine ${status === "exited" ? "stopped its container" : "went offline"} while starting`, "unavailable", id); + throw machineFault(`The Vast.ai machine ${status === "exited" ? "stopped its container" : "went offline"} while starting`, "unavailable", id); } if (current.cur_state === "scheduling" || status === "scheduling") scheduling ??= Date.now(); if (scheduling !== undefined && Date.now() - scheduling > timing.schedulingMs) { @@ -347,9 +357,9 @@ export function vast(options: VastOptions): VastProvider { } const sshGivenUp = running !== undefined && Date.now() - running > timing.sshMs; if (sshError !== undefined && (sshGivenUp || Date.now() > deadline)) { - throw fail(`The Vast.ai machine runs but did not answer over SSH${sshError}`, "timeout", id); + throw machineFault(`The Vast.ai machine runs but did not answer over SSH${sshError}`, "timeout", id); } - if (Date.now() > deadline) throw fail("The Vast.ai machine did not start in time", "timeout", id); + if (Date.now() > deadline) throw machineFault("The Vast.ai machine did not start in time", "timeout", id); await sleep(timing.pollMs); } } @@ -450,8 +460,9 @@ export function vast(options: VastOptions): VastProvider { return info(ready, labels); } catch (error) { lastError = error; - // The machine rented but would not start or let VM Bridge in: the next VM should not rent it again. - if (offer.machine_id !== undefined) skipMachine(offer.machine_id); + // The machine itself would not start or let VM Bridge in: the next VM should not rent it again. Other failures, + // such as an API error or setup failing after SSH worked, say nothing about the machine. + if (offer.machine_id !== undefined && machineFaults.has(error as object)) skipMachine(offer.machine_id); await destroy(id).catch(() => {}); } } diff --git a/apps/server/test/vast.test.ts b/apps/server/test/vast.test.ts index e4312e2..8adbc8d 100644 --- a/apps/server/test/vast.test.ts +++ b/apps/server/test/vast.test.ts @@ -248,6 +248,33 @@ describe("Vast.ai offer search", () => { expect((searches[1]!.machine_id as { notin: number[] }).notin).not.toContain(9002); }); + test("a machine where setup fails after SSH worked is not left out of later searches", async () => { + let rented = 0; + const searches: Record[] = []; + const { fetch } = fakeApi((call) => { + if (call.path === "/v0/ssh/" && call.method === "GET") return { json: [{ id: 1, public_key: "ssh-ed25519 AAAAvmbridge vmbridge" }] }; + if (call.path === "/v0/bundles/") { + searches.push(call.body as Record); + return { json: { offers: [{ id: 301, machine_id: 9101, gpu_name: "GTX 1070", dph_total: 0.058 }, { id: 302, machine_id: 9102, gpu_name: "GTX 1660 S", dph_total: 0.067 }] } }; + } + if (call.path.startsWith("/v0/asks/")) return { json: { success: true, new_contract: 7 + rented++ } }; + const id = Number(call.path.split("/")[3]); + if (call.method === "GET" && id >= 7) return { json: { instances: { ...instance("running"), id } } }; + return undefined; + }); + // SSH works everywhere, but setup on the first machine fails, as when a package mirror is down. + const transport: Transport = { + ...recordingTransport().transport, + run: async (id, command) => ({ exitCode: id === "7" && command.includes("mkdir -p /workspace") ? 100 : 0, stdout: new Uint8Array(), stderr: "" }), + }; + const provider = vast({ apiKey: "vast_secret", fetch, transport, publicKey, timing }); + + expect((await provider.create({ key: "vm-1", size: "small", labels: { vmbridge: "b1" } })).id).toBe("8"); + await provider.create({ key: "vm-2", size: "small", labels: { vmbridge: "b1" } }); + + expect((searches[1]!.machine_id as { notin: number[] } | undefined)?.notin ?? []).not.toContain(9101); + }); + test("a skipped machine is searched again after a day", () => { skipMachine(424242, 0); expect(skippedMachines(1_000)).toContain(424242); @@ -267,6 +294,9 @@ describe("Vast.ai offer search", () => { test("a max price that is not a price is refused with a reason, and an empty one sets no limit", () => { expect(maxPrice("")).toBeUndefined(); + expect(maxPrice(" ")).toBeUndefined(); + expect(maxPrice("$0.50")).toBe(0.5); + expect(() => maxPrice("$")).toThrow("must be a number of dollars"); expect(maxPrice(" 1.25 ")).toBe(1.25); expect(() => maxPrice("cheap")).toThrow("must be a number of dollars"); expect(() => maxPrice("0")).toThrow("must be a number of dollars");