economics page: say what the AWS bill covers
The bill table heading now carries the cost-basis label after the source (C1 or C2), and a co-note under the table carries the hint (C3 or C7) when the bill does not count as CARLOS cost. EconomicsView gains BillBasisLabels and BillBasisHints, keyed by month, filled from effectiveBillBasis/costBasisLabel/costBasisHint under the console's CostScope. The bill-entry form and its "No bill on file" note are untouched (Task 4 rebuilds them).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+75
−1
internal/console/economicspage_test.go+54 −0internal/console/economicsview.go+19 −0internal/console/templates/economics.html+2 −1
CI passed — run details
diff --git a/internal/console/economicspage_test.go b/internal/console/economicspage_test.go| index c4ab7cb85..b7217c6ed 100644 |
| --- a/internal/console/economicspage_test.go |
| +++ b/internal/console/economicspage_test.go |
| @@ -949,3 +949,57 @@ func TestEconomicsAccountsPageTierFormOnlyForConsoleRows(t *testing.T) { |
| t.Fatalf("console-row account %q (untiered) row must still render the tier-set form:\n%s", fixtureAcct, fixtureRow) |
| } |
| } |
| + |
| +// TestEconomicsPageShowsBillBasis: the bill table says what the AWS bill |
| +// covers. An unstated bill on a console declared CARLOS-only reads "CARLOS |
| +// only" with no hint; under the zero scope it reads "not only CARLOS" and |
| +// the hint says how to declare the account. The bill is this month's: the |
| +// page reads bills against the real clock (loadRecentBills), so a fixed |
| +// month would fall off it. |
| +func TestEconomicsPageShowsBillBasis(t *testing.T) { |
| + const ( |
| + c1 = "AWS, whole account: CARLOS only" |
| + c2 = "AWS, whole account: not only CARLOS" |
| + c3 = "This bill covers the whole AWS account, which may hold more than CARLOS. If the account runs only CARLOS, set CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true on the console." |
| + ) |
| + month := usage.MonthOf(time.Now().UTC()) |
| + for _, tc := range []struct { |
| + name string |
| + scope CostScope |
| + want, deny []string |
| + }{ |
| + {"account", CostScope{AccountCarlosOnly: true}, []string{c1}, []string{c2, c3}}, |
| + {"zero", CostScope{}, []string{c2, c3}, []string{c1}}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + fx.srv.cfg.CostScope = tc.scope |
| + putStoreJSON(t, fx.rel, economics.BillKey(month), economics.Bill{ |
| + Schema: 1, Month: month, TotalUSD: 12, |
| + Services: map[string]float64{"AmazonEC2": 12}, Source: economics.SourceCostExplorer, |
| + }) |
| + c := signInPaul(t, fx) |
| + if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil { |
| + t.Fatal(err) |
| + } |
| + status, _, body := get(t, c, fx.ts.URL+"/fleet/economics?period=mtd") |
| + if status != 200 { |
| + t.Fatalf("/fleet/economics = %d, want 200:\n%s", status, body) |
| + } |
| + heading := "Bill service (" + month + ", " + economics.SourceCostExplorer + ", " |
| + for _, want := range tc.want { |
| + if !strings.Contains(body, want) { |
| + t.Fatalf("page missing %q in:\n%s", want, body) |
| + } |
| + } |
| + if !strings.Contains(body, heading+costBasisLabel(effectiveBillBasis(economics.Bill{}, tc.scope), "")+")") { |
| + t.Fatalf("bill heading does not carry the label; want prefix %q in:\n%s", heading, body) |
| + } |
| + for _, deny := range tc.deny { |
| + if strings.Contains(body, deny) { |
| + t.Fatalf("page shows %q, want it absent:\n%s", deny, body) |
| + } |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/console/economicsview.go b/internal/console/economicsview.go| index 9cf334bb5..cdcf18fdd 100644 |
| --- a/internal/console/economicsview.go |
| +++ b/internal/console/economicsview.go |
| @@ -98,6 +98,14 @@ type EconomicsView struct { |
| Names map[string]string |
| // Pool is this period's fleet-pool ledger (Task 5) — see PoolLedger. |
| Pool PoolLedger |
| + // BillBasisLabels names what each bill in Bills covers, keyed by |
| + // month (costBasisLabel of the bill's effective basis under the |
| + // console's CostScope). BillBasisHints carries the one-line |
| + // explanation for a bill whose cost does not count as CARLOS cost, |
| + // keyed by month and absent when there is none. Both are shared, |
| + // read-only, like Bills; see copyEconomicsView. |
| + BillBasisLabels map[string]string |
| + BillBasisHints map[string]string |
| } |
| // PoolLedger is one period's fleet-pool revenue-sharing standing: how much |
| @@ -645,6 +653,15 @@ func (s *Server) buildEconomicsView(ctx context.Context, period string) (*Econom |
| if billsErr != nil { |
| return nil, fmt.Errorf("console: load economics: %w", billsErr) |
| } |
| + billBasisLabels := make(map[string]string, len(bills)) |
| + billBasisHints := make(map[string]string, len(bills)) |
| + for _, b := range bills { |
| + basis := effectiveBillBasis(b, s.cfg.CostScope) |
| + billBasisLabels[b.Month] = costBasisLabel(basis, "") |
| + if hint := costBasisHint(s.cfg.CostScope, basis, b.Month); hint != "" { |
| + billBasisHints[b.Month] = hint |
| + } |
| + } |
| payload := economicsPayload{ |
| Scenario: sc, |
| @@ -682,6 +699,8 @@ func (s *Server) buildEconomicsView(ctx context.Context, period string) (*Econom |
| Tiers: tiers, |
| Names: names, |
| Pool: pool, |
| + BillBasisLabels: billBasisLabels, |
| + BillBasisHints: billBasisHints, |
| }, nil |
| } |
diff --git a/internal/console/templates/economics.html b/internal/console/templates/economics.html| index 08259f92c..7fb737a62 100644 |
| --- a/internal/console/templates/economics.html |
| +++ b/internal/console/templates/economics.html |
| @@ -210,7 +210,7 @@ |
| {{$delta := sub $billChecked $modelTotal}} |
| <div rst-card class="co-table-wrap"> |
| <table co-table> |
| - <tr><th>Bill service ({{$curBill.Month}}, {{$curBill.Source}})</th><th>USD</th><th>Counts as CARLOS</th></tr> |
| + <tr><th>Bill service ({{$curBill.Month}}, {{$curBill.Source}}, {{index .Economics.BillBasisLabels $curBill.Month}})</th><th>USD</th><th>Counts as CARLOS</th></tr> |
| {{range $svc, $amt := $curBill.Services}} |
| <tr> |
| <td>{{$svc}}</td> |
| @@ -221,6 +221,7 @@ |
| <tr><th>Bill total (counted)</th><th id="bill-total-checked">{{usd $billChecked}}</th><th></th></tr> |
| </table> |
| </div> |
| +{{with index .Economics.BillBasisHints $curBill.Month}}<p co-note>{{.}}</p>{{end}} |
| <p>Delta, bill minus model: <strong id="breakdown-delta">{{usd $delta}}</strong></p> |
| {{else}} |
| <p co-note>No bill on file for {{periodMonth .Economics.Period}} — enter one manually.</p> |