Public: anyone can read this; the crew can change it.

New forge: Hetzner is selectable (cheapest place anywhere when none in the US), and Change place lists one entry per datacenter #16507

Merged opened this

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

Merged

sold/new-forge-places → main 0 commits

  • Merged. sold/new-forge-places was merged into main as b03b44b.

Review

Sign in to review this change.
10 files changed +204 −26
docs/features/cloud.md +3 −3
@@ -21,7 +21,7 @@ Not done: the route only lists. Attaching, rotating and removing stay on the pag
2121
2222 ## Places and prices in US dollars (#16203)
2323
24 `GET /api/v1/places` lists where a forge can run: provider + datacenter + machine size, each with vCPU, memory, disk, included traffic, city and country, `costCents` (machine + the 10 GiB volume + a public address, US dollars a month), the vendor's own `price` and the rate that converted it, `readAt`, `orderable` and, when not, `why`. Filters: `plan`, `provider`, `country`. `defaults` names each plan's default place and says why; the rule is: the cheapest place in the United States that can be ordered now and meets the plan's minimum, among providers with an account that allows writes; `PUT /api/v1/places/pin` (admin) pins one instead.
24 `GET /api/v1/places` lists where a forge can run: provider + datacenter + machine size, each with vCPU, memory, disk, included traffic, city and country, `costCents` (machine + the 10 GiB volume + a public address, US dollars a month), the vendor's own `price` and the rate that converted it, `readAt`, `orderable` and, when not, `why`. Filters: `plan`, `provider`, `country`. `defaults` names each plan's default place and says why; the rule is: the cheapest place in the United States that can be ordered now and meets the plan's minimum, among providers with an account that allows writes (a provider with no such place in the United States falls back to its cheapest place anywhere); `PUT /api/v1/places/pin` (admin) pins one instead.
2525
2626 - Prices come from the provider's API (Hetzner `/pricing`, `/server_types`, `/datacenters`; DigitalOcean `/sizes`, `/regions`) and are kept as the provider answered, so the dollars are derived at read time. A failed read keeps the last good one. Typed in by hand, and said so: DigitalOcean's block storage price (its API has none) and its regions' countries.
2727 - Every amount a person sees is dollars. A vendor billing in euro is converted at the European Central Bank's daily reference rate (`src/cloud/rates.ts`, no key), kept with its date; if the fetch fails the last good rate stands and the answer carries `rate.ageDays`. All conversion is `toUsd` in `src/cloud/prices.ts`; money that guards spending rounds `up`.
@@ -39,8 +39,8 @@ A site admin who has attached a cloud account that allows writes sees "Where it
3939
4040 - **Here** is the default: the forge runs inside this forge.
4141 - **A cloud account** runs the forge on its own machine. It is free to the admin; the cloud bills its own account. The page says "No charge to you; the cloud bills its account."
42 - **Each cloud option** shows the catalog's default place for the size, its price a month and the account's room under its ceiling, for example "New York · $14.00 a month; $36.00 of $50 left this month".
43 - **Change place**, under the option, lists the other orderable places on that provider, cheapest first. Pick one to run there instead of the default.
42 - **Each cloud option** shows the catalog's default place for the size, its price a month and the account's room under its ceiling, for example "New York · $14.00 a month; $36.00 of $50 left this month". The default is the cheapest orderable place in the United States. A provider with no such place, such as Hetzner, whose cheap line is in Europe only, falls back to its cheapest orderable place anywhere and shows that city, for example "Hetzner · Nuremberg · $8.48 a month".
43 - **Change place**, under the option, lists one entry for each other datacenter of that provider, at the cheapest size that meets the plan, cheapest first. Two datacenters in one city carry their number ("New York 1", "New York 3"), so no label repeats. Pick one to run there instead of the default.
4444 - **A refused deploy** is shown with the reason, and the option cannot be selected. The reasons are no account that allows writes, or a place that would go over the account's ceiling. The message links to Cloud accounts, where the account and its ceiling are set.
4545 - **Terminal**: the "Where it runs" field is chosen with left and right. The first choice is empty and means here. The others are `<provider>/<account>`, then `<provider>/<account>@<place>` for each other place. The same value is what the page posts as `where`.
4646
docs/features/deploy-to-hetzner.md +1 −1
@@ -14,7 +14,7 @@ A pinned forge can run in your own Hetzner Cloud project the way it runs on Digi
1414
1515 ## What it makes
1616
17 - The **place is the deploy's**: `hetzner:<location>:<type>` from the Places catalog (`pinned-forge.md`, "Where it is made"), named by the `place` field or, left out, the catalog's default for the small plan, which is the cheapest orderable place in the United States. A Nuremberg place, such as `hetzner:nbg1:cx23`, costs about a third of a US one for ten times the traffic, and is named on purpose. The server and its volume are made in that location; no location or type is named in the code. ARM types are never offered: the boot is x86.
17 - The **place is the deploy's**: `hetzner:<location>:<type>` from the Places catalog (`pinned-forge.md`, "Where it is made"), named by the `place` field or, left out, the catalog's default for the small plan, which is the cheapest orderable place in the United States, or, when the provider has none there, its cheapest orderable place anywhere. A Nuremberg place, such as `hetzner:nbg1:cx23`, costs about a third of a US one for ten times the traffic, and is named on purpose. The server and its volume are made in that location; no location or type is named in the code. ARM types are never offered: the boot is x86.
1818 - A 10 GiB volume, attached and automounted at `/mnt/HC_Volume_<id>`. Update deletes the server and makes a new one on the same volume; the data is not touched.
1919 - The server is made with a throwaway SSH key (made and deleted per create), so Hetzner never emails a root password; the machine accepts no password, no root login and nothing on port 22, and opens only 80 and 443. See "What the booted machine is" in `pinned-forge.md`.
2020 - The address is read back from the server, for the DNS record; the forge itself is served only on its name over HTTPS, by Caddy from Ubuntu's own packages, as on DigitalOcean.
docs/features/pinned-forge.md +1 −1
@@ -73,7 +73,7 @@ On a new machine (reach it through the provider's console, since SSH is closed):
7373
7474 ## Where it is made: the place (#16205)
7575
76 A deploy is made at a place from the Places catalog (`GET /api/v1/places`): `provider:datacenter:size`, such as `digitalocean:sfo2:s-1vcpu-2gb`. Every door takes it as `place` (the API body and MCP tool field, the Place select on `/deploy-to`, an optional last word of the terminal's `d` line). Left out, it is the catalog's default for the small plan among the chosen account's provider (the cheapest orderable place in the United States, or the one pinned on Places). The place must exist in the catalog, be orderable and be on the account's provider; otherwise the deploy is refused in a sentence, before any call to a provider. ARM sizes are listed with their reason and are never offered: the machine boots x86 only.
76 A deploy is made at a place from the Places catalog (`GET /api/v1/places`): `provider:datacenter:size`, such as `digitalocean:sfo2:s-1vcpu-2gb`. Every door takes it as `place` (the API body and MCP tool field, the Place select on `/deploy-to`, an optional last word of the terminal's `d` line). Left out, it is the catalog's default for the small plan among the chosen account's provider (the cheapest orderable place in the United States, or the provider's cheapest anywhere when it has none there, or the one pinned on Places). The place must exist in the catalog, be orderable and be on the account's provider; otherwise the deploy is refused in a sentence, before any call to a provider. ARM sizes are listed with their reason and are never offered: the machine boots x86 only.
7777
7878 The row records its place (`datacenter` and `size`, in `pinned_size`); the volume and the machine are made in that datacenter, and every replace (Update, Roll back, a new claim link) orders the row's own place, never today's default, because the volume lives there. The ceiling prices that place. A forge deployed before places were kept has none recorded and is read as the place the drivers once hard-coded (DigitalOcean `nyc3` `s-1vcpu-2gb`, Hetzner `nbg1`).
7979
src/actions/pinned.ts +16 −1
@@ -126,7 +126,7 @@ export interface IssuedClaim {
126126
127127 export type Issued = PinnedView & { readonly claim: IssuedClaim };
128128
129 const PLACE_HELP = "Places are listed at Places (GET /api/v1/places); a place is provider:datacenter:size.";
129 const PLACE_HELP = "Pick one of the places the Places page lists, or leave it out for the default.";
130130
131131 /**
132132 * The place a deploy is made at, from the catalog the forge last read (no call to a provider): the
@@ -166,6 +166,21 @@ export function deployPlaces(app: App, providers: readonly string[], plan: PlanN
166166 .slice(0, MAX_OFFERED);
167167 }
168168
169 /**
170 * One place for each datacenter of `providers`, for a New forge list: the cheapest size meeting
171 * `plan` in each, cheapest first. No size variants, so a datacenter is named once.
172 */
173 export function datacenterPlaces(app: App, providers: readonly string[], plan: PlanName = "small"): Place[] {
174 const best = new Map<string, Place>();
175 for (const p of keptPlaces(app.db, keptRate(app.db, "EUR"))) {
176 if (!p.orderable || !meets(p, plan) || !providers.includes(p.provider)) continue;
177 const key = `${p.provider}:${p.datacenter}`;
178 const kept = best.get(key);
179 if (kept === undefined || p.costCents < kept.costCents || (p.costCents === kept.costCents && p.id < kept.id)) best.set(key, p);
180 }
181 return [...best.values()].sort((a, b) => a.costCents - b.costCents || a.id.localeCompare(b.id));
182 }
183
169184 const HOST_WORDS = "A hostname is a full DNS name you control, such as forge.example.com: lowercase letters, digits, dashes and dots.";
170185 const RETIRED_REFUSAL = "This forge was retired: its machine is gone. Deploy it again, under a new name, to run it.";
171186 const RETIRE_CLAIMED =
src/cloud/places.ts +6 −2
@@ -19,7 +19,7 @@ export const PLAN_MINIMUMS: Readonly<Record<PlanName, { readonly memoryMiB: numb
1919 export const isPlan = (v: unknown): v is PlanName => v === "small" || v === "medium" || v === "large";
2020
2121 export const DEFAULT_RULE =
22 "The cheapest place in the United States that can be ordered now and meets the plan's minimum, among cloud accounts that allow writes.";
22 "The cheapest place in the United States that can be ordered now and meets the plan's minimum, among cloud accounts that allow writes. A provider with no such place in the United States falls back to its cheapest place anywhere.";
2323
2424 /** The data volume every forge gets, GiB. */
2525 export const VOLUME_GIB = 10;
@@ -180,11 +180,15 @@ export function chooseDefault(places: readonly Place[], plan: PlanName, writers:
180180 .filter((p) => p.country === "US")
181181 .sort((a, b) => a.costCents - b.costCents || a.id.localeCompare(b.id))[0];
182182 if (best) return { place: best, reason: `Runs in ${where(best)}: the cheapest place in the United States that can be ordered now.` };
183 // No orderable US place for these providers (Hetzner's cheap line is in Europe only): the
184 // cheapest place anywhere, and the reason names the city so the page can say it.
185 const anywhere = live.sort((a, b) => a.costCents - b.costCents || a.id.localeCompare(b.id))[0];
186 if (anywhere) return { place: anywhere, reason: `Runs in ${where(anywhere)}: the cheapest place that can be ordered now; none in the United States can be.` };
183187 return {
184188 place: undefined,
185189 reason: writers.size === 0
186190 ? "Nowhere can be ordered: no cloud account that allows writes is attached."
187 : "Nowhere can be ordered: no place in the United States that can be ordered now meets this plan.",
191 : "Nowhere can be ordered: no place that can be ordered now meets this plan.",
188192 };
189193 }
190194
src/spawn/clouds_offered.ts +43 −11
@@ -8,7 +8,7 @@
88 */
99
1010 import type { App } from "../app.ts";
11 import { defaultPlace, deployPlaces, deployRoom } from "../actions/pinned.ts";
11 import { datacenterPlaces, defaultPlace, deployRoom } from "../actions/pinned.ts";
1212 import { spendOf, type Spend } from "../cloud/ceiling.ts";
1313 import type { Place, PlanName } from "../cloud/places.ts";
1414 import { dollars } from "../cloud/prices.ts";
@@ -26,8 +26,10 @@ export interface CloudOffer {
2626 readonly label: string;
2727 /** The catalog's default place for the size; none when the catalog has not been read. */
2828 readonly place: Place | undefined;
29 /** Every orderable place on the provider for the size, cheapest first. */
29 /** One orderable place for each datacenter on the provider (its cheapest size for the plan), cheapest first. */
3030 readonly places: readonly Place[];
31 /** Each place's words by id: its city, with the datacenter's number when two share a city. */
32 readonly names: Readonly<Record<string, string>>;
3133 readonly spend: Spend;
3234 /** Why the default place would be refused now, in the deploy's words; undefined when it fits. */
3335 readonly refusal: string | undefined;
@@ -66,20 +68,45 @@ export function whereHint(o: CloudOffer | undefined, placeId = ""): string {
6668 if (o === undefined) return "Here: inside this forge.";
6769 if (o.refusal !== undefined) return o.refusal;
6870 const at = o.places.find((p) => p.id === placeId) ?? o.place;
69 return `${o.label}${at === undefined ? "" : ` · ${placeWords(at)}`}; ${roomWords(o.spend)}. ${NO_CHARGE}`;
71 return `${o.label}${at === undefined ? "" : ` · ${placeWords(at, o.names[at.id])}`}; ${roomWords(o.spend)}. ${NO_CHARGE}`;
7072 }
7173
74 /** The places under "Change place": every datacenter but the default's. */
75 export const otherPlaces = (o: CloudOffer): Place[] => o.places.filter((p) => p.datacenter !== o.place?.datacenter);
76
7277 /** Each offer's `where` values: its default place, then (unless refused) each other place. */
7378 export const whereChoices = (offers: readonly CloudOffer[]): string[] =>
74 offers.flatMap((o) => [o.key, ...(o.refusal !== undefined ? [] : o.places.filter((p) => p.id !== o.place?.id).map((p) => `${o.key}@${p.id}`))]);
79 offers.flatMap((o) => [o.key, ...(o.refusal !== undefined ? [] : otherPlaces(o).map((p) => `${o.key}@${p.id}`))]);
80
81 /**
82 * A distinct name for each place: its city, and when two datacenters share a city, the city with
83 * the number in the datacenter's code ("New York 1"), or the code when it has no number.
84 */
85 export function placeNames(places: readonly Place[]): Record<string, string> {
86 const count = new Map<string, number>();
87 for (const p of places) count.set(p.city, (count.get(p.city) ?? 0) + 1);
88 const names: Record<string, string> = {};
89 const used = new Set<string>();
90 for (const p of places) {
91 let name = p.city;
92 if ((count.get(p.city) ?? 0) > 1) {
93 const n = /(\d+)$/.exec(p.datacenter)?.[1];
94 name = `${p.city} ${n !== undefined ? String(Number(n)) : p.datacenter.toUpperCase()}`;
95 }
96 if (used.has(name)) name = `${name} (${p.datacenter})`;
97 used.add(name);
98 names[p.id] = name;
99 }
100 return names;
101 }
75102
76103 /** "$36.00 of $50 left this month". */
77104 export const roomWords = (s: Spend): string =>
78105 `${dollars(Math.max(0, s.leftCents))} of $${s.ceilingDollars} left this month`;
79106
80 /** "New York · $14.00 a month". */
81 export const placeWords = (p: Place): string =>
82 `${p.city} · ${dollars(p.costCents)} a month`;
107 /** "New York · $14.00 a month"; `name` replaces the city when the place has a distinct one. */
108 export const placeWords = (p: Place, name: string = p.city): string =>
109 `${name} · ${dollars(p.costCents)} a month`;
83110
84111 /** The clouds `user` may start a forge on, for a forge of `size`: none for anyone but a site admin. */
85112 export function cloudsOffered(
@@ -90,14 +117,19 @@ export function cloudsOffered(
90117 if (user?.isAdmin !== true) return [];
91118 return listCloudAccounts(app.db)
92119 .filter((a) => a.writeAllowed && target(a.provider)?.status === "first")
93 .map((a) => ({
120 .map((a) => {
121 const places = datacenterPlaces(app, [a.provider], size);
122 const place = defaultPlace(app, a.provider, size).place;
123 return {
94124 key: `${a.provider}/${a.name}`,
95125 provider: a.provider,
96126 account: a.name,
97127 label: target(a.provider)?.label ?? a.provider,
98 place: defaultPlace(app, a.provider, size).place,
99 places: deployPlaces(app, [a.provider], size),
128 place,
129 places,
130 names: placeNames(place !== undefined && !places.some((p) => p.id === place.id) ? [place, ...places] : places),
100131 spend: spendOf(app.db, a.provider, a.name),
101132 refusal: deployRoom(app, a.provider, a.name, size),
102 }));
133 };
134 });
103135 }
src/web/pages/new-forge.ts +4 −4
@@ -53,7 +53,7 @@ import { FREE, getPlans, type Plan } from "../../settings/plans.ts";
5353 import { linkToSend, madeBody, madeJs } from "../forge_made.ts";
5454 import { pickList } from "../pick.ts";
5555 import { btn, field as formField, selectField } from "../ui.ts";
56 import { cloudsOffered, NO_CHARGE, placeWords, roomWords, whereFields, type CloudOffer } from "../../spawn/clouds_offered.ts";
56 import { cloudsOffered, NO_CHARGE, otherPlaces, placeWords, roomWords, whereFields, type CloudOffer } from "../../spawn/clouds_offered.ts";
5757 import { catalogPlan } from "../../spawn/cloud_placement.ts";
5858 import { CEILING_PAGE } from "../../cloud/ceiling.ts";
5959
@@ -864,10 +864,10 @@ function whereView(offers: readonly CloudOffer[], chosen: string, error: string
864864 const radio = (value: string, refused = false) =>
865865 html`<input type="radio" name="where" value="${value}"${chosen === value ? html` checked` : null}${refused ? html` disabled` : null} />`;
866866 const offer = (o: CloudOffer) => {
867 const others = o.places.filter((p) => p.id !== o.place?.id);
867 const others = otherPlaces(o);
868868 return html`<label class="check">
869869 ${radio(o.key, o.refusal !== undefined)}
870 <span>${o.label}${o.place === undefined ? null : ` · ${placeWords(o.place)}`} <span class="muted small">${roomWords(o.spend)}</span></span>
870 <span>${o.label}${o.place === undefined ? null : ` · ${placeWords(o.place, o.names[o.place.id])}`} <span class="muted small">${roomWords(o.spend)}</span></span>
871871 </label>
872872 ${o.refusal === undefined
873873 ? null
@@ -876,7 +876,7 @@ function whereView(offers: readonly CloudOffer[], chosen: string, error: string
876876 ? null
877877 : html`<details class="field"${chosen.startsWith(`${o.key}@`) ? html` open` : null}>
878878 <summary class="small">Change place</summary>
879 ${others.map((p) => html`<label class="check">${radio(`${o.key}@${p.id}`)} <span class="small">${placeWords(p)}</span></label>`)}
879 ${others.map((p) => html`<label class="check">${radio(`${o.key}@${p.id}`)} <span class="small">${placeWords(p, o.names[p.id])}</span></label>`)}
880880 </details>`}`;
881881 };
882882 return html`<fieldset class="field" id="f-where" data-where ${error ? html`data-invalid` : null}>
test/new-forge-places.test.ts added +116
@@ -0,0 +1,116 @@
1 /**
2 * New forge's places: a provider with no orderable place in the United States (Hetzner's cheap line
3 * is in Europe) falls back to its cheapest place anywhere and is selectable; a provider's list is
4 * one entry for each datacenter at its cheapest size, with distinct labels.
5 */
6 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { addAccount, allowWrite, net as cloudNet } from "../src/actions/cloud.ts";
12 import { setCeiling } from "../src/actions/cloud_ceiling.ts";
13 import { changeBaseDomain } from "../src/actions/pinned.ts";
14 import type { Place } from "../src/cloud/places.ts";
15 import { readPlaces } from "../src/cloud/places_read.ts";
16 import { createUser, getUserByName } from "../src/core/users.ts";
17 import { cloudsOffered, otherPlaces, placeNames, placeWords, whereChoices, whereHint } from "../src/spawn/clouds_offered.ts";
18 import { quietLogs } from "./helpers/globals.ts";
19 import { seedHetzner, seedPlaces } from "./helpers/places-fixture.ts";
20
21 quietLogs();
22
23 const sizes = (slug: string, price: number, regions: string[], memory = 2048, vcpus = 1, disk = 50) =>
24 ({ slug, memory, vcpus, disk, transfer: 2, price_monthly: price, available: true, regions });
25
26 describe("new forge places", () => {
27 let dir = "";
28 let app: App;
29 const admin = () => getUserByName(app.db, "alice")!;
30
31 beforeAll(async () => {
32 dir = await mkdtemp(join(tmpdir(), "forge-new-forge-places-"));
33 app = createApp({ dataDir: dir, port: 0, forgeRepo: "alice/forge", url: "https://forge.test" });
34 await seedPlaces(app.db);
35 // DigitalOcean with size variants and two datacenters in one city.
36 const regions = ["nyc1", "nyc3", "sfo2", "sfo3", "ams3"].map((slug) => ({ slug, available: true }));
37 const body = {
38 sizes: [
39 sizes("s-1vcpu-2gb", 12, ["nyc1", "nyc3", "sfo2", "sfo3", "ams3"]),
40 sizes("s-1vcpu-2gb-amd", 14, ["nyc3", "sfo3"]),
41 sizes("s-1vcpu-2gb-70gb-intel", 18, ["nyc3"], 2048, 1, 70),
42 sizes("s-2vcpu-4gb", 24, ["nyc3", "ams3"], 4096, 2, 80),
43 sizes("s-1vcpu-2gb-intel", 16, ["sfo2"]),
44 ],
45 regions,
46 };
47 await readPlaces(app.db, "digitalocean", async (url) => new Response(JSON.stringify(String(url).includes("/sizes") ? { sizes: body.sizes } : { regions: body.regions }), { status: 200 }), "t");
48 const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
49 if (!a.ok) throw new Error(a.error);
50 cloudNet.fetch = async () => new Response(JSON.stringify({ account: { email: "[email protected]", status: "active" } }), { status: 200 });
51 for (const [provider, token] of [["digitalocean", "dop_v1_9Zq4TxLm7Kp2Vb8nWcR5"], ["hetzner", "Zq4TxLm7Kp2Vb8nWcR59Zq4TxLm7Kp2Vb8nWcR59Zq4TxLm7Kp2Vb8nWcR5ab"]] as const) {
52 const added = await addAccount(app, admin(), provider, "main", token);
53 if (!added.ok) throw new Error(String(added.error));
54 allowWrite(app, admin(), provider, "main", true);
55 expect(setCeiling(app, admin(), provider, "main", 50).ok).toBe(true);
56 }
57 expect(changeBaseDomain(app, admin(), "forges.test").ok).toBe(true);
58 }, 30_000);
59
60 afterAll(async () => {
61 app.close();
62 await rm(dir, { recursive: true, force: true });
63 });
64
65 const offers = () => cloudsOffered(app, admin());
66
67 test("Hetzner has no US place, so its option falls back to its cheapest place anywhere and can be chosen", () => {
68 const h = offers().find((o) => o.provider === "hetzner")!;
69 expect(h.refusal).toBeUndefined();
70 expect(h.place?.datacenter).toBe("nbg1");
71 expect(whereHint(h)).toMatch(/^Hetzner Cloud · Nuremberg · \$\d+\.\d\d a month; /);
72 expect(whereChoices([h])).toEqual(["hetzner/main"]);
73 });
74
75 test("a provider with US places keeps the US preference", () => {
76 const d = offers().find((o) => o.provider === "digitalocean")!;
77 expect(d.place?.country).toBe("US");
78 });
79
80 test("the Hetzner-only catalog still says nowhere when nothing can be ordered", async () => {
81 await seedHetzner(app.db, []);
82 const h = offers().find((o) => o.provider === "hetzner")!;
83 expect(h.place).toBeUndefined();
84 expect(h.refusal).toContain("Nowhere can be ordered");
85 expect(h.refusal).not.toContain("GET /api");
86 expect(h.refusal).not.toContain("provider:datacenter:size");
87 await seedHetzner(app.db);
88 });
89
90 test("DigitalOcean lists one entry for each datacenter at its cheapest size, with distinct labels", () => {
91 const d = offers().find((o) => o.provider === "digitalocean")!;
92 const dcs = d.places.map((p) => p.datacenter);
93 expect(new Set(dcs).size).toBe(dcs.length);
94 expect([...dcs].sort()).toEqual(["ams3", "nyc1", "nyc3", "sfo2", "sfo3"]);
95 for (const p of d.places) expect(p.size).toBe("s-1vcpu-2gb");
96 const costs = d.places.map((p) => p.costCents);
97 expect(costs).toEqual([...costs].sort((a, b) => a - b));
98 const labels = d.places.map((p) => placeWords(p, d.names[p.id]));
99 expect(new Set(labels).size).toBe(labels.length);
100 expect(d.names["digitalocean:nyc1:s-1vcpu-2gb"]).toBe("New York 1");
101 expect(d.names["digitalocean:nyc3:s-1vcpu-2gb"]).toBe("New York 3");
102 expect(d.names["digitalocean:ams3:s-1vcpu-2gb"]).toBe("Amsterdam");
103 // Nothing is listed twice: the default's datacenter is not under Change place.
104 expect(otherPlaces(d).some((p) => p.datacenter === d.place?.datacenter)).toBe(false);
105 expect(whereChoices([d]).length).toBe(d.places.length);
106 });
107
108 test("a unique city keeps its plain name, and a code stands in when a city has no number", () => {
109 const place = (id: string, city: string, datacenter: string): Place => ({
110 id, provider: "x", datacenter, city, country: "US", size: "s", vcpu: 1, memoryMiB: 2048, diskGiB: 20, trafficGiB: 0, costCents: 100,
111 price: { usdCents: 100, vendorAmount: 1, vendorCurrency: "USD" }, assumed: [], readAt: "t", orderable: true, why: "",
112 });
113 expect(placeNames([place("a", "Nuremberg", "nbg1")])).toEqual({ a: "Nuremberg" });
114 expect(placeNames([place("a", "Ashburn", "ash"), place("b", "Ashburn", "iad")])).toEqual({ a: "Ashburn ASH", b: "Ashburn IAD" });
115 });
116 });
test/pinned-hetzner.test.ts +13 −2
@@ -146,12 +146,23 @@ describe("hetzner target", () => {
146146 expect(calls).toEqual([]);
147147 });
148148
149 test("with no place named and none in the United States, the deploy says so and calls nothing", async () => {
149 test("with no place named and none orderable anywhere, the deploy says so and calls nothing", async () => {
150 app.db.run("DELETE FROM pinned_forge");
150151 calls.length = 0;
152 await seedHetzner(app.db, []);
151153 const r = await deployPinned(app, admin(), input({ name: "nowhere", place: "" }));
152154 expect(r).toMatchObject({ ok: false });
153 expect(String((r as any).error)).toContain("no place in the United States");
155 expect(String((r as any).error)).toContain("no place that can be ordered now meets this plan");
154156 expect(calls).toEqual([]);
157 await seedHetzner(app.db);
158 });
159
160 test("with no place named and none in the United States, the deploy falls back to the cheapest place anywhere", async () => {
161 app.db.run("DELETE FROM pinned_forge");
162 calls.length = 0;
163 const r = await deployPinned(app, admin(), input({ name: "europe", place: "" }));
164 expect(r.ok).toBe(true);
165 expect(calls.find((c) => c.method === "POST" && c.path === "/v1/servers")!.body).toMatchObject({ location: "nbg1" });
155166 });
156167
157168 test("an Update with the recorded place sold out keeps the running server", async () => {
test/places.test.ts +1 −1
@@ -97,7 +97,7 @@ describe("the default rule", () => {
9797 });
9898 test("nothing orderable says so, and says why", () => {
9999 expect(chooseDefault(all, "small", new Set()).reason).toContain("no cloud account");
100 expect(chooseDefault(all, "large", both).reason).toContain("no place in the United States");
100 expect(chooseDefault(all, "large", both).reason).toContain("no place that can be ordered now");
101101 });
102102 });
103103

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs