Public: anyone can read this; the crew can change it.
The v1 proof can read the lapse rule: /pricing states the grace period and that a lapsed forge sleeps, in text a probe can match #12514
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12513-the-v1-proof-can-read-the-lapse-rule-pri → main 6 commits fork 1 thread · 1 unresolved
8 files
changed +70
−9
docs/features/plans.md +3 −1
| @@ -16,7 +16,9 @@ These are the defaults. A forge admin who is a person edits them: | ||
| 16 | 16 | - the MCP `limits` tool with `plans` (dry run first, validated the same as the real change); |
| 17 | 17 | - the terminal: the Plans screen, `e` on a plan, `<field> <value>`, then a confirm. |
| 18 | 18 | |
| 19 | `GET /api/v1/plans` is public and answers the plans, no secrets. It is revalidated by ETag, so an edit shows at once. | |
| 19 | `GET /api/v1/plans` is public and answers the plans, no secrets, with the lapse rule beside them: `graceDays` (the days a lapsed payment has, the `billing.grace_days` setting) and `lapse: "sleep"` (after the grace the forge sleeps and keeps its data). It is revalidated by ETag, so an edit shows at once. | |
| 20 | ||
| 21 | `/pricing` says the same rule in one line, in text a probe can match: "If a payment lapses, you have 7 days of grace. After that your forge sleeps and keeps its data." The element carries `data-grace-days` with the number. The number is always the `billing.grace_days` setting (`src/billing/lapse_rule.ts`), never a second constant, so changing the setting changes the page and the API together. | |
| 20 | 22 | |
| 21 | 23 | ## What a spawn gets |
| 22 | 24 |
scripts/v1-proven.ts +11 −1
| @@ -144,7 +144,17 @@ export const probes: readonly Probe[] = [ | ||
| 144 | 144 | const offers = (JSON.parse(m?.[1] ?? "{}") as { offers?: { description?: string }[] }).offers ?? []; |
| 145 | 145 | expect(offers.length >= 2, `/pricing lists ${offers.length} plans, not two or more`); |
| 146 | 146 | expect(offers.some((o) => /sleeps/i.test(o.description ?? "")), "no plan says it sleeps when idle"); |
| 147 | return unproven(`${offers.length} plans are listed and one says it sleeps when idle; that the free plan sleeps rather than is deleted has no public read`); | |
| 147 | // The lapse rule: the page's sentence and data attribute, and the plans read, agree. | |
| 148 | const attr = /data-grace-days="(\d+)"/.exec(got.text); | |
| 149 | expect(attr !== null, "/pricing states no days of grace (data-grace-days)"); | |
| 150 | const said = /you have (\d+) days? of grace\. After that your forge sleeps and keeps its data/i.exec(got.text); | |
| 151 | expect(said !== null, "/pricing does not say that a lapsed forge sleeps and keeps its data after its grace"); | |
| 152 | expect(said?.[1] === attr?.[1], `/pricing says ${said?.[1]} days of grace in words and ${attr?.[1]} in its attribute`); | |
| 153 | const api = await bodyOk(get, "/api/v1/plans"); | |
| 154 | const rule = JSON.parse(api.text) as { graceDays?: unknown; lapse?: unknown }; | |
| 155 | expect(rule.lapse === "sleep", `/api/v1/plans says lapse ${JSON.stringify(rule.lapse)}, not "sleep"`); | |
| 156 | expect(String(rule.graceDays) === attr?.[1], `/pricing says ${attr?.[1]} days of grace, /api/v1/plans ${String(rule.graceDays)}`); | |
| 157 | return `${offers.length} plans; a lapsed payment has ${attr?.[1]} days of grace, then the forge sleeps and keeps its data (page and API agree)`; | |
| 148 | 158 | }, |
| 149 | 159 | }, |
| 150 | 160 | { |
src/billing/lapse_rule.ts added +18
| @@ -0,0 +1,18 @@ | ||
| 1 | /** | |
| 2 | * The lapse rule, said in public (#12513): how many days of grace a lapsed | |
| 3 | * payment has, and that the forge then sleeps and keeps its data. The number | |
| 4 | * is the `billing.grace_days` setting that enforces it, read here, never a | |
| 5 | * second constant. /pricing prints the sentence and `GET /api/v1/plans` carries | |
| 6 | * the same two facts, so a reader (the v1 proof) can match them. | |
| 7 | */ | |
| 8 | ||
| 9 | import type { Database } from "bun:sqlite"; | |
| 10 | import { limitValue } from "../settings/limits.ts"; | |
| 11 | ||
| 12 | export type LapseRule = { graceDays: number; lapse: "sleep" }; | |
| 13 | ||
| 14 | export const lapseRule = (db: Database): LapseRule => ({ graceDays: limitValue(db, "billing.grace_days"), lapse: "sleep" }); | |
| 15 | ||
| 16 | /** Two plain sentences, for customers. */ | |
| 17 | export const lapseRuleWords = (r: LapseRule): string => | |
| 18 | `If a payment lapses, you have ${r.graceDays} ${r.graceDays === 1 ? "day" : "days"} of grace. After that your forge sleeps and keeps its data.`; |
src/contract/openapi/routes/getApiV1Plans.ts +1 −1
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | import type { Route } from "../shared.ts"; |
| 2 | 2 | |
| 3 | export const route: Route = { method: "get", path: "/api/v1/plans", summary: "The plans (free, small, medium, large by default): key, name, says, size, priceUsd a month, creditUsd a month, forges one person may hold; public, revalidated by ETag, no secrets", auth: false, role: "anonymous" }; | |
| 3 | export const route: Route = { method: "get", path: "/api/v1/plans", summary: "The plans (free, small, medium, large by default): key, name, says, size, priceUsd a month, creditUsd a month, forges one person may hold; beside them graceDays (days a lapsed payment has, the billing.grace_days setting) and lapse sleep (the forge then sleeps and keeps its data); public, revalidated by ETag, no secrets", auth: false, role: "anonymous" }; | |
src/http/api/forges.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { lendCredit } from "../../actions/child_credit.ts"; |
| 8 | import { lapseRule } from "../../billing/lapse_rule.ts"; | |
| 8 | 9 | import { readPlans } from "../../actions/plans.ts"; |
| 9 | 10 | import { listChildren } from "../../actions/spawn.ts"; |
| 10 | 11 | import { usdWords } from "../../spawn/credit.ts"; |
| @@ -37,7 +38,7 @@ function publicTable(ctx: Ctx, phase: string, view: () => unknown): Response { | ||
| 37 | 38 | /** The plans (`settings/plans.ts`), public. Revalidated on every read, so an edit shows at once. */ |
| 38 | 39 | function plansAnswer(ctx: Ctx): Response { |
| 39 | 40 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 40 | const text = timePhase(ctx.request, "plans", () => JSON.stringify({ items: readPlans(ctx.app) })); | |
| 41 | const text = timePhase(ctx.request, "plans", () => JSON.stringify({ items: readPlans(ctx.app), ...lapseRule(ctx.app.db) })); | |
| 41 | 42 | const etag = weakEtag(text); |
| 42 | 43 | const headers = { etag, "cache-control": "public, no-cache" }; |
| 43 | 44 | if (holds(ctx.request, etag)) return new Response(null, { status: 304, headers }); |
src/web/pages/pricing.ts +3
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | |
| 9 | 9 | import { setCookie } from "../../auth/cookies.ts"; |
| 10 | 10 | import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder, resendLink, type Refusal } from "../../actions/order.ts"; |
| 11 | import { lapseRule, lapseRuleWords } from "../../billing/lapse_rule.ts"; | |
| 11 | 12 | import { checkoutOf } from "../../billing/checkout.ts"; |
| 12 | 13 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 13 | 14 | import { cookieValue, type Ctx } from "../../http/context.ts"; |
| @@ -43,6 +44,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 43 | 44 | const ordered = /^ord_[0-9a-f]{32}$/.test(held) ? held : undefined; |
| 44 | 45 | const selling = checkoutOf(ctx.app) !== undefined; |
| 45 | 46 | const plans = getPlans(ctx.app.db); |
| 47 | const rule = lapseRule(ctx.app.db); | |
| 46 | 48 | const rows = plans.map((p: Plan) => { |
| 47 | 49 | const free = p.key === FREE; |
| 48 | 50 | const paid = !free && selling; |
| @@ -82,6 +84,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 82 | 84 | : null} |
| 83 | 85 | <ul class="list setting-list">${rows}</ul> |
| 84 | 86 | </form> |
| 87 | <p class="muted small" data-lapse="sleep" data-grace-days="${rule.graceDays}">${lapseRuleWords(rule)}</p> | |
| 85 | 88 | <p class="muted small">Paid already? ${ordered === undefined ? null : html`<a href="/pricing/done?order=${ordered}">Open your order</a> · `}<a href="/pricing/resend">Lost your link?</a></p> |
| 86 | 89 | </div>`; |
| 87 | 90 | } |
test/pricing-order.test.ts +20
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | /** /pricing (#11138): order -> paid -> spawned -> claim link; duplicate delivery makes one forge; a failed spawn raises the alarm. */ |
| 2 | import { limitValue, setLimit } from "../src/settings/limits.ts"; | |
| 2 | 3 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 3 | 4 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 5 | import { tmpdir } from "node:os"; |
| @@ -75,6 +76,25 @@ async function buy(name: string, plan = "small") { | ||
| 75 | 76 | const completed = (o: { id: string; session_id: string }) => ({ id: o.session_id, metadata: { order: o.id }, customer: "cus_1", subscription: "sub_1", payment_status: "paid" }); |
| 76 | 77 | |
| 77 | 78 | describe("/pricing", () => { |
| 79 | test("says the lapse rule from the setting, and /api/v1/plans carries the same two facts (#12513)", async () => { | |
| 80 | const read = async () => { | |
| 81 | const text = await (await fetch(`${base}/pricing`)).text(); | |
| 82 | const api = (await (await fetch(`${base}/api/v1/plans`)).json()) as { graceDays: number; lapse: string }; | |
| 83 | return { text, api }; | |
| 84 | }; | |
| 85 | const first = await read(); | |
| 86 | const days = limitValue(app.db, "billing.grace_days"); | |
| 87 | expect(first.api).toMatchObject({ graceDays: days, lapse: "sleep" }); | |
| 88 | expect(first.text).toContain(`data-grace-days="${days}"`); | |
| 89 | expect(first.text).toContain(`you have ${days} ${days === 1 ? "day" : "days"} of grace. After that your forge sleeps and keeps its data.`); | |
| 90 | setLimit(app.db, "billing.grace_days", 11, admin.id); | |
| 91 | const next = await read(); | |
| 92 | expect(next.api.graceDays).toBe(11); | |
| 93 | expect(next.text).toContain('data-grace-days="11"'); | |
| 94 | expect(next.text).toContain("you have 11 days of grace"); | |
| 95 | setLimit(app.db, "billing.grace_days", days, admin.id); | |
| 96 | }); | |
| 97 | ||
| 78 | 98 | test("shows the plans with sizes and prices to a stranger, and a way to the free path", async () => { |
| 79 | 99 | const res = await fetch(`${base}/pricing`); |
| 80 | 100 | expect(res.status).toBe(200); |
test/v1-proven.test.ts +12 −5
| @@ -10,6 +10,8 @@ const HEADERS = { | ||
| 10 | 10 | "cross-origin-opener-policy": "same-origin", |
| 11 | 11 | }; |
| 12 | 12 | const ld = JSON.stringify({ offers: [{ description: "A small forge that sleeps when idle" }, { description: "Small, awake" }] }); |
| 13 | const rule = (days: number, words = days) => | |
| 14 | `<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>`; | |
| 13 | 15 | const health = (schedules?: unknown) => |
| 14 | 16 | Response.json({ ok: true, version: "1.0.0", commit: "058b6cf", draining: false, ...(schedules === undefined ? {} : { schedules }) }); |
| 15 | 17 | |
| @@ -22,7 +24,8 @@ function stub(over: Over = {}, seen: string[] = []): Fetch { | ||
| 22 | 24 | "/llms.txt": () => new Response("Running dev at 058b6cf\nPress Start my forge."), |
| 23 | 25 | "/api/v1/version": () => Response.json({ version: "1.0.0" }), |
| 24 | 26 | "/pricing": () => |
| 25 | new Response(`<form method="post" action="/pricing/order"></form><script type="application/ld+json">${ld}</script>`), | |
| 27 | new Response(`<form method="post" action="/pricing/order"></form><script type="application/ld+json">${ld}</script>${rule(7)}`), | |
| 28 | "/api/v1/plans": () => Response.json({ items: [], graceDays: 7, lapse: "sleep" }), | |
| 26 | 29 | "/settings/billing": () => new Response(null, { status: 303, headers: { location: "/signin?next=%2Fsettings%2Fbilling" } }), |
| 27 | 30 | "/settings/crew": () => new Response(null, { status: 303, headers: { location: "/signin?next=%2Fsettings%2Fcrew" } }), |
| 28 | 31 | "/api/v1/health": () => health({ overdue: 0, oldestSeconds: 0 }), |
| @@ -44,7 +47,7 @@ describe("v1-proven", () => { | ||
| 44 | 47 | expect(probes.length).toBe(12); |
| 45 | 48 | const status = (n: number) => results.find((r) => r.issue === n)?.status; |
| 46 | 49 | // What no public read can show is unproven, never a pass. |
| 47 | expect(results.filter((r) => r.status === "unproven").map((r) => r.issue).sort()).toEqual([11140, 11141]); | |
| 50 | expect(results.filter((r) => r.status === "unproven").map((r) => r.issue).sort()).toEqual([11141]); | |
| 48 | 51 | expect(results.filter((r) => r.status === "fail")).toEqual([]); |
| 49 | 52 | expect(status(11595)).toBe("pass"); |
| 50 | 53 | expect(line(results[0]!)).toStartWith("pass #11541"); |
| @@ -67,6 +70,10 @@ describe("v1-proven", () => { | ||
| 67 | 70 | [11507, { "/llms.txt": () => new Response("Start my forge") }, [11507]], |
| 68 | 71 | [11138, { "/pricing": () => new Response("<p>none</p>") }, [11138, 11140]], |
| 69 | 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]], | |
| 74 | [11140, { "/api/v1/plans": () => Response.json({ items: [], graceDays: 3, lapse: "sleep" }) }, [11140]], | |
| 75 | [11140, { "/api/v1/plans": () => Response.json({ items: [] }) }, [11140]], | |
| 76 | [11140, { "/pricing": () => new Response(`<form method="post" action="/pricing/order"></form><script type="application/ld+json">${ld}</script>${rule(7, 5)}`) }, [11140]], | |
| 70 | 77 | [11141, { "/settings/billing": () => new Response("x", { status: 404 }) }, [11141]], |
| 71 | 78 | [11515, { "/settings/crew": () => new Response("x", { status: 500 }) }, [11515]], |
| 72 | 79 | [11595, { "/api/v1/health": () => health({ overdue: 2, oldestSeconds: 86_400 }) }, [11595]], |
| @@ -119,12 +126,12 @@ describe("v1-proven", () => { | ||
| 119 | 126 | }); |
| 120 | 127 | |
| 121 | 128 | test("the script exits 3, not 0, when nothing fails but some items are unproven", async () => { |
| 122 | // Only the two no-public-read items are unproven. | |
| 129 | // Only the no-public-read item is unproven. | |
| 123 | 130 | const { code, out } = await run(stub()); |
| 124 | 131 | expect(out).not.toContain("fail #"); |
| 125 | 132 | expect(code).toBe(3); |
| 126 | expect(out).toContain("unproven #11140"); | |
| 127 | expect(out).toContain("v1.0.0 is not proven: none fail, 2 of 12 unproven"); | |
| 133 | expect(out).toContain("unproven #11141"); | |
| 134 | expect(out).toContain("v1.0.0 is not proven: none fail, 1 of 12 unproven"); | |
| 128 | 135 | }); |
| 129 | 136 | |
| 130 | 137 | test("the script exits 2 on bad usage", () => { |
new above
offline
The feature how-to, docs/features/plans.md line 19, must state the new graceDays and lapse fields and the lapse sentence on /pricing. It does not yet.