console: test the planExempt skip apart from the ops-owner pass
Review round 1 (no P1). P2: TestPlanExemptOwnershipIsNotAFreeAccount passed through opsOwner and never reached the planExempt skip; it now uses an exempt account owned by someone who does not own ops, and fails with the skip removed. P3s taken: the ops-owner test checks new accounts are on the default plan, and opsOwner logs a store error like its siblings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Review fixes: the planExempt-skip test no longer passes via opsOwner; default-plan assertion; opsOwner logs store errors.
3 files changed,
+27
−14
internal/console/plancaps_doors_test.go+3 −0internal/console/planexempt_test.go+20 −14internal/console/svcprincipal.go+4 −0
CI failed — run details
diff --git a/internal/console/plancaps_doors_test.go b/internal/console/plancaps_doors_test.go| index 43d802303..00f37b91e 100644 |
| --- a/internal/console/plancaps_doors_test.go |
| +++ b/internal/console/plancaps_doors_test.go |
| @@ -284,6 +284,9 @@ func TestOpsOwnerSkipsTheFreeAccountCap(t *testing.T) { |
| if l, err := fx.srv.EffectiveLimits(a); err != nil || l == nil { |
| t.Fatalf("account %s limits = %v, %v; want the default plan's, not exempt", name, l, err) |
| } |
| + if row, err := fx.st.AccountPlan(a.ID); err != nil || (row != nil && row.Plan != fx.srv.cfg.PlanCatalog.DefaultPlan) { |
| + t.Fatalf("account %s plan = %+v, %v; want the default plan", name, row, err) |
| + } |
| } |
| c := signInPaul(t, fx) |
| before := accountCount(t, fx) |
diff --git a/internal/console/planexempt_test.go b/internal/console/planexempt_test.go| index 98471ac67..e77526221 100644 |
| --- a/internal/console/planexempt_test.go |
| +++ b/internal/console/planexempt_test.go |
| @@ -161,29 +161,35 @@ func TestPlanExemptHasNoLimitsOrCaps(t *testing.T) { |
| } |
| } |
| +// TestPlanExemptOwnershipIsNotAFreeAccount is the planExempt skip in |
| +// checkNewFreeAccount. An ops owner never reaches it (opsOwner passes them |
| +// first), so the exempt account here is one kim owns without owning ops. |
| func TestPlanExemptOwnershipIsNotAFreeAccount(t *testing.T) { |
| fx := newConsoleFixture(t) |
| fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| - owner := "paul@example.com" |
| - ops := opsPlanAccount(t, fx, owner) |
| - if err := fx.srv.checkNewFreeAccount(owner); err != nil { |
| - t.Fatalf("owning ops alone counted as a free account: %v", err) |
| + owner := "kim@example.com" |
| + const exemptID = 503 |
| + if err := fx.st.CreateAccount(exemptID, "cdef", "exempt", owner, planNow); err != nil { |
| + t.Fatal(err) |
| } |
| - opsSponsoredRow(t, fx, ops) |
| + fx.st.planExemptID = exemptID |
| if err := fx.srv.checkNewFreeAccount(owner); err != nil { |
| - t.Fatalf("owning ops with a free row counted as a free account: %v", err) |
| + t.Fatalf("owning the exempt account alone counted as a free account: %v", err) |
| } |
| - // A member of ops who is not an owner is held to the cap by the free |
| - // account they own (ops owners have no cap: TestOpsOwnerSkipsTheFreeAccountCap). |
| - member := "member@example.com" |
| - if err := fx.st.AddMember(ops.ID, member, RoleMember, planNow); err != nil { |
| - t.Fatal(err) |
| + exempt, err := fx.st.AccountByID(exemptID) |
| + if err != nil || exempt == nil { |
| + t.Fatalf("exempt account: %v", err) |
| + } |
| + opsSponsoredRow(t, fx, exempt) |
| + if err := fx.srv.checkNewFreeAccount(owner); err != nil { |
| + t.Fatalf("owning the exempt account with a free row counted as a free account: %v", err) |
| } |
| - if err := fx.st.CreateAccount(502, "bac", "mine", member, planNow); err != nil { |
| + // The cap itself still holds for the person's real accounts. |
| + if err := fx.st.CreateAccount(502, "bac", "mine", owner, planNow); err != nil { |
| t.Fatal(err) |
| } |
| - if err := fx.srv.checkNewFreeAccount(member); !isCap(err) { |
| - t.Fatalf("member of ops owning one free account: %v, want the cap", err) |
| + if err := fx.srv.checkNewFreeAccount(owner); !isCap(err) { |
| + t.Fatalf("owner of the exempt account and one free account: %v, want the cap", err) |
| } |
| } |
diff --git a/internal/console/svcprincipal.go b/internal/console/svcprincipal.go| index bc8bc1d30..e56f50196 100644 |
| --- a/internal/console/svcprincipal.go |
| +++ b/internal/console/svcprincipal.go |
| @@ -24,6 +24,7 @@ import ( |
| "encoding/json" |
| "errors" |
| "fmt" |
| + "log" |
| "net/http" |
| "strconv" |
| "time" |
| @@ -611,6 +612,9 @@ func (s *Server) allowAppCreate(p Principal, now time.Time) bool { |
| // ownership. |
| func (s *Server) opsOwner(addr string) bool { |
| role, err := s.store.Role(OpsAccountID, addr) |
| + if err != nil { |
| + log.Printf("console: ops owner: role: %v", err) |
| + } |
| return err == nil && role == RoleOwner |
| } |