carlos / platform Public

console: launch carry marshals plans.Limits, not a decoded map

TestConsoleJSONNeverCarriesGateHash failed at HEAD: fix round 2's carry
json.Marshal'd the map[string]any jsonFields decodes, and the gate-hash
guard cannot follow a value a Decode call fills, so it reported a new
unresolved site at plansponsor.go:320. The map now only compares; the
row is decoded into plans.Limits and each missing launchCarried field
is set from launch through a typed setter before it is marshalled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 92d19816564f49f9b9eb40a5589d42fdb1e6b466 parent e7a3f22
2 files changed, +41 −18
  • internal/console/planmedia_test.go +19 −0
  • internal/console/plansponsor.go +22 −18
diff --git a/internal/console/planmedia_test.go b/internal/console/planmedia_test.go
index d698815fe..fbdd7977c 100644
--- a/internal/console/planmedia_test.go
+++ b/internal/console/planmedia_test.go
@@ -590,3 +590,22 @@ func TestLaunchCarryAndRuleAreOneTransaction(t *testing.T) {
})
}
}
+
+// Each launchCarried entry sets exactly the field its key names.
+func TestLaunchCarriedKeysMatchTheirFields(t *testing.T) {
+ for _, c := range launchCarried {
+ var l plans.Limits
+ c.set(&l, sponsorUnlimited())
+ b, err := json.Marshal(l)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var m map[string]json.RawMessage
+ if err := json.Unmarshal(b, &m); err != nil {
+ t.Fatal(err)
+ }
+ if _, ok := m[c.key]; !ok || len(m) != 1 {
+ t.Errorf("%s sets %s", c.key, b)
+ }
+ }
+}
diff --git a/internal/console/plansponsor.go b/internal/console/plansponsor.go
index 60bcdfe9e..f83ceed4c 100644
--- a/internal/console/plansponsor.go
+++ b/internal/console/plansponsor.go
@@ -200,7 +200,13 @@ func (s *Store) clearLaunchRuleCarrying(launch plans.Limits, reason, by string,
// 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"}
+var launchCarried = []struct {
+ key string // the field's JSON name
+ set func(l *plans.Limits, launch plans.Limits) // copies launch's figure into l
+}{
+ {"pdf_renders_month", func(l *plans.Limits, launch plans.Limits) { l.PDFRendersMonth = launch.PDFRendersMonth }},
+ {"media_minutes_month", func(l *plans.Limits, launch plans.Limits) { l.MediaMinutesMonth = launch.MediaMinutesMonth }},
+}
// carryLaunchFiguresTx gives every launch sponsorship that lacks one of
// launchCarried the figure launch now carries (Task 6 fix rounds 1 and 2),
@@ -227,9 +233,9 @@ func carryLaunchFiguresTx(tx *sql.Tx, launch plans.Limits, reason, by string, no
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)
+ for _, c := range launchCarried {
+ if _, ok := want[c.key]; !ok {
+ return 0, fmt.Errorf("console: the launch figures have no %s to carry", c.key)
}
}
rows, err := tx.Query(`SELECT account_id, sponsored FROM account_plans
@@ -261,8 +267,8 @@ func carryLaunchFiguresTx(tx *sql.Tx, launch plans.Limits, reason, by string, no
continue // not launch's shape: leave it
}
missing := false
- for _, k := range launchCarried {
- _, ok := have[k]
+ for _, c := range launchCarried {
+ _, ok := have[c.key]
missing = missing || !ok
}
if !missing {
@@ -278,21 +284,19 @@ func carryLaunchFiguresTx(tx *sql.Tx, launch plans.Limits, reason, by string, no
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
- }
+ // The row's own figures as plans.Limits, the missing ones set
+ // from launch, so the stored form is the one accountPlanUpsertArgs
+ // writes. (have only compares: marshalling it would hand the JSON
+ // guard a decoded map it cannot follow, gate_shadow_guard_test.go.)
var l plans.Limits
- if err := json.Unmarshal(mj, &l); err != nil {
+ if err := json.Unmarshal([]byte(r.sponsored), &l); err != nil {
continue
}
+ for _, c := range launchCarried {
+ if _, ok := have[c.key]; !ok {
+ c.set(&l, launch)
+ }
+ }
nj, err := json.Marshal(l)
if err != nil {
return 0, err