Flat plans: Stripe setup proven on the draft book, rollout runbook
Human
Prompt
Stripe: prepare the price changes (scripts or config, or documented steps) for the new flat prices. Make no live-mode changes; list exactly what Paul or an operator must run.
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
TestStripeSetupFlatBook runs scripts/stripe-setup.sh --apply against the fake Stripe with the draft book on top of the approved one: the 8 products are reused, 24 new prices made at the flat amounts, the printed map names only the new keys, and a live run refuses the draft. TestRepoPriceBooksLoad now loads the books that price the current catalog and keeps the 2026-10-20-v1 books as history. The runbook lists every step for Paul and an operator: approval as a new book file, sandbox and live script runs, renaming the Stripe product to Teams, merging both books' keys into CARLOS_BILLING_PRICES, swapping binary and config together, and moving the one existing subscription to the flat price before its renewal.
Agent notes
The script needed no change: plan prices were always per-unit, and quantity 1 makes them flat. It never renames objects, so the Community product's name is a Dashboard step. Merge only with the approved book on the branch: a live console refuses a draft, so merging first would block every console release.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+250
−7
cmd/console/stripesetup_script_test.go+104 −7docs/superpowers/plans/2026-11-14-flat-plans-rollout.md+146 −0
diff --git a/cmd/console/stripesetup_script_test.go b/cmd/console/stripesetup_script_test.go| index 71ad51b06..c61456fe2 100644 |
| --- a/cmd/console/stripesetup_script_test.go |
| +++ b/cmd/console/stripesetup_script_test.go |
| @@ -26,6 +26,7 @@ const ( |
| stripeSetupScript = "../../scripts/stripe-setup.sh" |
| approvedBook = "../../deploy/billing/pricebook-2026-11-01-v1.json" |
| draftBook = "../../deploy/billing/pricebook-2026-10-27-v1.json" |
| + flatDraftBook = "../../deploy/billing/pricebook-2026-11-14-v1.json" |
| sandboxAccount = "acct_1UVFkoIiAD0xflDQ" |
| liveAccount = "acct_LiveTest1" |
| ) |
| @@ -601,8 +602,14 @@ func TestStripeSetupReplayedArchivedPriceStops(t *testing.T) { |
| } |
| } |
| -// Every book in deploy/billing loads against the example catalog (the one |
| -// dev runs), and the newest one is approved for live. |
| +// Every book in deploy/billing names its own version and a known status. |
| +// The books that price the example catalog (the one dev runs, and the one |
| +// the flagship installs) load against it. Books for catalog 2026-10-20-v1 |
| +// priced its per-member team plans, which this console no longer loads |
| +// (#1033); they stay as the record of what was sold, and a subscription |
| +// bought under one keeps its price keys. approvedBook is the newest |
| +// approved book; the flat book 2026-11-14-v1 is a draft until Paul |
| +// approves it. |
| func TestRepoPriceBooksLoad(t *testing.T) { |
| cat, err := plans.LoadCatalog("../../internal/plans/testdata/example-catalog.json") |
| if err != nil { |
| @@ -614,16 +621,106 @@ func TestRepoPriceBooksLoad(t *testing.T) { |
| } |
| slices.Sort(files) |
| name := regexp.MustCompile(`pricebook-(.+)\.json$`) |
| + newestApproved, current := "", 0 |
| for _, f := range files { |
| - book, err := plans.LoadPriceBook(f, cat) |
| + b, err := os.ReadFile(f) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if v := name.FindStringSubmatch(f)[1]; book.Version != v { |
| - t.Errorf("%s holds version %q", f, book.Version) |
| + var head struct { |
| + Version string `json:"version"` |
| + Status string `json:"status"` |
| + CatalogVersion string `json:"catalog_version"` |
| } |
| + if err := json.Unmarshal(b, &head); err != nil { |
| + t.Fatalf("%s: %v", f, err) |
| + } |
| + if v := name.FindStringSubmatch(f)[1]; head.Version != v { |
| + t.Errorf("%s holds version %q", f, head.Version) |
| + } |
| + switch head.CatalogVersion { |
| + case cat.Version: |
| + current++ |
| + if _, err := plans.LoadPriceBook(f, cat); err != nil { |
| + t.Error(err) |
| + } |
| + case "2026-10-20-v1": |
| + default: |
| + t.Errorf("%s prices catalog %q, which the repo does not hold", f, head.CatalogVersion) |
| + } |
| + if head.Status == plans.BookApproved { |
| + newestApproved = f |
| + } |
| + } |
| + if current == 0 { |
| + t.Errorf("no book prices the example catalog %s", cat.Version) |
| + } |
| + if newestApproved != approvedBook { |
| + t.Errorf("the newest approved book is %s, not %s", newestApproved, approvedBook) |
| + } |
| + draft, err := plans.LoadPriceBook(flatDraftBook, cat) |
| + if err != nil || draft.Approved() { |
| + t.Fatalf("%s: %v, approved %v; want a draft that loads", flatDraftBook, err, err == nil && draft.Approved()) |
| + } |
| +} |
| + |
| +// The flat book (#1033) on an account that already has the approved book's |
| +// objects: a sandbox --apply reuses the eight products and adds the flat |
| +// book's 24 prices beside the earlier ones, Teams and Business at their flat |
| +// yearly price; the printed price map names only the flat book's keys. A |
| +// live run, dry runs included, refuses it while it is a draft. |
| +func TestStripeSetupFlatBook(t *testing.T) { |
| + w := newStripeWorld(t, sandboxAccount, false) |
| + if stdout, stderr, code := w.run(nil, "--apply"); code != 0 { |
| + t.Fatalf("approved --apply failed (%d):\n%s\n%s", code, stdout, stderr) |
| + } |
| + stdout, stderr, code := w.run([]string{"PRICE_BOOK=" + flatDraftBook}, "--apply") |
| + if code != 0 { |
| + t.Fatalf("flat --apply failed (%d):\n%s\n%s", code, stdout, stderr) |
| } |
| - if newest, _ := plans.LoadPriceBook(files[len(files)-1], cat); !newest.Approved() || files[len(files)-1] != approvedBook { |
| - t.Errorf("the newest book %s is not the approved one", files[len(files)-1]) |
| + fw := w.load() |
| + if n := len(fw.Objects["products"]); n != 8 { |
| + t.Errorf("%d products, want the approved run's 8 reused", n) |
| + } |
| + if n := len(fw.Objects["prices"]); n != 48 { |
| + t.Errorf("%d prices, want 24 per book", n) |
| + } |
| + want := map[string]float64{ |
| + "2026-11-14-v1/community/eur": 5000, "2026-11-14-v1/community/usd": 6000, "2026-11-14-v1/community/gbp": 4500, |
| + "2026-11-14-v1/business/eur": 50000, "2026-11-14-v1/business/usd": 60000, "2026-11-14-v1/business/gbp": 45000, |
| + "2026-11-14-v1/personal/eur": 2400, |
| + } |
| + for _, p := range fw.Objects["prices"] { |
| + k, _ := p["lookup_key"].(string) |
| + if amount, ok := want[k]; ok { |
| + if p["unit_amount"] != amount { |
| + t.Errorf("%s: unit_amount %v, want %v", k, p["unit_amount"], amount) |
| + } |
| + delete(want, k) |
| + } |
| + } |
| + if len(want) != 0 { |
| + t.Errorf("no prices for %v", want) |
| + } |
| + line := "" |
| + for _, l := range strings.Split(stdout, "\n") { |
| + if strings.HasPrefix(l, "CARLOS_BILLING_PRICES='") { |
| + line = strings.TrimSuffix(strings.TrimPrefix(l, "CARLOS_BILLING_PRICES='"), "'") |
| + } |
| + } |
| + var printed map[string]string |
| + if err := json.Unmarshal([]byte(line), &printed); err != nil || len(printed) != 24 { |
| + t.Fatalf("printed price map %q: %v, want the flat book's 24 keys", line, err) |
| + } |
| + for k := range printed { |
| + if !strings.HasPrefix(k, "2026-11-14-v1/") { |
| + t.Errorf("printed key %q is not the flat book's", k) |
| + } |
| + } |
| + |
| + live := newStripeWorld(t, liveAccount, true) |
| + _, stderr, code = live.run([]string{"STRIPE_LIVE_ACCOUNT=" + liveAccount, "PRICE_BOOK=" + flatDraftBook}, "--live") |
| + if code == 0 || !strings.Contains(stderr, "approved") { |
| + t.Fatalf("a live dry run of the draft = %d %q, want refused for not being approved", code, stderr) |
| } |
| } |
diff --git a/docs/superpowers/plans/2026-11-14-flat-plans-rollout.md b/docs/superpowers/plans/2026-11-14-flat-plans-rollout.md| new file mode 100644 |
| index 000000000..a43f5adeb |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-14-flat-plans-rollout.md |
| @@ -0,0 +1,146 @@ |
| +# 🤖 Flat plans rollout (#1033): what Paul and an operator run |
| + |
| +Branch `flat-plans`. Nothing here has been run against Stripe, live or |
| +sandbox, and no deployment has changed. Every step below is for Paul or an |
| +operator. |
| + |
| +## What the branch changes |
| + |
| +- Catalog `2026-11-14-v1` (`internal/plans/testdata/example-catalog.json`, |
| + the file the flagship installs as `/etc/carlos/plans.json`). Teams (key |
| + `community`) and Business are flat, with the limits a 10-member team had |
| + in `2026-10-20-v1`. Their ceilings are their own, scaled the same way, so |
| + no plan reaches more or less with packs than before. `max_members` is 3 |
| + on Free and unset on every paid plan. |
| +- Draft price book `deploy/billing/pricebook-2026-11-14-v1.json`. Teams is |
| + €50 / $60 / £45 a year and Business €500 / $600 / £450, the old per-member |
| + price times the 10-member minimum. Personal and the packs are unchanged. |
| +- The console sells one plan item at quantity 1. Inviting, joining and |
| + removing people never touches billing. Seat authorisations, Match seats, |
| + seat drift and `seats_unpaid` are gone. |
| +- A subscription bought under an earlier book is still recognised at any |
| + plan quantity from 1 to 10,000, and gets the flat plan's limits. It cannot |
| + upgrade in place: the earlier book's Teams and Business prices are per |
| + member, so quantity 1 would undercharge. The door refuses with the |
| + existing `change.book` copy, and the page offers no upgrade. |
| + |
| +## Order: binary and config change together |
| + |
| +The new console refuses a catalog with a `team` block (the current |
| +`2026-10-20-v1`), naming the problem. The current console refuses the new |
| +catalog, because `name` and `ceilings` are unknown fields to it. So the |
| +binary, the catalog, the book and the price map swap in one restart, on |
| +every console that runs plans: the flagship and dev. |
| + |
| +A live console refuses a draft book. Until Paul approves the book, no |
| +flagship console can run a binary built from this branch. **Merge only once |
| +the approved book is on the branch**, or every console release from `main` |
| +is blocked until then. |
| + |
| +## 1. Paul approves |
| + |
| +1. Approve the draft book `2026-11-14-v1` and the copy listed on the |
| + branch's review request. |
| +2. As the process requires (`docs/site/plans.md`, "A book is never |
| + edited"), approval is a new file: copy the draft to |
| + `deploy/billing/pricebook-<date>-v1.json` with `"status": "approved"` and |
| + the same amounts. On the branch, point `approvedBook` in |
| + `cmd/console/stripesetup_script_test.go` and the script's default |
| + `PRICE_BOOK` at it. |
| + |
| +## 2. Stripe sandbox (test mode; optional rehearsal) |
| + |
| +``` |
| +CONSOLE_URL=https://console.carloku.com \ |
| +PRICE_BOOK=deploy/billing/pricebook-2026-11-14-v1.json \ |
| +scripts/stripe-setup.sh --check |
| +# then the same with --apply |
| +``` |
| + |
| +It reuses the 8 products, the portal configuration, the coupon and the |
| +webhook endpoint, and makes 24 prices with lookup keys |
| +`2026-11-14-v1/...`. The script never renames anything, so rename the |
| +product whose `metadata[carlos_product]` is `community` from "Community" to |
| +"Teams" in the sandbox Dashboard. |
| + |
| +## 3. Stripe live (after approval) |
| + |
| +With `<book>` the approved file from step 1: |
| + |
| +``` |
| +STRIPE_LIVE_ACCOUNT=acct_... CONSOLE_URL=https://console.carloku.com \ |
| +PRICE_BOOK=deploy/billing/<book> scripts/stripe-setup.sh --live # dry run |
| +... scripts/stripe-setup.sh --live --check |
| +... scripts/stripe-setup.sh --live --apply |
| +``` |
| + |
| +Then: |
| + |
| +1. Rename the live product with `metadata[carlos_product]=community` to |
| + "Teams": Dashboard, Product catalog, the product, Edit. Or |
| + `stripe products update <prod_id> -d name=Teams --live`. Checkout pages |
| + and invoices show this name. |
| +2. Build the console's price map from **both** books, so the existing |
| + subscription stays recognised. `OLD` is the current |
| + `CARLOS_BILLING_PRICES` from `/etc/carlos/billing.env`, `NEW` the one the |
| + live `--apply` printed: |
| + |
| + ``` |
| + jq -cS -s '.[0] + .[1]' <(printf '%s' "$OLD") <(printf '%s' "$NEW") |
| + ``` |
| + |
| +## 4. Console config and release (flagship, then dev) |
| + |
| +1. Cut a release with this branch, as usual. |
| +2. On the console box, together: |
| + - `/etc/carlos/plans.json`: the new catalog, with the current file's |
| + `sponsor_accounts_before` line added back (it changes the catalog id, |
| + not its version, as before); |
| + - `/etc/carlos/<book>`: the approved book, root:root 0644, never edited |
| + afterwards; |
| + - `/etc/carlos/billing.env`: `CARLOS_PRICE_BOOK` pointing at it and |
| + `CARLOS_BILLING_PRICES` set to the merged map, in single quotes; |
| + - the new console binary; |
| + then restart `console.service`. |
| +3. Rollback is the same four things put back together. |
| +4. Dev runs in test mode, which accepts the draft book, so dev can take the |
| + draft with sandbox prices before approval. |
| + |
| +The new catalog id republishes every account's limits record, as any |
| +catalog change does. |
| + |
| +## 5. The existing subscription |
| + |
| +There is one paying customer. After step 4 their subscription is still on |
| +book `2026-11-01-v1` at its current quantities, and the console gives it |
| +the flat plan's limits. |
| + |
| +- **Check first** which plan it is on and its plan item's quantity. On |
| + Teams or Business above 10 seats, the limits fall to the 10-member values |
| + at the restart, before the renewal they paid for. If so, give the account |
| + sponsored limits until renewal (`carlos accounts plan --sponsored`), or |
| + move it before the restart. |
| +- **Move it to the flat price at renewal**, any time before its renewal |
| + date: one subscription update that swaps every item to the new book's |
| + price for the same plan or pack, the plan at quantity 1 and each pack at |
| + its current quantity, with no proration. All items in one call: a |
| + subscription with items from two books is not recognised. |
| + |
| + ``` |
| + stripe subscriptions update sub_... --live -d proration_behavior=none \ |
| + -d "items[0][id]=<plan item>" -d "items[0][price]=<new plan price>" -d "items[0][quantity]=1" \ |
| + -d "items[1][id]=<pack item>" -d "items[1][price]=<new pack price>" |
| + ``` |
| + |
| + Nothing is charged now; the renewal invoice charges the flat price. The |
| + console's next sync adopts it under the new book, and in-place upgrades |
| + work again. This loosens the price, which the published promise allows |
| + ("tightening applies to new subscriptions only"). |
| + |
| +## 6. Verify |
| + |
| +- `curl -sI https://console.carloku.com/` reports the new version. |
| +- A Teams account's billing page shows "Teams" and a flat yearly price. |
| +- `go run ./cmd/pricebook-export -catalog internal/plans/testdata/example-catalog.json -book deploy/billing/<book>` |
| + regenerates the public export for the carloku pricing page, which |
| + follows in its own repo. |