console: launch sponsorship carry also restores unlimited PDFs
Controller ruling on the Task 6 PDF concern: launch rows written before the PDF service (2026-11-03) lack pdf_renders_month and so get Free's 100 PDFs. carryLaunchFigures now adds both pdf_renders_month and media_minutes_month where missing, with the same marks (source, reason, writer of the launch rule), the same "every present field matches the launch value" rule and the same idempotence. The PDF email copy is unchanged (filed separately).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+85
−29
internal/console/planmedia_test.go+41 −8internal/console/plansponsor.go+44 −21
diff --git a/internal/console/planmedia_test.go b/internal/console/planmedia_test.go| index 821b2b14f..3ffd5cec1 100644 |
| --- a/internal/console/planmedia_test.go |
| +++ b/internal/console/planmedia_test.go |
| @@ -379,12 +379,16 @@ func planRowsNow(t *testing.T, st *Store) map[int64]planRowSnap { |
| // TestLaunchSponsorshipCarriesMedia (Astra T6 P2 3): a launch sponsorship |
| // persisted before media_minutes_month existed gets the launch file's |
| // media figure at the next start, so the account keeps no limit instead |
| -// of Free's 30; a deliberate override is left alone; a second start |
| -// changes nothing. |
| +// of Free's 30; one persisted before pdf_renders_month existed gets PDFs |
| +// and media (fix round 2), instead of Free's 100 PDFs; a deliberate |
| +// override is left alone; a second start changes nothing. |
| func TestLaunchSponsorshipCarriesMedia(t *testing.T) { |
| fx := newConsoleFixture(t) |
| ctx := t.Context() |
| cat := mediaSponsorCatalog(t, sponsorCutoffAt) |
| + free := cat.Plans["free"] |
| + free.Limits.PDFRendersMonth = 100 // the flagship's Free |
| + cat.Plans["free"] = free |
| fx.srv.cfg.PlanCatalog = cat |
| launch := planAccount(t, fx, 501) // written by the launch rule before media |
| @@ -401,6 +405,30 @@ func TestLaunchSponsorshipCarriesMedia(t *testing.T) { |
| set := preMediaLaunch() |
| set.MediaMinutesMonth = 600 |
| putPlanRow(t, fx.st, withMedia.ID, PlanSourceSponsored, set, planSponsorReason, planDefaultActor) |
| + // Before the PDF service: an operator's sponsorship of the launch |
| + // figures, a launch row someone edited, and one whose PDF figure was |
| + // set on purpose. All are left alone. |
| + prePDFOperator := planAccount(t, fx, 506) |
| + putPlanRow(t, fx.st, prePDFOperator.ID, PlanSourceSponsored, prePDFLaunch(), "launch partner", "ops@example.com") |
| + prePDFEdited := planAccount(t, fx, 507) |
| + pe := prePDFLaunch() |
| + pe.IdleSeconds = 600 |
| + putPlanRow(t, fx.st, prePDFEdited.ID, PlanSourceSponsored, pe, planSponsorReason, planDefaultActor) |
| + pdfSet := planAccount(t, fx, 508) |
| + ps := preMediaLaunch() |
| + ps.PDFRendersMonth = 5000 |
| + putPlanRow(t, fx.st, pdfSet.ID, PlanSourceSponsored, ps, planSponsorReason, planDefaultActor) |
| + pdfLimit := func(a *Account) int { |
| + t.Helper() |
| + l, err := fx.srv.EffectiveLimits(a) |
| + if err != nil || l == nil { |
| + t.Fatalf("limits %s: %+v, %v", a.Sqid, l, err) |
| + } |
| + return l.PDFRendersMonth |
| + } |
| + if got := pdfLimit(older); got != 100 { |
| + t.Fatalf("fixture: the pre-PDF row gives %d PDFs, want Free's 100", got) |
| + } |
| allowance := func(a *Account) int64 { |
| t.Helper() |
| @@ -428,12 +456,14 @@ func TestLaunchSponsorshipCarriesMedia(t *testing.T) { |
| t.Errorf("carried launch account: %d media minutes, want 0 (no limit)", got) |
| } |
| row, _ = fx.st.AccountPlan(older.ID) |
| - want := prePDFLaunch() |
| - want.MediaMinutesMonth = sponsorMost |
| - if row == nil || row.Sponsored == nil || *row.Sponsored != want || row.Revision != 2 { |
| - t.Fatalf("carried pre-PDF row = %+v, want media only added", row) |
| + if row == nil || row.Sponsored == nil || *row.Sponsored != sponsorUnlimited() || row.Revision != 2 { |
| + t.Fatalf("carried pre-PDF row = %+v, want PDFs and media added", row) |
| + } |
| + if got, media := pdfLimit(older), allowance(older); got != sponsorMost || media != 0 { |
| + t.Errorf("carried pre-PDF account: %d PDFs, %d media minutes; want unlimited", got, media) |
| } |
| - for name, a := range map[string]*Account{"operator": operator, "changed": changed, "with media": withMedia} { |
| + for name, a := range map[string]*Account{"operator": operator, "changed": changed, "with media": withMedia, |
| + "pre-PDF operator": prePDFOperator, "pre-PDF edited": prePDFEdited, "PDFs set": pdfSet} { |
| if after[a.ID] != before[a.ID] { |
| t.Errorf("%s row changed: %+v, was %+v", name, after[a.ID], before[a.ID]) |
| } |
| @@ -441,6 +471,9 @@ func TestLaunchSponsorshipCarriesMedia(t *testing.T) { |
| if got := allowance(operator); got != 30 { |
| t.Errorf("operator sponsorship: %d, want its own figures (Free's 30)", got) |
| } |
| + if got := pdfLimit(prePDFOperator); got != 100 { |
| + t.Errorf("pre-PDF operator sponsorship: %d PDFs, want its own figures (Free's 100)", got) |
| + } |
| // The publish pass sends the carried figures to the account's record. |
| fx.srv.planLimitsPass(ctx, planNow) |
| @@ -453,7 +486,7 @@ func TestLaunchSponsorshipCarriesMedia(t *testing.T) { |
| if n, err := SettleLaunchSponsorship(fx.st, cat, planNow.Add(time.Hour)); err != nil || n != 0 { |
| t.Fatalf("second settle = %d, %v", n, err) |
| } |
| - if n, err := fx.st.carryLaunchMedia(sponsorUnlimited(), planNow.Add(2*time.Hour)); err != nil || n != 0 { |
| + if n, err := fx.st.carryLaunchFigures(sponsorUnlimited(), planNow.Add(2*time.Hour)); err != nil || n != 0 { |
| t.Fatalf("second carry = %d, %v", n, err) |
| } |
| for id, r := range planRowsNow(t, fx.st) { |
diff --git a/internal/console/plansponsor.go b/internal/console/plansponsor.go| index 9b69bba4b..2e6dab838 100644 |
| --- a/internal/console/plansponsor.go |
| +++ b/internal/console/plansponsor.go |
| @@ -119,16 +119,16 @@ func sponsorUnlimited() plans.Limits { |
| // every account inserted. The console must not start then (Astra R3). |
| // |
| // With a catalog, it first carries launch sponsorships written before |
| -// media conversion forward (Store.carryLaunchMedia), cutoff or not: such |
| -// rows still sponsor their accounts. |
| +// the PDF service or media conversion forward (Store.carryLaunchFigures), |
| +// cutoff or not: such rows still sponsor their accounts. |
| func SettleLaunchSponsorship(st *Store, cat *plans.Catalog, now time.Time) (int, error) { |
| if cat != nil { |
| - carried, err := st.carryLaunchMedia(sponsorUnlimited(), now) |
| + carried, err := st.carryLaunchFigures(sponsorUnlimited(), now) |
| if err != nil { |
| return 0, errors.Join(fmt.Errorf("carrying the launch sponsorships forward: %w", err), clearLaunchRule(st)) |
| } |
| if carried > 0 { |
| - log.Printf("console: plans: %d launch sponsorships now include media minutes", carried) |
| + log.Printf("console: plans: %d launch sponsorships now include PDFs and media minutes", carried) |
| } |
| } |
| if cat == nil || cat.SponsorCutoff().IsZero() { |
| @@ -146,25 +146,28 @@ func SettleLaunchSponsorship(st *Store, cat *plans.Catalog, now time.Time) (int, |
| return n, nil |
| } |
| -// carryLaunchMedia gives every launch sponsorship written before |
| -// media_minutes_month existed the media figure launch now carries (Task 6 |
| -// fix round 1): without it such an account would get its plan's media |
| -// minutes (Free's 30) while every other figure is unlimited. One |
| -// transaction; idempotent, so every start runs it. |
| +// launchCarried are the launch figures added after launch sponsorships |
| +// were first written (2026-11-02): pdf_renders_month (the PDF service, |
| +// 2026-11-03) and media_minutes_month (media conversion). A launch row |
| +// lacking one gets its plan's figure (Free's 100 PDFs, 30 media minutes) |
| +// while every other figure is unlimited. |
| +var launchCarried = []string{"pdf_renders_month", "media_minutes_month"} |
| + |
| +// carryLaunchFigures gives every launch sponsorship that lacks one of |
| +// launchCarried the figure launch now carries (Task 6 fix rounds 1 and 2). |
| +// One transaction; idempotent, so every start runs it. |
| // |
| // A launch row is what launchRule.apply writes and nothing else does: |
| // source sponsored, reason planSponsorReason and writer planDefaultActor |
| // (the plan door records the operator's address, billing its own source). |
| -// It is carried only when its sponsored limits have no media field and |
| -// every field they do have holds launch's value: a row written by an |
| +// It is carried only when its sponsored limits lack a launchCarried field |
| +// and every field they do have holds launch's value: a row written by an |
| // earlier launch figure set may lack later fields, but a field that |
| -// differs is a deliberate change, and that row is left alone. A carried |
| -// row's revision is bumped so the publish pass sends its limits record |
| -// again; nothing else in it changes. |
| -func (s *Store) carryLaunchMedia(launch plans.Limits, now time.Time) (int, error) { |
| - if launch.MediaMinutesMonth == 0 { |
| - return 0, errors.New("console: the launch figures have no media minutes to carry") |
| - } |
| +// differs is a deliberate change, and that row is left alone. Only the |
| +// missing launchCarried fields are added; a carried row's revision is |
| +// bumped so the publish pass sends its limits record again; nothing else |
| +// in it changes. |
| +func (s *Store) carryLaunchFigures(launch plans.Limits, now time.Time) (int, error) { |
| lj, err := json.Marshal(launch) |
| if err != nil { |
| return 0, err |
| @@ -173,6 +176,11 @@ func (s *Store) carryLaunchMedia(launch plans.Limits, now time.Time) (int, error |
| if err != nil { |
| return 0, err |
| } |
| + for _, k := range launchCarried { |
| + if _, ok := want[k]; !ok { |
| + return 0, fmt.Errorf("console: the launch figures have no %s to carry", k) |
| + } |
| + } |
| tx, err := s.db.Begin() |
| if err != nil { |
| return 0, err |
| @@ -206,7 +214,12 @@ func (s *Store) carryLaunchMedia(launch plans.Limits, now time.Time) (int, error |
| if err != nil || len(have) == 0 { |
| continue // not launch's shape: leave it |
| } |
| - if _, ok := have["media_minutes_month"]; ok { |
| + missing := false |
| + for _, k := range launchCarried { |
| + _, ok := have[k] |
| + missing = missing || !ok |
| + } |
| + if !missing { |
| continue // carried already, or set on purpose |
| } |
| same := true |
| @@ -219,11 +232,21 @@ func (s *Store) carryLaunchMedia(launch plans.Limits, now time.Time) (int, error |
| if !same { |
| continue |
| } |
| + for _, k := range launchCarried { |
| + if _, ok := have[k]; !ok { |
| + have[k] = want[k] |
| + } |
| + } |
| + // Through plans.Limits, so the stored form is the one |
| + // accountPlanUpsertArgs writes. |
| + mj, err := json.Marshal(have) |
| + if err != nil { |
| + return 0, err |
| + } |
| var l plans.Limits |
| - if err := json.Unmarshal([]byte(r.sponsored), &l); err != nil { |
| + if err := json.Unmarshal(mj, &l); err != nil { |
| continue |
| } |
| - l.MediaMinutesMonth = launch.MediaMinutesMonth |
| nj, err := json.Marshal(l) |
| if err != nil { |
| return 0, err |