console: Billing in the operator rail, behind billing
Billing dashboard Plan 2, Task 2: the rail item, the three routes and the page shells. - opRail gains Billing directly under Dashboard (BillingOnly); opPage sets opShell.Billing from s.billing, and opRailFor drops the item without it. - /fleet/billing, /fleet/billing/accounts and /fleet/billing/payments are registered on every console without a method prefix (ruling P1); billingPageGate runs operatorOnly, then 404s a non-GET or a console with billing off, byte-identical to a missing route. - The three templates carry the page header and, in Stripe test mode, the test-mode line (BDP-3). opbilling_copy.go holds all 150 approved BDP rows as billCopy* constants; billingPagesCopyBuilt lists the seven this task renders. - Plan 1 follow-ups from the same copy review: BDC-20 in billing_cli_copy.go and BDC-36 in docs/site/cli.md, with Plan 1's record updated. BDC-20 re-pins the root (.) envelope of the root-read census (overlay billing-dash-2-pages, no unit changed). - Record-write census: NewServer re-pinned in billingDashboard2WriteCensusInventory.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 files changed,
+868
−13
approved_billing_dashboard_copy_test.go+94 −0billing_cli_copy.go+1 −1docs/site/cli.md+1 −1docs/superpowers/notes/census-claims-billing-dash-2-pages.tsv+3 −0docs/superpowers/notes/census-proposal-billing-dash-2-pages.md+11 −0docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md+3 −3internal/console/claim_invariant_fixtures_test.go+3 −0internal/console/claim_invariant_probes_read_test.go+3 −0internal/console/opbilling.go+108 −0internal/console/opbilling_copy.go+371 −0internal/console/opbilling_test.go+89 −0internal/console/opperson_test.go+1 −1internal/console/opshell.go+13 −2internal/console/opshell_test.go+91 −4internal/console/perfwalk_test.go+5 −0internal/console/server.go+15 −0internal/console/templates/ops_billing.html+12 −0internal/console/templates/ops_billing_accounts.html+6 −0internal/console/templates/ops_billing_payments.html+6 −0internal/provision/billing_dashboard_2_census_test.go+27 −0internal/provision/plan9_b8_census_test.go+1 −1internal/provision/testdata/plan14-root-reads-billing-dash-2-pages.tsv+3 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0
diff --git a/approved_billing_dashboard_copy_test.go b/approved_billing_dashboard_copy_test.go| index f5565e60e..dab470181 100644 |
| --- a/approved_billing_dashboard_copy_test.go |
| +++ b/approved_billing_dashboard_copy_test.go |
| @@ -93,3 +93,97 @@ func TestApprovedBillingDashboardCopy(t *testing.T) { |
| } |
| reportAll(t, append(problems, checkMovesApplied(whole, ".")...)) |
| } |
| + |
| +// The copy gate of the billing dashboard plan 2, the operator Billing pages. |
| +// The record is docs/superpowers/plans/2026-11-09-billing-dashboard-2-copy.md: |
| +// BDP-1 to BDP-150, whose files are relative to internal/console/, and the |
| +// two Plan 1 rows it carried to review again (BDC-20, BDC-36). |
| +// |
| +// - TestBillingPagesCopyInventory: the record names exactly |
| +// billingPagesCopyIDs, and no row holds an em dash; |
| +// - TestApprovedBillingPagesCopy: an id in billingPagesCopyBuilt is an |
| +// approved row, and its text is in internal/console/opbilling_copy.go. |
| +// The record's BDC rows are the same text as Plan 1's record, which |
| +// TestApprovedBillingDashboardCopy checks in the code and docs. |
| +const billingPagesCopyRecordPath = "docs/superpowers/plans/2026-11-09-billing-dashboard-2-copy.md" |
| + |
| +const billingPagesCopyRoot = "internal/console" |
| + |
| +var billingPagesCopyIDPattern = regexp.MustCompile(`^(BDP|BDC)-[0-9]+$`) |
| + |
| +// billingPagesCopyIDs is the record's inventory, pinned: BDP-1 to BDP-150, |
| +// then BDC-20 and BDC-36. |
| +var billingPagesCopyIDs = func() []string { |
| + ids := make([]string, 0, 152) |
| + for i := 1; i <= 150; i++ { |
| + ids = append(ids, "BDP-"+strconv.Itoa(i)) |
| + } |
| + return append(ids, "BDC-20", "BDC-36") |
| +}() |
| + |
| +// billingPagesCopyBuilt is every BDP row the pages render. Every row has |
| +// its constant in opbilling_copy.go from Task 2; the task that renders a |
| +// row adds its id here in the same commit. |
| +var billingPagesCopyBuilt = []string{ |
| + // Task 2: the rail label (also the overview's <h1>), the three pages' |
| + // titles and subheads, and the test-mode line. |
| + "BDP-1", "BDP-2", "BDP-3", "BDP-100", "BDP-116", "BDP-136", "BDP-137", |
| +} |
| + |
| +// billingPagesShortGoText is the built rows checked as a whole string |
| +// literal of opbilling_copy.go (checkShortGoText), so a word is never |
| +// matched as a fragment of a longer one. |
| +var billingPagesShortGoText = map[string]bool{ |
| + "BDP-1": true, "BDP-100": true, "BDP-136": true, |
| +} |
| + |
| +func mustParseBillingPagesCopyRecord(t *testing.T) []copyRow { |
| + t.Helper() |
| + raw, err := os.ReadFile(billingPagesCopyRecordPath) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + rows, err := parseCopyTable(string(raw), billingPagesCopyRecordPath, billingPagesCopyIDPattern, "a BDP-<n> or BDC-<n>") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return rows |
| +} |
| + |
| +func TestBillingPagesCopyInventory(t *testing.T) { |
| + rows := mustParseBillingPagesCopyRecord(t) |
| + reportAll(t, checkMovesInventory(rows, billingPagesCopyIDs)) |
| + reportAll(t, checkMovesNoEmDash(rows)) |
| +} |
| + |
| +func TestApprovedBillingPagesCopy(t *testing.T) { |
| + rows := mustParseBillingPagesCopyRecord(t) |
| + built, problems := entryBuiltRows(rows, billingPagesCopyBuilt, "billingPagesCopyBuilt") |
| + var whole []copyRow |
| + for _, r := range built { |
| + if !strings.HasPrefix(r.ID, "BDP-") { |
| + problems = append(problems, "billingPagesCopyBuilt names "+r.ID+": the BDC rows are built through Plan 1's record") |
| + continue |
| + } |
| + if billingPagesShortGoText[r.ID] { |
| + problems = append(problems, checkShortGoText(r, billingPagesCopyRoot)...) |
| + continue |
| + } |
| + whole = append(whole, r) |
| + } |
| + problems = append(problems, checkMovesApplied(whole, billingPagesCopyRoot)...) |
| + // The follow-ups: the approved text replaced Plan 1's row. |
| + plan1 := map[string]copyRow{} |
| + for _, r := range mustParseBillingDashboardCopyRecord(t) { |
| + plan1[r.ID] = r |
| + } |
| + for _, r := range rows { |
| + if !strings.HasPrefix(r.ID, "BDC-") || r.Status != "approved" { |
| + continue |
| + } |
| + if p, ok := plan1[r.ID]; !ok || p.Text != r.Text || p.Status != "approved" { |
| + problems = append(problems, r.ID+": Plan 1's record does not carry the approved text "+strconv.Quote(r.Text)) |
| + } |
| + } |
| + reportAll(t, problems) |
| +} |
diff --git a/billing_cli_copy.go b/billing_cli_copy.go| index ce5514e94..07ba4cf0e 100644 |
| --- a/billing_cli_copy.go |
| +++ b/billing_cli_copy.go |
| @@ -55,7 +55,7 @@ const ( |
| cliBillingCopyWhyFacts = "the hourly read of subscriptions from stripe is more than two hours old" |
| cliBillingCopyWhyPayments = "the payment record has not caught up with stripe in the last two hours" |
| cliBillingCopyWhyRates = "there is no current ecb rate for one of the currencies" |
| - cliBillingCopyWhyAmounts = "a paying account's yearly amount is not known yet" |
| + cliBillingCopyWhyAmounts = "a subscription's yearly amount is not known yet" |
| cliBillingCopyPaymentsHeader = "when (utc) account kind reason charged tax settled fee detail" |
| cliBillingCopyNoPayments = "no payments to show" |
diff --git a/docs/site/cli.md b/docs/site/cli.md| index 635420d45..ec7c8e77d 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -2321,7 +2321,7 @@ carlos billing house -account bac -off -note "now a customer" |
| `revenue` prints what the paying accounts bring in, before tax: ARR and MRR in euros, with each currency's own total beside ARR. When a total converts another currency, it is an estimate at the ECB rates of the day it names, for example `arr €2,425.00 a year before tax (€2,400.00 + $28.00), estimated at ecb rates of 2026-11-06`. Then it prints how many accounts pay, how many of those have a failing renewal or are cancelling, and how many accounts are paying, free, sponsored, house and ours. A figure the console can't stand behind yet, because a read from Stripe is behind or a rate is missing, says `not available yet` and why, instead of a wrong number. In test mode it says so. |
| -`payments` lists the money Stripe has taken and paid back, newest first, up to 500 lines: when it happened (UTC), the account, the kind, the amount charged, the tax, what settled in euros and Stripe's fee. `-month 2026-11` keeps one month. `-kind` keeps one of `subscription`, `once-off`, `refund`, `fee` or `unmatched`, a payment from a Stripe customer the console can't match to an account. |
| +`payments` lists the money Stripe has taken and paid back, newest first, up to 500 lines: when it happened (UTC), the account, the kind, the amount charged, the tax, what settled in the currency Stripe pays out in, and Stripe's fee. `-month 2026-11` keeps one month. `-kind` keeps one of `subscription`, `once-off`, `refund`, `fee` or `unmatched`, a payment from a Stripe customer the console can't match to an account. |
| `house` marks an account as a house account, whose checkout carries the house coupon and so pays nothing, or clears the mark. It needs `-account` (the account's sqid), exactly one of `-on` and `-off`, and `-note` saying why. The mark applies when the account starts a checkout, and does not change a subscription it already has. It works only against a console. See [Plans](plans#house-accounts). |
diff --git a/docs/superpowers/notes/census-claims-billing-dash-2-pages.tsv b/docs/superpowers/notes/census-claims-billing-dash-2-pages.tsv| new file mode 100644 |
| index 000000000..50218aac0 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-claims-billing-dash-2-pages.tsv |
| @@ -0,0 +1,3 @@ |
| +# Billing dashboard Plan 2 (branch billing-dash-2-pages). One line per changed root-read unit: <file>:<unit><TAB><what changed>. |
| +# Task 2 changes no unit; it re-pins the root (.) envelope only, which census-propose takes without a claim. The change, kept here for the reviewer: |
| +# billing_cli_copy.go:cliBillingCopyWhyAmounts: the approved BDC-20 text, one string constant the CLI prints; no read added |
diff --git a/docs/superpowers/notes/census-proposal-billing-dash-2-pages.md b/docs/superpowers/notes/census-proposal-billing-dash-2-pages.md| new file mode 100644 |
| index 000000000..439f1da48 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-billing-dash-2-pages.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: billing-dash-2-pages |
| + |
| +Ruling `census-ruling-billing-dash-2-pages`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `.`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `7ac2bde8301c37c7546e9aa19d375f1468fc8061876a618fa8f93dd4543c5652` → `7ac2bde8301c37c7546e9aa19d375f1468fc8061876a618fa8f93dd4543c5652`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-billing-dash-2-pages.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md b/docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md| index e152118b2..f2bbdd863 100644 |
| --- a/docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md |
| +++ b/docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md |
| @@ -1,6 +1,6 @@ |
| # Billing dashboard plan 1: copy record |
| -Every user-facing string plan 1 of the billing dashboard writes (spec `2026-11-09-billing-dashboard-design.md` §4.2 to §4.4): the `carlos billing revenue` and `carlos billing payments` verbs, the console door's refusals, the docs and the Stripe setup script. Paul approved all 38 rows unchanged on 2026-11-09 in copy review `il22ckkydvo2n7onrbwviz3sfq` (`2026-11-09-billing-dashboard-1-copy-approved.json`). Paul approved new text for BDC-6 and BDC-35 on 2026-11-09 in copy review `udf3zvfpk3xj3tlmj43qusluku` (`2026-11-09-billing-dashboard-1-copy-approved-2.json`), after the task review found converted figures were not labelled as estimates. The gate is `approved_billing_dashboard_copy_test.go` at the repo root, in the asset copy record's format: one table per heading, columns id, file, text, status. |
| +Every user-facing string plan 1 of the billing dashboard writes (spec `2026-11-09-billing-dashboard-design.md` §4.2 to §4.4): the `carlos billing revenue` and `carlos billing payments` verbs, the console door's refusals, the docs and the Stripe setup script. Paul approved all 38 rows unchanged on 2026-11-09 in copy review `il22ckkydvo2n7onrbwviz3sfq` (`2026-11-09-billing-dashboard-1-copy-approved.json`). Paul approved new text for BDC-6 and BDC-35 on 2026-11-09 in copy review `udf3zvfpk3xj3tlmj43qusluku` (`2026-11-09-billing-dashboard-1-copy-approved-2.json`), after the task review found converted figures were not labelled as estimates. Paul approved new text for BDC-20 and BDC-36 on 2026-11-09 in plan 2's copy review `qvntfzakoafxuulgbactxeeka4` (`2026-11-09-billing-dashboard-2-copy.md`, Plan 1 follow-ups). The gate is `approved_billing_dashboard_copy_test.go` at the repo root, in the asset copy record's format: one table per heading, columns id, file, text, status. |
| The rules are the asset copy record's (`2026-10-24-edge-asset-cache-copy.md`): a row's Go text is one literal or one `fmt.Sprintf`/`fmt.Errorf`/`errors.New` format, with a verb where the row has a placeholder (`<eur>`, `<amounts>`, `<day>` and `<reason>` are `%s`; `<n>` and `<all>` are `%d`); docs rows are one line per paragraph or code line in `docs/site/cli.md` and `docs/site/plans.md`; the task that writes a row adds its id to `billingDashboardCopyBuilt` in the same commit. Amounts are formatted by the code (`€24.00`, `$28.00`); `<amounts>` is each currency's own total joined with ` + `. A revenue line prints as its label, two spaces, then its value, or the label, two spaces, BDC-13 and the reason's text when the door refuses the figure. |
| @@ -37,7 +37,7 @@ The rules are the asset copy record's (`2026-10-24-edge-asset-cache-copy.md`): a |
| | BDC-17 | billing_cli_copy.go | the hourly read of subscriptions from stripe is more than two hours old | approved | |
| | BDC-18 | billing_cli_copy.go | the payment record has not caught up with stripe in the last two hours | approved | |
| | BDC-19 | billing_cli_copy.go | there is no current ecb rate for one of the currencies | approved | |
| -| BDC-20 | billing_cli_copy.go | a paying account's yearly amount is not known yet | approved | |
| +| BDC-20 | billing_cli_copy.go | a subscription's yearly amount is not known yet | approved | |
| BDC-17 to BDC-20 are the texts for the door's `why` codes `facts`, `payments`, `rates` and `amounts`, in that order. |
| @@ -72,7 +72,7 @@ BDC-23 fills the account column when the door's `account` is empty: a payment fr |
| | BDC-33 | docs/site/cli.md | carlos billing payments -month 2026-11 | approved | |
| | BDC-34 | docs/site/cli.md | carlos billing payments -kind unmatched | approved | |
| | BDC-35 | docs/site/cli.md | `revenue` prints what the paying accounts bring in, before tax: ARR and MRR in euros, with each currency's own total beside ARR. When a total converts another currency, it is an estimate at the ECB rates of the day it names, for example `arr €2,425.00 a year before tax (€2,400.00 + $28.00), estimated at ecb rates of 2026-11-06`. Then it prints how many accounts pay, how many of those have a failing renewal or are cancelling, and how many accounts are paying, free, sponsored, house and ours. A figure the console can't stand behind yet, because a read from Stripe is behind or a rate is missing, says `not available yet` and why, instead of a wrong number. In test mode it says so. | approved | |
| -| BDC-36 | docs/site/cli.md | `payments` lists the money Stripe has taken and paid back, newest first, up to 500 lines: when it happened (UTC), the account, the kind, the amount charged, the tax, what settled in euros and Stripe's fee. `-month 2026-11` keeps one month. `-kind` keeps one of `subscription`, `once-off`, `refund`, `fee` or `unmatched`, a payment from a Stripe customer the console can't match to an account. | approved | |
| +| BDC-36 | docs/site/cli.md | `payments` lists the money Stripe has taken and paid back, newest first, up to 500 lines: when it happened (UTC), the account, the kind, the amount charged, the tax, what settled in the currency Stripe pays out in, and Stripe's fee. `-month 2026-11` keeps one month. `-kind` keeps one of `subscription`, `once-off`, `refund`, `fee` or `unmatched`, a payment from a Stripe customer the console can't match to an account. | approved | |
| BDC-32 to BDC-34 are new lines in the section's `sh` block, after `carlos billing problems -all`. |
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index 85a21f5bb..a1af3c39c 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -740,6 +740,9 @@ var claimFixtures = map[string]claimFixture{ |
| "route /api/economics/backhaul": claimRead("operator backhaul report (GET only) computed from the economics view; writes nothing"), |
| "route /api/economics/bill": claimNonApp("operator bill import, stored under economics/; names no app"), |
| "route /fleet/architecture": claimRead("renders the deployment map from the cached snapshot; refreshing it is its own door"), |
| + "route /fleet/billing": claimRead("operator billing view; reads billing records; names no app"), |
| + "route /fleet/billing/accounts": claimRead("operator billing view; reads billing records; names no app"), |
| + "route /fleet/billing/payments": claimRead("operator billing view; reads billing records; names no app"), |
| "route /fleet/architecture/refresh": claimNonApp("rebuilds the deployment map snapshot from box and edge files; no app object or row"), |
| "route /fleet/economics/bill": claimNonApp("operator bill form, stored under economics/"), |
| "route /fleet/economics/scenarios": claimNonApp("operator pricing scenarios, stored under economics/"), |
diff --git a/internal/console/claim_invariant_probes_read_test.go b/internal/console/claim_invariant_probes_read_test.go| index b959bc46d..c52400b38 100644 |
| --- a/internal/console/claim_invariant_probes_read_test.go |
| +++ b/internal/console/claim_invariant_probes_read_test.go |
| @@ -179,6 +179,9 @@ var claimReadProbes = map[string]claimProbe{ |
| // ---- methodless ---- |
| "route /api/economics/backhaul": claimAPIRead(nil, "/api/economics/backhaul", `"period"`, `"accounts"`), |
| "route /fleet/architecture": claimPageRead(nil, "/fleet/architecture", "<h1>Architecture</h1>"), |
| + "route /fleet/billing": claimPageRead(claimBillingWorld, "/fleet/billing", "<h1>"+billCopyRail+"</h1>"), |
| + "route /fleet/billing/accounts": claimPageRead(claimBillingWorld, "/fleet/billing/accounts", "<h1>"+billCopyAccounts+"</h1>"), |
| + "route /fleet/billing/payments": claimPageRead(claimBillingWorld, "/fleet/billing/payments", "<h1>"+billCopyPaymentsTitle+"</h1>"), |
| // ---- browser pages ---- |
| "route GET /a/{sqid}/apps/new": claimPageRead(nil, "/a/bab/apps/new", `action="/a/bab/apps/new"`), |
diff --git a/internal/console/opbilling.go b/internal/console/opbilling.go| new file mode 100644 |
| index 000000000..01dba271c |
| --- /dev/null |
| +++ b/internal/console/opbilling.go |
| @@ -0,0 +1,108 @@ |
| +package console |
| + |
| +import ( |
| + "fmt" |
| + "net/http" |
| +) |
| + |
| +// The operator Billing pages (billing dashboard plan 2, spec 2026-11-09 |
| +// §4.1): the overview at /fleet/billing, the accounts list at |
| +// /fleet/billing/accounts and the payments list at /fleet/billing/payments. |
| +// They exist only on a console with billing on. The routes are registered |
| +// on every console, without a method prefix, so the claim census sees them |
| +// and a POST cannot draw a 405; billingPageGate answers everything else |
| +// exactly as a missing route does, operators included. Every word comes |
| +// from opbilling_copy.go. |
| + |
| +// opBillingView is the overview's data. |
| +type opBillingView struct { |
| + Header opHeader |
| + TestMode bool |
| +} |
| + |
| +// opBillingAccountsView is the accounts list's data. |
| +type opBillingAccountsView struct { |
| + Header opHeader |
| + TestMode bool |
| +} |
| + |
| +// opBillingPaymentsView is the payments list's data. |
| +type opBillingPaymentsView struct { |
| + Header opHeader |
| + TestMode bool |
| +} |
| + |
| +// billingPageGate admits an operator's GET on a console with billing on. |
| +// The order is operatorOnly first, then the method and the billing switch, |
| +// each a plain http.NotFound, so nobody can tell a billing page from a |
| +// missing route without being an operator on a billing console. ok=false |
| +// means the response is written. |
| +func (s *Server) billingPageGate(w http.ResponseWriter, r *http.Request) (addr, raw string, ok bool) { |
| + addr, raw, ok = s.operatorOnly(w, r) |
| + if !ok { |
| + return "", "", false |
| + } |
| + if r.Method != http.MethodGet || s.billing == nil { |
| + http.NotFound(w, r) |
| + return "", "", false |
| + } |
| + return addr, raw, true |
| +} |
| + |
| +// billingTestMode reports whether the console runs on Stripe's test mode. |
| +// Only called past billingPageGate, so billing is on. |
| +func (s *Server) billingTestMode() bool { return !s.billing.cfg.LiveMode } |
| + |
| +// billingPage is the page a billing page renders with: under the Billing |
| +// rail item, titled title. |
| +func (s *Server) billingPage(addr, raw, title string) page { |
| + p := s.opPage(addr, raw, "billing") |
| + p.Title = title |
| + return p |
| +} |
| + |
| +// handleOpBilling is the overview. |
| +func (s *Server) handleOpBilling(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, ok := s.billingPageGate(w, r) |
| + if !ok { |
| + return |
| + } |
| + p := s.billingPage(addr, raw, billCopyRail) |
| + p.OpBilling = &opBillingView{ |
| + Header: opHeader{Title: billCopyRail, Sub: fmt.Sprintf(billCopyOverviewSub, s.brandName())}, |
| + TestMode: s.billingTestMode(), |
| + } |
| + s.render(w, http.StatusOK, "ops_billing", p) |
| +} |
| + |
| +// handleOpBillingAccounts is the accounts list. |
| +func (s *Server) handleOpBillingAccounts(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, ok := s.billingPageGate(w, r) |
| + if !ok { |
| + return |
| + } |
| + p := s.billingPage(addr, raw, billCopyAccounts) |
| + p.OpBillingAccounts = &opBillingAccountsView{ |
| + Header: opHeader{Title: billCopyAccounts, Sub: billCopyAccountsSub}, |
| + TestMode: s.billingTestMode(), |
| + } |
| + s.render(w, http.StatusOK, "ops_billing_accounts", p) |
| +} |
| + |
| +// handleOpBillingPayments is the payments list. |
| +func (s *Server) handleOpBillingPayments(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, ok := s.billingPageGate(w, r) |
| + if !ok { |
| + return |
| + } |
| + p := s.billingPage(addr, raw, billCopyPaymentsTitle) |
| + p.OpBillingPayments = &opBillingPaymentsView{ |
| + Header: opHeader{Title: billCopyPaymentsTitle, Sub: billCopyPaymentsSub}, |
| + TestMode: s.billingTestMode(), |
| + } |
| + s.render(w, http.StatusOK, "ops_billing_payments", p) |
| +} |
| + |
| +// opBillingTestModeText is the test-mode line, the template func |
| +// opBillingTestMode (op_billing_head in templates/ops_billing.html). |
| +func opBillingTestModeText() string { return billCopyTestMode } |
diff --git a/internal/console/opbilling_copy.go b/internal/console/opbilling_copy.go| new file mode 100644 |
| index 000000000..b5d4569df |
| --- /dev/null |
| +++ b/internal/console/opbilling_copy.go |
| @@ -0,0 +1,371 @@ |
| +package console |
| + |
| +// The billing pages' words (billing dashboard plan 2), one constant per row |
| +// of the approved copy record, |
| +// docs/superpowers/plans/2026-11-09-billing-dashboard-2-copy.md, each with |
| +// its BDP id. Templates and builders take every user-facing string from |
| +// here; none is typed anywhere else. A %s is a format verb: the brand, a |
| +// date, a month or a figure, filled in where the row is used. |
| +// |
| +// approved_billing_dashboard_copy_test.go (the repo root) checks the text of |
| +// every row the pages render against this file (billingPagesCopyBuilt). |
| + |
| +// Rail and overview header. |
| +const ( |
| + // BDP-1: the rail label, directly under Dashboard; the overview's h1 uses the same row. |
| + billCopyRail = "Billing" |
| + // BDP-2: the overview's subhead. |
| + billCopyOverviewSub = "Who pays, how much, and whether it covers what %s costs to run." |
| +) |
| + |
| +// Every billing page. |
| +const ( |
| + // BDP-3: every billing page, under the subhead, only in test mode. |
| + billCopyTestMode = "Test mode: these are Stripe test-mode figures, not real money." |
| + // BDP-4: after a converted total, for example the ARR note. |
| + billCopyRateNote = "estimated at ECB rates of %s" |
| + // BDP-5: under the subhead of the accounts and payments pages. |
| + billCopyRateNoteLine = "Euro figures converted from another currency are estimated at ECB rates of %s." |
| + // BDP-6: beside per-account costs and cost to run. |
| + billCopyEstimate = "estimate" |
| + // BDP-7: in place of any money figure the console can't stand behind. |
| + billCopyNotAvailable = "Not available yet" |
| + // BDP-8: beside Not available yet. |
| + billCopyWhyFacts = "The hourly read of subscriptions from Stripe is more than two hours old." |
| + // BDP-9: beside Not available yet. |
| + billCopyWhyPayments = "The payment record has not caught up with Stripe in the last two hours." |
| + // BDP-10: beside Not available yet. |
| + billCopyWhyRates = "There is no current ECB rate for one of the currencies." |
| + // BDP-11: beside Not available yet. |
| + billCopyWhyAmounts = "A subscription's yearly amount is not known yet." |
| + // BDP-12: beside Not available yet. |
| + billCopyWhyEconomics = "Economics does not have complete usage figures for last month." |
| + // BDP-13: beside Not available yet, for a month's per-account earnings and margins. |
| + billCopyWhyHistory = "Not every day of %s has a complete daily record." |
| + // BDP-14: under the per-account lists while the history is shorter than a month. |
| + billCopyHistoryShort = "Earnings and margins for a past month show once every day of that month has been recorded." |
| + // BDP-15: the full lists' pager. |
| + billCopyPagerPage = "Page %s of %s" |
| + // BDP-16: the full lists' pager. |
| + billCopyPagerPrev = "Previous" |
| + // BDP-17: the full lists' pager. |
| + billCopyPagerNext = "Next" |
| +) |
| + |
| +// Overview: tiles. |
| +const ( |
| + // BDP-18: the first tile. |
| + billCopyTileARR = "ARR" |
| + // BDP-19: under the ARR figure; the rate note follows after a comma when a total was converted. |
| + billCopyARRNote = "%s before tax" |
| + // BDP-20: under the ARR and Paying accounts tiles. |
| + billCopyDeltaUp = "+%s this month" |
| + // BDP-21: under the ARR and Paying accounts tiles. |
| + billCopyDeltaDown = "−%s this month" |
| + // BDP-22: under the ARR and Paying accounts tiles. |
| + billCopyDeltaNone = "no change this month" |
| + // BDP-23: the second tile. |
| + billCopyTileMRR = "MRR" |
| + // BDP-24: under the MRR figure. |
| + billCopyMRRNote = "ARR ÷ 12" |
| + // BDP-25: the third tile. |
| + billCopyTileReceived = "Received this month" |
| + // BDP-26: under the Received this month figure. |
| + billCopyReceivedNote = "after refunds and Stripe fees, before tax" |
| + // BDP-27: the fourth tile; also the heading of the newest paying accounts list. |
| + billCopyTilePaying = "Paying accounts" |
| + // BDP-28: under the Paying accounts figure. |
| + billCopyPayingNote = "%s of %s (%s)" |
| + // BDP-29: the fifth tile. |
| + billCopyTileAttention = "Needs attention" |
| + // BDP-30: under the Needs attention figure. |
| + billCopyAttentionNote = "failing renewals or pending cancellations" |
| +) |
| + |
| +// Overview: ARR by day. |
| +const ( |
| + // BDP-31: the chart under the tiles. |
| + billCopyARRChart = "ARR by day" |
| + // BDP-32: the chart axis's last label; the first is a date, like 9 Nov. |
| + billCopyChartToday = "Today" |
| + // BDP-33: the chart's hidden table caption. |
| + billCopyARRTableCaption = "ARR in euros at the end of each day" |
| + // BDP-34: the chart's hidden table. |
| + billCopyARRTableDay = "Day" |
| + // BDP-35: the chart's hidden table. |
| + billCopyARRTableEUR = "ARR in euros" |
| + // BDP-36: under the chart. |
| + billCopyARRGapOne = "1 day has no complete record and shows no bar." |
| + // BDP-37: under the chart. |
| + billCopyARRGapMany = "%s days have no complete record and show no bar." |
| + // BDP-38: in place of the chart. |
| + billCopyARRChartEmpty = "No daily record yet. The first is written within a day." |
| +) |
| + |
| +// Overview: paying accounts list. |
| +const ( |
| + // BDP-39: beside the heading. |
| + billCopyAllPaying = "All paying accounts" |
| + // BDP-40: the account column in every list on all three pages. |
| + billCopyColAccount = "Account" |
| + // BDP-41: every list's plan column. |
| + billCopyColPlan = "Plan" |
| + // BDP-42: the paying list and the accounts page. |
| + billCopyColEarns = "Earns a month" |
| + // BDP-43: the paying list and the accounts page; the estimate label sits beside it. |
| + billCopyColCosts = "Costs a month" |
| + // BDP-44: the paying list and the accounts page. |
| + billCopyColMargin = "Margin" |
| + // BDP-45: the paying list. |
| + billCopyColRenews = "Renews" |
| + // BDP-46: the paying list, recent payments and the payments page. |
| + billCopyColStatus = "Status" |
| + // BDP-47: the paying list's status, and a payment's status. |
| + billCopyStatusPaid = "Paid" |
| + // BDP-48: the paying list's status. |
| + billCopyStatusCancels = "Cancels at renewal" |
| + // BDP-49: the paying list's status. |
| + billCopyStatusFailing = "Payment failing" |
| + // BDP-50: under the account name in the paying list. |
| + billCopyPayingSince = "paying since %s" |
| + // BDP-51: under the paying list. |
| + billCopyPayingListNote = "The 5 newest, with %s's figures. Earnings are the yearly price ÷ 12 plus once-off payments less refunds, before tax. Costs are estimates from Economics." |
| + // BDP-52: in place of the paying list; also the accounts page's Paying tab. |
| + billCopyPayingEmpty = "No account pays yet." |
| +) |
| + |
| +// Overview: earned this month. |
| +const ( |
| + // BDP-53: the earned panel's heading. |
| + billCopyEarnedHeading = "%s so far, earned" |
| + // BDP-54: the earned panel. |
| + billCopyEarnedRecurring = "Recurring (MRR)" |
| + // BDP-55: the earned panel; also the money table's column and the payments page's kind filter. |
| + billCopyOnceOff = "Once-off" |
| + // BDP-56: the earned panel; also the money table's column and the payments page's kind filter. |
| + billCopyRefunds = "Refunds" |
| + // BDP-57: the earned panel; the cost basis label (Plan 3's C1) sits beside it. |
| + billCopyEarnedAWS = "AWS bill (month to date)" |
| + // BDP-58: the earned panel's last line. |
| + billCopyEarnedProfit = "Profit" |
| + // BDP-59: under the earned panel. |
| + billCopyEarnedNote = "The steady view: yearly payments spread across the year and counted to today, before tax." |
| +) |
| + |
| +// Overview: sign-up to paying. |
| +const ( |
| + // BDP-60: beside the earned panel. |
| + billCopyFunnelHeading = "From sign-up to paying" |
| + // BDP-61: the funnel. |
| + billCopyFunnelSignedUp = "Signed up" |
| + // BDP-62: the funnel. |
| + billCopyFunnelMadeApp = "Made an app" |
| + // BDP-63: the funnel. |
| + billCopyFunnelActive = "Active, last 30 days" |
| + // BDP-64: the funnel; also the accounts page's first tab. |
| + billCopyFunnelPaying = "Paying" |
| +) |
| + |
| +// Overview: money received by month. |
| +const ( |
| + // BDP-65: the money table. |
| + billCopyMoneyHeading = "Money received, by month" |
| + // BDP-66: the money table; also the payments page's month filter label. |
| + billCopyColMonth = "Month" |
| + // BDP-67: the money table; also the payments page's kind filter. |
| + billCopyColSubscriptions = "Subscriptions" |
| + // BDP-68: the money table. |
| + billCopyColTax = "Tax" |
| + // BDP-69: the money table. |
| + billCopyColFees = "Stripe fees" |
| + // BDP-70: the money table. |
| + billCopyColNet = "Net received" |
| + // BDP-71: the money table. |
| + billCopyColAWS = "AWS bill" |
| + // BDP-72: the money table. |
| + billCopyColCash = "Cash after costs" |
| + // BDP-73: the money table's first row. |
| + billCopyMonthSoFar = "%s so far" |
| + // BDP-74: under the money table. |
| + billCopyMoneyNote = "Straight from Stripe: what customers paid before tax, what was refunded and what Stripe kept. Tax is shown on its own and never counts as revenue." |
| +) |
| + |
| +// Overview: recent payments. |
| +const ( |
| + // BDP-75: the recent payments list. |
| + billCopyRecentHeading = "Recent payments" |
| + // BDP-76: beside the heading. |
| + billCopyAllPayments = "All payments" |
| + // BDP-77: recent payments and the payments page. |
| + billCopyColWhen = "When" |
| + // BDP-78: recent payments and the payments page. |
| + billCopyColWhat = "What" |
| + // BDP-79: recent payments. |
| + billCopyColAmount = "Amount" |
| + // BDP-80: after the plan's name, like Personal, first year. |
| + billCopyWhatFirst = "first year" |
| + // BDP-81: after the plan's name. |
| + billCopyWhatRenewal = "renewal" |
| + // BDP-82: after the plan's name. |
| + billCopyWhatChange = "plan change" |
| + // BDP-83: a domain payment; the domain follows after a comma. |
| + billCopyWhatDomain = "Domain" |
| + // BDP-84: a once-off payment with no plan or domain. |
| + billCopyWhatOnceOff = "Once-off payment" |
| + // BDP-85: a refund. |
| + billCopyWhatRefund = "Refund" |
| + // BDP-86: a refund that failed and came back. |
| + billCopyWhatReversed = "Refund reversed" |
| + // BDP-87: a charge that succeeded and later failed, like a returned bank debit. |
| + billCopyWhatReturned = "Payment returned" |
| + // BDP-88: a payment's status. |
| + billCopyStatusRefunded = "Refunded" |
| + // BDP-89: a payment's status; also the payments page's kind filter. |
| + billCopyStatusUnmatched = "Unmatched" |
| + // BDP-90: the account cell of a payment whose account is deleted. |
| + billCopyDeletedAccount = "Deleted account" |
| + // BDP-91: in place of recent payments; also the payments page with no filter. |
| + billCopyPaymentsEmpty = "No payments yet." |
| +) |
| + |
| +// Overview: new paying accounts by week. |
| +const ( |
| + // BDP-92: the weekly chart. |
| + billCopyWeeklyHeading = "New paying accounts, by week" |
| + // BDP-93: the chart axis's last label; the first is the date the first week starts, like 18 Aug. |
| + billCopyChartThisWeek = "This week" |
| + // BDP-94: the chart's hidden table caption. |
| + billCopyWeeklyTableCaption = "New paying accounts each week, last 12 weeks" |
| + // BDP-95: the chart's hidden table. |
| + billCopyWeeklyTableWeek = "Week starting" |
| + // BDP-96: the chart's hidden table. |
| + billCopyWeeklyTableCount = "New paying accounts" |
| +) |
| + |
| +// Overview: not paying, by reason. |
| +const ( |
| + // BDP-97: the reasons table. |
| + billCopyReasonsHeading = "Not paying, by reason" |
| + // BDP-98: beside the heading. |
| + billCopyAllAccounts = "All accounts" |
| + // BDP-99: the reasons table. |
| + billCopyColWhy = "Why" |
| + // BDP-100: the reasons table; also the accounts page's title. |
| + billCopyAccounts = "Accounts" |
| + // BDP-101: the reasons table and the free accounts list. |
| + billCopyColCostToRun = "Cost to run, %s" |
| + // BDP-102: the reasons table. |
| + billCopyColCostliest = "Costliest" |
| + // BDP-103: the reasons table. |
| + billCopyReasonFree = "Free plan" |
| + // BDP-104: the reasons table. |
| + billCopyReasonSponsored = "Sponsored" |
| + // BDP-105: the reasons table. |
| + billCopyReasonHouse = "House (free by arrangement)" |
| + // BDP-106: the reasons table. |
| + billCopyReasonOurs = "Ours (ops)" |
| + // BDP-107: the reasons table's last row. |
| + billCopyReasonShared = "Shared and idle" |
| + // BDP-108: under the reasons table. |
| + billCopyReasonsNote = "Shared and idle is the AWS bill less every account's estimated cost: idle boxes and shared overhead." |
| +) |
| + |
| +// Overview: free accounts closest to their limits. |
| +const ( |
| + // BDP-109: the limits list. |
| + billCopyLimitsHeading = "Free accounts closest to their limits" |
| + // BDP-110: beside the heading. |
| + billCopyAllFree = "All free accounts" |
| + // BDP-111: the limits list. |
| + billCopyColNearestLimit = "Nearest limit" |
| + // BDP-112: the limits list. |
| + billCopyColUsed = "Used" |
| + // BDP-113: the limits list's used cell. |
| + billCopyUsedOf = "%s of %s" |
| + // BDP-114: under the limits list. |
| + billCopyLimitsNote = "The accounts most likely to upgrade next." |
| + // BDP-115: in place of the limits list. |
| + billCopyLimitsEmpty = "No free account is close to a limit." |
| +) |
| + |
| +// Accounts page. |
| +const ( |
| + // BDP-116: the accounts page's subhead (its h1 reuses the reasons table's Accounts row). |
| + billCopyAccountsSub = "What each account earns and costs a month." |
| + // BDP-117: above or under the accounts list. |
| + billCopyAccountsMonthNote = "Figures are for %s, the last complete month. Costs are estimates from Economics." |
| + // BDP-118: the tabs' screen-reader label. |
| + billCopyTabsLabel = "Group" |
| + // BDP-119: the accounts tabs (the Paying tab uses Paying, above). |
| + billCopyTabFree = "Free" |
| + // BDP-120: the accounts tabs. |
| + billCopyTabSponsored = "Sponsored" |
| + // BDP-121: the accounts tabs. |
| + billCopyTabHouse = "House" |
| + // BDP-122: the accounts tabs. |
| + billCopyTabOurs = "Ours" |
| + // BDP-123: the accounts list. |
| + billCopyColApps = "Apps" |
| + // BDP-124: the accounts list. |
| + billCopyColJoined = "Joined" |
| + // BDP-125: before the sort choices. |
| + billCopySortBy = "Sort by" |
| + // BDP-126: a sort choice. |
| + billCopySortEarnings = "Earnings" |
| + // BDP-127: a sort choice (the default). |
| + billCopySortCosts = "Costs" |
| + // BDP-128: a sort choice. |
| + billCopySortMargin = "Margin" |
| + // BDP-129: a sort choice. |
| + billCopySortNewest = "Newest" |
| + // BDP-130: a sort choice. |
| + billCopySortLimit = "Closest to a limit" |
| + // BDP-131: above the list when the chosen sort's column is not available. |
| + billCopySortFallback = "Sorted by newest instead. %s" |
| + // BDP-132: the Free tab with no rows. |
| + billCopyFreeEmpty = "No account is on the free plan." |
| + // BDP-133: the Sponsored tab with no rows. |
| + billCopySponsoredEmpty = "No account is sponsored." |
| + // BDP-134: the House tab with no rows. |
| + billCopyHouseEmpty = "No account is free by arrangement." |
| + // BDP-135: the Ours tab with no rows. |
| + billCopyOursEmpty = "There is no operations account." |
| +) |
| + |
| +// Payments page. |
| +const ( |
| + // BDP-136: the payments page's h1. |
| + billCopyPaymentsTitle = "Payments" |
| + // BDP-137: the payments page's subhead. |
| + billCopyPaymentsSub = "Every payment Stripe has taken or paid back, newest first." |
| + // BDP-138: the month filter's first choice. |
| + billCopyAllMonths = "All months" |
| + // BDP-139: the kind filter's label. |
| + billCopyKindLabel = "Kind" |
| + // BDP-140: the kind filter's first choice. |
| + billCopyAllKinds = "All kinds" |
| + // BDP-141: the payments list. |
| + billCopyColCharged = "Charged" |
| + // BDP-142: the payments list. |
| + billCopyColNetEUR = "Net in euros" |
| + // BDP-143: the payments list. |
| + billCopyColFee = "Fee" |
| + // BDP-144: in place of the list when a month or kind is chosen. |
| + billCopyPaymentsNoMatch = "No payments match these filters." |
| +) |
| + |
| +// Dashboard tile. |
| +const ( |
| + // BDP-145: opdashboard.go's extra tile (the text lives in opbilling_copy.go). |
| + billCopyDashTile = "Paying accounts" |
| + // BDP-146: under the tile's count. |
| + billCopyDashTileNote = "%s a year" |
| + // BDP-147: after the note. |
| + billCopyDashTileLink = "Billing" |
| + // BDP-148: after the note, only in test mode. |
| + billCopyDashTileTestMode = "Stripe test mode" |
| + // BDP-149: overview and accounts page, under the plan name. |
| + billCopySeats = "%s seats" |
| + // BDP-150: overview and accounts page, under the plan name, after BDP-149 joined by a comma. |
| + billCopyPacks = "%s packs" |
| +) |
diff --git a/internal/console/opbilling_test.go b/internal/console/opbilling_test.go| new file mode 100644 |
| index 000000000..c53faf04d |
| --- /dev/null |
| +++ b/internal/console/opbilling_test.go |
| @@ -0,0 +1,89 @@ |
| +package console |
| + |
| +import ( |
| + "fmt" |
| + "html" |
| + "net/http" |
| + "net/url" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// opBillingRoutes is the three billing pages and the <h1> each carries. |
| +var opBillingRoutes = []struct{ Path, H1 string }{ |
| + {"/fleet/billing", billCopyRail}, |
| + {"/fleet/billing/accounts", billCopyAccounts}, |
| + {"/fleet/billing/payments", billCopyPaymentsTitle}, |
| +} |
| + |
| +// missingRoute is what the console answers for a route it does not have. |
| +func missingRoute(t *testing.T, fx *consoleFixture, c *http.Client) (int, string) { |
| + t.Helper() |
| + status, _, body := get(t, c, fx.ts.URL+"/fleet/no-such") |
| + if status != http.StatusNotFound { |
| + t.Fatalf("sanity: /fleet/no-such = %d", status) |
| + } |
| + return status, body |
| +} |
| + |
| +// assertBillingRoutesMissing holds when every billing route, GET and POST, |
| +// answers exactly what a missing route answers. |
| +func assertBillingRoutesMissing(t *testing.T, fx *consoleFixture, c *http.Client, who string) { |
| + t.Helper() |
| + ghostStatus, ghost := missingRoute(t, fx, c) |
| + for _, r := range opBillingRoutes { |
| + if st, _, body := get(t, c, fx.ts.URL+r.Path); st != ghostStatus || body != ghost { |
| + t.Errorf("GET %s %s = %d %q, want the missing-route 404", r.Path, who, st, body) |
| + } |
| + if st, _, body := postForm(t, c, fx.ts.URL+r.Path, url.Values{}); st != ghostStatus || body != ghost { |
| + t.Errorf("POST %s %s = %d %q, want the missing-route 404", r.Path, who, st, body) |
| + } |
| + } |
| +} |
| + |
| +func TestBillingRoutesHiddenWhenOff(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInOperator(t, fx) |
| + if fx.srv.billing != nil { |
| + t.Fatal("sanity: the fixture has billing on") |
| + } |
| + assertBillingRoutesMissing(t, fx, c, "operator, billing off") |
| +} |
| + |
| +func TestBillingRoutesOperatorOnly(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + enableBilling(t, fx.srv) |
| + assertBillingRoutesMissing(t, fx, signInPaul(t, fx), "member, billing on") |
| + assertBillingRoutesMissing(t, fx, newBrowser(t), "signed out, billing on") |
| +} |
| + |
| +func TestBillingRoutesRender(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + enableBilling(t, fx.srv) |
| + c := signInOperator(t, fx) |
| + testLine := html.EscapeString(billCopyTestMode) |
| + subs := map[string]string{ |
| + "/fleet/billing": fmt.Sprintf(billCopyOverviewSub, fx.srv.brandName()), |
| + "/fleet/billing/accounts": billCopyAccountsSub, |
| + "/fleet/billing/payments": billCopyPaymentsSub, |
| + } |
| + for _, live := range []bool{false, true} { |
| + fx.srv.billing.cfg.LiveMode = live |
| + for _, r := range opBillingRoutes { |
| + status, _, body := get(t, c, fx.ts.URL+r.Path) |
| + if status != http.StatusOK { |
| + t.Errorf("%s (live %v) = %d, want 200", r.Path, live, status) |
| + continue |
| + } |
| + if !strings.Contains(body, "<h1>"+html.EscapeString(r.H1)+"</h1>") { |
| + t.Errorf("%s: no <h1>%s</h1>", r.Path, r.H1) |
| + } |
| + if want := "<p rst-page-header-sub>" + html.EscapeString(subs[r.Path]) + "</p>"; !strings.Contains(body, want) { |
| + t.Errorf("%s: lacks the subhead %s", r.Path, want) |
| + } |
| + if got := strings.Contains(body, testLine); got == live { |
| + t.Errorf("%s (live %v): shows the test-mode line = %v", r.Path, live, got) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/console/opperson_test.go b/internal/console/opperson_test.go| index ebfd1400d..ef1c5caf7 100644 |
| --- a/internal/console/opperson_test.go |
| +++ b/internal/console/opperson_test.go |
| @@ -62,7 +62,7 @@ func TestPersonPageIsOperatorOnly(t *testing.T) { |
| } |
| // The operator sees the page, in the shell, under People and accounts. |
| body := personGet(t, fx, w.c, "ann@example.com") |
| - assertOpShell(t, "/fleet/people/ann@example.com", body) |
| + assertOpShell(t, "/fleet/people/ann@example.com", body, false) |
| } |
| // TestPersonPageUnknownAddressWritesNothing: an address with no users row |
diff --git a/internal/console/opshell.go b/internal/console/opshell.go| index 0cf2b8282..726aa2b09 100644 |
| --- a/internal/console/opshell.go |
| +++ b/internal/console/opshell.go |
| @@ -13,22 +13,28 @@ import "net/http" |
| // opShell is what the shell needs to know about the page it frames. Rail is |
| // the current rail item's key ("" on the index); View is "page" or "index"; |
| -// Up is the back control's target on a phone. |
| +// Up is the back control's target on a phone. Billing is whether this |
| +// console has billing on. |
| type opShell struct { |
| Rail, View, Up string |
| StoreOperator bool |
| + Billing bool |
| } |
| // opRailItem is one link in the rail. StoreOnly items show only to a store |
| // operator (Config.StoreOperators), since their page refuses everyone else. |
| +// BillingOnly items show only on a console with billing on: without it |
| +// their pages answer as a missing route does (opbilling.go). |
| type opRailItem struct { |
| Key, Href, Label string |
| StoreOnly bool |
| + BillingOnly bool |
| } |
| // opRail is the rail, top to bottom. Each label is also its page's <h1>. |
| var opRail = []opRailItem{ |
| {Key: "dashboard", Href: "/fleet", Label: "Dashboard"}, |
| + {Key: "billing", Href: "/fleet/billing", Label: billCopyRail, BillingOnly: true}, |
| {Key: "people", Href: "/fleet/people", Label: "People and accounts"}, |
| {Key: "activity", Href: "/fleet/activity", Label: "Activity"}, |
| {Key: "boxes", Href: "/fleet/boxes", Label: "Boxes"}, |
| @@ -44,13 +50,17 @@ var opRail = []opRailItem{ |
| const opIndexTitle = "Operator pages" |
| // opRailFor is the rail op's viewer sees: StoreOnly items only for a store |
| -// operator. It is the template func opRail. |
| +// operator, BillingOnly items only with billing on. It is the template func |
| +// opRail. |
| func opRailFor(op *opShell) []opRailItem { |
| out := make([]opRailItem, 0, len(opRail)) |
| for _, it := range opRail { |
| if it.StoreOnly && (op == nil || !op.StoreOperator) { |
| continue |
| } |
| + if it.BillingOnly && (op == nil || !op.Billing) { |
| + continue |
| + } |
| out = append(out, it) |
| } |
| return out |
| @@ -78,6 +88,7 @@ func (s *Server) opPage(addr, raw, rail string) page { |
| View: "page", |
| Up: "/fleet/index#nav-" + rail, |
| StoreOperator: s.storeOperator(addr), |
| + Billing: s.billing != nil, |
| }, |
| } |
| } |
diff --git a/internal/console/opshell_test.go b/internal/console/opshell_test.go| index 3127886d3..13dd2b121 100644 |
| --- a/internal/console/opshell_test.go |
| +++ b/internal/console/opshell_test.go |
| @@ -95,8 +95,9 @@ func opNavLinks(t *testing.T, body string) []opNavLinkSeen { |
| } |
| // assertOpShell holds for every operator page in the shell, seen by a store |
| -// operator. |
| -func assertOpShell(t *testing.T, path, body string) { |
| +// operator on a console with billing on or off: the rail is opRailFor with |
| +// those flags. |
| +func assertOpShell(t *testing.T, path, body string, billing bool) { |
| t.Helper() |
| view := "page" |
| if path == "/fleet/index" { |
| @@ -123,7 +124,7 @@ func assertOpShell(t *testing.T, path, body string) { |
| } |
| } |
| } |
| - for _, it := range opRail { |
| + for _, it := range opRailFor(&opShell{StoreOperator: true, Billing: billing}) { |
| want = append(want, it.Href) |
| } |
| if !slices.Equal(hrefs, want) { |
| @@ -168,17 +169,103 @@ func TestEveryOperatorPageRendersInTheShell(t *testing.T) { |
| } |
| seen++ |
| status, _, body := get(t, c, fx.ts.URL+path) |
| + // The fixture has billing off, so the billing pages answer the |
| + // missing-route 404 (TestBillingRoutesHiddenWhenOff holds the body). |
| + if opBillingPath(path) { |
| + if status != http.StatusNotFound { |
| + t.Errorf("%s = %d with billing off, want 404", path, status) |
| + } |
| + continue |
| + } |
| if status != http.StatusOK { |
| t.Errorf("%s = %d, want 200", path, status) |
| continue |
| } |
| - assertOpShell(t, path, body) |
| + assertOpShell(t, path, body, false) |
| } |
| if seen < 2 { |
| t.Fatalf("checked %d operator pages; /fleet/index and /fleet/store at least", seen) |
| } |
| } |
| +// opBillingPath reports whether path is one of the billing pages, which a |
| +// console has only with billing on. |
| +func opBillingPath(path string) bool { |
| + return path == "/fleet/billing" || strings.HasPrefix(path, "/fleet/billing/") |
| +} |
| + |
| +// With billing on, every billing page renders in the shell, its rail |
| +// carrying the Billing item, current. |
| +func TestEveryBillingPageRendersInTheShell(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + enableBilling(t, fx.srv) |
| + c := signInOperator(t, fx) |
| + seen := 0 |
| + for _, path := range operatorScreens(fx) { |
| + if !opBillingPath(path) { |
| + continue |
| + } |
| + seen++ |
| + status, _, body := get(t, c, fx.ts.URL+path) |
| + if status != http.StatusOK { |
| + t.Errorf("%s = %d, want 200", path, status) |
| + continue |
| + } |
| + assertOpShell(t, path, body, true) |
| + if want := `<a id="nav-billing" href="/fleet/billing" aria-current="page">` + billCopyRail + `</a>`; !strings.Contains(body, want) { |
| + t.Errorf("%s: the rail lacks %s", path, want) |
| + } |
| + } |
| + if seen != 3 { |
| + t.Fatalf("checked %d billing pages, want 3", seen) |
| + } |
| +} |
| + |
| +// The rail's Billing item: second, directly under Dashboard, when the page's |
| +// shell says billing is on; absent otherwise. /fleet/index's rail likewise. |
| +func TestOpRailBillingGate(t *testing.T) { |
| + keys := func(items []opRailItem) []string { |
| + var out []string |
| + for _, it := range items { |
| + out = append(out, it.Key) |
| + } |
| + return out |
| + } |
| + on := keys(opRailFor(&opShell{Billing: true})) |
| + if len(on) < 2 || on[0] != "dashboard" || on[1] != "billing" { |
| + t.Errorf("billing on: rail %q, want billing second", on) |
| + } |
| + for _, op := range []*opShell{nil, {}, {StoreOperator: true}} { |
| + if got := keys(opRailFor(op)); slices.Contains(got, "billing") { |
| + t.Errorf("billing off (%+v): rail %q holds billing", op, got) |
| + } |
| + } |
| + if got := opRailLabel("billing"); got != billCopyRail { |
| + t.Errorf("opRailLabel(billing) = %q, want %q", got, billCopyRail) |
| + } |
| + |
| + fx := newConsoleFixture(t) |
| + c := signInOperator(t, fx) |
| + _, _, body := get(t, c, fx.ts.URL+"/fleet/index") |
| + if links := opNavKeys(opNavLinks(t, body)); slices.Contains(links, "billing") { |
| + t.Errorf("/fleet/index with billing off: rail %q holds billing", links) |
| + } |
| + enableBilling(t, fx.srv) |
| + _, _, body = get(t, c, fx.ts.URL+"/fleet/index") |
| + if links := opNavKeys(opNavLinks(t, body)); len(links) < 2 || links[1] != "billing" { |
| + t.Errorf("/fleet/index with billing on: rail %q, want billing second", links) |
| + } |
| +} |
| + |
| +// opNavKeys is the keys of the rail links seen on a page. |
| +func opNavKeys(links []opNavLinkSeen) []string { |
| + var out []string |
| + for _, l := range links { |
| + out = append(out, l.Key) |
| + } |
| + return out |
| +} |
| + |
| func TestOperatorShellPendingShrinks(t *testing.T) { |
| if len(opShellPending) != 0 { |
| t.Errorf("opShellPending holds %d screens; every operator page is in the shell", len(opShellPending)) |
diff --git a/internal/console/perfwalk_test.go b/internal/console/perfwalk_test.go| index 3b88a02ae..ccf86426e 100644 |
| --- a/internal/console/perfwalk_test.go |
| +++ b/internal/console/perfwalk_test.go |
| @@ -517,6 +517,11 @@ func perfTargets(fx *consoleFixture) map[string][]perfTarget { |
| } |
| // GET /upgrade has no parameter but is gated the same way (billingpage.go). |
| m["GET /upgrade"] = []perfTarget{{Path: "/upgrade", Expect: http.StatusNotFound}} |
| + // The operator billing pages answer the missing-route 404 with billing |
| + // off, after operatorOnly and before any read (opbilling.go). |
| + for _, p := range []string{"/fleet/billing", "/fleet/billing/accounts", "/fleet/billing/payments"} { |
| + m[p] = []perfTarget{{Path: p, Expect: http.StatusNotFound}} |
| + } |
| // The walk also leaves domain buying unconfigured. All three pages |
| // answer domainBuyBrowserGate's 404 before any purchase or provider read. |
| for _, p := range []string{"buy", "purchases/{id}", "purchases/{id}/status"} { |
diff --git a/internal/console/server.go b/internal/console/server.go| index a8796e5ac..a5373ffcf 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -227,6 +227,8 @@ var templates = template.Must(template.New("").Funcs(template.FuncMap{ |
| // template. |
| "opRail": opRailFor, |
| "opnum": opNumber, |
| + // opBillingTestMode is the billing pages' test-mode line (opbilling.go). |
| + "opBillingTestMode": opBillingTestModeText, |
| // opWhat is how an audit row's Detail shows on the operator pages, and |
| // auditText its words alone for the customer console (auditdetail.go). |
| "opWhat": auditWhatOf, |
| @@ -2012,6 +2014,13 @@ func NewServer(cfg Config, st *Store) (*Server, error) { |
| // Account tier (economics-v2, Task 4): same bare-registration/method- |
| // first reasoning as the two doors above. |
| s.registerRoute("/fleet/economics/tier", s.handleEconomicsTierSave) |
| + // The operator Billing pages (opbilling.go). Registered on every console |
| + // and WITHOUT a method prefix, for the reason above: with billing off, a |
| + // wrong method, or anyone but an operator, billingPageGate answers the |
| + // missing-route 404 itself. |
| + s.registerRoute("/fleet/billing", s.handleOpBilling) |
| + s.registerRoute("/fleet/billing/accounts", s.handleOpBillingAccounts) |
| + s.registerRoute("/fleet/billing/payments", s.handleOpBillingPayments) |
| // CLI identity: the device-code login `carlos auth login` drives, the |
| // approval page, and the tokens an owner can see and kill (authcli.go). |
| // The db door's production replica reader (apidb.go); tests repoint it. |
| @@ -2787,6 +2796,12 @@ type page struct { |
| EconTabs opTabs |
| EconBar opListBar |
| + // The operator Billing pages (opbilling.go): the overview, the accounts |
| + // list and the payments list. Each is nil on every other page. |
| + OpBilling *opBillingView |
| + OpBillingAccounts *opBillingAccountsView |
| + OpBillingPayments *opBillingPaymentsView |
| + |
| // App page, "Resources": this app's OWN instances' unit readings (Task |
| // 12), one row per route host. Nil renders no section at all — metrics |
| // are decoration on this page and must never be the reason it fails. |
diff --git a/internal/console/templates/ops_billing.html b/internal/console/templates/ops_billing.html| new file mode 100644 |
| index 000000000..f048c3966 |
| --- /dev/null |
| +++ b/internal/console/templates/ops_billing.html |
| @@ -0,0 +1,12 @@ |
| +{{/* Billing (/fleet/billing, opbilling.go): the overview. Every word comes |
| + from opbilling_copy.go through .OpBilling. */}} |
| +{{define "ops_billing"}}{{template "op_top" .}} |
| +{{template "op_billing_head" .OpBilling}} |
| +{{template "op_bottom" .}}{{end}} |
| + |
| +{{/* op_billing_head is every billing page's header: the page header and, |
| + on a console on Stripe's test mode, the line saying so. Its data is a |
| + billing view (.Header, .TestMode). */}} |
| +{{define "op_billing_head"}}{{template "op_page_header" .Header}} |
| +{{if .TestMode}}<div rst-callout rst-tone="info"><span rst-callout-ic aria-hidden="true">{{icon "info"}}</span><div rst-callout-body><p>{{opBillingTestMode}}</p></div></div> |
| +{{end}}{{end}} |
diff --git a/internal/console/templates/ops_billing_accounts.html b/internal/console/templates/ops_billing_accounts.html| new file mode 100644 |
| index 000000000..c2232f674 |
| --- /dev/null |
| +++ b/internal/console/templates/ops_billing_accounts.html |
| @@ -0,0 +1,6 @@ |
| +{{/* Accounts (/fleet/billing/accounts, opbilling.go): what each account |
| + earns and costs. Every word comes from opbilling_copy.go through |
| + .OpBillingAccounts. */}} |
| +{{define "ops_billing_accounts"}}{{template "op_top" .}} |
| +{{template "op_billing_head" .OpBillingAccounts}} |
| +{{template "op_bottom" .}}{{end}} |
diff --git a/internal/console/templates/ops_billing_payments.html b/internal/console/templates/ops_billing_payments.html| new file mode 100644 |
| index 000000000..7438bd33a |
| --- /dev/null |
| +++ b/internal/console/templates/ops_billing_payments.html |
| @@ -0,0 +1,6 @@ |
| +{{/* Payments (/fleet/billing/payments, opbilling.go): every payment, newest |
| + first. Every word comes from opbilling_copy.go through |
| + .OpBillingPayments. */}} |
| +{{define "ops_billing_payments"}}{{template "op_top" .}} |
| +{{template "op_billing_head" .OpBillingPayments}} |
| +{{template "op_bottom" .}}{{end}} |
diff --git a/internal/provision/billing_dashboard_2_census_test.go b/internal/provision/billing_dashboard_2_census_test.go| new file mode 100644 |
| index 000000000..da61f9619 |
| --- /dev/null |
| +++ b/internal/provision/billing_dashboard_2_census_test.go |
| @@ -0,0 +1,27 @@ |
| +package provision |
| + |
| +// billingDashboard2WriteCensusInventory is the billing dashboard plan 2 |
| +// review of the record-write census, layered on Plan 1's |
| +// billingDashboard1WriteCensusInventory. NewServer keeps its key site; its |
| +// one change is three registerRoute calls for the operator Billing pages |
| +// (/fleet/billing and its accounts and payments lists), whose handlers |
| +// (opbilling.go) write no record. Its kinds and class are unchanged; only |
| +// the digest moves. |
| +func billingDashboard2WriteCensusInventory() []censusEntry { |
| + entries := append([]censusEntry(nil), billingDashboard1WriteCensusInventory()...) |
| + reviewed := []censusEntry{ |
| + {"internal/console/server.go", "NewServer", "key-site", "lit:instances", "989405ba6eca3a7d7d9548c64763cc58da40aeafc523b6fea44cc46323bc220d"}, |
| + } |
| + for _, r := range reviewed { |
| + found := false |
| + for i, e := range entries { |
| + if e.File == r.File && e.Unit == r.Unit { |
| + entries[i], found = r, true |
| + } |
| + } |
| + if !found { |
| + panic("billing-dash-2 replacement of an unlisted unit " + r.File + ":" + r.Unit) |
| + } |
| + } |
| + return entries |
| +} |
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go| index c939a79db..43ec0543e 100644 |
| --- a/internal/provision/plan9_b8_census_test.go |
| +++ b/internal/provision/plan9_b8_census_test.go |
| @@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) { |
| if len(got) < 100 { |
| t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root) |
| } |
| - inventory := billingDashboard1WriteCensusInventory() |
| + inventory := billingDashboard2WriteCensusInventory() |
| problems := append(censusDiff(inventory, got), censusPolicy(inventory)...) |
| if len(problems) > 0 { |
| t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n ")) |
diff --git a/internal/provision/testdata/plan14-root-reads-billing-dash-2-pages.tsv b/internal/provision/testdata/plan14-root-reads-billing-dash-2-pages.tsv| new file mode 100644 |
| index 000000000..68549a3d9 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-billing-dash-2-pages.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay billing-dash-2-pages, written by census-propose (#369). census-ruling-billing-dash-2-pages, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-billing-dash-2-pages.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage . e071abca4d68a64cfe933fce55da8e0bfa44718c6aaa8ba3062756529d30e7f0 |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 6cdf860b4..4e21afd68 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -138,3 +138,4 @@ plan14-root-reads-gvisor-demos.tsv f05716181a82721b38cba9b2d89c47925dc2ca426e5c4 |
| plan14-root-reads-dns-fresh-lookup-724.tsv 7ac2bde8301c37c7546e9aa19d375f1468fc8061876a618fa8f93dd4543c5652 |
| plan14-root-reads-billing-dashboard-1.tsv 7ac2bde8301c37c7546e9aa19d375f1468fc8061876a618fa8f93dd4543c5652 |
| plan14-root-reads-billing-dash-3-cost.tsv 7ac2bde8301c37c7546e9aa19d375f1468fc8061876a618fa8f93dd4543c5652 |
| +plan14-root-reads-billing-dash-2-pages.tsv 7ac2bde8301c37c7546e9aa19d375f1468fc8061876a618fa8f93dd4543c5652 |