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

The v1 proof passes #11141: a public read states what each plan does at its CPU ceiling and when a lapsed forge sleeps #12576

Merged opened this

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

Merged

scout/forge:scout/12560-the-v1-proof-passes-11141-a-public-read → main 3 commits fork

  • Merged. scout/12560-the-v1-proof-passes-11141-a-public-read was merged into main as 1b9aebe.

Review

Sign in to review this change.
6 files changed +77 −12
scripts/v1-proven.ts +19 −2
@@ -160,8 +160,25 @@ export const probes: readonly Probe[] = [
160160 {
161161 issue: 11141,
162162 item: "an owner's plan and billing page exists",
163 run: async (get) =>
164 unproven(`${await gated(get, "/settings/billing")}; CPU slowing, the first change landing and lapsed-payment sleep have no public read`),
163 run: async (get) => {
164 const gate = await gated(get, "/settings/billing");
165 const got = await bodyOk(get, "/pricing");
166 const m = /<script[^>]*application\/ld\+json[^>]*>([\s\S]*?)<\/script>/i.exec(got.text);
167 expect(m !== null, "/pricing lists no plans");
168 type Prop = { name?: string; value?: unknown };
169 const offers = (JSON.parse(m?.[1] ?? "{}") as { offers?: { name?: string; additionalProperty?: Prop[] }[] }).offers ?? [];
170 expect(offers.length > 0, "/pricing lists no plans");
171 const attr = /data-grace-days="(\d+)"/.exec(got.text)?.[1];
172 for (const o of offers) {
173 const prop = (n: string): unknown => (o.additionalProperty ?? []).find((p) => p.name === n)?.value;
174 const ceiling = prop("At its CPU ceiling");
175 expect(typeof ceiling === "string" && /slowed/i.test(ceiling), `the ${o.name ?? "?"} offer says nothing of what its CPU ceiling does`);
176 const days = prop("Days of grace after a lapsed payment");
177 expect(attr !== undefined && String(days) === attr, `the ${o.name ?? "?"} offer says ${String(days)} days of grace, the page ${String(attr)}`);
178 expect(/sleeps/i.test(String(prop("After the grace") ?? "")), `the ${o.name ?? "?"} offer does not say the forge sleeps after its grace`);
179 }
180 return `${gate}; each of ${offers.length} plans says what its CPU ceiling does and that a lapsed forge sleeps after ${attr} days of grace`;
181 },
165182 },
166183 {
167184 issue: 11515,
src/spawn/cores.ts +9
@@ -76,6 +76,15 @@ export function coresWords(c: Cores): string {
7676 return `${head} Nothing limits this forge to its cores. A build that stays above ${CPU_STOP_FACTOR === 2 ? "twice" : `${CPU_STOP_FACTOR}×`} its cores for ${minutes(CPU_STOP_HOLD_MS)} is stopped; the first ${minutes(CPU_STOP_GRACE_MS)} are safe.`;
7777 }
7878
79 /**
80 * What a plan's CPU ceiling does, for a public reader, from the same constants the watch uses.
81 * Both holds are said because which one applies is the host's: slowed where the kernel or pinning
82 * holds the cores, stopped only by the watch where neither does.
83 */
84 export function ceilingWords(cpus: number): string {
85 return `At ${coreWord(cpus)}, a busy build is slowed, never stopped, where the kernel or pinning holds the cores. Where neither does, a build above ${CPU_STOP_FACTOR === 2 ? "twice" : `${CPU_STOP_FACTOR}×`} its cores for ${minutes(CPU_STOP_HOLD_MS)} is stopped; the first ${minutes(CPU_STOP_GRACE_MS)} are safe.`;
86 }
87
7988 /** The line, or undefined on a forge that is no cell child. */
8089 export function coresLine(s: CoresSource = realCores()): string | undefined {
8190 const c = coresOf(s);
src/web/offer.ts +10 −1
@@ -4,12 +4,14 @@
44 * from the plans setting so they cannot disagree with the pricing page.
55 */
66 import { SIZES } from "../spawn/sizes.ts";
7 import { ceilingWords } from "../spawn/cores.ts";
8 import type { LapseRule } from "../billing/lapse_rule.ts";
79 import type { Plan } from "../settings/plans.ts";
810
911 const gb = (mib: number): number => mib / 1024;
1012
1113 /** One schema.org Offer per plan, with its size and monthly crew credit as plain properties. */
12 export function offerData(plans: readonly Plan[], origin: string): object[] {
14 export function offerData(plans: readonly Plan[], origin: string, rule?: LapseRule): object[] {
1315 return plans.map((p) => {
1416 const s = SIZES[p.size];
1517 return {
@@ -24,6 +26,13 @@ export function offerData(plans: readonly Plan[], origin: string): object[] {
2426 { "@type": "PropertyValue", name: "Memory (GB)", value: gb(s.memoryMiB) },
2527 { "@type": "PropertyValue", name: "Disk (GB)", value: gb(s.diskMiB) },
2628 { "@type": "PropertyValue", name: "Crew credit (USD a month)", value: p.creditUsd },
29 ...(rule === undefined
30 ? []
31 : [
32 { "@type": "PropertyValue", name: "At its CPU ceiling", value: ceilingWords(s.cpu) },
33 { "@type": "PropertyValue", name: "Days of grace after a lapsed payment", value: rule.graceDays },
34 { "@type": "PropertyValue", name: "After the grace", value: "The forge sleeps and keeps its data." },
35 ]),
2736 ],
2837 };
2938 });
src/web/pages/pricing.ts +1 −1
@@ -99,7 +99,7 @@ export function pricingPage(ctx: Ctx): Response {
9999 ctx,
100100 title: "Open Platform Forge: pricing and your own forge",
101101 description: SITE_PATH(ctx.url.origin),
102 jsonLd: safeJson({ "@context": "https://schema.org", "@type": "Product", name: "Open Platform Forge", url: `${ctx.url.origin}/`, offers: offerData(plans, ctx.url.origin) }),
102 jsonLd: safeJson({ "@context": "https://schema.org", "@type": "Product", name: "Open Platform Forge", url: `${ctx.url.origin}/`, offers: offerData(plans, ctx.url.origin, lapseRule(ctx.app.db)) }),
103103 body: plansView(ctx, { name: (ctx.url.searchParams.get("name") ?? "").slice(0, 38), email: "" }, {}),
104104 });
105105 notePhase(ctx.request, "render", performance.now() - rendering);
test/offer-lapse.test.ts added +16
@@ -0,0 +1,16 @@
1 import { expect, test } from "bun:test";
2 import { CPU_STOP_HOLD_MS } from "../src/apps/cpu_rule.ts";
3 import { offerData } from "../src/web/offer.ts";
4 import { SIZES } from "../src/spawn/sizes.ts";
5 import type { Plan } from "../src/settings/plans.ts";
6
7 const plan: Plan = { key: "free", name: "Free", says: "x", size: "small", priceUsd: 0, creditUsd: 0, forges: 1 };
8
9 test("each offer states its CPU ceiling and the grace before a lapsed forge sleeps, from the constants", () => {
10 const [o] = offerData([plan], "https://f.test", { graceDays: 9, lapse: "sleep" }) as { additionalProperty: { name: string; value: unknown }[] }[];
11 const v = (n: string) => o!.additionalProperty.find((p) => p.name === n)?.value;
12 expect(String(v("At its CPU ceiling"))).toContain(`${SIZES["small" as keyof typeof SIZES].cpu} CPU`);
13 expect(String(v("At its CPU ceiling"))).toContain(`${CPU_STOP_HOLD_MS / 60_000} minutes`);
14 expect(v("Days of grace after a lapsed payment")).toBe(9);
15 expect(String(v("After the grace"))).toContain("sleeps");
16 });
test/v1-proven.test.ts +22 −8
@@ -9,7 +9,19 @@ const HEADERS = {
99 "permissions-policy": "camera=()",
1010 "cross-origin-opener-policy": "same-origin",
1111 };
12 const ld = JSON.stringify({ offers: [{ description: "A small forge that sleeps when idle" }, { description: "Small, awake" }] });
12 const props = (days = 7, ceiling = "At 1 CPU, a busy build is slowed, never stopped.") => [
13 { name: "At its CPU ceiling", value: ceiling },
14 { name: "Days of grace after a lapsed payment", value: days },
15 { name: "After the grace", value: "The forge sleeps and keeps its data." },
16 ];
17 const ld = JSON.stringify({
18 offers: [
19 { name: "Free", description: "A small forge that sleeps when idle", additionalProperty: props() },
20 { name: "Small", description: "Small, awake", additionalProperty: props() },
21 ],
22 });
23 const ldWith = (additionalProperty: unknown[]) => JSON.stringify({ offers: [{ name: "Free", description: "sleeps", additionalProperty }, { name: "Small", description: "x", additionalProperty: props() }] });
24 const pricing = (json: string) => () => new Response(`<form method="post" action="/pricing/order"></form><script type="application/ld+json">${json}</script>${rule(7)}`);
1325 const rule = (days: number, words = days) =>
1426 `<p data-lapse="sleep" data-grace-days="${days}">If a payment lapses, you have ${words} days of grace. After that your forge sleeps and keeps its data.</p>`;
1527 const health = (schedules?: unknown) =>
@@ -47,7 +59,7 @@ describe("v1-proven", () => {
4759 expect(probes.length).toBe(12);
4860 const status = (n: number) => results.find((r) => r.issue === n)?.status;
4961 // What no public read can show is unproven, never a pass.
50 expect(results.filter((r) => r.status === "unproven").map((r) => r.issue).sort()).toEqual([11141]);
62 expect(results.filter((r) => r.status === "unproven").map((r) => r.issue).sort()).toEqual([]);
5163 expect(results.filter((r) => r.status === "fail")).toEqual([]);
5264 expect(status(11595)).toBe("pass");
5365 expect(line(results[0]!)).toStartWith("pass #11541");
@@ -68,13 +80,16 @@ describe("v1-proven", () => {
6880 [11573, { "/readyz": () => new Response("draining", { status: 503 }) }, [11573]],
6981 [10304, { "/api/v1/version": () => Response.json({ version: "dev" }) }, [10304]],
7082 [11507, { "/llms.txt": () => new Response("Start my forge") }, [11507]],
71 [11138, { "/pricing": () => new Response("<p>none</p>") }, [11138, 11140]],
72 [11140, { "/pricing": () => new Response('<form method="post" action="/pricing/order"></form><script type="application/ld+json">{"offers":[]}</script>') }, [11140]],
73 [11140, { "/pricing": () => new Response(`<form method="post" action="/pricing/order"></form><script type="application/ld+json">${ld}</script>`) }, [11140]],
83 [11138, { "/pricing": () => new Response("<p>none</p>") }, [11138, 11140, 11141]],
84 [11140, { "/pricing": () => new Response('<form method="post" action="/pricing/order"></form><script type="application/ld+json">{"offers":[]}</script>') }, [11140, 11141]],
85 [11140, { "/pricing": () => new Response(`<form method="post" action="/pricing/order"></form><script type="application/ld+json">${ld}</script>`) }, [11140, 11141]],
7486 [11140, { "/api/v1/plans": () => Response.json({ items: [], graceDays: 3, lapse: "sleep" }) }, [11140]],
7587 [11140, { "/api/v1/plans": () => Response.json({ items: [] }) }, [11140]],
7688 [11140, { "/pricing": () => new Response(`<form method="post" action="/pricing/order"></form><script type="application/ld+json">${ld}</script>${rule(7, 5)}`) }, [11140]],
7789 [11141, { "/settings/billing": () => new Response("x", { status: 404 }) }, [11141]],
90 [11141, { "/pricing": pricing(ldWith(props().slice(1))) }, [11141]],
91 [11141, { "/pricing": pricing(ldWith(props(5))) }, [11141]],
92 [11141, { "/pricing": pricing(ldWith(props().slice(0, 2))) }, [11141]],
7893 [11515, { "/settings/crew": () => new Response("x", { status: 500 }) }, [11515]],
7994 [11595, { "/api/v1/health": () => health({ overdue: 2, oldestSeconds: 86_400 }) }, [11595]],
8095 [10441, { "/healthz": () => new Response("ok") }, [10441]],
@@ -126,11 +141,10 @@ describe("v1-proven", () => {
126141 });
127142
128143 test("the script exits 3, not 0, when nothing fails but some items are unproven", async () => {
129 // Only the no-public-read item is unproven.
130 const { code, out } = await run(stub());
144 const { code, out } = await run(stub({ "/api/v1/health": () => health() }));
131145 expect(out).not.toContain("fail #");
132146 expect(code).toBe(3);
133 expect(out).toContain("unproven #11141");
147 expect(out).toContain("unproven #11595");
134148 expect(out).toContain("v1.0.0 is not proven: none fail, 1 of 12 unproven");
135149 });
136150

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs