Public: anyone can read this; the crew can change it.
The shared tier is sold beside the dedicated one, with a density number a test measured #17008
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16857-the-shared-tier-is-sold-beside-the-dedic → main 0 commits fork 5 threads · 5 unresolved
22 files
changed +272
−23
- docs/features/shared-tier.md
- scripts/gate.ts
- src/billing/density.ts
- src/billing/plan_words.ts
- src/settings/plans.ts
- src/spawn/making.ts
- src/tui/screens/pricing.ts
- src/web/pages/pricing.ts
- src/web/plans_row.ts
- test/billing-links.test.ts
- test/llms-budget.test.ts
- test/mcp-limits.test.ts
- test/perf-home-signed-out.test.ts
- test/plans-row.test.ts
- test/plans.test.ts
- test/pricing-line.test.ts
- test/pricing-plans-agree.test.ts
- test/pricing-size.test.ts
- test/shared-density.test.ts
- test/shared-pricing.test.ts
- test/tui-plans.test.ts
- test/tui-pricing.test.ts
scripts/gate.ts +1
| @@ -51,6 +51,7 @@ export const EXCLUDED: readonly Exclusion[] = []; | ||
| 51 | 51 | * short: an entry is a debt with an owner, not a home. |
| 52 | 52 | */ |
| 53 | 53 | export const SLOW: readonly Exclusion[] = [ |
| 54 | { file: "test/shared-density.test.ts", reason: "spawns a fresh bun child that loads the whole app and makes forges to read its own RSS; 2 s alone, 2.3 s a test under full-suite load", issue: 16857 }, | |
| 54 | 55 | { file: "test/bundle-boot.test.ts", reason: "bundles src/main.ts with bun build --minify and boots the one file with no source beside it; 2.6 s a test under full-suite load", issue: 16853 }, |
| 55 | 56 | { file: "test/boot-idle-memory.test.ts", reason: "boots the real src/main.ts and waits real seconds for its RSS to settle; 8.6 s a test", issue: 16851 }, |
| 56 | 57 | { file: "test/landsim.test.ts", reason: "runs seeded landing simulations over real repositories and queues; 16 s a file alone, 28.8 s and 2.8 s a test under full-suite load", issue: 13765 }, |
src/billing/density.ts added +76
| @@ -0,0 +1,76 @@ | ||
| 1 | /** | |
| 2 | * The shared tier's density (#16857): how many sleeping forges one shared machine holds, and the | |
| 3 | * price that follows, from two measured numbers instead of a guess. `MEASURED` is what | |
| 4 | * `test/shared-density.test.ts` re-measures on every run and holds the figures to: the awake | |
| 5 | * resident memory of one forge, and the fraction of a day a forge is awake under a stated | |
| 6 | * pattern of visits and the quiet minutes before it sleeps. Plain data in, plain data out. | |
| 7 | */ | |
| 8 | ||
| 9 | import { SIZES } from "../spawn/sizes.ts"; | |
| 10 | ||
| 11 | /** The key of the shared plan: a paid forge that sleeps when idle, hosted beside others. */ | |
| 12 | export const SHARED = "shared"; | |
| 13 | ||
| 14 | /** The stated use the active fraction is worked out under: visits a day, minutes each. */ | |
| 15 | export const PATTERN = { visitsPerDay: 3, visitMinutes: 4 } as const; | |
| 16 | ||
| 17 | /** | |
| 18 | * The quiet minutes before a forge sleeps that the claim assumes: `forges.idle_minutes`' default. | |
| 19 | */ | |
| 20 | export const IDLE_MINUTES = 10; | |
| 21 | ||
| 22 | /** | |
| 23 | * Minutes of a day a forge is awake: each visit keeps it awake until `idleMinutes` after it ends. | |
| 24 | */ | |
| 25 | export function awakeFraction(visitsPerDay: number, visitMinutes: number, idleMinutes: number): number { | |
| 26 | return Math.min(1, (visitsPerDay * (visitMinutes + idleMinutes)) / 1440); | |
| 27 | } | |
| 28 | ||
| 29 | /** What the test measured, rounded up (never down) so the claim is the cautious side of it. */ | |
| 30 | export const MEASURED = { | |
| 31 | /** Resident memory of one awake forge, MiB: a ceiling over what the test measures. */ | |
| 32 | awakeRssMib: 8, | |
| 33 | /** Share of the day a forge is awake under `PATTERN`, rounded up to a whole percent. */ | |
| 34 | activeFraction: Math.ceil(awakeFraction(PATTERN.visitsPerDay, PATTERN.visitMinutes, IDLE_MINUTES) * 100) / 100, | |
| 35 | } as const; | |
| 36 | ||
| 37 | /** What the offer promises that nothing measures: it is a choice, and the page says so. */ | |
| 38 | export const PROMISE = { | |
| 39 | /** Disk each shared forge may hold, MiB. */ | |
| 40 | diskMib: 50, | |
| 41 | /** Memory kept free for one build at a time (a first deploy took 1195 MiB, `spawn/sizes.ts`). */ | |
| 42 | buildReserveMib: 1200, | |
| 43 | /** Awake forges at the busiest moment, as a multiple of the average. */ | |
| 44 | peak: 10, | |
| 45 | /** The price covers the machine this many times over. */ | |
| 46 | cover: 2, | |
| 47 | } as const; | |
| 48 | ||
| 49 | export interface Density { | |
| 50 | readonly forgesPerMachine: number; | |
| 51 | readonly priceUsd: number; | |
| 52 | /** Which limit set the count. */ | |
| 53 | readonly boundBy: "memory" | "disk"; | |
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * Forges on one machine of `machineUsd` a month, from the numbers given (the measured ones by | |
| 58 | * default). | |
| 59 | */ | |
| 60 | export function densityOf(machineUsd: number, m: { awakeRssMib: number; activeFraction: number } = MEASURED): Density { | |
| 61 | const { memoryMiB, diskMiB } = SIZES.small; | |
| 62 | const awakeSlots = Math.max(1, Math.floor((memoryMiB - PROMISE.buildReserveMib) / m.awakeRssMib)); | |
| 63 | const byMemory = Math.floor(awakeSlots / (m.activeFraction * PROMISE.peak)); | |
| 64 | const byDisk = Math.floor(diskMiB / PROMISE.diskMib); | |
| 65 | const forgesPerMachine = Math.max(1, Math.min(byMemory, byDisk)); | |
| 66 | const priceUsd = Math.max(1, Math.ceil((machineUsd * PROMISE.cover) / forgesPerMachine)); | |
| 67 | return { forgesPerMachine, priceUsd, boundBy: byMemory <= byDisk ? "memory" : "disk" }; | |
| 68 | } | |
| 69 | ||
| 70 | /** The dedicated machine the shared price is a share of: Small's price (`settings/plans.ts`). */ | |
| 71 | export const DEDICATED_USD = 19; | |
| 72 | ||
| 73 | /** The shared plan's one line, the same on /pricing and in the terminal. */ | |
| 74 | export function sharedSays(d: Density = densityOf(DEDICATED_USD)): string { | |
| 75 | return `Shares a machine with up to ${d.forgesPerMachine} forges; sleeps when idle, wakes in a second.`; | |
| 76 | } |
src/billing/plan_words.ts +4 −2
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * `actions/spawn.ts` lends a new forge on no paid plan that brings no key. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { SHARED } from "./density.ts"; | |
| 10 | 11 | import type { BillingLinks } from "../settings/billing.ts"; |
| 11 | 12 | import { sizeWords } from "../settings/billing.ts"; |
| 12 | 13 | import { LIMITS } from "../settings/limits.ts"; |
| @@ -74,11 +75,12 @@ export function firstChangeWords(secs: number | undefined): string { | ||
| 74 | 75 | |
| 75 | 76 | export function planWords(p: Plan, links: BillingLinks = {}, startUsd = 0, askUsd: number = ASK_USD): PlanWords { |
| 76 | 77 | const free = p.priceUsd === 0; |
| 77 | const buy = free ? undefined : links[p.size]; | |
| 78 | // A shared forge is $1, not Small's $19: Small's buy link must not stand in for it. | |
| 79 | const buy = free || p.key === SHARED ? undefined : links[p.size]; | |
| 78 | 80 | return { |
| 79 | 81 | name: p.name, |
| 80 | 82 | price: usdPerMonthWords(p.priceUsd), |
| 81 | is: [`${sizeWords(p.size)}. ${p.says}`, firstChangeWords(p.firstChangeSecs), creditWords(p, startUsd, askUsd)].filter((x) => x !== "").join(" "), | |
| 83 | is: [p.key === SHARED ? p.says : `${sizeWords(p.size)}. ${p.says}`, firstChangeWords(p.firstChangeSecs), creditWords(p, startUsd, askUsd)].filter((x) => x !== "").join(" "), | |
| 82 | 84 | buy, |
| 83 | 85 | }; |
| 84 | 86 | } |
src/settings/plans.ts +3 −1
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | import type { Database } from "bun:sqlite"; |
| 13 | 13 | import { moneyWords, centsOfUsd, usdPerMonthWords } from "../billing/money.ts"; |
| 14 | 14 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 15 | import { DEDICATED_USD, densityOf, SHARED, sharedSays } from "../billing/density.ts"; | |
| 15 | 16 | import { isSize, SIZES, type Size } from "../spawn/sizes.ts"; |
| 16 | 17 | import { writeSetting } from "./limits.ts"; |
| 17 | 18 | |
| @@ -46,7 +47,8 @@ export const MAX_FIRST_CHANGE_SECS = 86_400; | ||
| 46 | 47 | |
| 47 | 48 | export const DEFAULT_PLANS: readonly Plan[] = [ |
| 48 | 49 | { key: "free", name: "Free", says: "Sleeps when idle and wakes on the next visit.", size: "small", priceUsd: 0, creditUsd: 0, forges: 3 }, |
| 49 | { key: "small", name: "Small", says: "The same size as Free, always awake.", size: "small", priceUsd: 19, creditUsd: 5, forges: 3 }, | |
| 50 | { key: SHARED, name: "Shared", says: sharedSays(), size: "small", priceUsd: densityOf(DEDICATED_USD).priceUsd, creditUsd: 0, forges: 3 }, | |
| 51 | { key: "small", name: "Small", says: "The same size as Free, always awake.", size: "small", priceUsd: DEDICATED_USD, creditUsd: 5, forges: 3 }, | |
| 50 | 52 | { key: "medium", name: "Medium", says: "Twice Small's CPU and memory, always awake.", size: "medium", priceUsd: 49, creditUsd: 15, forges: 3 }, |
| 51 | 53 | { key: "large", name: "Large", says: "Four times Small's CPU and memory, always awake.", size: "large", priceUsd: 149, creditUsd: 50, forges: 3 }, |
| 52 | 54 | ]; |
src/spawn/making.ts +4 −1
| @@ -30,6 +30,7 @@ import { getPinned } from "../core/pinned.ts"; | ||
| 30 | 30 | import { deleteSecret, resolveSecrets, setSecret } from "../core/secret_store.ts"; |
| 31 | 31 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 32 | 32 | import { during } from "../perf/jobs.ts"; |
| 33 | import { SHARED } from "../billing/density.ts"; | |
| 33 | 34 | import { getPaidPlacement } from "../settings/paid_placement.ts"; |
| 34 | 35 | import { FREE, type Plan } from "../settings/plans.ts"; |
| 35 | 36 | import { |
| @@ -57,7 +58,9 @@ export function whereFor( | ||
| 57 | 58 | named?: { readonly provider: string; readonly account: string }, |
| 58 | 59 | ): Where { |
| 59 | 60 | if (named !== undefined) return { where: "cloud", ...named }; |
| 60 | if (plan === undefined || plan.key === FREE) return { where: "hosted" }; | |
| 61 | // Free and shared forges are hosted beside others and sleep; only a dedicated plan may be placed | |
| 62 | // on a cloud. | |
| 63 | if (plan === undefined || plan.key === FREE || plan.key === SHARED) return { where: "hosted" }; | |
| 61 | 64 | return getPaidPlacement(app.db); |
| 62 | 65 | } |
| 63 | 66 |
src/tui/screens/pricing.ts +2 −1
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder } from "../../actions/order.ts"; |
| 13 | 13 | import { usdPerMonthWords } from "../../billing/money.ts"; |
| 14 | import { SHARED } from "../../billing/density.ts"; | |
| 14 | 15 | import { AFTER_PAYMENT_STEPS, priceLine } from "../../billing/plan_words.ts"; |
| 15 | 16 | import { receiptFacts } from "../../billing/receipt.ts"; |
| 16 | 17 | import { lapseRule, lapseRuleWords } from "../../billing/lapse_rule.ts"; |
| @@ -158,7 +159,7 @@ export function pricingScreen(f: Session, ctx: Ctx): Screen { | ||
| 158 | 159 | for (const p of plans()) { |
| 159 | 160 | const isPaid = p.key !== FREE && p.priceUsd > 0; |
| 160 | 161 | const mark = isPaid && list[at]?.key === p.key ? "▸" : " "; |
| 161 | line(`${mark} ${p.name.padEnd(12)} ${usdPerMonthWords(p.priceUsd)} ${sizeWords(p.size)}`, isPaid ? c.fg : c.mutedFg); | |
| 162 | line(`${mark} ${p.name.padEnd(12)} ${usdPerMonthWords(p.priceUsd)} ${p.key === SHARED ? p.says : sizeWords(p.size)}`, isPaid ? c.fg : c.mutedFg); | |
| 162 | 163 | } |
| 163 | 164 | y++; |
| 164 | 165 | const base = y - area.y; |
src/web/pages/pricing.ts +2 −1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * one without says whom to ask. The rules are in `actions/order.ts`. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { SHARED } from "../../billing/density.ts"; | |
| 10 | 11 | import { setCookie } from "../../auth/cookies.ts"; |
| 11 | 12 | import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder, resendLink, type Refusal } from "../../actions/order.ts"; |
| 12 | 13 | import { cloudLapseWords, lapseRule, lapseRuleWords } from "../../billing/lapse_rule.ts"; |
| @@ -127,7 +128,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 127 | 128 | const quoted = quote?.ok === true ? quote.value : undefined; |
| 128 | 129 | const price = quoted !== undefined && (quoted.atCost || quoted.surchargeUsd > 0) ? quotedPrice(p, quoted) : unquotedPrice(p, words, free || paid, buy); |
| 129 | 130 | const act = free ? btn(START_BUTTON, { formaction: "/forges/start" }) : paid ? btn(`Get ${p.name}`, { name: "plan", value: p.key, variant: "primary" }) : null; |
| 130 | const count = ` Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}.`; | |
| 131 | const count = p.key === SHARED ? ` You can have up to ${p.forges}.` : ` Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}.`; | |
| 131 | 132 | return planOfferRow({ key: p.key, name: p.name, says: `${planWords(p, links, door.startUsd, door.askUsd).is}${count}`, price, action: act }); |
| 132 | 133 | }); |
| 133 | 134 | return html`<div class="narrow-wide" id="pricing" data-pricing> |
src/web/plans_row.ts +3 −1
| @@ -5,13 +5,15 @@ | ||
| 5 | 5 | * not a second button, and the after-payment line follows the list. Words come from `billing/plan_words.ts`, the terminal's too. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { SHARED } from "../billing/density.ts"; | |
| 8 | 9 | import { AFTER_PAYMENT, planWords } from "../billing/plan_words.ts"; |
| 9 | 10 | import type { BillingLinks } from "../settings/billing.ts"; |
| 10 | 11 | import type { Plan } from "../settings/plans.ts"; |
| 11 | 12 | import { html, type Html } from "./html.ts"; |
| 12 | 13 | |
| 13 | 14 | export function plansRow(plans: readonly Plan[], links: BillingLinks = {}, startUsd = 0, askUsd?: number): Html { |
| 14 | const words = plans.map((p) => planWords(p, links, startUsd, askUsd)); | |
| 15 | // The home is the pitch; the shared plan, with its count and its order form, is on /pricing. | |
| 16 | const words = plans.filter((p) => p.key !== SHARED).map((p) => planWords(p, links, startUsd, askUsd)); | |
| 15 | 17 | const list = html`<ul class="door-plans">${words.map((w) => { |
| 16 | 18 | const action = |
| 17 | 19 | w.buy !== undefined |
test/billing-links.test.ts +1
| @@ -119,6 +119,7 @@ test("with three links each paid plan carries a pay link; the button stays one", | ||
| 119 | 119 | expect(read.billingLinks).toEqual(LINKS); |
| 120 | 120 | const section = yours(await home()); |
| 121 | 121 | const anchors = payAnchors(section); |
| 122 | // Shared is $1, not Small's $19: it carries no pay link of Small's. | |
| 122 | 123 | expect(anchors).toHaveLength(3); |
| 123 | 124 | for (const [i, size] of (["small", "medium", "large"] as const).entries()) { |
| 124 | 125 | expect(anchors[i]).toContain(`href="${LINKS[size]}"`); |
test/llms-budget.test.ts +2 −1
| @@ -62,8 +62,9 @@ const get = async (token?: string): Promise<string> => | ||
| 62 | 62 | * admin 98,939). Raised to 100,700 for the profile tool's `gift` action (admin 99,756; 100,036 with |
| 63 | 63 | * the changes tool of #10839). Then a tool's line inlines at most `LINE_DOC_MAX` (800) characters |
| 64 | 64 | * of its doc and names find_tool, which returns the whole of it: admin 92,689, signed-in 70,251. |
| 65 | * Anonymous 9,760 at #16857: Shared's plan row measured 9,659, one byte under the old 9,660. | |
| 65 | 66 | */ |
| 66 | const BUDGET = { anonymous: 9_650, signedIn: 84_100, admin: 100_700 } as const; | |
| 67 | const BUDGET = { anonymous: 9_760, signedIn: 84_100, admin: 100_700 } as const; | |
| 67 | 68 | |
| 68 | 69 | test("/llms.txt stays under its byte budget for each role", async () => { |
| 69 | 70 | const sizes = { |
test/mcp-limits.test.ts +3 −3
| @@ -157,7 +157,7 @@ describe("MCP limits", () => { | ||
| 157 | 157 | const dry = await call(adaAdmin, { plans: PLANS }); |
| 158 | 158 | expect(dry.error).toBe(false); |
| 159 | 159 | expect(JSON.parse(dry.text).plans.map((p: any) => p.key)).toEqual(["free", "pro"]); |
| 160 | expect(JSON.parse((await call(adaAdmin, {})).text).plans.map((p: any) => p.key)).toEqual(["free", "small", "medium", "large"]); | |
| 160 | expect(JSON.parse((await call(adaAdmin, {})).text).plans.map((p: any) => p.key)).toEqual(["free", "shared", "small", "medium", "large"]); | |
| 161 | 161 | // A dry run tells the truth: a bad list is refused as the real change would refuse it. |
| 162 | 162 | const bad = await call(adaAdmin, { plans: PLANS.slice(1) }); |
| 163 | 163 | expect(bad.error).toBe(true); |
| @@ -168,11 +168,11 @@ describe("MCP limits", () => { | ||
| 168 | 168 | const ro = await call(adaRw, { plans: PLANS, dryRun: false }); |
| 169 | 169 | expect(ro.error).toBe(true); |
| 170 | 170 | expect(ro.text).toContain("admin-scope"); |
| 171 | expect(JSON.parse((await call(adaAdmin, {})).text).plans).toHaveLength(4); | |
| 171 | expect(JSON.parse((await call(adaAdmin, {})).text).plans).toHaveLength(5); | |
| 172 | 172 | // A non-admin and an agent are told there is no such tool. |
| 173 | 173 | expect((await call(cyToken, { plans: PLANS, dryRun: false })).error).toBe(true); |
| 174 | 174 | expect((await call(botToken, { plans: PLANS, dryRun: false })).error).toBe(true); |
| 175 | expect(JSON.parse((await call(adaAdmin, {})).text).plans).toHaveLength(4); | |
| 175 | expect(JSON.parse((await call(adaAdmin, {})).text).plans).toHaveLength(5); | |
| 176 | 176 | const applied = await call(adaAdmin, { plans: PLANS, dryRun: false }); |
| 177 | 177 | expect(applied.error).toBe(false); |
| 178 | 178 | expect(JSON.parse((await call(adaAdmin, {})).text).plans.map((p: any) => p.key)).toEqual(["free", "pro"]); |
test/perf-home-signed-out.test.ts +2 −2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * The signed-out home is the fastest page (#12986): its `render` phase stays |
| 3 | * under 30 ms (median of 20 renders) and its HTML under 30 KB, on a forge | |
| 3 | * under 30 ms (median of 20 renders) and its HTML under its byte budget, on a forge | |
| 4 | 4 | * seeded the way a busy one is: many public apps with plans that moved this |
| 5 | 5 | * week, merged changes (merged across the last 90 days). |
| 6 | 6 | */ |
| @@ -125,7 +125,7 @@ test("the signed-out home's render phase is under 30 ms, median of 20", async () | ||
| 125 | 125 | expect(median).toBeLessThan(RENDER_MS); |
| 126 | 126 | }); |
| 127 | 127 | |
| 128 | test("the signed-out home's HTML is under 30 KB", async () => { | |
| 128 | test("the signed-out home's HTML is under its byte budget", async () => { | |
| 129 | 129 | const { bytes } = await renders(1); |
| 130 | 130 | console.log("bytes", bytes); |
| 131 | 131 | const page = await (await fetch(`${servers.url}/`)).text(); |
test/plans-row.test.ts +4 −2
| @@ -26,7 +26,9 @@ const SMALL = DEFAULT_PLANS.find((p) => p.key === "small")!; | ||
| 26 | 26 | |
| 27 | 27 | test("every plan shows its price from the plans setting, the free plan Free; no Paid anywhere", () => { |
| 28 | 28 | const row = plansRow(DEFAULT_PLANS, {}).toString(); |
| 29 | for (const p of DEFAULT_PLANS) { | |
| 29 | // The home is the pitch: the shared plan, with its count, is on /pricing only. | |
| 30 | expect(row).not.toContain("Shared"); | |
| 31 | for (const p of DEFAULT_PLANS.filter((p) => p.key !== "shared")) { | |
| 30 | 32 | expect(row).toContain(p.name); |
| 31 | 33 | expect(row).toContain(sizeWords(p.size)); |
| 32 | 34 | } |
| @@ -79,7 +81,7 @@ const yours = async (): Promise<string> => { | ||
| 79 | 81 | |
| 80 | 82 | test("the signed-out home shows each plan and one button to a page that exists", async () => { |
| 81 | 83 | const section = await yours(); |
| 82 | for (const p of DEFAULT_PLANS) expect(section).toContain(p.name); | |
| 84 | for (const p of DEFAULT_PLANS.filter((p) => p.key !== "shared")) expect(section).toContain(p.name); | |
| 83 | 85 | expect(section).toContain('href="#start-forge"'); |
| 84 | 86 | expect(section).not.toContain("/pricing"); |
| 85 | 87 | expect(section).toContain("$19.00 / month"); |
test/plans.test.ts +4 −2
| @@ -16,6 +16,7 @@ import { hostedPlacement, memoryBodies } from "../src/spawn/placement.ts"; | ||
| 16 | 16 | import { usePlacement, useProbe } from "../src/spawn/door.ts"; |
| 17 | 17 | import { addSpend, periodOf, readCredit } from "../src/spawn/credit.ts"; |
| 18 | 18 | import { DEFAULT_PLANS, getPlan, getPlans, parsePlans } from "../src/settings/plans.ts"; |
| 19 | import { DEDICATED_USD, densityOf } from "../src/billing/density.ts"; | |
| 19 | 20 | import { planRefusal } from "../src/spawn/sleep.ts"; |
| 20 | 21 | import { grantPlanCredit } from "../src/actions/spawn.ts"; |
| 21 | 22 | import { setLimit } from "../src/settings/limits.ts"; |
| @@ -65,10 +66,11 @@ describe("plans", () => { | ||
| 65 | 66 | await rm(dir, { recursive: true, force: true }); |
| 66 | 67 | }); |
| 67 | 68 | |
| 68 | test("the defaults: free, small, medium and large, public and without secrets", async () => { | |
| 69 | test("the defaults: free, shared, small, medium and large, public and without secrets", async () => { | |
| 69 | 70 | const items = await plans(); |
| 70 | 71 | expect(items.map((p) => [p.key, p.size, p.priceUsd, p.creditUsd])).toEqual([ |
| 71 | 72 | ["free", "small", 0, 0], |
| 73 | ["shared", "small", densityOf(DEDICATED_USD).priceUsd, 0], | |
| 72 | 74 | ["small", "small", 19, 5], |
| 73 | 75 | ["medium", "medium", 49, 15], |
| 74 | 76 | ["large", "large", 149, 50], |
| @@ -86,7 +88,7 @@ describe("plans", () => { | ||
| 86 | 88 | expect(((await dear.json()) as any).message).toBe("the free plan costs $0"); |
| 87 | 89 | expect(parsePlans([{ ...DEFAULT_PLANS[0], size: "huge" }]).ok).toBe(false); |
| 88 | 90 | expect(parsePlans([{ ...DEFAULT_PLANS[0], creditUsd: 1.234 }]).ok).toBe(false); |
| 89 | expect((await plans())[1].priceUsd).toBe(19); | |
| 91 | expect((await plans())[2].priceUsd).toBe(19); | |
| 90 | 92 | }); |
| 91 | 93 | |
| 92 | 94 | test("a spawn on each plan takes its size and its credit", async () => { |
test/pricing-line.test.ts +1 −1
| @@ -45,7 +45,7 @@ test("the line is the cheapest paid plan's price, in the head's one sub, above t | ||
| 45 | 45 | }); |
| 46 | 46 | |
| 47 | 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); | |
| 48 | setPlans(app.db, DEFAULT_PLANS.map((p) => (p.key === "shared" ? { ...p, priceUsd: 23 } : p.key === "small" ? { ...p, priceUsd: 29 } : p)), actor); | |
| 49 | 49 | expect((await firstLine()).line).toContain("A forge is $23.00 / month"); |
| 50 | 50 | expect(priceLine([])).toBe("A forge is free"); |
| 51 | 51 | }); |
test/pricing-plans-agree.test.ts +2 −2
| @@ -36,7 +36,7 @@ test("every plan's card shows the price, credit and forge count the API lists", | ||
| 36 | 36 | if (p.priceUsd === 0) expect(card).toContain(`Crew credit for ${asksWords(api.startCreditUsd)}, once, to start`); |
| 37 | 37 | else if (p.creditUsd > 0) expect(card).toContain(`Crew credit for ${asksWords(p.creditUsd)} each month`); |
| 38 | 38 | else expect(card).toContain("No crew credit included"); |
| 39 | expect(card).toContain(`Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}`); | |
| 39 | expect(card).toContain(p.key === "shared" ? `You can have up to ${p.forges}.` : `Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}`); | |
| 40 | 40 | if (p.priceUsd > 0) { |
| 41 | 41 | expect(card).toContain("ask the operator"); |
| 42 | 42 | expect(card).not.toContain("not on sale"); |
| @@ -50,7 +50,7 @@ test("with no checkout, a plan's buy link on /pricing is the one the home carrie | ||
| 50 | 50 | try { |
| 51 | 51 | const pricing = await (await fetch(`${servers.url}/pricing`)).text(); |
| 52 | 52 | const home = await (await fetch(`${servers.url}/`)).text(); |
| 53 | for (const p of getPlans(app.db).filter((p) => p.priceUsd > 0)) { | |
| 53 | for (const p of getPlans(app.db).filter((p) => p.priceUsd > 0 && p.key !== "shared")) { | |
| 54 | 54 | const link = links[p.size as keyof typeof links]; |
| 55 | 55 | const start = pricing.indexOf(`data-plan="${p.key}"`); |
| 56 | 56 | const card = pricing.slice(start, pricing.indexOf("</div>", start)); |
test/pricing-size.test.ts +1 −1
| @@ -30,7 +30,7 @@ afterAll(async () => { | ||
| 30 | 30 | |
| 31 | 31 | test("signed out, /pricing is well under its old 16.7 KB and its plans are dl rows, not list cards", async () => { |
| 32 | 32 | const text = await (await fetch(`${servers.url}/pricing`)).text(); |
| 33 | expect(new TextEncoder().encode(text).length).toBeLessThan(14.3 * 1024); // +~0.65 KB: the theme select and four themes' boot rules (14,569 B measured); +~50 B: the theme <link> on every page (#6297); was 16.7 KB, 12.5 before each card said its price, credit and forges (#13886); the issue asks < 10 KB, the shared shell is ~8 KB of the rest | |
| 33 | expect(new TextEncoder().encode(text).length).toBeLessThan(15.2 * 1024); // +~0.8 KB: the shared plan row and its density sentence (#16857); +~0.65 KB: the theme select and four themes' boot rules (14,569 B measured); +~50 B: the theme <link> on every page (#6297); was 16.7 KB, 12.5 before each card said its price, credit and forges (#13886); the issue asks < 10 KB, the shared shell is ~8 KB of the rest | |
| 34 | 34 | expect(text).toContain('<dl class="status-rows">'); |
| 35 | 35 | expect(text.match(/class="status-row" data-plan="/g)?.length).toBeGreaterThanOrEqual(2); |
| 36 | 36 | expect(text).not.toContain("setting-list"); |
test/tui-plans.test.ts +2 −2
| @@ -88,7 +88,7 @@ describe("plans in the terminal", () => { | ||
| 88 | 88 | test("a change applies only after the confirm; a bad value is refused in the page's words", async () => { |
| 89 | 89 | const h = boot("alice"); |
| 90 | 90 | await open(h); |
| 91 | await h.press("j", "e"); | |
| 91 | await h.press("j", "j", "e"); | |
| 92 | 92 | await h.type("credit 6"); |
| 93 | 93 | await h.press("enter"); |
| 94 | 94 | expect(h.text()).toContain("creditUsd 5 → 6"); |
| @@ -114,7 +114,7 @@ describe("plans in the terminal", () => { | ||
| 114 | 114 | test("first sets the measured seconds to a first change, and 0 clears it", async () => { |
| 115 | 115 | const h = boot("alice"); |
| 116 | 116 | await open(h); |
| 117 | await h.press("j", "e"); | |
| 117 | await h.press("j", "j", "e"); | |
| 118 | 118 | await h.type("first 240"); |
| 119 | 119 | await h.press("enter"); |
| 120 | 120 | expect(h.text()).toContain("first change not measured → 240s"); |
test/tui-pricing.test.ts +9
| @@ -10,6 +10,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 10 | 10 | import { childDirOf } from "../src/actions/spawn.ts"; |
| 11 | 11 | import { deliverLink, NO_PROVIDER, reconcileOrder } from "../src/actions/order.ts"; |
| 12 | 12 | import { useCheckout, type CheckoutProvider } from "../src/billing/checkout.ts"; |
| 13 | import { sharedSays } from "../src/billing/density.ts"; | |
| 13 | 14 | import { usdPerMonthWords } from "../src/billing/money.ts"; |
| 14 | 15 | import { getOrder, MAX_PENDING_PER_ADDRESS, pendingFrom } from "../src/billing/orders.ts"; |
| 15 | 16 | import { createUser } from "../src/core/users.ts"; |
| @@ -357,3 +358,11 @@ test("the terminal prints the receipt's four facts on every ready branch, the cl | ||
| 357 | 358 | expect(flat(c.h)).toContain("is taken over"); |
| 358 | 359 | for (const t of facts("receipt-claimed")) expect(flat(c.h)).toContain(t); |
| 359 | 360 | }); |
| 361 | ||
| 362 | test("the shared plan is offered with its measured density, in the page's words (#16857)", async () => { | |
| 363 | const f = await fixture(); | |
| 364 | const h = f.open("203.0.113.40"); | |
| 365 | await settleApp(h.tui); | |
| 366 | expect(flat(h)).toContain("Shared"); | |
| 367 | expect(flat(h)).toContain(sharedSays()); | |
| 368 | }); |
new above
offline
awakeFraction is used only by a test; wire it into production (derive MEASURED.activeFraction) or remove it, instead of allowlisting it as dead code.