carlos / platform Public

merge billing-dash-3-cost (Plan 3) into Plan 2

The census chain conflicted on its last line; Plan 3's overlay was
re-proposed on top of Plan 1's with census-propose, as its handoff says.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev aaa1fbdaa4d66b99819110a20eeb529fa1d4d274 parent dc97184parent c1596c4
25 files changed, +961 −47
  • cmd/console/costscope.go +26 −0
  • cmd/console/costscope_test.go +34 −0
  • cmd/console/main.go +7 −0
  • docs/site/cli.md +1 −1
  • docs/superpowers/notes/census-claims-billing-dash-3-cost.tsv +7 −0
  • docs/superpowers/notes/census-proposal-billing-dash-3-cost.md +11 −0
  • economics.go +30 −4
  • economics_test.go +71 −4
  • internal/console/cepull.go +6 −6
  • internal/console/claim_invariant_probes_worker_test.go +1 −1
  • internal/console/costscope.go +34 −0
  • internal/console/economicsbill_test.go +294 −10
  • internal/console/economicspage_test.go +66 −0
  • internal/console/economicspass.go +52 −4
  • internal/console/economicsview.go +29 −0
  • internal/console/platformcost.go +90 −0
  • internal/console/platformcost_test.go +99 −0
  • internal/console/server.go +6 −1
  • internal/console/static/ops.css +6 −2
  • internal/console/templates/economics.html +22 −12
  • internal/economics/bill.go +22 −2
  • internal/economics/bill_test.go +40 −0
  • internal/hostops/storage_classifier_test.go +2 −0
  • internal/provision/testdata/plan14-root-reads-billing-dash-3-cost.tsv +4 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0

CI passed — run details

diff --git a/cmd/console/costscope.go b/cmd/console/costscope.go
new file mode 100644
index 000000000..dde6244e6
--- /dev/null
+++ b/cmd/console/costscope.go
@@ -0,0 +1,26 @@
+package main
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+
+ "github.com/carlosframework/platform/internal/console"
+)
+
+// costScopeFromEnv reads CONSOLE_COST_ACCOUNT_CARLOS_ONLY, the operator's
+// declaration that the deployment's AWS account runs CARLOS and nothing
+// else (console.Config.CostScope). Unset means the zero scope; a value
+// strconv.ParseBool cannot read is an error, and main stops the boot on it,
+// the way domainProof does for CONSOLE_DOMAIN_PROOF.
+func costScopeFromEnv(getenv func(string) string) (console.CostScope, error) {
+ v := strings.TrimSpace(getenv("CONSOLE_COST_ACCOUNT_CARLOS_ONLY"))
+ if v == "" {
+ return console.CostScope{}, nil
+ }
+ b, err := strconv.ParseBool(v)
+ if err != nil {
+ return console.CostScope{}, fmt.Errorf("console: CONSOLE_COST_ACCOUNT_CARLOS_ONLY %q is not a boolean (use true or false)", v)
+ }
+ return console.CostScope{AccountCarlosOnly: b}, nil
+}
diff --git a/cmd/console/costscope_test.go b/cmd/console/costscope_test.go
new file mode 100644
index 000000000..123617bbf
--- /dev/null
+++ b/cmd/console/costscope_test.go
@@ -0,0 +1,34 @@
+package main
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/console"
+)
+
+func TestCostScopeFromEnv(t *testing.T) {
+ env := func(v string) func(string) string {
+ return func(k string) string {
+ if k == "CONSOLE_COST_ACCOUNT_CARLOS_ONLY" {
+ return v
+ }
+ return ""
+ }
+ }
+ got, err := costScopeFromEnv(env(""))
+ if err != nil || got != (console.CostScope{}) {
+ t.Fatalf("unset: got %+v, %v; want zero scope", got, err)
+ }
+ got, err = costScopeFromEnv(env(" true "))
+ if err != nil || !got.AccountCarlosOnly {
+ t.Fatalf("true: got %+v, %v; want AccountCarlosOnly", got, err)
+ }
+ got, err = costScopeFromEnv(env("false"))
+ if err != nil || got.AccountCarlosOnly {
+ t.Fatalf("false: got %+v, %v; want zero scope", got, err)
+ }
+ if _, err := costScopeFromEnv(env("maybe")); err == nil || !strings.Contains(err.Error(), "CONSOLE_COST_ACCOUNT_CARLOS_ONLY") {
+ t.Fatalf("maybe: err = %v, want an error naming CONSOLE_COST_ACCOUNT_CARLOS_ONLY", err)
+ }
+}
diff --git a/cmd/console/main.go b/cmd/console/main.go
index 111f1f64f..8ce8d7810 100644
--- a/cmd/console/main.go
+++ b/cmd/console/main.go
@@ -483,6 +483,10 @@ func serve() {
if err != nil {
log.Fatal(err)
}
+ costScope, err := costScopeFromEnv(os.Getenv)
+ if err != nil {
+ log.Fatal(err)
+ }
cfg := console.Config{
DemoAlerts: demoAlerts,
DemoAPIOrigin: os.Getenv("CONSOLE_DEMO_API_ORIGIN"),
@@ -505,6 +509,9 @@ func serve() {
// The deployment's AWS account id, the trust anchor of the Phase 1
// move door's box identity check (unset: no box verifies).
AWSAccount: strings.TrimSpace(os.Getenv("CARLOS_AWS_ACCOUNT")),
+ // What the operator declares that AWS account holds: the bill pull
+ // stamps each bill's basis from it.
+ CostScope: costScope,
AppRegions: appRegionsSwitch(os.Getenv("CONSOLE_APP_REGIONS")),
// Region HA P1a: hosts created in these regions are born HA.
HARegions: haRegionsList(os.Getenv("CONSOLE_HA_REGIONS")),
diff --git a/docs/site/cli.md b/docs/site/cli.md
index 059e101b2..635420d45 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -2699,7 +2699,7 @@ Records one month's AWS bill so the console's economics dashboard has a real
number to divide by.
```sh
-carlos economics bill --month 2026-08 --total 412.55 --line AmazonEC2=55.00
+carlos economics bill --month 2026-08 --total 412.55 --line AmazonEC2=55.00 --basis account
```
Operator only, and the console answers everyone else with the same bare 404
diff --git a/docs/superpowers/notes/census-claims-billing-dash-3-cost.tsv b/docs/superpowers/notes/census-claims-billing-dash-3-cost.tsv
new file mode 100644
index 000000000..b285c778e
--- /dev/null
+++ b/docs/superpowers/notes/census-claims-billing-dash-3-cost.tsv
@@ -0,0 +1,7 @@
+# Billing dashboard Plan 3 (branch billing-dash-3-cost). One line per changed root-read unit: <file>:<unit><TAB><what changed>.
+# Task 1 changes no unit; it re-pins the internal/economics envelope only, which census-propose takes without a claim. The brief's claim, kept here for the reviewer:
+# internal/economics/bill.go:Bill: one additive string field and two consts; no read added
+# Task 4 changes no unit; it re-pins the root (.) envelope only. The brief's claims, kept here for the reviewer:
+# economics.go:economicsBill: request gains optional basis; no read added
+# economics.go:runEconomicsBill: request gains optional basis; no read added
+# economics.go:economicsBillResult: request gains optional basis; no read added
diff --git a/docs/superpowers/notes/census-proposal-billing-dash-3-cost.md b/docs/superpowers/notes/census-proposal-billing-dash-3-cost.md
new file mode 100644
index 000000000..073ad7bd1
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-billing-dash-3-cost.md
@@ -0,0 +1,11 @@
+# Census approval: billing-dash-3-cost
+
+Ruling `census-ruling-billing-dash-3-cost`. 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: `.`, `internal/economics`.
+
+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-3-cost.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/economics.go b/economics.go
index 2129431bb..67facaa99 100644
--- a/economics.go
+++ b/economics.go
@@ -28,7 +28,7 @@ import (
"time"
)
-const economicsUsage = `usage: carlos economics bill --month <YYYY-MM> --total <usd> [--line Service=usd ...] [--console <origin>]
+const economicsUsage = `usage: carlos economics bill --month <YYYY-MM> --total <usd> [--line Service=usd ...] [--basis account|whole] [--console <origin>]
carlos economics backhaul [--period mtd|last|7d] [--console <origin>]
Records one month's AWS bill for the economics dashboard. Operator only: the
@@ -40,6 +40,18 @@ A manual entry always overwrites whatever the console already holds for that
month — a previous Cost Explorer pull or an earlier manual entry alike.
`
+// validBillBasis accepts what --basis may say: account, whole, or nothing
+// (the console then stamps the bill from its own CostScope). It is checked
+// here so a typo stops before any request is built; the console refuses
+// the same values with the same words.
+func validBillBasis(s string) error {
+ switch s {
+ case "", "account", "whole":
+ return nil
+ }
+ return errors.New("basis must be account or whole")
+}
+
// serviceLines is a repeatable -line Service=usd flag collector
// (flag.Value): every -line adds one entry to the map, the way a single
// map-typed flag cannot — flag.NewFlagSet has no MapVar, only Var, which
@@ -234,6 +246,9 @@ type economicsBillResult struct {
TotalUSD float64 `json:"total_usd"`
Services map[string]float64 `json:"services"`
Source string `json:"source"`
+ // Basis is what the stored bill covers: account, whole, or "" when it
+ // is unstated (or the console predates the field).
+ Basis string `json:"basis,omitempty"`
}
// economicsBill posts one month's manual bill entry to the console
@@ -247,12 +262,16 @@ type economicsBillResult struct {
// ("check --account and --app") does not fit here at all (this door has
// neither flag), so this is the one call in the package that writes its own
// 404 message rather than reusing it.
-func (s *apiSession) economicsBill(ctx context.Context, month string, total float64, services map[string]float64) (economicsBillResult, error) {
+//
+// basis "" sends no basis key at all, so an older console sees exactly the
+// body it always did.
+func (s *apiSession) economicsBill(ctx context.Context, month string, total float64, services map[string]float64, basis string) (economicsBillResult, error) {
in := struct {
Month string `json:"month"`
TotalUSD float64 `json:"total_usd"`
Services map[string]float64 `json:"services,omitempty"`
- }{month, total, services}
+ Basis string `json:"basis,omitempty"`
+ }{month, total, services, basis}
status, body, err := s.postJSON(ctx, "/api/economics/bill", in)
if err != nil {
return economicsBillResult{}, err
@@ -278,6 +297,7 @@ func runEconomicsBill(args []string) {
total := fs.Float64("total", 0, "invoice total in US dollars (required)")
lines := serviceLines{}
fs.Var(lines, "line", "one line item, repeatable: Service=usd")
+ basis := fs.String("basis", "", "what the total covers: account (the whole account, which runs only CARLOS) or whole (the whole account, CARLOS and other things)")
consoleFlag := consoleOption(fs, "console to record through (default: the only logged-in one)")
fs.Usage = flagUsage(fs, economicsUsage)
fs.Parse(args)
@@ -293,6 +313,9 @@ func runEconomicsBill(args []string) {
if err := validAmount(*total); err != nil {
log.Fatalf("economics bill: --total %v", err)
}
+ if err := validBillBasis(*basis); err != nil {
+ log.Fatalf("economics bill: --%v", err)
+ }
sess, err := resolveMode(*consoleFlag)
if err != nil {
@@ -305,7 +328,7 @@ func runEconomicsBill(args []string) {
}
printUsing(stdout, sess)
- res, err := sess.economicsBill(context.Background(), *month, *total, map[string]float64(lines))
+ res, err := sess.economicsBill(context.Background(), *month, *total, map[string]float64(lines), *basis)
if err != nil {
log.Fatalf("economics bill: %v", err)
}
@@ -324,4 +347,7 @@ func runEconomicsBill(args []string) {
w.Flush()
}
fmt.Fprintf(stdout, "%s %s: $%.2f\n", colorFor(stdout).ok("recorded bill for"), res.Month, res.TotalUSD)
+ if res.Basis != "" {
+ fmt.Fprintf(stdout, "basis: %s\n", res.Basis)
+ }
}
diff --git a/economics_test.go b/economics_test.go
index 1a087ea9f..ec095fcc9 100644
--- a/economics_test.go
+++ b/economics_test.go
@@ -8,6 +8,7 @@ package main
import (
"context"
"encoding/json"
+ "io"
"math"
"net/http"
"net/http/httptest"
@@ -94,7 +95,7 @@ func TestAPISessionEconomicsBillWireShape(t *testing.T) {
}))
defer ts.Close()
- res, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 123.45, map[string]float64{"AmazonEC2": 55.0})
+ res, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 123.45, map[string]float64{"AmazonEC2": 55.0}, "")
if err != nil {
t.Fatalf("economicsBill: %v", err)
}
@@ -115,6 +116,56 @@ func TestAPISessionEconomicsBillWireShape(t *testing.T) {
}
}
+// TestAPISessionEconomicsBillBasisWireShape: a basis rides as "basis" in
+// the request and comes back in the echoed bill; no basis sends no key at
+// all, so an older console sees exactly the body it always did.
+func TestAPISessionEconomicsBillBasisWireShape(t *testing.T) {
+ for _, tc := range []struct {
+ basis string
+ want string // substring the raw body must carry, "" for none
+ }{
+ {"account", `"basis":"account"`},
+ {"", ""},
+ } {
+ var raw []byte
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ raw, _ = io.ReadAll(r.Body)
+ out := map[string]any{"month": "2026-08", "total_usd": 1, "source": "manual"}
+ if tc.basis != "" {
+ out["basis"] = tc.basis
+ }
+ json.NewEncoder(w).Encode(out)
+ }))
+ res, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil, tc.basis)
+ ts.Close()
+ if err != nil {
+ t.Fatalf("economicsBill(basis %q): %v", tc.basis, err)
+ }
+ if tc.want != "" && !strings.Contains(string(raw), tc.want) {
+ t.Fatalf("basis %q: body %s, want %s", tc.basis, raw, tc.want)
+ }
+ if tc.want == "" && strings.Contains(string(raw), `"basis"`) {
+ t.Fatalf("no basis: body %s carries a basis key", raw)
+ }
+ if res.Basis != tc.basis {
+ t.Fatalf("result basis = %q, want %q", res.Basis, tc.basis)
+ }
+ }
+}
+
+func TestValidBillBasis(t *testing.T) {
+ for _, good := range []string{"", "account", "whole"} {
+ if err := validBillBasis(good); err != nil {
+ t.Errorf("validBillBasis(%q) = %v, want nil", good, err)
+ }
+ }
+ for _, bad := range []string{"tagged", "Account", "bogus", " whole"} {
+ if err := validBillBasis(bad); err == nil {
+ t.Errorf("validBillBasis(%q) = nil, want an error", bad)
+ }
+ }
+}
+
// TestAPISessionEconomicsBillNotFoundNamesOperatorBit: handleAPIEconomicsBill
// answers a non-operator's token with the same bare 404 an unknown route
// gets — notFoundErr's own "-account and -app" text does not fit this
@@ -125,7 +176,7 @@ func TestAPISessionEconomicsBillNotFoundNamesOperatorBit(t *testing.T) {
}))
defer ts.Close()
- _, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil)
+ _, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil, "")
if err == nil {
t.Fatal("a 404 must error")
}
@@ -147,7 +198,7 @@ func TestAPISessionEconomicsBillServerErrorSurfacesVerbatim(t *testing.T) {
}))
defer ts.Close()
- _, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil)
+ _, err := newTestSession(ts.URL).economicsBill(context.Background(), "2026-08", 1, nil, "")
if err == nil || !strings.Contains(err.Error(), "try again") {
t.Fatalf("economicsBill 409 = %v, want the console's own text", err)
}
@@ -205,6 +256,14 @@ func TestEconomicsVerbRefusals(t *testing.T) {
t.Fatalf("bill with no -total = %q, want the usage string", out)
}
+ out, err = run(nil, "economics", "bill", "-month", "2026-08", "-total", "1", "-basis", "tagged")
+ if err == nil {
+ t.Fatalf("bill with --basis tagged exited 0:\n%s", out)
+ }
+ if !strings.Contains(out, "basis must be account or whole") {
+ t.Fatalf("bill with --basis tagged = %q, want the basis refusal", out)
+ }
+
out, err = run(nil, "economics", "bill", "-month", "2026-8", "-total", "1")
if err == nil {
t.Fatalf("bill with a malformed --month exited 0:\n%s", out)
@@ -248,10 +307,15 @@ func TestEconomicsBillCLIHappyPath(t *testing.T) {
http.NotFound(w, r)
return
}
+ var in struct {
+ Basis string `json:"basis"`
+ }
+ json.NewDecoder(r.Body).Decode(&in)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]any{
"month": "2026-08", "total_usd": 123.45,
"services": map[string]float64{"AmazonEC2": 55.0}, "source": "manual",
+ "basis": in.Basis,
})
}))
defer ts.Close()
@@ -259,7 +323,7 @@ func TestEconomicsBillCLIHappyPath(t *testing.T) {
env := carlosTestEnv(t)
writeTestCredential(t, envSliceValue(env, "CARLOS_CREDENTIALS"), ts.URL)
- cmd := exec.Command(bin, "economics", "bill", "-month", "2026-08", "-total", "123.45", "-line", "AmazonEC2=55.00")
+ cmd := exec.Command(bin, "economics", "bill", "-month", "2026-08", "-total", "123.45", "-line", "AmazonEC2=55.00", "-basis", "whole")
cmd.Env = env
cmd.Dir = scratch
out, err := cmd.CombinedOutput()
@@ -273,6 +337,9 @@ func TestEconomicsBillCLIHappyPath(t *testing.T) {
if !strings.Contains(got, "123.45") {
t.Fatalf("stdout = %q, want the total", got)
}
+ if !strings.Contains(got, "basis: whole\n") {
+ t.Fatalf("stdout = %q, want the stored basis line", got)
+ }
}
// envSliceValue returns the value of the last occurrence of key=... in env,
diff --git a/internal/console/cepull.go b/internal/console/cepull.go
index 52c4c08b1..2a1aad57b 100644
--- a/internal/console/cepull.go
+++ b/internal/console/cepull.go
@@ -39,18 +39,18 @@ import (
// rather than a mutex because billPass only ever runs from
// StartEconomicsPass's single-goroutine hourly ticker (economicspass.go) —
// there is no concurrent caller for these fields to race against.
-func (s *Server) resolveCECosts(ctx context.Context, start, end time.Time) (map[string]float64, error) {
+func (s *Server) resolveCECosts(ctx context.Context, q ceQuery) (map[string]float64, error) {
if s.ceCosts != nil {
- return s.ceCosts(ctx, start, end)
+ return s.ceCosts(ctx, q)
}
- return s.realCECosts(ctx, start, end)
+ return s.realCECosts(ctx, q)
}
// realCECosts builds the Cost Explorer client once (s.ceClientOnce) and
// reuses it for the life of the process. See the package doc comment above
// for which failures latch s.ceDisabled (auth-shaped, permanent) versus
// which just fail this one tick (everything else, retried next hour).
-func (s *Server) realCECosts(ctx context.Context, start, end time.Time) (map[string]float64, error) {
+func (s *Server) realCECosts(ctx context.Context, q ceQuery) (map[string]float64, error) {
if s.ceDisabled {
return nil, fmt.Errorf("console: cost explorer disabled for this process")
}
@@ -95,8 +95,8 @@ func (s *Server) realCECosts(ctx context.Context, start, end time.Time) (map[str
{Type: cetypes.GroupDefinitionTypeDimension, Key: aws.String("SERVICE")},
},
TimePeriod: &cetypes.DateInterval{
- Start: aws.String(start.Format("2006-01-02")),
- End: aws.String(end.Format("2006-01-02")),
+ Start: aws.String(q.Start.Format("2006-01-02")),
+ End: aws.String(q.End.Format("2006-01-02")),
},
})
if err != nil {
diff --git a/internal/console/claim_invariant_probes_worker_test.go b/internal/console/claim_invariant_probes_worker_test.go
index 0d5a44c5e..dff8f90fd 100644
--- a/internal/console/claim_invariant_probes_worker_test.go
+++ b/internal/console/claim_invariant_probes_worker_test.go
@@ -154,7 +154,7 @@ var claimWorkerProbes = map[string]claimProbe{
"worker StartEconomicsPass": {
setup: func(t *testing.T, cx *claimCase) {
// The bill pull is the one stage that would reach AWS: a seam answers it.
- cx.srv.ceCosts = func(context.Context, time.Time, time.Time) (map[string]float64, error) {
+ cx.srv.ceCosts = func(context.Context, ceQuery) (map[string]float64, error) {
return map[string]float64{"AmazonEC2": 1}, nil
}
},
diff --git a/internal/console/costscope.go b/internal/console/costscope.go
new file mode 100644
index 000000000..fef99914e
--- /dev/null
+++ b/internal/console/costscope.go
@@ -0,0 +1,34 @@
+package console
+
+import (
+ "time"
+
+ "github.com/carlosframework/platform/internal/economics"
+)
+
+// CostScope is what the operator has declared about the deployment's AWS
+// account (Config.CostScope). The zero value declares nothing: the account
+// may hold non-CARLOS resources, so a pulled bill is stored BasisUnstated.
+type CostScope struct {
+ // AccountCarlosOnly (CONSOLE_COST_ACCOUNT_CARLOS_ONLY) says the AWS
+ // account runs CARLOS and nothing else, so a Cost Explorer pull of the
+ // whole account is CARLOS platform cost and is stamped BasisAccount.
+ AccountCarlosOnly bool
+}
+
+// ceQuery is one Cost Explorer request through the ceCosts seam: the
+// billing period, Start inclusive and End exclusive, as CE takes it.
+type ceQuery struct {
+ Start, End time.Time
+}
+
+// billBasisFor decides, for one bill period, what to ask Cost Explorer and
+// which basis the resulting bill is stamped with. The query is the whole
+// account either way; only the declared scope decides the basis.
+func (s *Server) billBasisFor(start, end time.Time) (q ceQuery, basis string) {
+ q = ceQuery{Start: start, End: end}
+ if s.cfg.CostScope.AccountCarlosOnly {
+ return q, economics.BasisAccount
+ }
+ return q, economics.BasisUnstated
+}
diff --git a/internal/console/economicsbill_test.go b/internal/console/economicsbill_test.go
index 901639a1c..cfb3bca63 100644
--- a/internal/console/economicsbill_test.go
+++ b/internal/console/economicsbill_test.go
@@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"os"
+ "strings"
"testing"
"time"
@@ -23,7 +24,7 @@ func TestBillPassPullsAndManualWins(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 8, 11, 3, 0, 0, 0, time.UTC)
- fx.srv.ceCosts = func(ctx context.Context, start, end time.Time) (map[string]float64, error) {
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
return map[string]float64{"AmazonEC2": 55.5}, nil
}
@@ -93,7 +94,7 @@ func TestBillPassNoCEIsQuiet(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 8, 11, 3, 0, 0, 0, time.UTC)
- fx.srv.ceCosts = func(ctx context.Context, start, end time.Time) (map[string]float64, error) {
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
return nil, errors.New("AccessDeniedException: user is not authorized")
}
@@ -121,9 +122,9 @@ func TestBillPassHandlesMonthBoundary(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 9, 1, 3, 0, 0, 0, time.UTC)
- fx.srv.ceCosts = func(ctx context.Context, start, end time.Time) (map[string]float64, error) {
- if start.Format("2006-01-02") == end.Format("2006-01-02") {
- t.Fatalf("ceCosts called with start == end == %s (day 1 collapse)", start.Format("2006-01-02"))
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
+ if q.Start.Format("2006-01-02") == q.End.Format("2006-01-02") {
+ t.Fatalf("ceCosts called with start == end == %s (day 1 collapse)", q.Start.Format("2006-01-02"))
}
return map[string]float64{"AmazonEC2": 10}, nil
}
@@ -147,7 +148,7 @@ func TestBillPassSkipsSecondPullSameDay(t *testing.T) {
now := time.Date(2026, 8, 11, 3, 0, 0, 0, time.UTC)
var calls int
- fx.srv.ceCosts = func(ctx context.Context, start, end time.Time) (map[string]float64, error) {
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
calls++
return map[string]float64{"AmazonEC2": 10}, nil
}
@@ -185,7 +186,7 @@ func TestBillPassStopsPullingSettledClosedMonth(t *testing.T) {
putStoreJSON(t, fx.rel, economics.BillKey("2026-07"), settled)
var calls int
- fx.srv.ceCosts = func(ctx context.Context, start, end time.Time) (map[string]float64, error) {
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
calls++
return map[string]float64{"AmazonEC2": 99}, nil
}
@@ -228,8 +229,8 @@ func TestBillPassRepullsJustClosedMonth(t *testing.T) {
putStoreJSON(t, fx.rel, economics.BillKey("2026-07"), notYetSettled)
var julyPulled bool
- fx.srv.ceCosts = func(ctx context.Context, start, end time.Time) (map[string]float64, error) {
- if start.Format("2006-01") == "2026-07" {
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
+ if q.Start.Format("2006-01") == "2026-07" {
julyPulled = true
}
return map[string]float64{"AmazonEC2": 99}, nil
@@ -268,7 +269,7 @@ func TestBillPassRetriesAfterTransientCEFailure(t *testing.T) {
now := time.Date(2026, 8, 11, 3, 0, 0, 0, time.UTC)
var calls int
- fx.srv.ceCosts = func(ctx context.Context, start, end time.Time) (map[string]float64, error) {
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
calls++
if calls <= 2 { // both months fail on the first tick
return nil, errors.New("ThrottlingException: rate exceeded")
@@ -446,3 +447,286 @@ func TestAPIBillDoor(t *testing.T) {
t.Fatalf("stored bill = %+v", stored)
}
}
+
+// readBillRaw returns the stored bytes and parsed bill for month.
+func readBillRaw(t *testing.T, fx *consoleFixture, month string) ([]byte, economics.Bill) {
+ t.Helper()
+ raw, _, err := fx.rel.Get(context.Background(), economics.BillKey(month))
+ if err != nil {
+ t.Fatalf("bill %s: %v", month, err)
+ }
+ var b economics.Bill
+ if err := json.Unmarshal(raw, &b); err != nil {
+ t.Fatal(err)
+ }
+ return raw, b
+}
+
+// TestBillPassStampsBasis: billPass records what each pulled bill covers.
+// With the AWS account declared CARLOS-only both months are stamped
+// "account"; with the zero scope both are unstated and carry no basis key.
+func TestBillPassStampsBasis(t *testing.T) {
+ now := time.Date(2026, 8, 11, 3, 0, 0, 0, time.UTC)
+ for _, tc := range []struct {
+ name string
+ scope CostScope
+ want string
+ }{
+ {"account", CostScope{AccountCarlosOnly: true}, economics.BasisAccount},
+ {"zero", CostScope{}, economics.BasisUnstated},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.CostScope = tc.scope
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
+ return map[string]float64{"AmazonEC2": 7}, nil
+ }
+ if err := fx.srv.billPass(context.Background(), now); err != nil {
+ t.Fatal(err)
+ }
+ for _, month := range []string{"2026-08", "2026-07"} {
+ raw, b := readBillRaw(t, fx, month)
+ if b.Basis != tc.want {
+ t.Fatalf("%s basis = %q, want %q", month, b.Basis, tc.want)
+ }
+ if tc.want == economics.BasisUnstated && strings.Contains(string(raw), `"basis"`) {
+ t.Fatalf("%s unstated bill carries a basis key: %s", month, raw)
+ }
+ }
+ })
+ }
+}
+
+// TestBillPassRepullsOnBasisChange: declaring the account CARLOS-only
+// changes what a pulled bill means, so the same-day and settle rules must
+// not keep a bill stamped with the old basis. Each month re-pulls exactly
+// once after the switch, then the usual rules apply again.
+func TestBillPassRepullsOnBasisChange(t *testing.T) {
+ ctx := context.Background()
+ now := time.Date(2026, 8, 11, 3, 0, 0, 0, time.UTC)
+
+ t.Run("same day", func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ var calls int
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
+ calls++
+ return map[string]float64{"AmazonEC2": 3}, nil
+ }
+ if err := fx.srv.billPass(ctx, now); err != nil {
+ t.Fatal(err)
+ }
+ if calls != 2 {
+ t.Fatalf("zero-scope billPass made %d ceCosts calls, want 2", calls)
+ }
+ fx.srv.cfg.CostScope = CostScope{AccountCarlosOnly: true}
+ if err := fx.srv.billPass(ctx, now.Add(time.Hour)); err != nil {
+ t.Fatal(err)
+ }
+ if calls != 4 {
+ t.Fatalf("billPass after the basis change made %d more ceCosts calls, want 2", calls-2)
+ }
+ for _, month := range []string{"2026-08", "2026-07"} {
+ if _, b := readBillRaw(t, fx, month); b.Basis != economics.BasisAccount {
+ t.Fatalf("%s basis = %q after re-pull, want account", month, b.Basis)
+ }
+ }
+ if err := fx.srv.billPass(ctx, now.Add(2*time.Hour)); err != nil {
+ t.Fatal(err)
+ }
+ if calls != 4 {
+ t.Fatalf("third billPass made %d more ceCosts calls, want 0", calls-4)
+ }
+ })
+
+ t.Run("settled closed month", func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ settled := economics.Bill{
+ Schema: 1, Month: "2026-07", TotalUSD: 10,
+ Services: map[string]float64{"AmazonEC2": 10}, Source: economics.SourceCostExplorer,
+ PulledAt: time.Date(2026, 8, 5, 3, 0, 0, 0, time.UTC),
+ }
+ putStoreJSON(t, fx.rel, economics.BillKey("2026-07"), settled)
+ fx.srv.cfg.CostScope = CostScope{AccountCarlosOnly: true}
+ var julyCalls int
+ fx.srv.ceCosts = func(ctx context.Context, q ceQuery) (map[string]float64, error) {
+ if q.Start.Format("2006-01") == "2026-07" {
+ julyCalls++
+ }
+ return map[string]float64{"AmazonEC2": 20}, nil
+ }
+ for i := 0; i < 3; i++ {
+ if err := fx.srv.billPass(ctx, now.AddDate(0, 0, i)); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if julyCalls != 1 {
+ t.Fatalf("settled July re-pulled %d times after the basis change, want exactly 1", julyCalls)
+ }
+ if _, b := readBillRaw(t, fx, "2026-07"); b.Basis != economics.BasisAccount || b.TotalUSD != 20 {
+ t.Fatalf("July after re-pull: basis %q total %v, want account 20", b.Basis, b.TotalUSD)
+ }
+ })
+}
+
+// TestEconomicsBillBasisDoors: both manual-bill doors (the console form and
+// the CLI's API) store the basis the operator gave, default an absent one
+// from the console's CostScope, and refuse anything else without writing.
+func TestEconomicsBillBasisDoors(t *testing.T) {
+ ctx := context.Background()
+ carlosOnly := CostScope{AccountCarlosOnly: true}
+ for _, tc := range []struct {
+ name string
+ scope CostScope
+ basis string // "-" sends no basis at all
+ want string
+ bad bool
+ }{
+ {"account given", CostScope{}, "account", economics.BasisAccount, false},
+ {"absent, account scope", carlosOnly, "-", economics.BasisAccount, false},
+ {"absent, zero scope", CostScope{}, "-", economics.BasisUnstated, false},
+ {"whole, account scope", carlosOnly, "whole", economics.BasisWhole, false},
+ {"tagged refused", carlosOnly, "tagged", "", true},
+ {"bogus refused", CostScope{}, "bogus", "", true},
+ } {
+ for _, door := range []string{"form", "api"} {
+ t.Run(door+"/"+tc.name, func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.CostScope = tc.scope
+ if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil {
+ t.Fatal(err)
+ }
+ var status int
+ var body string
+ switch door {
+ case "form":
+ c := signInPaul(t, fx)
+ form := url.Values{"csrf": {sessionToken(t, fx, c)}, "month": {"2026-08"}, "total": {"12.5"}, "lines": {"AmazonEC2=12.5"}}
+ if tc.basis != "-" {
+ form.Set("basis", tc.basis)
+ }
+ status, _, body = postForm(t, c, fx.ts.URL+"/fleet/economics/bill", form)
+ case "api":
+ token := cliToken(t, fx, "paul@keymail.dev", "code-basis")
+ req := map[string]any{"month": "2026-08", "total_usd": 12.5, "services": map[string]float64{"AmazonEC2": 12.5}}
+ if tc.basis != "-" {
+ req["basis"] = tc.basis
+ }
+ raw, err := json.Marshal(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var out []byte
+ status, out = postBody(t, fx.ts.URL+"/api/economics/bill", token, string(raw))
+ body = string(out)
+ }
+ if tc.bad {
+ if status != http.StatusBadRequest {
+ t.Fatalf("basis %q = %d %s, want 400", tc.basis, status, body)
+ }
+ if door == "api" && !jsonErrorContains(t, body, "basis must be account or whole") {
+ t.Fatalf("api 400 body = %s, want %q", body, "basis must be account or whole")
+ }
+ if _, _, err := fx.rel.Get(ctx, economics.BillKey("2026-08")); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("a refused basis still wrote a bill (err %v)", err)
+ }
+ return
+ }
+ if door == "form" && status != http.StatusSeeOther {
+ t.Fatalf("form save = %d %s, want 303", status, body)
+ }
+ if door == "api" && status != http.StatusOK {
+ t.Fatalf("api save = %d %s, want 200", status, body)
+ }
+ raw, b := readBillRaw(t, fx, "2026-08")
+ if b.Basis != tc.want {
+ t.Fatalf("stored basis = %q, want %q", b.Basis, tc.want)
+ }
+ if tc.want == economics.BasisUnstated && strings.Contains(string(raw), `"basis"`) {
+ t.Fatalf("unstated manual bill carries a basis key: %s", raw)
+ }
+ })
+ }
+ }
+}
+
+// TestManualWholeBillStaysExcluded: a hand-entered bill marked "whole" on a
+// console that declares the account CARLOS-only is never counted as CARLOS
+// platform cost; only an absent basis is promoted by the setting.
+func TestManualWholeBillStaysExcluded(t *testing.T) {
+ ctx := context.Background()
+ for _, door := range []string{"form", "api"} {
+ t.Run(door, func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.CostScope = CostScope{AccountCarlosOnly: true}
+ if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil {
+ t.Fatal(err)
+ }
+ switch door {
+ case "form":
+ c := signInPaul(t, fx)
+ form := url.Values{"csrf": {sessionToken(t, fx, c)}, "month": {"2026-10"}, "total": {"300"}, "lines": {"AmazonEC2=300"}, "basis": {"whole"}}
+ if status, _, body := postForm(t, c, fx.ts.URL+"/fleet/economics/bill", form); status != http.StatusSeeOther {
+ t.Fatalf("form save = %d %s", status, body)
+ }
+ case "api":
+ token := cliToken(t, fx, "paul@keymail.dev", "code-whole")
+ body := `{"month":"2026-10","total_usd":300,"services":{"AmazonEC2":300},"basis":"whole"}`
+ if status, out := postBody(t, fx.ts.URL+"/api/economics/bill", token, body); status != http.StatusOK {
+ t.Fatalf("api save = %d %s", status, out)
+ }
+ }
+ usd, basis, ok := fx.srv.carlosPlatformCostUSD(ctx, "2026-10")
+ if ok || basis != economics.BasisWhole {
+ t.Fatalf("carlosPlatformCostUSD = %v, %q, %v; want ok=false, basis whole", usd, basis, ok)
+ }
+ })
+ }
+}
+
+// TestEconomicsBillFormBasisDefault: with no bill on file the Economics page
+// offers the bill-entry form, whose "what this bill covers" select starts
+// on the option that matches the console's CostScope.
+func TestEconomicsBillFormBasisDefault(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ scope CostScope
+ selected string
+ }{
+ {"account scope", CostScope{AccountCarlosOnly: true}, "account"},
+ {"zero scope", CostScope{}, "whole"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.CostScope = tc.scope
+ 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")
+ if status != http.StatusOK {
+ t.Fatalf("/fleet/economics = %d", status)
+ }
+ for _, want := range []string{
+ "No AWS bill on file for ",
+ " yet. Enter it below.",
+ `<form rst-card co-pad co-billform method="post" action="/fleet/economics/bill">`,
+ `<label rst-field-label for="bill-basis">What this bill covers</label>`,
+ `<option value="` + tc.selected + `" selected>`,
+ "The whole account, which runs only CARLOS",
+ "The whole account, CARLOS and other things",
+ } {
+ if !strings.Contains(body, want) {
+ t.Fatalf("/fleet/economics missing %q", want)
+ }
+ }
+ if strings.Contains(body, "enter one manually") {
+ t.Fatal("the old no-bill note is still on the page")
+ }
+ _, sel, _ := strings.Cut(body, `id="bill-basis"`)
+ sel, _, _ = strings.Cut(sel, "</select>")
+ if n := strings.Count(sel, " selected>"); n != 1 {
+ t.Fatalf("%d selected bill-basis options, want 1: %s", n, sel)
+ }
+ })
+ }
+}
diff --git a/internal/console/economicspage_test.go b/internal/console/economicspage_test.go
index c4ab7cb85..3f6702564 100644
--- a/internal/console/economicspage_test.go
+++ b/internal/console/economicspage_test.go
@@ -949,3 +949,69 @@ 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, with the label after the heading's closing parenthesis. 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. A bill stated as "whole" reads "not only
+// CARLOS" even on a CARLOS-only console, and its hint says it does not
+// count. 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."
+ c7 = "This bill was entered as covering the whole AWS account, CARLOS and other things, so it does not count as CARLOS cost."
+ )
+ month := usage.MonthOf(time.Now().UTC())
+ for _, tc := range []struct {
+ name string
+ scope CostScope
+ basis string
+ label string
+ hint string // "" when the page shows none
+ deny []string
+ }{
+ {"account", CostScope{AccountCarlosOnly: true}, economics.BasisUnstated, c1, "", []string{c2, c3, c7}},
+ {"zero", CostScope{}, economics.BasisUnstated, c2, c3, []string{c1, c7}},
+ {"whole under account", CostScope{AccountCarlosOnly: true}, economics.BasisWhole, c2, c7, []string{c1, c3}},
+ } {
+ 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, Basis: tc.basis,
+ 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 + ") " + tc.label + "</th>"
+ if !strings.Contains(body, heading) {
+ t.Fatalf("bill heading missing %q in:\n%s", heading, body)
+ }
+ if tc.hint != "" {
+ note := "<p co-note>" + tc.hint + "</p>"
+ i := strings.Index(body, note)
+ if i < 0 {
+ t.Fatalf("page missing hint %q in:\n%s", note, body)
+ }
+ if j := strings.Index(body, heading); i < strings.Index(body[j:], "</table>")+j {
+ t.Fatalf("hint %q is not under the bill table:\n%s", tc.hint, 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/economicspass.go b/internal/console/economicspass.go
index e965260cf..0108dd95c 100644
--- a/internal/console/economicspass.go
+++ b/internal/console/economicspass.go
@@ -1068,17 +1068,19 @@ func (s *Server) billPass(ctx context.Context, now time.Time) error {
// $14/mo (2 months × 24 ticks/day × 30 days) pulling data that, most hours,
// hasn't changed since the last pull. shouldSkipCEPull enforces "at most
// once per UTC day" for both months, plus the day-3-of-next-month
-// settle-and-stop rule for closedMonth.
+// settle-and-stop rule for closedMonth, except that a stored bill whose
+// basis differs from the one billBasisFor gives now is re-pulled once.
func (s *Server) pullBillMonth(ctx context.Context, month string, start, end, now time.Time, closedMonth bool) error {
+ q, basis := s.billBasisFor(start, end)
existing, err := s.getBill(ctx, month)
if err != nil {
return fmt.Errorf("read existing bill: %w", err)
}
- if shouldSkipCEPull(existing, closedMonth, now) {
+ if shouldSkipCEPull(existing, closedMonth, now, basis) {
return nil
}
- costs, err := s.resolveCECosts(ctx, start, end)
+ costs, err := s.resolveCECosts(ctx, q)
if err != nil {
return fmt.Errorf("cost explorer: %w", err)
}
@@ -1093,6 +1095,7 @@ func (s *Server) pullBillMonth(ctx context.Context, month string, start, end, no
Services: costs,
Source: economics.SourceCostExplorer,
PulledAt: now,
+ Basis: basis,
}
return s.upsertBill(ctx, bill, true)
}
@@ -1103,10 +1106,18 @@ func (s *Server) pullBillMonth(ctx context.Context, month string, start, end, no
// ever consults a SourceCostExplorer bill: a SourceManual bill is a
// different caller's business (upsertBill's manualWins check handles it at
// write time), not a reason to skip a pull here.
-func shouldSkipCEPull(existing *economics.Bill, closedMonth bool, now time.Time) bool {
+//
+// basis is the basis a pull made now would be stamped with. A stored bill
+// with a different basis was pulled under a different cost scope, so it is
+// re-pulled whatever the settle and same-day rules say. The re-pull stamps
+// the new basis, so this fires once per change, not every tick.
+func shouldSkipCEPull(existing *economics.Bill, closedMonth bool, now time.Time, basis string) bool {
if existing == nil || existing.Source != economics.SourceCostExplorer {
return false
}
+ if existing.Basis != basis {
+ return false
+ }
if closedMonth && usage.MonthOf(existing.PulledAt) > existing.Month && existing.PulledAt.Day() >= billCEDayGrace {
// Settled: a closed month pulled on or after day 3 of a LATER
// month has already seen CE's late-arriving line items land. Its
@@ -1387,6 +1398,30 @@ func parseBillLines(text string) (map[string]float64, error) {
return services, nil
}
+// errManualBillBasis is both manual-bill doors' refusal of a basis other
+// than account or whole. "tagged" is refused too: it is a value a later
+// version may write, never one an operator types today.
+var errManualBillBasis = errors.New("basis must be account or whole")
+
+// manualBillBasis is the stored basis for a hand-entered bill. An explicit
+// account or whole is stored as written, whatever the console's CostScope
+// says. An absent basis (an older CLI, a form without the field) is
+// account when the account is declared CARLOS-only and otherwise left
+// unstated, the same stamp billBasisFor gives a pulled bill.
+func (s *Server) manualBillBasis(raw string) (string, error) {
+ switch raw {
+ case "":
+ if s.cfg.CostScope.AccountCarlosOnly {
+ return economics.BasisAccount, nil
+ }
+ return economics.BasisUnstated, nil
+ case economics.BasisAccount, economics.BasisWhole:
+ return raw, nil
+ default:
+ return "", errManualBillBasis
+ }
+}
+
// handleEconomicsBillSave writes a manually-entered bill for one month —
// SourceManual, always overwriting whatever is there (upsertBill's
// manualWins=false). Same gate shape as handleEconomicsScenarioSave,
@@ -1436,6 +1471,11 @@ func (s *Server) handleEconomicsBillSave(w http.ResponseWriter, r *http.Request)
s.renderMessage(w, r, http.StatusBadRequest, "Invalid bill", err.Error())
return
}
+ basis, err := s.manualBillBasis(r.FormValue("basis"))
+ if err != nil {
+ s.renderMessage(w, r, http.StatusBadRequest, "Invalid bill", err.Error())
+ return
+ }
bill := economics.Bill{
Schema: 1,
@@ -1443,6 +1483,7 @@ func (s *Server) handleEconomicsBillSave(w http.ResponseWriter, r *http.Request)
TotalUSD: total,
Services: services,
Source: economics.SourceManual,
+ Basis: basis,
}
if err := s.upsertBill(r.Context(), bill, false); err != nil {
if errors.Is(err, release.ErrCASConflict) {
@@ -1569,6 +1610,7 @@ func (s *Server) handleAPIEconomicsBill(w http.ResponseWriter, r *http.Request)
Month string `json:"month"`
TotalUSD float64 `json:"total_usd"`
Services map[string]float64 `json:"services"`
+ Basis string `json:"basis,omitempty"`
}
if !readJSON(w, r, &req) {
return
@@ -1577,6 +1619,11 @@ func (s *Server) handleAPIEconomicsBill(w http.ResponseWriter, r *http.Request)
jsonError(w, http.StatusBadRequest, "month must be formatted YYYY-MM")
return
}
+ basis, err := s.manualBillBasis(req.Basis)
+ if err != nil {
+ jsonError(w, http.StatusBadRequest, err.Error())
+ return
+ }
bill := economics.Bill{
Schema: 1,
@@ -1584,6 +1631,7 @@ func (s *Server) handleAPIEconomicsBill(w http.ResponseWriter, r *http.Request)
TotalUSD: req.TotalUSD,
Services: req.Services,
Source: economics.SourceManual,
+ Basis: basis,
}
if err := s.upsertBill(r.Context(), bill, false); err != nil {
if errors.Is(err, release.ErrCASConflict) {
diff --git a/internal/console/economicsview.go b/internal/console/economicsview.go
index 9cf334bb5..14a17fa22 100644
--- a/internal/console/economicsview.go
+++ b/internal/console/economicsview.go
@@ -98,6 +98,18 @@ 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
+ // BillFormBasis is the option the bill-entry form's "what this bill
+ // covers" select starts on: account when the console declares the AWS
+ // account CARLOS-only, otherwise whole.
+ BillFormBasis string
}
// PoolLedger is one period's fleet-pool revenue-sharing standing: how much
@@ -645,6 +657,20 @@ 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
+ }
+ }
+
+ billFormBasis := economics.BasisWhole
+ if s.cfg.CostScope.AccountCarlosOnly {
+ billFormBasis = economics.BasisAccount
+ }
payload := economicsPayload{
Scenario: sc,
@@ -682,6 +708,9 @@ func (s *Server) buildEconomicsView(ctx context.Context, period string) (*Econom
Tiers: tiers,
Names: names,
Pool: pool,
+ BillBasisLabels: billBasisLabels,
+ BillBasisHints: billBasisHints,
+ BillFormBasis: billFormBasis,
}, nil
}
diff --git a/internal/console/platformcost.go b/internal/console/platformcost.go
new file mode 100644
index 000000000..72ad60eac
--- /dev/null
+++ b/internal/console/platformcost.go
@@ -0,0 +1,90 @@
+package console
+
+import (
+ "context"
+ "fmt"
+ "log"
+
+ "github.com/carlosframework/platform/internal/economics"
+)
+
+// costBasisMissing is the basis carlosPlatformCostUSD reports when there is
+// no readable bill for the month. It is never stored on a bill.
+const costBasisMissing = "missing"
+
+// billTaxService is the Services line Cost Explorer puts tax under. Tax is
+// not platform cost, so it comes off the bill total.
+const billTaxService = "Tax"
+
+// Approved copy (C1-C4, C7), verbatim.
+const (
+ costLabelAccount = "AWS, whole account: CARLOS only"
+ costLabelOther = "AWS, whole account: not only CARLOS"
+ costHintUnstated = "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."
+ costHintNoBillFmt = "No AWS bill on file for %s yet."
+ costHintWhole = "This bill was entered as covering the whole AWS account, CARLOS and other things, so it does not count as CARLOS cost."
+)
+
+// effectiveBillBasis is what a stored bill counts as under the declared
+// scope. Only an unstated bill is promoted to "account", and only when the
+// account is declared CARLOS-only; "account" and "whole" stand as stored.
+// Any other value is not something this console wrote, so it reads as
+// "whole", which the setting never promotes.
+func effectiveBillBasis(b economics.Bill, scope CostScope) string {
+ switch b.Basis {
+ case economics.BasisUnstated:
+ if scope.AccountCarlosOnly {
+ return economics.BasisAccount
+ }
+ return economics.BasisUnstated
+ case economics.BasisAccount, economics.BasisWhole:
+ return b.Basis
+ default:
+ return economics.BasisWhole
+ }
+}
+
+// carlosPlatformCostUSD is month's ("2006-01") CARLOS-only AWS cost: the
+// stored bill's total less tax. ok is true only when the bill's effective
+// basis is "account". Otherwise usd is 0 and basis says why the figure is
+// hidden: the effective basis (unstated or whole), or costBasisMissing when
+// there is no readable bill. Callers own caching and currency conversion.
+func (s *Server) carlosPlatformCostUSD(ctx context.Context, month string) (usd float64, basis string, ok bool) {
+ b, err := s.getBill(ctx, month)
+ if err != nil {
+ log.Printf("console: platform cost %s: read bill: %v", month, err)
+ return 0, costBasisMissing, false
+ }
+ if b == nil {
+ return 0, costBasisMissing, false
+ }
+ basis = effectiveBillBasis(*b, s.cfg.CostScope)
+ if basis != economics.BasisAccount {
+ return 0, basis, false
+ }
+ return b.TotalUSD - b.Services[billTaxService], basis, true
+}
+
+// costBasisLabel names what the cost figure covers. deployment is unused
+// for now; the tag follow-up will need it.
+func costBasisLabel(basis, deployment string) string {
+ if basis == economics.BasisAccount {
+ return costLabelAccount
+ }
+ return costLabelOther
+}
+
+// costBasisHint is the one-line explanation the Billing pages show in place
+// of a hidden cost, or "" when the cost is shown. month is "2006-01".
+func costBasisHint(scope CostScope, basis, month string) string {
+ switch basis {
+ case economics.BasisAccount:
+ return ""
+ case economics.BasisUnstated:
+ return costHintUnstated
+ case costBasisMissing:
+ return fmt.Sprintf(costHintNoBillFmt, month)
+ default:
+ return costHintWhole
+ }
+}
diff --git a/internal/console/platformcost_test.go b/internal/console/platformcost_test.go
new file mode 100644
index 000000000..ee53fcf16
--- /dev/null
+++ b/internal/console/platformcost_test.go
@@ -0,0 +1,99 @@
+package console
+
+import (
+ "context"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/economics"
+)
+
+// TestCarlosPlatformCostBasis: the one figure Billing shows as CARLOS
+// platform cost exists only when the effective basis of the stored bill is
+// "account". Every other case hides the figure and says why.
+func TestCarlosPlatformCostBasis(t *testing.T) {
+ const month = "2026-08"
+ account := CostScope{AccountCarlosOnly: true}
+ bill := func(basis, source string) economics.Bill {
+ return economics.Bill{
+ Schema: 1, Month: month, TotalUSD: 100,
+ Services: map[string]float64{"AmazonEC2": 90, "Tax": 10},
+ Source: source, Basis: basis,
+ }
+ }
+ ce := economics.SourceCostExplorer
+ for _, tc := range []struct {
+ name string
+ raw []byte // stored bytes, when set
+ stored *economics.Bill // stored bill, when set
+ scope CostScope
+ wantUSD float64
+ wantBasis string
+ wantOK bool
+ }{
+ {name: "no object", scope: account, wantBasis: costBasisMissing},
+ {name: "unparseable", raw: []byte(`{"schema":1,"month":`), scope: account, wantBasis: costBasisMissing},
+ {name: "unstated bill zero scope", stored: ptrBill(bill("", ce)), wantBasis: economics.BasisUnstated},
+ {name: "whole bill account scope", stored: ptrBill(bill("whole", ce)), scope: account, wantBasis: economics.BasisWhole},
+ {name: "unstated bill account scope", stored: ptrBill(bill("", ce)), scope: account, wantUSD: 90, wantBasis: economics.BasisAccount, wantOK: true},
+ {name: "account bill zero scope", stored: ptrBill(bill("account", ce)), wantUSD: 90, wantBasis: economics.BasisAccount, wantOK: true},
+ {name: "tagged bill account scope", stored: ptrBill(bill("tagged", ce)), scope: account, wantBasis: economics.BasisWhole},
+ {name: "bogus bill account scope", stored: ptrBill(bill("bogus", ce)), scope: account, wantBasis: economics.BasisWhole},
+ {name: "manual unstated bill account scope", stored: ptrBill(bill("", economics.SourceManual)), scope: account, wantUSD: 90, wantBasis: economics.BasisAccount, wantOK: true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.CostScope = tc.scope
+ switch {
+ case tc.raw != nil:
+ if _, err := fx.rel.Put(context.Background(), economics.BillKey(month), tc.raw, ""); err != nil {
+ t.Fatal(err)
+ }
+ case tc.stored != nil:
+ putStoreJSON(t, fx.rel, economics.BillKey(month), *tc.stored)
+ }
+ usd, basis, ok := fx.srv.carlosPlatformCostUSD(context.Background(), month)
+ if usd != tc.wantUSD || basis != tc.wantBasis || ok != tc.wantOK {
+ t.Fatalf("carlosPlatformCostUSD = (%v, %q, %v), want (%v, %q, %v)",
+ usd, basis, ok, tc.wantUSD, tc.wantBasis, tc.wantOK)
+ }
+ })
+ }
+}
+
+func ptrBill(b economics.Bill) *economics.Bill { return &b }
+
+// TestCostBasisLabelAndHint pins the approved copy (C1-C4, C7) byte for byte.
+func TestCostBasisLabelAndHint(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."
+ c4 = "No AWS bill on file for 2026-11 yet."
+ c7 = "This bill was entered as covering the whole AWS account, CARLOS and other things, so it does not count as CARLOS cost."
+ )
+ for _, tc := range []struct{ basis, want string }{
+ {economics.BasisAccount, c1},
+ {economics.BasisUnstated, c2},
+ {economics.BasisWhole, c2},
+ {costBasisMissing, c2},
+ } {
+ if got := costBasisLabel(tc.basis, "flagship"); got != tc.want {
+ t.Errorf("costBasisLabel(%q) = %q, want %q", tc.basis, got, tc.want)
+ }
+ }
+ for _, scope := range []CostScope{{}, {AccountCarlosOnly: true}} {
+ for _, tc := range []struct{ basis, want string }{
+ {economics.BasisUnstated, c3},
+ {economics.BasisWhole, c7},
+ {costBasisMissing, c4},
+ {economics.BasisAccount, ""},
+ } {
+ if got := costBasisHint(scope, tc.basis, "2026-11"); got != tc.want {
+ t.Errorf("costBasisHint(%+v, %q) = %q, want %q", scope, tc.basis, got, tc.want)
+ }
+ }
+ }
+ if billTaxService != "Tax" {
+ t.Errorf("billTaxService = %q, want Tax", billTaxService)
+ }
+}
diff --git a/internal/console/server.go b/internal/console/server.go
index 797b15c9e..a8796e5ac 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -759,6 +759,11 @@ type Config struct {
// record against (boxid.Verifier.Account). Unset, no box verifies and
// no region can take a move. Only the Phase 1 move door reads it.
AWSAccount string
+ // CostScope (CONSOLE_COST_ACCOUNT_CARLOS_ONLY) is what the operator
+ // declares the AWS account holds. The hourly bill pull stamps each bill
+ // with the basis it implies (billBasisFor) and re-pulls a stored bill
+ // once when that basis changes. The zero value declares nothing.
+ CostScope CostScope
// DomainProof (CONSOLE_DOMAIN_PROOF) is the opt-in for proof of control
// on custom hostnames (#215). With it set, a member's attach is stored
// pending until a TXT record at _carlos-challenge.<host> carries the
@@ -1333,7 +1338,7 @@ type Server struct {
// economicspass.go): nil means "use the real, lazily-built CE client"
// (s.realCECosts); tests inject a fake so a pull can be proven to
// succeed, or to degrade quietly, without live AWS billing IAM.
- ceCosts func(ctx context.Context, start, end time.Time) (map[string]float64, error)
+ ceCosts func(ctx context.Context, q ceQuery) (map[string]float64, error)
// ceClientOnce/ceClient/ceWarnOnce/ceDisabled cache s.realCECosts'
// Cost Explorer client and its process-lifetime disabled state — see
// cepull.go's doc comment for why a mutex isn't needed here.
diff --git a/internal/console/static/ops.css b/internal/console/static/ops.css
index 6ba6babb4..5c02b4144 100644
--- a/internal/console/static/ops.css
+++ b/internal/console/static/ops.css
@@ -205,8 +205,8 @@
economics knob drawer's parts. */
[co-h3] { font-size: var(--rst-fs-base); margin: var(--rst-sp-5) 0 var(--rst-sp-2); }
-/* The economics knob drawer and the bill form: one row per number, its
- label then its control. The drawer is a card that opens. */
+/* The economics knob drawer: one row per number, its label then its
+ control. The drawer is a card that opens. */
[co-knobs] > summary { cursor: pointer; font-weight: 600; }
[co-knobs] > summary + * { margin-block-start: var(--rst-sp-4); }
[co-knob] { align-items: center; display: flex; flex-wrap: wrap; gap: var(--rst-sp-2) var(--rst-sp-3); margin: 0 0 var(--rst-sp-2); }
@@ -216,6 +216,10 @@
[co-knobs] [rst-textarea] { max-inline-size: 32rem; }
[co-knobs] .co-table-wrap { border: 1px solid var(--rst-line); border-radius: var(--rst-radius-sm); }
+/* The economics bill-entry form: Rastrillo fields, kept to a readable
+ width. */
+[co-billform] { max-inline-size: 34rem; }
+
/* The economics accounts page's tier form, under the tier's pill. */
[co-tier] { align-items: center; display: flex; flex-wrap: wrap; gap: var(--rst-sp-2); margin-block-start: var(--rst-sp-2); }
[co-tier] [rst-input] { font-size: var(--rst-fs-sm); inline-size: auto; min-block-size: 0; padding: 0.2rem 0.4rem; }
diff --git a/internal/console/templates/economics.html b/internal/console/templates/economics.html
index 08259f92c..d7ea3373d 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,23 +221,33 @@
<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>
-<form rst-card co-pad co-knobs method="post" action="/fleet/economics/bill">
+<p co-note>{{printf "No AWS bill on file for %s yet. Enter it below." (periodMonth .Economics.Period)}}</p>
+<form rst-card co-pad co-billform method="post" action="/fleet/economics/bill">
<input type="hidden" name="csrf" value="{{.CSRF}}">
- <div co-knob>
- <label for="bill-month">Month</label>
- <input rst-input type="text" id="bill-month" name="month" pattern="\d{4}-\d{2}" value="{{periodMonth .Economics.Period}}" required>
+ <div rst-field-row>
+ <div rst-field>
+ <label rst-field-label for="bill-month">Month</label>
+ <input rst-input type="text" id="bill-month" name="month" pattern="\d{4}-\d{2}" value="{{periodMonth .Economics.Period}}" size="8" required>
+ </div>
+ <div rst-field class="rst-grow">
+ <label rst-field-label for="bill-total">Total USD</label>
+ <input rst-input type="number" step="0.01" min="0" id="bill-total" name="total" required>
+ </div>
</div>
- <div co-knob>
- <label for="bill-total">Total USD</label>
- <input rst-input type="number" step="0.01" min="0" id="bill-total" name="total" required>
+ <div rst-field>
+ <label rst-field-label for="bill-basis">What this bill covers</label>
+ <select rst-input id="bill-basis" name="basis">
+ <option value="account"{{if eq .Economics.BillFormBasis "account"}} selected{{end}}>The whole account, which runs only CARLOS</option>
+ <option value="whole"{{if eq .Economics.BillFormBasis "whole"}} selected{{end}}>The whole account, CARLOS and other things</option>
+ </select>
</div>
- <div co-knob>
- <label for="bill-lines">Services, one "Service=USD" per line</label>
+ <div rst-field>
+ <label rst-field-label for="bill-lines">Services, one "Service=USD" per line</label>
+ <textarea rst-textarea id="bill-lines" name="lines" rows="5" placeholder="EC2=120.50&#10;S3=42.10"></textarea>
</div>
- <p><textarea rst-textarea id="bill-lines" name="lines" rows="6" cols="48" placeholder="EC2=120.50&#10;S3=42.10"></textarea></p>
<button rst-btn type="submit">Save bill</button>
</form>
{{end}}
diff --git a/internal/economics/bill.go b/internal/economics/bill.go
index 506dd7aaa..98dd54c1b 100644
--- a/internal/economics/bill.go
+++ b/internal/economics/bill.go
@@ -8,9 +8,26 @@ const (
SourceCostExplorer = "costexplorer"
)
+// Bill bases: what a stored bill covers. Basis is additive on the wire: a
+// bill written before it existed, or one whose basis nobody stated, reads
+// as BasisUnstated and marshals with no basis key at all.
+const (
+ // BasisUnstated: nobody said what the bill covers. Every bill written
+ // before Basis existed, and every pull on a console without a declared
+ // cost scope.
+ BasisUnstated = ""
+ // BasisAccount: the whole AWS account, declared CARLOS-only (the
+ // console's CONSOLE_COST_ACCOUNT_CARLOS_ONLY cost scope).
+ BasisAccount = "account"
+ // BasisWhole: the whole AWS account, stated to hold more than CARLOS.
+ // Only manual entry writes it.
+ BasisWhole = "whole"
+)
+
// Bill is economics/bills/<month>.json — the real AWS bill for one month,
-// whole-account by-service (attribution to CARLOS is a dashboard knob, not
-// a pull-time filter — both AWS accounts hold non-CARLOS resources).
+// whole-account by-service. The pull never filters to CARLOS resources;
+// Basis records what the stored bill covers, so the dashboard can tell a
+// CARLOS-only account's bill from one that also holds other resources.
type Bill struct {
Schema int `json:"schema"` // 1
Month string `json:"month"` // "2006-01"
@@ -22,6 +39,9 @@ type Bill struct {
// own rule), so a manually-entered bill — which never sets this field —
// would otherwise marshal a lying "0001-01-01T00:00:00Z" pulled_at key.
PulledAt time.Time `json:"pulled_at,omitzero"`
+ // Basis is BasisUnstated | BasisAccount | BasisWhole; omitempty keeps an
+ // unstated bill byte-identical to one written before the field existed.
+ Basis string `json:"basis,omitempty"`
}
// BillsPrefix lists stored bills.
diff --git a/internal/economics/bill_test.go b/internal/economics/bill_test.go
index bf505ab6e..c5e1e8e79 100644
--- a/internal/economics/bill_test.go
+++ b/internal/economics/bill_test.go
@@ -26,3 +26,43 @@ func TestManualBillMarshalsWithoutPulledAt(t *testing.T) {
t.Fatalf("manual bill marshalled a pulled_at key: %s", raw)
}
}
+
+// TestBillBasisWireShape: basis is additive. A bill stored before basis
+// existed reads as BasisUnstated, an unstated bill marshals with no basis
+// key (byte-identical to the old shape), and the two stated bases round-trip.
+func TestBillBasisWireShape(t *testing.T) {
+ old := `{"schema":1,"month":"2026-10","total_usd":5,"services":{},"source":"costexplorer"}`
+ var b Bill
+ if err := json.Unmarshal([]byte(old), &b); err != nil {
+ t.Fatal(err)
+ }
+ if b.Basis != BasisUnstated {
+ t.Fatalf("old bill basis = %q, want unstated", b.Basis)
+ }
+ raw, err := json.Marshal(Bill{Schema: 1, Month: "2026-10", TotalUSD: 5, Services: map[string]float64{}, Source: SourceCostExplorer, Basis: BasisUnstated})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if strings.Contains(string(raw), `"basis"`) {
+ t.Fatalf("unstated bill marshalled a basis key: %s", raw)
+ }
+ if string(raw) != old {
+ t.Fatalf("unstated bill wire shape changed:\n got %s\n want %s", raw, old)
+ }
+ for _, basis := range []string{BasisAccount, BasisWhole} {
+ raw, err := json.Marshal(Bill{Schema: 1, Month: "2026-10", Source: SourceManual, Basis: basis})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(string(raw), `"basis":"`+basis+`"`) {
+ t.Fatalf("basis %q not on the wire: %s", basis, raw)
+ }
+ var back Bill
+ if err := json.Unmarshal(raw, &back); err != nil {
+ t.Fatal(err)
+ }
+ if back.Basis != basis {
+ t.Fatalf("basis round-trip: got %q, want %q", back.Basis, basis)
+ }
+ }
+}
diff --git a/internal/hostops/storage_classifier_test.go b/internal/hostops/storage_classifier_test.go
index 8c9352a89..317c2d9db 100644
--- a/internal/hostops/storage_classifier_test.go
+++ b/internal/hostops/storage_classifier_test.go
@@ -54,6 +54,8 @@ func TestReviewedStorageBodiesBindIdentityAndScope(t *testing.T) {
{"status/consoles/console-a.json", `{"component":"console","actor":"console-b","instance_id":"console-b"}`, false},
{"control/moves-console.json", `{"v":99,"protocol":1}`, false},
{"economics/bills/2026-10.json", `{"schema":1,"month":"2026-09","source":"manual"}`, false},
+ {"economics/bills/2026-10.json", "{\"schema\":1,\"month\":\"2026-10\",\"source\":\"costexplorer\",\"basis\":\"account\"}", true},
+ {"economics/bills/2026-10.json", "{\"schema\":1,\"month\":\"2026-10\",\"source\":\"costexplorer\"}", true},
} {
t.Run(tc.key+tc.body, func(t *testing.T) {
_, _, err := classifyDeploymentFamily(nil, MutationTarget{Method: "Put", Key: tc.key, After: []byte(tc.body)})
diff --git a/internal/provision/testdata/plan14-root-reads-billing-dash-3-cost.tsv b/internal/provision/testdata/plan14-root-reads-billing-dash-3-cost.tsv
new file mode 100644
index 000000000..55ef0fb95
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-billing-dash-3-cost.tsv
@@ -0,0 +1,4 @@
+# Census overlay billing-dash-3-cost, written by census-propose (#369). census-ruling-billing-dash-3-cost, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-billing-dash-3-cost.md.
+# 0 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage . d2e65da57e3385e69bb2cabdf2d94bc5d0e3c2b5f9b324546ae8ee2e6be23e57
+@coverage internal/economics 2c7a25baab91215d83101249e4966e37781b06f5a4d0ba889c03e88cb465408a
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index b495ccc62..6cdf860b4 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -137,3 +137,4 @@ plan14-root-reads-cli-default-console-carloku.tsv 2774b43ac5970e4340339b859204bc
plan14-root-reads-gvisor-demos.tsv f05716181a82721b38cba9b2d89c47925dc2ca426e5c4876ebf1df7b45895ee3
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