plans: record the flagship catalog; draft catalog and book 2026-11-15-v1
Summary
deploy/billing/catalog-2026-11-14-v1.json is the flagship's installed catalog, byte-equivalent (id 2026-11-14-v1@6f2e7f29d318, PDF allowances and sponsor cutoff included). Draft catalog 2026-11-15-v1 changes Free only: 50 MB self-serve object storage with scanning required, 5 emails an hour beside 50 a day, and 1 GB kept for accounts approved before 2026-11-15. Draft book 2026-11-15-v1 prices it at the approved amounts. New catalog fields storage_scan_required, email_per_hour and a plan's kept_storage, all omitted when unset so older catalogs keep their IDs.
Agent notes
Flagship id read from control/plans.json on 2026-11-15; the reconstruction (example catalog + sponsor_accounts_before 2026-11-02T11:20:56Z + pdf 100/2000/4000/40000) hashes to it exactly. Books now load against deploy/billing/catalog-<version>.json.
6 files changed,
+533
−45
cmd/console/stripesetup_script_test.go+41 −24deploy/billing/catalog-2026-11-14-v1.json+102 −0deploy/billing/catalog-2026-11-15-v1.json+106 −0deploy/billing/pricebook-2026-11-15-v1.json+23 −0internal/plans/catalog.go+78 −21internal/plans/repo_catalog_test.go+183 −0
diff --git a/cmd/console/stripesetup_script_test.go b/cmd/console/stripesetup_script_test.go| index e3d04c2d1..ae3e1aa2f 100644 |
| --- a/cmd/console/stripesetup_script_test.go |
| +++ b/cmd/console/stripesetup_script_test.go |
| @@ -603,18 +603,28 @@ func TestStripeSetupReplayedArchivedPriceStops(t *testing.T) { |
| } |
| } |
| -// 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, 2026-11-14-v2 (Paul, 2026-11-14), written from the draft |
| -// 2026-11-14-v1, which stays as it was. |
| +// Every book in deploy/billing names its own version and a known status, |
| +// and loads against the catalog it prices, which lives beside it as |
| +// deploy/billing/catalog-<version>.json (#1076: the file a console |
| +// installs). 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, 2026-11-14-v2 |
| +// (Paul, 2026-11-14), written from the draft 2026-11-14-v1, which stays as |
| +// it was. The draft 2026-11-15-v1 (#1076) prices the draft catalog of the |
| +// same version and stays a draft until Paul approves it. |
| func TestRepoPriceBooksLoad(t *testing.T) { |
| - cat, err := plans.LoadCatalog("../../internal/plans/testdata/example-catalog.json") |
| - if err != nil { |
| - t.Fatal(err) |
| + catalogs := map[string]*plans.Catalog{} |
| + catalogFor := func(version string) *plans.Catalog { |
| + if c, ok := catalogs[version]; ok { |
| + return c |
| + } |
| + c, err := plans.LoadCatalog("../../deploy/billing/catalog-" + version + ".json") |
| + if err != nil { |
| + c = nil |
| + } |
| + catalogs[version] = c |
| + return c |
| } |
| files, _ := filepath.Glob("../../deploy/billing/pricebook-*.json") |
| if len(files) == 0 { |
| @@ -639,32 +649,39 @@ func TestRepoPriceBooksLoad(t *testing.T) { |
| 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.CatalogVersion == "2026-10-20-v1" { |
| + continue |
| + } |
| + cat := catalogFor(head.CatalogVersion) |
| + if cat == nil { |
| + t.Errorf("%s prices catalog %q, which deploy/billing does not hold", f, head.CatalogVersion) |
| + continue |
| + } |
| + current++ |
| + if _, err := plans.LoadPriceBook(f, cat); err != nil { |
| + t.Error(err) |
| } |
| if head.Status == plans.BookApproved { |
| newestApproved = f |
| } |
| } |
| if current == 0 { |
| - t.Errorf("no book prices the example catalog %s", cat.Version) |
| + t.Error("no book prices a catalog in deploy/billing") |
| } |
| 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()) |
| + for book, catalog := range map[string]string{flatDraftBook: "2026-11-14-v1", freeStorageDraftBook: "2026-11-15-v1"} { |
| + draft, err := plans.LoadPriceBook(book, catalogFor(catalog)) |
| + if err != nil || draft.Approved() { |
| + t.Fatalf("%s: %v, approved %v; want a draft that loads", book, err, err == nil && draft.Approved()) |
| + } |
| } |
| } |
| +// freeStorageDraftBook is the draft for catalog 2026-11-15-v1 (#1076). |
| +const freeStorageDraftBook = "../../deploy/billing/pricebook-2026-11-15-v1.json" |
| + |
| // The flat book (#1033) on an account that already has the previous |
| // approved book's objects: a sandbox --apply of the default (approved flat) |
| // book reuses the eight products and adds its 24 prices beside the earlier |
diff --git a/deploy/billing/catalog-2026-11-14-v1.json b/deploy/billing/catalog-2026-11-14-v1.json| new file mode 100644 |
| index 000000000..940a3cf62 |
| --- /dev/null |
| +++ b/deploy/billing/catalog-2026-11-14-v1.json |
| @@ -0,0 +1,102 @@ |
| +{ |
| + "version": "2026-11-14-v1", |
| + "default_plan": "free", |
| + "free_accounts_per_person": 1, |
| + "sponsor_accounts_before": "2026-11-02T11:20:56Z", |
| + "plans": { |
| + "free": { |
| + "paid": false, |
| + "max_members": 3, |
| + "limits": { |
| + "running_things": 3, |
| + "sidecars_per_app": 1, |
| + "idle_seconds": 90, |
| + "memory_tier": "small", |
| + "awake_hours_month": 90, |
| + "disk_bytes": 1073741824, |
| + "storage_bytes": 1073741824, |
| + "email_per_day": 50, |
| + "bandwidth_bytes_month": 10737418240, |
| + "pdf_renders_month": 100, |
| + "min_schedule_seconds": 900 |
| + } |
| + }, |
| + "personal": { |
| + "paid": true, |
| + "limits": { |
| + "running_things": 25, |
| + "sidecars_per_app": 5, |
| + "idle_seconds": 900, |
| + "memory_tier": "default", |
| + "awake_hours_month": 1500, |
| + "disk_bytes": 10737418240, |
| + "storage_bytes": 26843545600, |
| + "storage_self_serve": true, |
| + "email_per_day": 1000, |
| + "bandwidth_bytes_month": 53687091200, |
| + "pdf_renders_month": 2000, |
| + "custom_domains": true, |
| + "fleets": true, |
| + "min_schedule_seconds": 60, |
| + "history_days": 7 |
| + }, |
| + "packs": ["apps", "disk", "storage", "email", "bandwidth"] |
| + }, |
| + "community": { |
| + "name": "Teams", |
| + "paid": true, |
| + "limits": { |
| + "running_things": 50, |
| + "sidecars_per_app": 5, |
| + "idle_seconds": 900, |
| + "memory_tier": "default", |
| + "awake_hours_month": 3000, |
| + "disk_bytes": 10737418240, |
| + "storage_bytes": 53687091200, |
| + "storage_self_serve": true, |
| + "email_per_day": 2000, |
| + "bandwidth_bytes_month": 107374182400, |
| + "pdf_renders_month": 4000, |
| + "custom_domains": true, |
| + "fleets": true, |
| + "min_schedule_seconds": 60 |
| + }, |
| + "packs": ["apps", "disk", "storage", "email", "bandwidth"], |
| + "ceilings": {"running_things": 400, "email_per_day": 20000, "idle_seconds": 900} |
| + }, |
| + "business": { |
| + "paid": true, |
| + "limits": { |
| + "running_things": 500, |
| + "sidecars_per_app": 5, |
| + "idle_seconds": 900, |
| + "memory_tier": "default", |
| + "awake_hours_month": 30000, |
| + "disk_bytes": 10737418240, |
| + "storage_bytes": 536870912000, |
| + "storage_self_serve": true, |
| + "email_per_day": 20000, |
| + "bandwidth_bytes_month": 1073741824000, |
| + "pdf_renders_month": 40000, |
| + "custom_domains": true, |
| + "fleets": true, |
| + "min_schedule_seconds": 60, |
| + "history_days": 7 |
| + }, |
| + "packs": ["apps", "disk", "storage", "email", "bandwidth"], |
| + "ceilings": {"running_things": 4000, "email_per_day": 200000, "idle_seconds": 900} |
| + } |
| + }, |
| + "packs": { |
| + "apps": {"adds": {"running_things": 5}, "max_quantity": 20}, |
| + "disk": {"adds": {"disk_bytes": 10737418240}, "max_quantity": 20}, |
| + "storage": {"adds": {"storage_bytes": 53687091200}, "max_quantity": 20}, |
| + "email": {"adds": {"email_per_day": 1000}, "max_quantity": 20}, |
| + "bandwidth": {"adds": {"bandwidth_bytes_month": 53687091200}, "max_quantity": 20} |
| + }, |
| + "ceilings": { |
| + "running_things": 200, |
| + "email_per_day": 10000, |
| + "idle_seconds": 900 |
| + } |
| +} |
diff --git a/deploy/billing/catalog-2026-11-15-v1.json b/deploy/billing/catalog-2026-11-15-v1.json| new file mode 100644 |
| index 000000000..08c4aad25 |
| --- /dev/null |
| +++ b/deploy/billing/catalog-2026-11-15-v1.json |
| @@ -0,0 +1,106 @@ |
| +{ |
| + "version": "2026-11-15-v1", |
| + "default_plan": "free", |
| + "free_accounts_per_person": 1, |
| + "sponsor_accounts_before": "2026-11-02T11:20:56Z", |
| + "plans": { |
| + "free": { |
| + "paid": false, |
| + "max_members": 3, |
| + "limits": { |
| + "running_things": 3, |
| + "sidecars_per_app": 1, |
| + "idle_seconds": 90, |
| + "memory_tier": "small", |
| + "awake_hours_month": 90, |
| + "disk_bytes": 1073741824, |
| + "storage_bytes": 52428800, |
| + "storage_self_serve": true, |
| + "storage_scan_required": true, |
| + "email_per_day": 50, |
| + "email_per_hour": 5, |
| + "bandwidth_bytes_month": 10737418240, |
| + "pdf_renders_month": 100, |
| + "min_schedule_seconds": 900 |
| + }, |
| + "kept_storage": {"approved_before": "2026-11-15T00:00:00Z", "storage_bytes": 1073741824} |
| + }, |
| + "personal": { |
| + "paid": true, |
| + "limits": { |
| + "running_things": 25, |
| + "sidecars_per_app": 5, |
| + "idle_seconds": 900, |
| + "memory_tier": "default", |
| + "awake_hours_month": 1500, |
| + "disk_bytes": 10737418240, |
| + "storage_bytes": 26843545600, |
| + "storage_self_serve": true, |
| + "email_per_day": 1000, |
| + "bandwidth_bytes_month": 53687091200, |
| + "pdf_renders_month": 2000, |
| + "custom_domains": true, |
| + "fleets": true, |
| + "min_schedule_seconds": 60, |
| + "history_days": 7 |
| + }, |
| + "packs": ["apps", "disk", "storage", "email", "bandwidth"] |
| + }, |
| + "community": { |
| + "name": "Teams", |
| + "paid": true, |
| + "limits": { |
| + "running_things": 50, |
| + "sidecars_per_app": 5, |
| + "idle_seconds": 900, |
| + "memory_tier": "default", |
| + "awake_hours_month": 3000, |
| + "disk_bytes": 10737418240, |
| + "storage_bytes": 53687091200, |
| + "storage_self_serve": true, |
| + "email_per_day": 2000, |
| + "bandwidth_bytes_month": 107374182400, |
| + "pdf_renders_month": 4000, |
| + "custom_domains": true, |
| + "fleets": true, |
| + "min_schedule_seconds": 60 |
| + }, |
| + "packs": ["apps", "disk", "storage", "email", "bandwidth"], |
| + "ceilings": {"running_things": 400, "email_per_day": 20000, "idle_seconds": 900} |
| + }, |
| + "business": { |
| + "paid": true, |
| + "limits": { |
| + "running_things": 500, |
| + "sidecars_per_app": 5, |
| + "idle_seconds": 900, |
| + "memory_tier": "default", |
| + "awake_hours_month": 30000, |
| + "disk_bytes": 10737418240, |
| + "storage_bytes": 536870912000, |
| + "storage_self_serve": true, |
| + "email_per_day": 20000, |
| + "bandwidth_bytes_month": 1073741824000, |
| + "pdf_renders_month": 40000, |
| + "custom_domains": true, |
| + "fleets": true, |
| + "min_schedule_seconds": 60, |
| + "history_days": 7 |
| + }, |
| + "packs": ["apps", "disk", "storage", "email", "bandwidth"], |
| + "ceilings": {"running_things": 4000, "email_per_day": 200000, "idle_seconds": 900} |
| + } |
| + }, |
| + "packs": { |
| + "apps": {"adds": {"running_things": 5}, "max_quantity": 20}, |
| + "disk": {"adds": {"disk_bytes": 10737418240}, "max_quantity": 20}, |
| + "storage": {"adds": {"storage_bytes": 53687091200}, "max_quantity": 20}, |
| + "email": {"adds": {"email_per_day": 1000}, "max_quantity": 20}, |
| + "bandwidth": {"adds": {"bandwidth_bytes_month": 53687091200}, "max_quantity": 20} |
| + }, |
| + "ceilings": { |
| + "running_things": 200, |
| + "email_per_day": 10000, |
| + "idle_seconds": 900 |
| + } |
| +} |
diff --git a/deploy/billing/pricebook-2026-11-15-v1.json b/deploy/billing/pricebook-2026-11-15-v1.json| new file mode 100644 |
| index 000000000..6adf03a0e |
| --- /dev/null |
| +++ b/deploy/billing/pricebook-2026-11-15-v1.json |
| @@ -0,0 +1,23 @@ |
| +{ |
| + "version": "2026-11-15-v1", |
| + "status": "draft", |
| + "catalog_version": "2026-11-15-v1", |
| + "default_currency": "usd", |
| + "currencies": ["usd", "eur", "gbp"], |
| + "country_currency": { |
| + "eur": ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE"], |
| + "gbp": ["GB"] |
| + }, |
| + "plans": { |
| + "personal": {"usd": 2800, "eur": 2400, "gbp": 2200}, |
| + "community": {"usd": 6000, "eur": 5000, "gbp": 4500}, |
| + "business": {"usd": 60000, "eur": 50000, "gbp": 45000} |
| + }, |
| + "packs": { |
| + "apps": {"usd": 1200, "eur": 1000, "gbp": 900}, |
| + "disk": {"usd": 3600, "eur": 3100, "gbp": 2800}, |
| + "storage": {"usd": 1200, "eur": 1000, "gbp": 900}, |
| + "email": {"usd": 2400, "eur": 2100, "gbp": 1900}, |
| + "bandwidth": {"usd": 4800, "eur": 4100, "gbp": 3800} |
| + } |
| +} |
diff --git a/internal/plans/catalog.go b/internal/plans/catalog.go| index be4a2e324..3c0dd677a 100644 |
| --- a/internal/plans/catalog.go |
| +++ b/internal/plans/catalog.go |
| @@ -30,21 +30,31 @@ import ( |
| // any packed plan may reach. Zero means "not set" for sponsored overrides |
| // and ceilings. |
| type Limits struct { |
| - RunningThings int `json:"running_things,omitempty"` |
| - SidecarsPerApp int `json:"sidecars_per_app,omitempty"` |
| - IdleSeconds int `json:"idle_seconds,omitempty"` |
| - MemoryTier string `json:"memory_tier,omitempty"` // MemorySmall | MemoryDefault |
| - AwakeHoursMonth int `json:"awake_hours_month,omitempty"` |
| - DiskBytes int64 `json:"disk_bytes,omitempty"` // per running thing |
| - StorageBytes int64 `json:"storage_bytes,omitempty"` // per account |
| - StorageSelfServe bool `json:"storage_self_serve,omitempty"` |
| - EmailPerDay int `json:"email_per_day,omitempty"` |
| - BandwidthBytesMonth int64 `json:"bandwidth_bytes_month,omitempty"` |
| - PDFRendersMonth int `json:"pdf_renders_month,omitempty"` |
| - CustomDomains bool `json:"custom_domains,omitempty"` |
| - Fleets bool `json:"fleets,omitempty"` |
| - MinScheduleSeconds int `json:"min_schedule_seconds,omitempty"` |
| - HistoryDays int `json:"history_days,omitempty"` |
| + RunningThings int `json:"running_things,omitempty"` |
| + SidecarsPerApp int `json:"sidecars_per_app,omitempty"` |
| + IdleSeconds int `json:"idle_seconds,omitempty"` |
| + MemoryTier string `json:"memory_tier,omitempty"` // MemorySmall | MemoryDefault |
| + AwakeHoursMonth int `json:"awake_hours_month,omitempty"` |
| + DiskBytes int64 `json:"disk_bytes,omitempty"` // per running thing |
| + StorageBytes int64 `json:"storage_bytes,omitempty"` // per account |
| + StorageSelfServe bool `json:"storage_self_serve,omitempty"` |
| + // StorageScanRequired is set on a plan whose self-serve stores are |
| + // always virus-scanned (#1076): the console turns scanning and its |
| + // enforcement on when it provisions one, and refuses a store it cannot |
| + // scan. A requirement, not an allowance, so a sponsored override never |
| + // lifts it (generous). |
| + StorageScanRequired bool `json:"storage_scan_required,omitempty"` |
| + EmailPerDay int `json:"email_per_day,omitempty"` |
| + // EmailPerHour caps the account's sends in one UTC hour (#1076). Zero |
| + // is no hourly limit. The console holds the account's mail back once |
| + // the hour's sends reach it, until the hour rolls (planmail.go). |
| + EmailPerHour int `json:"email_per_hour,omitempty"` |
| + BandwidthBytesMonth int64 `json:"bandwidth_bytes_month,omitempty"` |
| + PDFRendersMonth int `json:"pdf_renders_month,omitempty"` |
| + CustomDomains bool `json:"custom_domains,omitempty"` |
| + Fleets bool `json:"fleets,omitempty"` |
| + MinScheduleSeconds int `json:"min_schedule_seconds,omitempty"` |
| + HistoryDays int `json:"history_days,omitempty"` |
| // What an instance owner may set for the edge rate limit (spec |
| // 2026-10-24-edge-rate-limit-design.md §5.3). Zero is no ceiling. The |
| @@ -88,8 +98,27 @@ type Plan struct { |
| // alone (CeilingsFor). A plan whose own limits sit near the catalog's |
| // ceilings needs room above them for its packs. |
| Ceilings *Limits `json:"ceilings,omitempty"` |
| + // KeptStorage, when set, is the object storage an account on this plan |
| + // keeps from the plan's earlier offer (#1076): an account an operator |
| + // approved for object storage before ApprovedBefore keeps StorageBytes |
| + // when the plan's own is lower. The console records it on the account |
| + // once (internal/console/plankept.go); Limits.WithKept applies it. |
| + KeptStorage *KeptStorage `json:"kept_storage,omitempty"` |
| } |
| +// KeptStorage is a plan's grandfathered object storage (Plan.KeptStorage). |
| +type KeptStorage struct { |
| + // ApprovedBefore is an RFC 3339 time in whole seconds: only an |
| + // approval decided before it is kept. |
| + ApprovedBefore string `json:"approved_before"` |
| + StorageBytes int64 `json:"storage_bytes"` |
| + |
| + approvedBefore time.Time |
| +} |
| + |
| +// Cutoff is ApprovedBefore as a time. |
| +func (k *KeptStorage) Cutoff() time.Time { return k.approvedBefore } |
| + |
| // Pack is one pack type: what a unit adds, and how many units one account |
| // may hold. |
| type Pack struct { |
| @@ -196,6 +225,14 @@ var sponsorCutoffShape = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2 |
| var errSponsorCutoffShape = errors.New("not whole seconds") |
| +// wholeSecondTime parses s, which must have sponsorCutoffShape. |
| +func wholeSecondTime(s string) (time.Time, error) { |
| + if !sponsorCutoffShape.MatchString(s) { |
| + return time.Time{}, errSponsorCutoffShape |
| + } |
| + return time.Parse(time.RFC3339, s) |
| +} |
| + |
| // SponsorCutoff is SponsorAccountsBefore as a time, or the zero time when |
| // it is unset. |
| func (c *Catalog) SponsorCutoff() time.Time { return c.sponsorCutoff } |
| @@ -219,11 +256,7 @@ func (c *Catalog) validate() error { |
| // second, so any fraction would be compared truncated, and Go's |
| // parser takes '.' and ',' fractions and drops digits past the |
| // ninth. Anything the pattern lets through is a whole second. |
| - var t time.Time |
| - err := errSponsorCutoffShape |
| - if sponsorCutoffShape.MatchString(c.SponsorAccountsBefore) { |
| - t, err = time.Parse(time.RFC3339, c.SponsorAccountsBefore) |
| - } |
| + t, err := wholeSecondTime(c.SponsorAccountsBefore) |
| if err != nil { |
| return fmt.Errorf("sponsor_accounts_before %q is not an RFC 3339 time in whole seconds, like 2026-11-01T09:00:00Z", c.SponsorAccountsBefore) |
| } |
| @@ -256,6 +289,16 @@ func (c *Catalog) validate() error { |
| if err := p.Limits.rateAboveDefault(); err != nil { |
| return fmt.Errorf("plan %q: %w", name, err) |
| } |
| + if k := p.KeptStorage; k != nil { |
| + t, err := wholeSecondTime(k.ApprovedBefore) |
| + if err != nil { |
| + return fmt.Errorf("plan %q: kept_storage approved_before %q is not an RFC 3339 time in whole seconds, like 2026-11-15T00:00:00Z", name, k.ApprovedBefore) |
| + } |
| + if k.StorageBytes <= 0 { |
| + return fmt.Errorf("plan %q: kept_storage storage_bytes must be positive", name) |
| + } |
| + k.approvedBefore = t |
| + } |
| switch p.Limits.MemoryTier { |
| case "", MemorySmall, MemoryDefault: |
| default: |
| @@ -317,7 +360,7 @@ func (c *Catalog) CeilingsFor(plan string) Limits { |
| func (l Limits) nonNegative() error { |
| if l.RunningThings < 0 || l.SidecarsPerApp < 0 || l.IdleSeconds < 0 || l.AwakeHoursMonth < 0 || |
| - l.DiskBytes < 0 || l.StorageBytes < 0 || l.EmailPerDay < 0 || l.BandwidthBytesMonth < 0 || |
| + l.DiskBytes < 0 || l.StorageBytes < 0 || l.EmailPerDay < 0 || l.EmailPerHour < 0 || l.BandwidthBytesMonth < 0 || |
| l.MinScheduleSeconds < 0 || l.HistoryDays < 0 || l.PDFRendersMonth < 0 || |
| l.RateClientShare < 0 || l.RatePerSecond < 0 || l.RateBurst < 0 { |
| return errors.New("limits may not be negative") |
| @@ -431,6 +474,9 @@ func (l Limits) generous(o Limits) Limits { |
| l.DiskBytes = max(l.DiskBytes, o.DiskBytes) |
| l.StorageBytes = max(l.StorageBytes, o.StorageBytes) |
| l.EmailPerDay = max(l.EmailPerDay, o.EmailPerDay) |
| + // Zero on the plan side is no hourly limit, the most generous value |
| + // (generousRate's rule). |
| + l.EmailPerHour = generousRate(l.EmailPerHour, o.EmailPerHour) |
| l.BandwidthBytesMonth = max(l.BandwidthBytesMonth, o.BandwidthBytesMonth) |
| l.PDFRendersMonth = max(l.PDFRendersMonth, o.PDFRendersMonth) |
| l.HistoryDays = max(l.HistoryDays, o.HistoryDays) |
| @@ -438,6 +484,7 @@ func (l Limits) generous(o Limits) Limits { |
| l.RatePerSecond = generousRate(l.RatePerSecond, o.RatePerSecond) |
| l.RateBurst = generousRate(l.RateBurst, o.RateBurst) |
| l.StorageSelfServe = l.StorageSelfServe || o.StorageSelfServe |
| + // StorageScanRequired stays the plan's: o cannot lift a requirement. |
| l.CustomDomains = l.CustomDomains || o.CustomDomains |
| l.Fleets = l.Fleets || o.Fleets |
| if o.MemoryTier == MemoryDefault { |
| @@ -450,6 +497,16 @@ func (l Limits) generous(o Limits) Limits { |
| return l |
| } |
| +// WithKept is l with an account's kept limits (Plan.KeptStorage, recorded |
| +// on the account) merged in, keeping the more generous value per field. nil |
| +// keeps l. |
| +func (l Limits) WithKept(kept *Limits) Limits { |
| + if kept == nil { |
| + return l |
| + } |
| + return l.generous(*kept) |
| +} |
| + |
| // generousRate is generous for a rate field. On the plan side zero is no |
| // ceiling, the most generous value there is, so it stays zero whatever is |
| // sponsored; plain max would turn an unlimited plan and a sponsored 1 into |
diff --git a/internal/plans/repo_catalog_test.go b/internal/plans/repo_catalog_test.go| new file mode 100644 |
| index 000000000..92f55dac4 |
| --- /dev/null |
| +++ b/internal/plans/repo_catalog_test.go |
| @@ -0,0 +1,183 @@ |
| +package plans |
| + |
| +import ( |
| + "os" |
| + "path/filepath" |
| + "regexp" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// The real catalogs live beside the price books that price them, in |
| +// deploy/billing (#1076): catalog-<version>.json is the file a console |
| +// installs as /etc/carlos/plans.json, byte for byte, and the file the public |
| +// export is built from. testdata/example-catalog.json stays a fixture. |
| +const repoBilling = "../../deploy/billing" |
| + |
| +// flagshipCatalogID is the flagship's installed catalog as its console |
| +// published it in control/plans.json (read 2026-11-15): the repo's record |
| +// of it must keep that exact ID, sponsor cutoff and PDF allowances |
| +// included, so an export built from it names the catalog the flagship |
| +// runs. |
| +const flagshipCatalogID = "2026-11-14-v1@6f2e7f29d318" |
| + |
| +func TestRepoCatalogsLoad(t *testing.T) { |
| + files, _ := filepath.Glob(filepath.Join(repoBilling, "catalog-*.json")) |
| + if len(files) == 0 { |
| + t.Fatal("no catalogs in deploy/billing") |
| + } |
| + name := regexp.MustCompile(`catalog-(.+)\.json$`) |
| + for _, f := range files { |
| + c, err := LoadCatalog(f) |
| + if err != nil { |
| + t.Error(err) |
| + continue |
| + } |
| + if v := name.FindStringSubmatch(f)[1]; c.Version != v { |
| + t.Errorf("%s holds version %q", f, c.Version) |
| + } |
| + } |
| +} |
| + |
| +func TestRepoCatalogIsTheFlagships(t *testing.T) { |
| + c, err := LoadCatalog(filepath.Join(repoBilling, "catalog-2026-11-14-v1.json")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if c.ID() != flagshipCatalogID { |
| + t.Fatalf("ID %s, want the flagship's %s: a recorded catalog is never edited", c.ID(), flagshipCatalogID) |
| + } |
| + for plan, want := range map[string]int{"free": 100, "personal": 2000, "community": 4000, "business": 40000} { |
| + if got := c.Plans[plan].Limits.PDFRendersMonth; got != want { |
| + t.Errorf("%s pdf_renders_month %d, want %d", plan, got, want) |
| + } |
| + } |
| +} |
| + |
| +// The draft (#1076) changes Free alone: 50 MB of object storage, self-serve |
| +// and always scanned, at most 5 emails in an hour, and the 1 GB kept for |
| +// accounts approved before the cutoff. Every paid plan, pack and ceiling is |
| +// the flagship's. |
| +func TestDraftCatalogChangesFreeOnly(t *testing.T) { |
| + was, err := LoadCatalog(filepath.Join(repoBilling, "catalog-2026-11-14-v1.json")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + c, err := LoadCatalog(filepath.Join(repoBilling, "catalog-2026-11-15-v1.json")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + free := c.Plans["free"] |
| + l := free.Limits |
| + if l.StorageBytes != 50<<20 || !l.StorageSelfServe || !l.StorageScanRequired || |
| + l.EmailPerDay != 50 || l.EmailPerHour != 5 || l.DiskBytes != 1<<30 { |
| + t.Errorf("free limits %+v", l) |
| + } |
| + k := free.KeptStorage |
| + if k == nil || k.StorageBytes != 1<<30 || !k.Cutoff().Equal(time.Date(2026, 11, 15, 0, 0, 0, 0, time.UTC)) { |
| + t.Errorf("free kept_storage %+v", k) |
| + } |
| + wasFree := was.Plans["free"] |
| + wasFree.Limits.StorageBytes, wasFree.Limits.StorageSelfServe, wasFree.Limits.StorageScanRequired, wasFree.Limits.EmailPerHour = |
| + l.StorageBytes, true, true, 5 |
| + if wasFree.Limits != l || wasFree.MaxMembers != free.MaxMembers { |
| + t.Errorf("free changed beyond storage and the hourly email limit:\n was %+v\n now %+v", wasFree.Limits, l) |
| + } |
| + for name, p := range was.Plans { |
| + if name == "free" { |
| + continue |
| + } |
| + q := c.Plans[name] |
| + if p.Limits != q.Limits || p.Name != q.Name || p.Paid != q.Paid || strings.Join(p.Packs, ",") != strings.Join(q.Packs, ",") || q.KeptStorage != nil { |
| + t.Errorf("%s changed", name) |
| + } |
| + } |
| + if len(c.Plans) != len(was.Plans) || c.Ceilings != was.Ceilings || c.SponsorAccountsBefore != was.SponsorAccountsBefore { |
| + t.Error("the plan set, the ceilings or the sponsor cutoff changed") |
| + } |
| + for name, pk := range was.Packs { |
| + if c.Packs[name] != pk { |
| + t.Errorf("pack %s changed", name) |
| + } |
| + } |
| +} |
| + |
| +func TestKeptStorageRefuses(t *testing.T) { |
| + base, err := os.ReadFile(filepath.Join(repoBilling, "catalog-2026-11-15-v1.json")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + good := `"kept_storage": {"approved_before": "2026-11-15T00:00:00Z", "storage_bytes": 1073741824}` |
| + if !strings.Contains(string(base), good) { |
| + t.Fatal("draft catalog's kept_storage line moved") |
| + } |
| + for _, bad := range []string{ |
| + `"kept_storage": {"approved_before": "2026-11-15", "storage_bytes": 1073741824}`, |
| + `"kept_storage": {"approved_before": "2026-11-15T00:00:00.5Z", "storage_bytes": 1073741824}`, |
| + `"kept_storage": {"approved_before": "2026-11-15T00:00:00Z", "storage_bytes": 0}`, |
| + `"kept_storage": {"approved_before": "2026-11-15T00:00:00Z", "storage_bytes": 1073741824, "extra": 1}`, |
| + } { |
| + if _, err := ParseCatalog([]byte(strings.Replace(string(base), good, bad, 1))); err == nil { |
| + t.Errorf("accepted %s", bad) |
| + } |
| + } |
| + if _, err := ParseCatalog([]byte(strings.Replace(string(base), `"email_per_hour": 5`, `"email_per_hour": -1`, 1))); err == nil { |
| + t.Error("accepted a negative email_per_hour") |
| + } |
| +} |
| + |
| +// A catalog without the new fields keeps its ID: they are omitted when |
| +// unset. |
| +func TestNewFieldsKeepOldIDs(t *testing.T) { |
| + c, err := LoadCatalog(examplePath) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + b, _ := os.ReadFile(examplePath) |
| + again, err := ParseCatalog(b) |
| + if err != nil || again.ID() != c.ID() { |
| + t.Fatal(err) |
| + } |
| + for _, p := range c.Plans { |
| + if p.KeptStorage != nil || p.Limits.EmailPerHour != 0 || p.Limits.StorageScanRequired { |
| + t.Fatal("example catalog grew a #1076 field") |
| + } |
| + } |
| +} |
| + |
| +func TestEffectiveScanRequiredAndHourlyEmail(t *testing.T) { |
| + c, err := LoadCatalog(filepath.Join(repoBilling, "catalog-2026-11-15-v1.json")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + // A sponsored override cannot lift the scanning requirement, and its |
| + // hourly figure only ever raises one. |
| + l, err := c.Effective("free", nil, &Limits{StorageBytes: 1 << 40, StorageSelfServe: true, EmailPerHour: 50}) |
| + if err != nil || !l.StorageScanRequired || l.EmailPerHour != 50 || l.StorageBytes != 1<<40 { |
| + t.Fatalf("sponsored free = %+v, %v", l, err) |
| + } |
| + l, _ = c.Effective("free", nil, &Limits{EmailPerHour: 1}) |
| + if l.EmailPerHour != 5 { |
| + t.Errorf("a smaller sponsored hourly figure lowered the plan's: %d", l.EmailPerHour) |
| + } |
| + // A plan with no hourly limit keeps none, whatever is sponsored. |
| + l, _ = c.Effective("personal", nil, &Limits{EmailPerHour: 50}) |
| + if l.EmailPerHour != 0 || l.StorageScanRequired { |
| + t.Errorf("personal = %+v", l) |
| + } |
| +} |
| + |
| +func TestWithKept(t *testing.T) { |
| + l := Limits{StorageBytes: 50 << 20, EmailPerDay: 50, StorageScanRequired: true} |
| + if got := l.WithKept(nil); got != l { |
| + t.Errorf("nil kept changed %+v", got) |
| + } |
| + got := l.WithKept(&Limits{StorageBytes: 1 << 30}) |
| + if got.StorageBytes != 1<<30 || got.EmailPerDay != 50 || !got.StorageScanRequired { |
| + t.Errorf("kept 1 GB = %+v", got) |
| + } |
| + if got := (Limits{StorageBytes: 25 << 30}).WithKept(&Limits{StorageBytes: 1 << 30}); got.StorageBytes != 25<<30 { |
| + t.Errorf("kept lowered a bigger plan: %d", got.StorageBytes) |
| + } |
| +} |