usage: cover the two review-flagged gaps in per-source day counting
TestStatementsPassUnsweptStorageIsNotComplete only asserted the negative storage case, which a nil SourceDays map also satisfies; nothing checked that a clean storage day actually counts. Added TestStatementsPassCleanStorageDayCounts for the positive case. TestStatementsPassSourceDaysNeedsEveryBox never asserted metrics stayed at 0 when no metrics box exists at all, so the len(metricsBoxes) > 0 guard in sweepUsage had no test catching its removal. Added that assertion to the existing test. Verified both by deleting the guarded line, watching the new assertion fail, and restoring it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011cEe5te3cyEcdF3JL2rN5M
1 file changed,
+38
−0
internal/console/economicspass_test.go+38 −0
diff --git a/internal/console/economicspass_test.go b/internal/console/economicspass_test.go| index 97a0cbc12..2831e035e 100644 |
| --- a/internal/console/economicspass_test.go |
| +++ b/internal/console/economicspass_test.go |
| @@ -774,6 +774,13 @@ func TestStatementsPassSourceDaysNeedsEveryBox(t *testing.T) { |
| if got := st.SourceDays[usage.SourceEdge]; got != 0 { |
| t.Errorf("edge source days = %d, want 0 — box2 reported nothing on 1 Aug", got) |
| } |
| + // No metrics box exists at all, so metricsBoxes is empty. Without the |
| + // len(metricsBoxes) > 0 guard, 0 == 0 would read the day as complete — |
| + // exactly the "absent must not read as complete" failure this task |
| + // exists to prevent. |
| + if got := st.SourceDays[usage.SourceMetrics]; got != 0 { |
| + t.Errorf("metrics source days = %d, want 0 — no metrics box exists at all", got) |
| + } |
| if st.CoveredDays != 1 { |
| t.Errorf("CoveredDays = %d, want 1 — box1 alone still covers for modelling", st.CoveredDays) |
| } |
| @@ -808,6 +815,37 @@ func TestStatementsPassUnsweptStorageIsNotComplete(t *testing.T) { |
| } |
| } |
| +// A storage day that sized every tenant store cleanly counts as a complete |
| +// source day — the positive case TestStatementsPassUnsweptStorageIsNotComplete |
| +// does not exercise, so storageOK actually being set is verified somewhere. |
| +func TestStatementsPassCleanStorageDayCounts(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + ctx := context.Background() |
| + now := time.Date(2026, 8, 1, 23, 0, 0, 0, time.UTC) |
| + |
| + putStoreJSON(t, fx.rel, usage.StorageDayKey("2026-08-01"), usage.StorageDay{ |
| + V: 1, Date: "2026-08-01", |
| + Apps: map[string]usage.AppStorage{ |
| + fixtureAcct + "/" + fixtureApp: {BucketBytes: 1000}, |
| + }, |
| + }) |
| + |
| + if err := fx.srv.statementsPass(ctx, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + raw, _, err := fx.rel.Get(ctx, usage.StatementKey(fixtureAcct, "2026-08")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var st usage.Statement |
| + if err := json.Unmarshal(raw, &st); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := st.SourceDays[usage.SourceStorage]; got != 1 { |
| + t.Errorf("storage source days = %d, want 1 — every store sized cleanly", got) |
| + } |
| +} |
| + |
| // A census snapshot is not a measurement. Census must feed its own source |
| // count without touching CoveredDays, which foldStorageAndCensus documents |
| // as metrics/edge/storage only (economicspass.go:516-517) and which reaches |