Public: anyone can read this; the crew can change it.
The ceiling counts a machine whose datacenter stopped listing its size at that size's price #16384
Check · Review · Land · Live done — Landed and live in production.
sold/ceiling-same-size → main 0 commits 1 thread · 1 unresolved
2 files
changed +30
−7
src/cloud/ceiling.ts +15 −6
| @@ -43,6 +43,8 @@ export interface Priced { | ||
| 43 | 43 | /** The price of a Places id (`provider:datacenter:size`). */ |
| 44 | 44 | forge(id: string): number | undefined; |
| 45 | 45 | dearest(cloud: string, datacenter?: string): number | undefined; |
| 46 | /** The dearest price of this exact size anywhere on the cloud: a size keeps its price across datacenters. */ | |
| 47 | sameSize(cloud: string, size: string): number | undefined; | |
| 46 | 48 | /** What keeping a forge's data volume alone costs a month on a cloud, in US cents rounded up. */ |
| 47 | 49 | volume(cloud: string): number | undefined; |
| 48 | 50 | /** Why a listed place cannot be ordered now; undefined when it can, or is not listed. */ |
| @@ -70,13 +72,13 @@ function keptVolumeCents(db: Database, provider: string, rate: Rate | undefined) | ||
| 70 | 72 | |
| 71 | 73 | export function priced(db: Database): Priced { |
| 72 | 74 | const rate = keptRate(db, "EUR"); |
| 73 | const cents = new Map<string, { cloud: string; datacenter: string; cents: number }>(); | |
| 75 | const cents = new Map<string, { cloud: string; datacenter: string; size: string; cents: number }>(); | |
| 74 | 76 | const closed = new Map<string, string>(); |
| 75 | 77 | for (const p of keptPlaces(db, rate)) { |
| 76 | 78 | // A place the catalog could not price says so with no cost; it is not a place that costs nothing. |
| 77 | 79 | if (p.costCents <= 0) continue; |
| 78 | 80 | try { |
| 79 | cents.set(p.id, { cloud: p.provider, datacenter: p.datacenter, cents: toUsd(p.price.vendorAmount, p.price.vendorCurrency, rate, "up").usdCents }); | |
| 81 | cents.set(p.id, { cloud: p.provider, datacenter: p.datacenter, size: p.size, cents: toUsd(p.price.vendorAmount, p.price.vendorCurrency, rate, "up").usdCents }); | |
| 80 | 82 | if (!p.orderable) closed.set(p.id, p.why); |
| 81 | 83 | } catch { |
| 82 | 84 | // no rate for its currency: no price |
| @@ -91,6 +93,10 @@ export function priced(db: Database): Priced { | ||
| 91 | 93 | const all = (here.length > 0 ? here : mine).map((c) => c.cents); |
| 92 | 94 | return all.length === 0 ? undefined : Math.max(...all); |
| 93 | 95 | }, |
| 96 | sameSize: (cloud, size) => { | |
| 97 | const all = [...cents.values()].filter((c) => c.cloud === cloud && c.size === size).map((c) => c.cents); | |
| 98 | return all.length === 0 ? undefined : Math.max(...all); | |
| 99 | }, | |
| 94 | 100 | closed: (id) => closed.get(id), |
| 95 | 101 | }; |
| 96 | 102 | } |
| @@ -100,16 +106,19 @@ type Row = Pick<Pinned, "target" | "remote" | "volume" | "datacenter" | "size" | | ||
| 100 | 106 | /** |
| 101 | 107 | * What one pinned row costs a month, cents. A row with a machine or a volume is counted as the |
| 102 | 108 | * whole forge of its recorded place: the catalog prices a place whole, and a volume waiting for |
| 103 | * its machine is about to be one. A place the catalog no longer lists is counted at the dearest | |
| 104 | * the cloud has in that datacenter: the reckoning errs high. Zero only for a row with nothing | |
| 109 | * its machine is about to be one. A place the catalog no longer lists is counted at its size's | |
| 110 | * dearest price elsewhere on that cloud, and only when the size is unknown everywhere at the | |
| 111 | * dearest the cloud has in that datacenter: the reckoning errs high, not wildly (test3 on | |
| 112 | * 2026-11-25 sat in a datacenter that stopped listing its size and was counted at $157, not $13). Zero only for a row with nothing | |
| 105 | 113 | * made, or when the catalog holds nothing for the cloud at all (then nothing new is admitted |
| 106 | 114 | * either). A retired forge costs only the volume it kept (the whole forge's price when the catalog |
| 107 | 115 | * has none for volumes), and nothing once the volume is deleted. |
| 108 | 116 | */ |
| 109 | 117 | export function rowCents(p: Row, prices: Priced): number { |
| 110 | 118 | if (p.remote === "" && p.volume === "") return 0; |
| 111 | if (p.state === "retired") return p.volume === "" ? 0 : (prices.volume(p.target) ?? prices.forge(placeIdOf(p)) ?? prices.dearest(p.target, p.datacenter) ?? 0); | |
| 112 | return prices.forge(placeIdOf(p)) ?? prices.dearest(p.target, p.datacenter) ?? 0; | |
| 119 | const unlisted = (): number | undefined => prices.sameSize(p.target, p.size) ?? prices.dearest(p.target, p.datacenter); | |
| 120 | if (p.state === "retired") return p.volume === "" ? 0 : (prices.volume(p.target) ?? prices.forge(placeIdOf(p)) ?? unlisted() ?? 0); | |
| 121 | return prices.forge(placeIdOf(p)) ?? unlisted() ?? 0; | |
| 113 | 122 | } |
| 114 | 123 | |
| 115 | 124 | /** What the forge reckons an account costs a month, in cents: the sum over its own pinned rows. */ |
test/pinned-ceiling.test.ts +15 −1
| @@ -12,7 +12,7 @@ import { addAccount, allowWrite, net as cloudNet } from "../src/actions/cloud.ts | ||
| 12 | 12 | import { setCeiling } from "../src/actions/cloud_ceiling.ts"; |
| 13 | 13 | import { claimPinned, deployPinned, net, updatePinned } from "../src/actions/pinned.ts"; |
| 14 | 14 | import { cloudOverview } from "../src/cloud/overview.ts"; |
| 15 | import { priced } from "../src/cloud/ceiling.ts"; | |
| 15 | import { priced, rowCents } from "../src/cloud/ceiling.ts"; | |
| 16 | 16 | import { keptPlaces } from "../src/cloud/places_read.ts"; |
| 17 | 17 | import { keptRate } from "../src/cloud/rates.ts"; |
| 18 | 18 | import { getCloudAccount } from "../src/core/cloud_account.ts"; |
| @@ -79,6 +79,19 @@ describe("cloud account ceiling", () => { | ||
| 79 | 79 | expect(o.ok && o.value.accounts.find((a) => a.provider === "digitalocean")).toMatchObject({ ceilingDollars: 50, monthlyCents: 0, leftCents: 5000 }); |
| 80 | 80 | }); |
| 81 | 81 | |
| 82 | test("a machine whose datacenter stopped listing its size is counted at that size's price elsewhere, from the real catalog (test3, 2026-11-25)", () => { | |
| 83 | const p = priced(app.db); | |
| 84 | // The fixture lists s-1vcpu-2gb in nyc3 and ams3 ($12 + $1 volume) and a gpu-h100 in nyc3 alone. | |
| 85 | expect(p.sameSize("digitalocean", "s-1vcpu-2gb")).toBe(1300); | |
| 86 | expect(p.sameSize("digitalocean", "no-such-size")).toBeUndefined(); | |
| 87 | expect(p.sameSize("hetzner", "s-1vcpu-2gb")).toBeUndefined(); | |
| 88 | const row = (datacenter: string, size: string) => ({ target: "digitalocean", remote: "1", volume: "v", datacenter, size, state: "running" }) as Parameters<typeof rowCents>[0]; | |
| 89 | // sfo2 is not in the catalog at all: the size's price elsewhere, not the dearest machine. | |
| 90 | expect(rowCents(row("sfo2", "s-1vcpu-2gb"), p)).toBe(1300); | |
| 91 | // A size known nowhere still errs high: the dearest in its datacenter. | |
| 92 | expect(rowCents(row("nyc3", "no-such-size"), p)).toBe(p.dearest("digitalocean", "nyc3") ?? -1); | |
| 93 | }); | |
| 94 | ||
| 82 | 95 | test("a forge is priced from the Places catalog, where the drivers order it: euros at the day's rate, rounded up; what it does not list has no price", () => { |
| 83 | 96 | const p = priced(app.db); |
| 84 | 97 | // DigitalOcean: $12 machine + $1 volume, in dollars as the provider says. |
| @@ -360,3 +373,4 @@ describe("cloud account ceiling", () => { | ||
| 360 | 373 | expect(uses).toBe(6); |
| 361 | 374 | }); |
| 362 | 375 | }); |
| 376 |
new above
offline