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

/pricing says in plain words what a plan's included credit buys #16161

Merged opened this

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

Merged

scout/forge:scout/16132-pricing-says-in-plain-words-what-a-plan → main 0 commits fork 3 threads · 3 unresolved

  • Merged. scout/16132-pricing-says-in-plain-words-what-a-plan was merged into main as ec8e190.

Review

Sign in to review this change.
15 files changed +148 −36
docs/features/pricing.md +2 −1
@@ -4,8 +4,9 @@ row: Buy a forge at /pricing
44 ---
55 # Buy a forge at /pricing (#11138)
66
7 Open `/pricing` with no account. Each plan shows its size, price, monthly crew credit (left out when it is $0) and forge count, read from the same plans as `GET /api/v1/plans` (`test/pricing-plans-agree.test.ts`). Type the forge's name and an email, press the paid plan's button, pay at the provider's checkout, and the page you return to (`/pricing/done`) shows the claim link once. Open it to take the forge over.
7 Open `/pricing` with no account. Each plan shows its size, price, crew credit said as a count of ordinary asks ("Crew credit for 10 ordinary asks each month."; the free plan's is "…once, to start"; left out when it is under one ask) and forge count, read from the same plans as `GET /api/v1/plans` (`test/pricing-plans-agree.test.ts`). Type the forge's name and an email, press the paid plan's button, pay at the provider's checkout, and the page you return to (`/pricing/done`) shows the claim link once. Open it to take the forge over.
88
9 - **Asks, not dollars (#16132):** an ask costs the `billing.ask_cents` limit (default 50 cents; the operator sets it from the crew's ledger, under Limits), and a credit is shown as whole asks, rounded down. `creditWords` in `src/billing/plan_words.ts` builds the sentence for /pricing, the home's plans, the terminal's plans screen and the owner's plan row (the host writes the ask price into the forge's `plan.json`). `GET /api/v1/plans` and the structured data on /pricing stay in dollars (`creditUsd`, "Crew credit (USD a month)"). Test: `bun test test/pricing-words.test.ts`.
910 - **Free plan:** its button goes to `/forges/new`.
1011 - **Closed the tab?** `/pricing/resend`: name and email you bought with; a new link is mailed there (needs mail configured) and the old one stops.
1112 - **No provider connected:** paid plans show their price and one muted phrase, "not on sale yet · ask the operator".
src/billing/notice.ts +8
@@ -14,6 +14,7 @@ import type { App } from "../app.ts";
1414 import { readPrivate, writePrivate } from "../kernel/file_modes.ts";
1515 import { childDirOf, listChildrenNow } from "../actions/spawn.ts";
1616 import { getPortalUrl, parseLink } from "../settings/billing.ts";
17 import { limitValue } from "../settings/limits.ts";
1718 import { getPlan } from "../settings/plans.ts";
1819 import { lapseFor } from "./lapse.ts";
1920 import { entitlementOf, getStored } from "./store.ts";
@@ -24,6 +25,11 @@ export interface PlanNotice {
2425 readonly size: string;
2526 readonly priceUsd: number;
2627 readonly creditUsd: number;
28 /**
29 * Dollars one ordinary ask costs on the host (`billing.ask_cents`); absent in a notice from
30 * before it.
31 */
32 readonly askUsd?: number;
2733 readonly status: EntitlementStatus;
2834 /** Unix seconds the paid period ends (and a past-due forge sleeps), when known. */
2935 readonly periodEnd?: number;
@@ -60,6 +66,7 @@ export function noticeOf(dataDir: string): PlanNotice | undefined {
6066 size,
6167 priceUsd: money(r["priceUsd"]),
6268 creditUsd: money(r["creditUsd"]),
69 ...(money(r["askUsd"]) > 0 ? { askUsd: money(r["askUsd"]) } : {}),
6370 status: r["status"] as EntitlementStatus,
6471 ...(typeof r["periodEnd"] === "number" && Number.isFinite(r["periodEnd"]) && r["periodEnd"] > 0 ? { periodEnd: r["periodEnd"] } : {}),
6572 ...(portal === undefined || portal === "" ? {} : { portalUrl: portal }),
@@ -98,6 +105,7 @@ export function tellPlan(app: App, forge: string): boolean {
98105 size: plan?.size ?? child.size,
99106 priceUsd: plan?.priceUsd ?? 0,
100107 creditUsd: plan?.creditUsd ?? 0,
108 askUsd: limitValue(app.db, "billing.ask_cents") / 100,
101109 status: e.status,
102110 ...(periodEnd === undefined ? {} : { periodEnd }),
103111 ...(paysAtProvider && portal !== "" ? { portalUrl: portal } : {}),
src/billing/plan_words.ts +28 −8
@@ -9,6 +9,7 @@
99
1010 import type { BillingLinks } from "../settings/billing.ts";
1111 import { sizeWords } from "../settings/billing.ts";
12 import { LIMITS } from "../settings/limits.ts";
1213 import type { Plan } from "../settings/plans.ts";
1314
1415 export interface PlanWords {
@@ -25,13 +26,32 @@ export interface PlanWords {
2526 }
2627
2728 /**
28 * A plan's crew credit in one sentence, the same on every surface: a paid plan's monthly credit, or
29 * the free plan's start credit, lent once (`startUsd`, the `spawn.included_credit_usd` limit).
29 * What one ordinary ask costs the crew, in dollars: the unit a plan's credit is counted in. It is
30 * the `billing.ask_cents` limit (an operator's setting, read where the page is made and passed in);
31 * this default is the limit's own, so a caller with no forge to ask says what a fresh one says.
outdated

ASK_USD = 0.5 is unmeasured. Source it from something real (a limit or measured median) and say where it comes from, or the page promises a guess.

32 * Nothing in the repository measures an ask: the operator sets it from the crew's ledger.
3033 */
31 export function creditWords(p: Pick<Plan, "priceUsd" | "creditUsd">, startUsd: number): string {
32 if (p.priceUsd > 0) return p.creditUsd > 0 ? `$${p.creditUsd} of crew credit each month.` : "No crew credit included.";
33 return startUsd > 0
34 ? `$${startUsd} of crew credit once, to start. Then your own AI account key.`
34 export const ASK_USD = LIMITS["billing.ask_cents"].default / 100;
35
outdated

A positive credit below one ask yields "0 ordinary asks". Say "No crew credit" instead, or round up to at least 1.

36 /**
37 * "10 ordinary asks", "1 ordinary ask": whole asks a credit buys, rounded down; 0 when under one.
38 */
39 export function asksWords(usd: number, askUsd: number = ASK_USD): string {
40 const n = Math.max(0, Math.floor((usd + 1e-9) / askUsd));
41 return `${n} ordinary ${n === 1 ? "ask" : "asks"}`;
42 }
43
44 const asksOf = (usd: number, askUsd: number): number => Math.floor((usd + 1e-9) / askUsd);
45
46 /**
47 * A plan's crew credit in one sentence, the same on every surface (/pricing, the home, the
48 * terminal, the owner's plan row): a paid plan's monthly credit, or the free plan's start credit,
49 * lent once (`startUsd`, the `spawn.included_credit_usd` limit), as a count of ordinary asks.
50 */
51 export function creditWords(p: Pick<Plan, "priceUsd" | "creditUsd">, startUsd: number, askUsd: number = ASK_USD): string {
52 if (p.priceUsd > 0) return asksOf(p.creditUsd, askUsd) > 0 ? `Crew credit for ${asksWords(p.creditUsd, askUsd)} each month.` : "No crew credit included.";
53 return asksOf(startUsd, askUsd) > 0
54 ? `Crew credit for ${asksWords(startUsd, askUsd)}, once, to start. Then your own AI account key.`
3555 : "No crew credit: the crew runs on your own AI account key.";
3656 }
3757
@@ -41,13 +61,13 @@ export function creditWords(p: Pick<Plan, "priceUsd" | "creditUsd">, startUsd: n
4161 */
4262 export const monthlyPrice = (usd: number): string => (usd === 0 ? "Free" : `$${usd} a month`);
4363
44 export function planWords(p: Plan, links: BillingLinks = {}, startUsd = 0): PlanWords {
64 export function planWords(p: Plan, links: BillingLinks = {}, startUsd = 0, askUsd: number = ASK_USD): PlanWords {
4565 const free = p.priceUsd === 0;
4666 const buy = free ? undefined : links[p.size];
4767 return {
4868 name: p.name,
4969 price: monthlyPrice(p.priceUsd),
50 is: `${sizeWords(p.size)}. ${p.says} ${creditWords(p, startUsd)}`,
70 is: `${sizeWords(p.size)}. ${p.says} ${creditWords(p, startUsd, askUsd)}`,
5171 buy,
5272 };
5373 }
src/settings/door.ts +12 −4
@@ -14,6 +14,7 @@ import { SIGNUP_DEFAULT, parseSignup, type SignupMode } from "./signup.ts";
1414
1515 const SIGNUP_KEY = "signup";
1616 const START_CREDIT = "spawn.included_credit_usd";
17 const ASK_COST = "billing.ask_cents";
1718
1819 export interface DoorSettings {
1920 readonly mode: SignupMode;
@@ -21,25 +22,32 @@ export interface DoorSettings {
2122 readonly links: BillingLinks;
2223 /** Dollars of crew credit lent once to a new free forge that brings no key (`spawn.included_credit_usd`). */
2324 readonly startUsd: number;
25 /** Dollars one ordinary ask costs (`billing.ask_cents`), the unit a plan's credit is said in. */
26 readonly askUsd: number;
2427 }
2528
29 /** Dollars from whole cents; absent stays absent. */
30 const centsToUsd = (cents: number | undefined): number | undefined => (cents === undefined ? undefined : cents / 100);
31
2632 export function getDoorSettings(db: Database): DoorSettings {
2733 let mode: SignupMode = SIGNUP_DEFAULT;
2834 let plans: string | undefined;
2935 let links: BillingLinks = {};
3036 let startUsd: number | undefined;
37 let askUsd: number | undefined;
3138 const rows = db
32 .query<{ key: string; value: string }, [string, string, string, string]>(
33 "SELECT key, value FROM forge_setting WHERE key IN (?1, ?2, ?3, ?4)",
39 .query<{ key: string; value: string }, [string, string, string, string, string]>(
40 "SELECT key, value FROM forge_setting WHERE key IN (?1, ?2, ?3, ?4, ?5)",
3441 )
35 .all(SIGNUP_KEY, PLANS_KEY, BILLING_LINKS_KEY, storeKey(START_CREDIT));
42 .all(SIGNUP_KEY, PLANS_KEY, BILLING_LINKS_KEY, storeKey(START_CREDIT), storeKey(ASK_COST));
3643 for (const row of rows) {
3744 if (row.key === SIGNUP_KEY) {
3845 const m = parseSignup(row.value);
3946 if (m.ok) mode = m.value;
4047 } else if (row.key === PLANS_KEY) plans = row.value;
4148 else if (row.key === BILLING_LINKS_KEY) links = decodeLinks(row.value);
49 else if (row.key === storeKey(ASK_COST)) askUsd = centsToUsd(decodeLimit(ASK_COST, row.value));
4250 else startUsd = decodeLimit(START_CREDIT, row.value);
4351 }
44 return { mode, plans: decodePlans(plans), links, startUsd: startUsd ?? LIMITS[START_CREDIT].default };
52 return { mode, plans: decodePlans(plans), links, startUsd: startUsd ?? LIMITS[START_CREDIT].default, askUsd: askUsd ?? LIMITS[ASK_COST].default / 100 };
4553 }
src/settings/limits.ts +9
@@ -69,6 +69,7 @@ export type LimitKey =
6969 | "model_review.slack_pct"
7070 | "shell_idle_minutes"
7171 | "billing.grace_days"
72 | "billing.ask_cents"
7273 | "billing.retention_days"
7374 | "retention.event_days"
7475 | "retention.deploy_pull_days"
@@ -417,6 +418,14 @@ export const LIMITS: Record<LimitKey, LimitDef> = {
417418 max: 1440,
418419 reason: "A shell nobody types in and that prints nothing holds a process and memory for no reason; one that prints, like a build, is never stopped.",
419420 },
421 "billing.ask_cents": {
422 label: "Cents one ordinary crew ask costs, for saying a plan credit in asks",
423 unit: "cents",
424 default: 50,
425 min: 1,
426 max: 100_000,
427 reason: "A plan's credit is said on /pricing as a count of ordinary asks, so this is the price of one; the operator sets it from the crew's own ledger, and a plan that sells more asks than the crew can do for it is a promise broken.",
428 },
420429 "billing.grace_days": {
421430 label: "Days a forge keeps working after its payment fails",
422431 unit: "days",
src/tui/screens/getforge.ts +2 −2
@@ -22,9 +22,9 @@ import { Scroll } from "./common.ts";
2222 /** The screen as text lines, read fresh on every draw. */
2323 export function getForgeLines(app: App, width = 80): string[] {
2424 const w = Math.max(20, width);
25 const { plans, links, startUsd } = getDoorSettings(app.db);
25 const { plans, links, startUsd, askUsd } = getDoorSettings(app.db);
2626 const origin = (app.config.url ?? "").replace(/\/$/, "");
27 const words = publicPlans(plans).map((p) => planWords(p, links, startUsd));
27 const words = publicPlans(plans).map((p) => planWords(p, links, startUsd, askUsd));
2828 return [
2929 "Get your own forge",
3030 ...wrap("Hosted for you, or free and open source on a machine you keep.", w),
src/web/pages/new-forge.ts +4 −3
@@ -209,8 +209,8 @@ function freshError(errors: Errors, repoCount: number): string | undefined {
209209 * The line under the heading: the crew starts on the included credit when there is one, else on the
210210 * person's AI account.
211211 */
212 function hostingTerms(includedUsd: number): string {
213 return `Free within limits: it sleeps when idle. ${creditWords({ priceUsd: 0, creditUsd: 0 }, includedUsd)}`;
212 function hostingTerms(includedUsd: number, askUsd: number): string {
213 return `Free within limits: it sleeps when idle. ${creditWords({ priceUsd: 0, creditUsd: 0 }, includedUsd, askUsd)}`;
214214 }
215215
216216 function formView(
@@ -235,6 +235,7 @@ function formView(
235235 </div>`;
236236 const anon = user === undefined;
237237 const includedUsd = limitValue(ctx.app.db, "spawn.included_credit_usd");
238 const askUsd = limitValue(ctx.app.db, "billing.ask_cents") / 100;
238239 const freshErr = freshError(errors, repos.length);
239240 const lead = repos.length === 0 ? "Pick a name, and say what it is for if you like" : "Pick a name and the apps to start from";
240241 return html`<div class="narrow-wide" data-forges>
@@ -439,7 +440,7 @@ function formView(
439440 </div>
440441 </form>
441442 </section>
442 <p class="muted small" id="hosting-terms">${hostingTerms(includedUsd)}</p>
443 <p class="muted small" id="hosting-terms">${hostingTerms(includedUsd, askUsd)}</p>
443444 <p class="muted small"><a href="/terms">Terms of a paid forge</a></p>
444445 </div>`;
445446 }
src/web/pages/pricing.ts +3 −3
@@ -55,11 +55,11 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie
5555 const plans = door.plans;
5656 const rule = lapseRule(ctx.app.db);
5757 const links = selling ? {} : door.links;
58 const buyable = selling || plans.some((p) => planWords(p, links).buy !== undefined);
58 const buyable = selling || plans.some((p) => planWords(p, links, 0, door.askUsd).buy !== undefined);
5959 const rows = plans.map((p: Plan) => {
6060 const free = p.key === FREE;
6161 const paid = !free && selling;
62 const words = planWords(p, links);
62 const words = planWords(p, links, 0, door.askUsd);
6363 const buy = words.buy;
6464 const price = free
6565 ? html`<span data-price>${words.price}</span>`
@@ -70,7 +70,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie
7070 : html`<span data-price>${words.price}</span> <span class="muted">ask the operator · for organizations, <a href="https://www.espodev.com">EspoDev</a></span>`;
7171 const act = free ? btn(START_BUTTON, { formaction: "/forges/start" }) : paid ? btn(`Get ${p.name}`, { name: "plan", value: p.key, variant: "primary" }) : null;
7272 const count = ` Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}.`;
73 return planOfferRow({ key: p.key, name: p.name, says: `${planWords(p, links, door.startUsd).is}${count}`, price, action: act });
73 return planOfferRow({ key: p.key, name: p.name, says: `${planWords(p, links, door.startUsd, door.askUsd).is}${count}`, price, action: act });
7474 });
7575 return html`<div class="narrow-wide" id="pricing" data-pricing>
7676 ${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." })}
src/web/plan_row.ts +3 −1
@@ -12,6 +12,7 @@
1212 import { noticeOf, type PlanNotice } from "../billing/notice.ts";
1313 import { fundingOf } from "../spawn/funding.ts";
1414 import { uncountedWords } from "../actions/crew_means.ts";
15 import { creditWords } from "../billing/plan_words.ts";
1516 import { usdWords } from "../spawn/credit.ts";
1617 import { sizeWords } from "../settings/billing.ts";
1718 import { isSize } from "../spawn/sizes.ts";
@@ -43,7 +44,8 @@ export function planLine(dataDir: string): string | undefined {
4344 // when the host lent no cap.
4445 const cap = f?.capUsd ?? n.creditUsd;
4546 const credit = cap > 0 && f?.spentUsd != null ? ` ${usdWords(f.spentUsd)} of ${usdWords(cap)} crew credit used this month.${uncountedWords(f.uncountedUsd ?? 0)}` : "";
46 return `${n.name}${size}. ${statusWords(n)}.${credit}`;
47 const buys = n.priceUsd > 0 && n.creditUsd > 0 ? ` ${creditWords(n, 0, n.askUsd)}` : "";
48 return `${n.name}${size}. ${statusWords(n)}.${credit}${buys}`;
4749 }
4850
4951 /**
src/web/plans_row.ts +2 −2
@@ -10,8 +10,8 @@ import type { BillingLinks } from "../settings/billing.ts";
1010 import type { Plan } from "../settings/plans.ts";
1111 import { html, type Html } from "./html.ts";
1212
13 export function plansRow(plans: readonly Plan[], links: BillingLinks = {}, startUsd = 0): Html {
14 const words = plans.map((p) => planWords(p, links, startUsd));
13 export function plansRow(plans: readonly Plan[], links: BillingLinks = {}, startUsd = 0, askUsd?: number): Html {
14 const words = plans.map((p) => planWords(p, links, startUsd, askUsd));
1515 const list = html`<ul class="door-plans">${words.map((w) => {
1616 const action =
1717 w.buy !== undefined
src/web/studio/home.ts +3 −3
@@ -731,7 +731,7 @@ export function studioDoor(ctx: Ctx): Response {
731731 const featured = front.featured;
732732 const all = [...(featured === undefined ? [] : [featured]), ...front.shelf];
733733 const made = all.slice(0, Math.max(DOOR_TILES, all.filter((e) => e.pinned).length));
734 const { mode, plans: allPlans, links, startUsd } = getDoorSettings(ctx.app.db);
734 const { mode, plans: allPlans, links, startUsd, askUsd } = getDoorSettings(ctx.app.db);
735735 const accounts = !accountsClosedIn(ctx.app.db, mode);
736736 const drawTiles = (): Html[] =>
737737 timePhase(ctx.request, "tiles", () => made.map((e, at) => tile(e, at, accounts, e === featured ? html`role="region" aria-label="Featured"` : undefined)));
@@ -756,7 +756,7 @@ export function studioDoor(ctx: Ctx): Response {
756756 // holds it gets a 304 and no render. The ages in "Just finished" are inputs, as is the page's own
757757 // script (the tag is of the whole document); `/front` is an admin's and never tagged.
758758 const script = `${liveClientJs}\n${liveRegionsJs}\n${funnelJs}\n${startNameJs}`;
759 const tag = visitor && ctx.url.pathname === "/" ? pageTag(ctx, [front, front.pulse.changes.map((c) => timeAgo(c.mergedAt)), mode, allPlans, links, startUsd, accounts, refusal ?? null, keptName, startWaitIn(ctx.url.searchParams) ?? null, origin, signup, catalog().packs, running().version], script) : undefined;
759 const tag = visitor && ctx.url.pathname === "/" ? pageTag(ctx, [front, front.pulse.changes.map((c) => timeAgo(c.mergedAt)), mode, allPlans, links, startUsd, askUsd, accounts, refusal ?? null, keptName, startWaitIn(ctx.url.searchParams) ?? null, origin, signup, catalog().packs, running().version], script) : undefined;
760760 const held = heldCopy(ctx, tag, script);
761761 if (held !== undefined) {
762762 notePhaseRest(ctx.request, "render", rendering, []);
@@ -870,7 +870,7 @@ export function studioDoor(ctx: Ctx): Response {
870870 <p class="door-support">
871871 Hosted for you, or free and open source on a machine you keep.
872872 </p>
873 ${plansRow(publicPlans(allPlans), links, startUsd)}
873 ${plansRow(publicPlans(allPlans), links, startUsd, askUsd)}
874874 <div class="bar" data-plan="${freePlanName(allPlans)}">${btn("Get a forge", { href: visitor ? "#start-forge" : GET_A_FORGE_PATH, variant: "primary", size: "lg" })}</div>
875875 <p class="door-support">Or run it yourself, free and open source: <a href="${FORGE_REPO}">read the step-by-step guide</a>.</p>
876876 <pre class="door-code"><code>${selfHostCommands(FORGE_REPO).join("\n")}</code></pre>
test/new-forge-language.test.ts +1 −1
@@ -56,7 +56,7 @@ test("the hosting line says the crew starts on the included credit only when the
5656 const id = app.db.query<{ id: string }, []>("SELECT id FROM user LIMIT 1").get()!.id;
5757 setLimit(app.db, "spawn.included_credit_usd", 3, id);
5858 expect(await say()).toBe(
59 "Free within limits: it sleeps when idle. $3 of crew credit once, to start. Then your own AI account key.",
59 "Free within limits: it sleeps when idle. Crew credit for 6 ordinary asks, once, to start. Then your own AI account key.",
6060 );
6161 setLimit(app.db, "spawn.included_credit_usd", 0, id);
6262 expect(await say()).toBe(
test/plans-row.test.ts +6 −6
@@ -30,7 +30,7 @@ test("every plan shows its price from the plans setting, the free plan Free; no
3030 expect(row).toContain(p.name);
3131 expect(row).toContain(sizeWords(p.size));
3232 }
33 for (const t of ["$19 a month", "$49 a month", "$149 a month", "$5 of crew credit each month"]) expect(row).toContain(t);
33 for (const t of ["$19 a month", "$49 a month", "$149 a month", "Crew credit for 10 ordinary asks each month"]) expect(row).toContain(t);
3434 expect(row).not.toContain("Paid");
3535 expect(planWords(FREE).price).toBe("Free");
3636 expect(planWords(SMALL).price).toBe("$19 a month");
@@ -113,7 +113,7 @@ test("getDoorSettings: the start credit is the spawn.included_credit_usd limit,
113113
114114 test("getDoorSettings: nothing stored, or a stored value that does not parse, reads as the defaults", () => {
115115 const empty = getDoorSettings(app.db);
116 expect(empty).toEqual({ mode: SIGNUP_DEFAULT, plans: DEFAULT_PLANS.map((p) => ({ ...p })), links: {}, startUsd: 2 });
116 expect(empty).toEqual({ mode: SIGNUP_DEFAULT, plans: DEFAULT_PLANS.map((p) => ({ ...p })), links: {}, startUsd: 2, askUsd: 0.5 });
117117 put("signup", "sometimes");
118118 put("plans", "{not json");
119119 put("billing.links", "[1]");
@@ -135,8 +135,8 @@ test("a guest in the terminal is offered Get your own forge", () => {
135135 });
136136
137137 test("a paid plan keeps its own sentence and adds its monthly credit; the free plan says its start credit, once", () => {
138 expect(planWords(SMALL).is).toBe(`${sizeWords(SMALL.size)}. ${SMALL.says} $${SMALL.creditUsd} of crew credit each month.`);
139 expect(planWords(FREE, {}, 2).is).toBe(`${sizeWords(FREE.size)}. ${FREE.says} $2 of crew credit once, to start. Then your own AI account key.`);
138 expect(planWords(SMALL).is).toBe(`${sizeWords(SMALL.size)}. ${SMALL.says} Crew credit for 10 ordinary asks each month.`);
139 expect(planWords(FREE, {}, 2).is).toBe(`${sizeWords(FREE.size)}. ${FREE.says} Crew credit for 4 ordinary asks, once, to start. Then your own AI account key.`);
140140 expect(planWords(FREE, {}, 0).is).toBe(`${sizeWords(FREE.size)}. ${FREE.says} No crew credit: the crew runs on your own AI account key.`);
141141 });
142142
@@ -160,7 +160,7 @@ test("with buy links set the plans show price, credit, Get anchors and the after
160160 put("signup", "closed");
161161 put("billing.links", JSON.stringify({ small: "https://buy.example/s", medium: "https://buy.example/m", large: "https://buy.example/l" }));
162162 const section = await yours();
163 for (const t of ["$19 a month", "$49 a month", "$149 a month", "$5 of crew credit each month", "$15 of crew credit each month", "$50 of crew credit each month", "Your forge is created"])
163 for (const t of ["$19 a month", "$49 a month", "$149 a month", "Crew credit for 10 ordinary asks each month", "Crew credit for 30 ordinary asks each month", "Crew credit for 100 ordinary asks each month", "Your forge is created"])
164164 expect(section).toContain(t);
165165 for (const n of ["Small", "Medium", "Large"]) expect(section).toContain(`>Get ${n}</a>`);
166166 expect(section).not.toContain("Get Free");
@@ -175,7 +175,7 @@ test("changing a price in the plans setting changes the page", async () => {
175175 put("plans", JSON.stringify(DEFAULT_PLANS.map((p) => (p.key === "small" ? { ...p, priceUsd: 23, creditUsd: 7 } : p))));
176176 const section = await yours();
177177 expect(section).toContain("$23 a month");
178 expect(section).toContain("$7 of crew credit each month");
178 expect(section).toContain("Crew credit for 14 ordinary asks each month");
179179 expect(section).not.toContain("$19 a month");
180180 });
181181
test/pricing-plans-agree.test.ts +3 −2
@@ -7,6 +7,7 @@ import { createApp, type App } from "../src/app.ts";
77 import { serve, type Servers } from "../src/http/server.ts";
88 import { setBillingLinks } from "../src/settings/billing.ts";
99 import { getPlans } from "../src/settings/plans.ts";
10 import { asksWords } from "../src/billing/plan_words.ts";
1011
1112 let dir: string;
1213 let app: App;
@@ -32,8 +33,8 @@ test("every plan's card shows the price, credit and forge count the API lists",
3233 expect(start).toBeGreaterThan(-1);
3334 const card = text.slice(start, text.indexOf("</div>", start));
3435 expect(card).toContain(p.priceUsd === 0 ? ">Free<" : `$${p.priceUsd} a month`);
35 if (p.priceUsd === 0) expect(card).toContain(`$${api.startCreditUsd} of crew credit once, to start`);
36 else if (p.creditUsd > 0) expect(card).toContain(`$${p.creditUsd} of crew credit each month`);
36 if (p.priceUsd === 0) expect(card).toContain(`Crew credit for ${asksWords(api.startCreditUsd)}, once, to start`);
37 else if (p.creditUsd > 0) expect(card).toContain(`Crew credit for ${asksWords(p.creditUsd)} each month`);
3738 else expect(card).toContain("No crew credit included");
3839 expect(card).toContain(`Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}`);
3940 if (p.priceUsd > 0) {
test/pricing-words.test.ts added +62
@@ -0,0 +1,62 @@
1 /**
2 * A plan's credit is said as a count of ordinary asks, the same words on /pricing and the owner's
3 * plan row.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, writeFile } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { serve, type Servers } from "../src/http/server.ts";
11 import { ASK_USD, asksWords, creditWords } from "../src/billing/plan_words.ts";
12 import { getForgeLines } from "../src/tui/screens/getforge.ts";
13 import { setLimit } from "../src/settings/limits.ts";
14 import { planLine } from "../src/web/plan_row.ts";
15
16 let dir: string;
17 let app: App;
18 let servers: Servers;
19 beforeAll(async () => {
20 dir = await mkdtemp(join(tmpdir(), "forge-pricing-words-"));
21 app = createApp({ dataDir: dir, port: 0 });
22 servers = await serve(app);
23 });
24 afterAll(() => {
25 servers.stop();
26 app.close();
27 });
28
29 test("a credit is a count of asks, rounded down, singular at one", () => {
30 expect(asksWords(5)).toBe("10 ordinary asks");
31 expect(asksWords(ASK_USD)).toBe("1 ordinary ask");
32 expect(asksWords(0.7)).toBe("1 ordinary ask");
33 expect(asksWords(0.1)).toBe("0 ordinary asks");
34 });
35
36 test("/pricing says the credit in asks, no raw dollars of credit", async () => {
37 const text = await (await fetch(`${servers.url}/pricing`)).text();
38 expect(text).toContain("Crew credit for 10 ordinary asks each month.");
39 expect(text).toContain("Crew credit for 4 ordinary asks, once, to start.");
40 expect(text).not.toMatch(/\$\d+ of crew credit/);
41 });
42
43 test("the owner's plan row says the same sentence /pricing says", async () => {
44 await writeFile(join(dir, "plan.json"), JSON.stringify({ name: "Small", size: "small", priceUsd: 19, creditUsd: 5, status: "active" }));
45 const line = planLine(dir) ?? "";
46 expect(line).toContain(creditWords({ priceUsd: 19, creditUsd: 5 }, 0));
47 });
48
49 test("a credit under one ask says no crew credit, not 0 asks", () => {
50 expect(creditWords({ priceUsd: 19, creditUsd: 0.4 }, 0)).toBe("No crew credit included.");
51 expect(creditWords({ priceUsd: 0, creditUsd: 0 }, 0.4)).toBe("No crew credit: the crew runs on your own AI account key.");
52 });
53
54 test("an ask costs what billing.ask_usd says: /pricing, the terminal and the plan row follow it", async () => {
55 const set = setLimit(app.db, "billing.ask_cents", 100, "test");
56 expect(set.ok).toBe(true);
57 const text = await (await fetch(`${servers.url}/pricing`)).text();

Non-blocking: the title says billing.ask_usd but the limit is now billing.ask_cents.

58 expect(text).toContain("Crew credit for 5 ordinary asks each month.");
59 expect(getForgeLines(app, 200).join("\n")).toContain("Crew credit for 5 ordinary asks each month.");
60 await writeFile(join(dir, "plan.json"), JSON.stringify({ name: "Small", size: "small", priceUsd: 19, creditUsd: 5, askUsd: 1, status: "active" }));
61 expect(planLine(dir)).toContain("Crew credit for 5 ordinary asks each month.");
62 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs