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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

sold/ceiling-same-size → main 0 commits 1 thread · 1 unresolved

  • Merged. sold/ceiling-same-size was merged into main as 044f360.

Review

Sign in to review this change.
2 files changed +30 −7
src/cloud/ceiling.ts +15 −6
@@ -43,6 +43,8 @@ export interface Priced {
4343 /** The price of a Places id (`provider:datacenter:size`). */
4444 forge(id: string): number | undefined;
4545 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;
4648 /** What keeping a forge's data volume alone costs a month on a cloud, in US cents rounded up. */
4749 volume(cloud: string): number | undefined;
4850 /** 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)
7072
7173 export function priced(db: Database): Priced {
7274 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 }>();
7476 const closed = new Map<string, string>();
7577 for (const p of keptPlaces(db, rate)) {
7678 // A place the catalog could not price says so with no cost; it is not a place that costs nothing.
7779 if (p.costCents <= 0) continue;
7880 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 });
8082 if (!p.orderable) closed.set(p.id, p.why);
8183 } catch {
8284 // no rate for its currency: no price
@@ -91,6 +93,10 @@ export function priced(db: Database): Priced {
9193 const all = (here.length > 0 ? here : mine).map((c) => c.cents);
9294 return all.length === 0 ? undefined : Math.max(...all);
9395 },
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 },
94100 closed: (id) => closed.get(id),
95101 };
96102 }
@@ -100,16 +106,19 @@ type Row = Pick<Pinned, "target" | "remote" | "volume" | "datacenter" | "size" |
100106 /**
101107 * What one pinned row costs a month, cents. A row with a machine or a volume is counted as the
102108 * 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
105113 * made, or when the catalog holds nothing for the cloud at all (then nothing new is admitted
106114 * either). A retired forge costs only the volume it kept (the whole forge's price when the catalog
107115 * has none for volumes), and nothing once the volume is deleted.
108116 */
109117 export function rowCents(p: Row, prices: Priced): number {
110118 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;
113122 }
114123
115124 /** 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
1212 import { setCeiling } from "../src/actions/cloud_ceiling.ts";
1313 import { claimPinned, deployPinned, net, updatePinned } from "../src/actions/pinned.ts";
1414 import { cloudOverview } from "../src/cloud/overview.ts";
15 import { priced } from "../src/cloud/ceiling.ts";
15 import { priced, rowCents } from "../src/cloud/ceiling.ts";
1616 import { keptPlaces } from "../src/cloud/places_read.ts";
1717 import { keptRate } from "../src/cloud/rates.ts";
1818 import { getCloudAccount } from "../src/core/cloud_account.ts";
@@ -79,6 +79,19 @@ describe("cloud account ceiling", () => {
7979 expect(o.ok && o.value.accounts.find((a) => a.provider === "digitalocean")).toMatchObject({ ceilingDollars: 50, monthlyCents: 0, leftCents: 5000 });
8080 });
8181
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
8295 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", () => {
8396 const p = priced(app.db);
8497 // DigitalOcean: $12 machine + $1 volume, in dollars as the provider says.
@@ -360,3 +373,4 @@ describe("cloud account ceiling", () => {
360373 expect(uses).toBe(6);
361374 });
362375 });
376

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs