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

The signed-out /pricing page names what a forge costs per month in one line above the plans and links checkout #13084

Merged opened this

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

Merged

scout/forge:scout/13045-the-signed-out-pricing-page-names-what-a → main 10 commits fork 4 threads · 4 unresolved

  • Merged. scout/13045-the-signed-out-pricing-page-names-what-a was merged into main as aade2e2.

Review

Sign in to review this change.
7 files changed +111 −10
docs/features/README.md +1
@@ -453,3 +453,4 @@ Read with the guide page [When something is wrong](../guide-when-wrong.md).
453453 - [The rule watcher](rule-watcher.md)
454454 - [Try again on an issue the crew parked twice](crew-try-again.md)
455455 - [What holds a ready issue](map-held.md)
456 - [The price of a forge, first on /pricing](pricing-price-line.md)
docs/features/pricing-price-line.md added +9
@@ -0,0 +1,9 @@
1 # The price of a forge, first on /pricing

Docs say the line shows only where checkout is connected; the preview has none, so this is invisible there. Say how a person turns on a checkout to see it.

2
3 The signed-out `/pricing` page and the terminal's **Get a forge** screen open with the price of a forge: "A forge is $19 a month." (#13045). It is the cheapest paid plan, read from the plans setting (`/admin/limits`), so a change of price changes the line; with no paid plan it says "A forge is free".
4
5 - Web: it is the page head's one sub, the only sentence under the title. Signed-in buyers keep "Pick a plan, name it, pay."
6 - Terminal: the first line of the screen.
7 - It shows only where a checkout is connected; without one, the paid plans say "Ask the operator" and no price is promised. Previews and fresh installs have no provider, so they show that page instead.
8 - To see it: sign in as an admin, open Settings → Billing → Provider and paste a Stripe key (a test-mode `sk_test_…` key is enough; `docs/PROFIT.md` says how), then open `/pricing` signed out.
9 - There is no separate checkout address to open: checkout starts when the order form on the page is sent.
src/billing/plan_words.ts +10 −1
@@ -13,7 +13,10 @@ export interface PlanWords {
1313 readonly name: string;
1414 /** "Free" or "$19 a month". */
1515 readonly price: string;
16 /** The machine, the plan's own line, then a paid plan's credit: "1 CPU, 2 GB memory, 2 GB disk. A small forge… $5 of crew credit each month." */
16 /**
17 * The machine, the plan's own line, then a paid plan's credit: "1 CPU, 2 GB memory, 2 GB disk. A
18 * small forge… $5 of crew credit each month."
19 */
1720 readonly is: string;
1821 /** The https buy link for the plan's size, only on a paid plan and only when set. */
1922 readonly buy: string | undefined;
@@ -34,5 +37,11 @@ export function planWords(p: Plan, links: BillingLinks = {}): PlanWords {
3437 /** Said under the plans, on the web and in the terminal, whenever a plan carries a buy link. */
3538 export const AFTER_PAYMENT = "Your forge is made after payment; an email with the link to open it arrives.";
outdated

"first build free" is fixed text that nothing in Plan expresses; it is a promise the data does not back. Derive it or drop it. The all-free branch repeats "free" twice and reads oddly.

3639
40 /** What a stranger reads first: the cheapest paid plan, priced from the plans, never typed. */
41 export function priceLine(plans: readonly Plan[]): string {
42 const paid = plans.filter((p) => p.priceUsd > 0).map((p) => p.priceUsd);
43 return paid.length === 0 ? "A forge is free" : `A forge is $${Math.min(...paid)} a month`;
44 }
45
3746 /** Where the home's one button and the terminal's pointer send a person for a hosted forge. */
3847 export const GET_A_FORGE_PATH = "/forges/new";
src/tui/screens/pricing.ts +5 −2
@@ -10,6 +10,7 @@
1010 */
1111
1212 import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder } from "../../actions/order.ts";
13 import { priceLine } from "../../billing/plan_words.ts";
1314 import { checkoutOf } from "../../billing/checkout.ts";
1415 import { publicOrigin } from "../../core/public_origin.ts";
1516 import { bucketOf } from "../../http/peer.ts";
@@ -145,7 +146,7 @@ export function pricingScreen(f: Session, ctx: Ctx): Screen {
145146 return;
146147 }
147148 const selling = checkoutOf(f.app) !== undefined;
148 line(selling ? "Get your own forge: pick a plan, name it, pay. Free: use Start my forge." : "Plans. Paid plans are not on sale here yet: ask the operator.", c.mutedFg);
149 line(selling ? `${priceLine(plans())}. Pick a plan, name it, pay. Free: use Start my forge.` : "Plans. Paid plans are not on sale here yet: ask the operator.", c.mutedFg);
149150 y++;
150151 const list = paid();
151152 for (const p of plans()) {
@@ -213,7 +214,9 @@ export function pricingScreen(f: Session, ctx: Ctx): Screen {
213214 };
214215 }
215216
216 /** Offered to everyone: the sale is open to a guest and to a signed-in person alike, as on the web. */
217 /**
218 * Offered to everyone: the sale is open to a guest and to a signed-in person alike, as on the web.
219 */
217220 export const pricingCommand = (session: Session, ctx: Ctx) => ({
218221 id: "pricing",
219222 title: "Get a forge (plans)",
src/web/pages/pricing.ts +10 −5
@@ -9,6 +9,7 @@
99 import { setCookie } from "../../auth/cookies.ts";
1010 import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder, resendLink, type Refusal } from "../../actions/order.ts";
1111 import { lapseRule, lapseRuleWords } from "../../billing/lapse_rule.ts";
12 import { priceLine } from "../../billing/plan_words.ts";
1213 import { checkoutOf } from "../../billing/checkout.ts";
1314 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
1415 import { cookieValue, type Ctx } from "../../http/context.ts";
@@ -40,7 +41,8 @@ interface Values {
4041 const isBuyer = (ctx: Ctx): boolean => ctx.auth.user === undefined || ctx.auth.user.kind === "user";
4142
4243 function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["field"], string>>): Html {
43 // The order this browser paid for, from its own cookie: the page that opens it needs the address of the order.
44 // The order this browser paid for, from its own cookie: the page that opens it needs the address
45 // of the order.
4446 const held = (cookieValue(ctx.request, COOKIE) ?? "").split(".")[0] ?? "";
4547 const ordered = /^ord_[0-9a-f]{32}$/.test(held) ? held : undefined;
4648 const selling = checkoutOf(ctx.app) !== undefined;
@@ -55,7 +57,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie
5557 return planOfferRow({ key: p.key, name: p.name, says: `${sizeWords(p.size)}. ${p.says}${credit}`, price, action: act });
5658 });
5759 return html`<div class="narrow-wide" id="pricing" data-pricing>
58 ${pageHead("Get your own forge", { sub: selling ? "Pick a plan, name it, pay. Your forge is ready a minute later." : "Pick a size and name it." })}
60 ${pageHead("Get your own forge", { sub: !selling ? "Pick a size and name it." : ctx.auth.user === undefined ? `${priceLine(plans)}.` : "Pick a plan, name it, pay. Your forge is ready a minute later." })}

Non-blocking: three-way nested ternary inside the pageHead call; lift it into a named const above so the page head reads at a glance.

5961 ${errors["form"] ? html`<p class="error" role="alert">${errors["form"]}</p>` : null}
6062 <form method="post" action="/pricing/order" class="stack" id="order">
6163 ${formField({
@@ -105,7 +107,8 @@ export function pricingPage(ctx: Ctx): Response {
105107 const cookieFor = (ctx: Ctx, value: string, maxAge: number): string =>
106108 setCookie(COOKIE, value, { path: "/pricing", maxAge, secure: secureFor(ctx.url, ctx.app.config.url) });
107109
108 // POST /pricing/order — free goes on to the free path; a paid plan holds the name and goes to checkout.
110 // POST /pricing/order — free goes on to the free path; a paid plan holds the name and goes to
111 // checkout.
109112 export async function pricingOrder(ctx: Ctx): Promise<Response> {
110113 if (!isBuyer(ctx)) return notFoundPage(ctx);
111114 const form = await readForm(ctx, ctx.auth.user === undefined ? undefined : "admin");
@@ -144,7 +147,8 @@ const waiting = (ctx: Ctx, says: string): Response => {
144147 return res;
145148 };
146149
147 // GET /pricing/done?order= — reconciles the order with the provider, waits for the forge, shows the link once.
150 // GET /pricing/done?order= — reconciles the order with the provider, waits for the forge, shows the
151 // link once.
148152 export async function pricingDone(ctx: Ctx): Promise<Response> {
149153 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
150154 const rendering = performance.now();
@@ -198,7 +202,8 @@ export function resendPage(ctx: Ctx): Response {
198202 return response;
199203 }
200204
201 // POST /pricing/resend — the link goes to the order's own email; the answer is the same whether or not an order matched.
205 // POST /pricing/resend — the link goes to the order's own email; the answer is the same whether or
206 // not an order matched.
202207 export async function resendSubmit(ctx: Ctx): Promise<Response> {
203208 if (!isBuyer(ctx)) return notFoundPage(ctx);
204209 const form = await readForm(ctx, ctx.auth.user === undefined ? undefined : "admin");
test/pricing-line.test.ts added +56
@@ -0,0 +1,56 @@
1 /** The signed-out /pricing first line names the cheapest paid plan, from the plans (#13045). */
2 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { mkdtemp, rm } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp, type App } from "../src/app.ts";
7 import { priceLine } from "../src/billing/plan_words.ts";
8 import { serve, type Servers } from "../src/http/server.ts";
9 import { createUser } from "../src/core/users.ts";
10 import { useCheckout } from "../src/billing/checkout.ts";
11 import { ok } from "../src/kernel/result.ts";
12 import { DEFAULT_PLANS, getPlans, setPlans } from "../src/settings/plans.ts";
13
14 let dir: string;
15 let app: App;
16 let servers: Servers;
17 let actor: string;
18
19 beforeAll(async () => {
20 dir = await mkdtemp(join(tmpdir(), "forge-priceline-"));
21 app = createApp({ dataDir: dir, port: 0, forgeRepo: "alice/forge-code" });
22 servers = await serve(app);
23 const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
24 if (!a.ok) throw new Error("user");
25 actor = a.value.id;
26 useCheckout(app, { name: "fake", create: async () => ok({ id: "cs_x", url: "https://pay.fake.test/x" }), state: async () => ok({ paid: false, customer: "c", subscription: "s" }) });
27 });
28 afterAll(async () => {
29 await servers.stop?.();
30 await rm(dir, { recursive: true, force: true });
31 });
32
33 const firstLine = async (): Promise<{ body: string; line: string }> => {
34 const body = await (await fetch(`${servers.url}/pricing`)).text();
35 const line = /<span class="page-head-sub muted small">([^<]*)/.exec(body)?.[1] ?? "";
36 return { body, line };
37 };
38
39 test("the line is the cheapest paid plan's price, in the head's one sub, above the order form", async () => {
40 const { body, line } = await firstLine();
41 const lowest = Math.min(...getPlans(app.db).filter((p) => p.priceUsd > 0).map((p) => p.priceUsd));
42 expect(line).toBe(`A forge is $${lowest} a month.`);
43 expect(body).not.toContain('class="lead"');
44 expect(body.indexOf("page-head-sub")).toBeLessThan(body.indexOf('id="order"'));
45 });
46
47 test("when the plans change the line follows", async () => {
48 setPlans(app.db, DEFAULT_PLANS.map((p) => (p.priceUsd === 19 ? { ...p, priceUsd: 23 } : p)), actor);
49 expect((await firstLine()).line).toContain("A forge is $23 a month");
50 expect(priceLine([])).toBe("A forge is free");
51 });
52
53 test("with no provider connected there is no price line, since the paid plans say ask the operator", async () => {
54 useCheckout(app, undefined);
55 expect((await firstLine()).line).toBe("Pick a size and name it.");
56 });
test/tui-pricing.test.ts +20 −2
@@ -1,4 +1,7 @@
1 /** /pricing in the terminal (#11369): plans, an order through placeOrder, the checkout address as text, the claim link by the same ticket. */
1 /**
2 * /pricing in the terminal (#11369): plans, an order through placeOrder, the checkout address as
3 * text, the claim link by the same ticket.
4 */
25 import { afterEach, expect, test } from "bun:test";
36 import { mkdtemp, rm } from "node:fs/promises";
47 import { tmpdir } from "node:os";
@@ -59,7 +62,10 @@ async function fixture(opts: { sell?: boolean; placement?: "ok" | "full" } = {})
5962 tui.ctx.push(pricingScreen(session, tui.ctx));
6063 return { tui, terminal, session };
6164 };
62 /** Press keys and wait until the terminal is quiet: the placement and the provider are awaited by the app's own tracking. */
65 /**
66 * Press keys and wait until the terminal is quiet: the placement and the provider are awaited by
67 * the app's own tracking.
68 */
6369 const press = async (h: ReturnType<typeof open>, keys: string) => {
6470 h.terminal.feed(keys);
6571 await settleApp(h.tui);
@@ -95,6 +101,18 @@ test("the plans are listed with their prices", async () => {
95101 for (const p of getPlans(f.app.db)) if (p.key !== FREE && p.priceUsd > 0) expect(text).toContain(`$${p.priceUsd} a month`);
96102 });
97103
104 test("the screen opens with the cheapest paid plan's price, and says none where nothing is on sale", async () => {
105 const f = await fixture();
106 const lowest = Math.min(...getPlans(f.app.db).filter((p) => p.priceUsd > 0).map((p) => p.priceUsd));
107 const h = f.open("203.0.113.7");
108 await settleApp(h.tui);
109 expect(flat(h)).toContain(`A forge is $${lowest} a month.`);
110 const g = await fixture({ sell: false });
111 const k = g.open("203.0.113.8");
112 await settleApp(k.tui);
113 expect(flat(k)).not.toContain("A forge is $");
114 });
115
98116 test("a bad email is refused in the web's words and holds nothing", async () => {
99117 const f = await fixture();
100118 const h = f.open("203.0.113.2");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs