fix: settle unknown charges in their original accounting period
15 files changed,
+131
−35
internal/equipo/task_views.go+6 −0internal/equipo/team/actions.go+4 −1internal/equipo/team/actions_test.go+1 −1internal/equipo/team/budget.go+22 −5internal/equipo/team/budget_test.go+5 −5internal/equipo/team/final_period_test.go+72 −0internal/equipo/team/periodbudget.go+6 −8internal/equipo/team/periodbudget_test.go+2 −2internal/equipo/team/periodquery_test.go+3 −3internal/equipo/team/recovery_release_test.go+2 −2internal/equipo/team/review_regression_test.go+1 −1internal/equipo/team/settletime_test.go+3 −3internal/equipo/team/subscription_test.go+1 −1internal/equipotest/recovery_test.go+1 −1internal/equipotest/runner_events_test.go+2 −2
diff --git a/internal/equipo/task_views.go b/internal/equipo/task_views.go| index b9dc4a3d..b9b79e2b 100644 |
| --- a/internal/equipo/task_views.go |
| +++ b/internal/equipo/task_views.go |
| @@ -300,6 +300,9 @@ func (s *Store) taskViewAt(tx *gorm.DB, actor Actor, task Task) (TaskViewData, e |
| card.CountedTurns += u.SCalls |
| card.InputTokens += u.SInput |
| card.OutputTokens += u.SOutput |
| + if u.SettledBy == "unknown" { |
| + card.UsageKnown = false |
| + } |
| if u.State == "open" { |
| card.UsageKnown = false |
| card.CountedTurns += u.RCalls |
| @@ -408,6 +411,9 @@ func (s *Store) taskViewAt(tx *gorm.DB, actor Actor, task Task) (TaskViewData, e |
| v.CountedTurns += u.SCalls |
| v.InputTokens += u.SInput |
| v.OutputTokens += u.SOutput |
| + if u.SettledBy == "unknown" { |
| + v.UsageKnown = false |
| + } |
| if u.State == "open" { |
| v.UsageKnown = false |
| v.CountedTurns += u.RCalls |
diff --git a/internal/equipo/team/actions.go b/internal/equipo/team/actions.go| index a4d12b56..c37a50fa 100644 |
| --- a/internal/equipo/team/actions.go |
| +++ b/internal/equipo/team/actions.go |
| @@ -524,7 +524,7 @@ func resumeIfResolved(ctx context.Context, tx *sql.Tx, j jobRow, now time.Time) |
| } |
| // Lost marks a dispatching action's reply as lost. The action becomes |
| -// uncertain, its reservation stays open and the job waits on the outcome. |
| +// uncertain, its full reservation is charged and the job waits on the outcome. |
| func (s *Store) Lost(ctx context.Context, scope Scope, id ActionID, detail string) error { |
| return s.tx(ctx, func(tx *sql.Tx) error { |
| now := s.clock.Now() |
| @@ -542,6 +542,9 @@ func (s *Store) Lost(ctx context.Context, scope Scope, id ActionID, detail strin |
| if _, err := tx.ExecContext(ctx, `UPDATE actions SET state='uncertain', last_error=?, updated_at=? WHERE id=?`, detail, ts(now), int64(a.ID)); err != nil { |
| return fail(CodeInvalid, "lost: %v", err) |
| } |
| + if err := settleUnknown(ctx, tx, a.Reservation, now); err != nil { |
| + return err |
| + } |
| if err := appendEvent(ctx, tx, scope, "action.uncertain", "broker", map[string]any{"action": a.ID, "key": a.Key, "detail": detail}, now); err != nil { |
| return err |
| } |
diff --git a/internal/equipo/team/actions_test.go b/internal/equipo/team/actions_test.go| index 85a844ce..59c03749 100644 |
| --- a/internal/equipo/team/actions_test.go |
| +++ b/internal/equipo/team/actions_test.go |
| @@ -145,7 +145,7 @@ func TestReconcileWithoutReceiptNeverRedispatches(t *testing.T) { |
| must(t, err) |
| rows, err := e.store.Reservations(e.ctx, scope) |
| must(t, err) |
| - if len(rows) != 1 || rows[0].State != ReservationOpen { |
| + if len(rows) != 1 || rows[0].State != ReservationSettled || rows[0].Settled != rows[0].Reserved { |
| t.Fatalf("lost usage was released: %+v", rows) |
| } |
| } |
diff --git a/internal/equipo/team/budget.go b/internal/equipo/team/budget.go| index 9aa13e3c..d30dd140 100644 |
| --- a/internal/equipo/team/budget.go |
| +++ b/internal/equipo/team/budget.go |
| @@ -151,8 +151,8 @@ func reserve(ctx context.Context, tx *sql.Tx, j jobRow, step StepID, attempt Att |
| return ReservationID(id), priced, nil |
| } |
| -// settle closes an open reservation at measured usage. A receipt without |
| -// usage leaves it open (unknown usage keeps its reservation). The same |
| +// settle closes an open reservation at measured usage or the full unknown |
| +// reservation. Unknown charges cannot be refunded by a later receipt. The same |
| // receipt id with the same usage is idempotent; a different receipt or |
| // different usage for a settled row is ErrReceiptConflict. Settlement is |
| // accepted whatever the attempt or job state: late usage is still usage. |
| @@ -164,7 +164,7 @@ func settle(ctx context.Context, tx *sql.Tx, id ReservationID, rc Receipt, now t |
| switch r.State { |
| case ReservationOpen: |
| if rc.Usage == nil { |
| - return nil |
| + return settleUnknown(ctx, tx, id, now) |
| } |
| u := settlementUsage(r, *rc.Usage) |
| if err := u.validate(); err != nil { |
| @@ -188,6 +188,17 @@ func settle(ctx context.Context, tx *sql.Tx, id ReservationID, rc Receipt, now t |
| } |
| return nil |
| case ReservationSettled: |
| + if r.SettledBy == "unknown" { |
| + if rc.Usage == nil { |
| + return nil |
| + } |
| + u := settlementUsage(r, *rc.Usage) |
| + if err := u.validate(); err != nil { |
| + return err |
| + } |
| + _, err := tx.ExecContext(ctx, `UPDATE reservations SET s_calls=max(s_calls,?),s_input=max(s_input,?),s_output=max(s_output,?),s_cost=max(s_cost,?),s_cached=max(s_cached,?) WHERE id=?`, u.Calls, u.InputTokens, u.OutputTokens, u.CostMicros, u.CachedInputTokens, id) |
| + return err |
| + } |
| if rc.Usage == nil { |
| return nil |
| } |
| @@ -251,7 +262,7 @@ func (s *Store) SettleAudited(ctx context.Context, scope Scope, id ReservationID |
| if r.Job != scope.Job { |
| return fail(CodeScope, "reservation %d", id) |
| } |
| - if r.State != ReservationOpen { |
| + if r.State != ReservationOpen && !(r.State == ReservationSettled && r.SettledBy == "unknown") { |
| return fail(CodeState, "reservation %d is %s", id, r.State) |
| } |
| var inflight int |
| @@ -261,7 +272,7 @@ func (s *Store) SettleAudited(ctx context.Context, scope Scope, id ReservationID |
| if inflight > 0 { |
| return fail(CodeState, "reservation %d backs a dispatching action", id) |
| } |
| - _, err = tx.ExecContext(ctx, `UPDATE reservations SET s_calls=r_calls, s_input=r_input, s_output=r_output, s_cost=r_cost, state='settled_audited', settled_by=?, settled_at=? WHERE id=? AND state='open'`, |
| + _, err = tx.ExecContext(ctx, `UPDATE reservations SET s_calls=r_calls, s_input=r_input, s_output=r_output, s_cost=r_cost, state='settled_audited', settled_by=?, settled_at=? WHERE id=? AND (state='open' OR settled_by='unknown')`, |
| "operator:"+operator, ts(now), int64(id)) |
| if err != nil { |
| return fail(CodeInvalid, "audited settle: %v", err) |
| @@ -448,3 +459,9 @@ func releaseNotDispatched(ctx context.Context, tx *sql.Tx, id ReservationID, rc |
| _, err = tx.ExecContext(ctx, `UPDATE reservations SET state='released', receipt_id=?, settled_by=?, settled_at=? WHERE id=? AND state='open'`, rc.ID, "adapter:not_dispatched", ts(now), int64(id)) |
| return err |
| } |
| + |
| +// settleUnknown keeps uncertainty explicit without carrying it into later months. |
| +func settleUnknown(ctx context.Context, tx *sql.Tx, id ReservationID, now time.Time) error { |
| + _, err := tx.ExecContext(ctx, `UPDATE reservations SET s_calls=r_calls,s_input=r_input,s_output=r_output,s_cost=r_cost,state='settled',settled_by='unknown',settled_at=? WHERE id=? AND state='open'`, ts(now), id) |
| + return err |
| +} |
diff --git a/internal/equipo/team/budget_test.go b/internal/equipo/team/budget_test.go| index ac322681..d86179fa 100644 |
| --- a/internal/equipo/team/budget_test.go |
| +++ b/internal/equipo/team/budget_test.go |
| @@ -68,26 +68,26 @@ func TestSettlementRules(t *testing.T) { |
| if d.Action != id || d.Hash == "" { |
| t.Fatalf("dispatch %+v", d) |
| } |
| - // Unknown usage keeps the reservation open; the action is still done. |
| + // Unknown usage settles at the full reservation; the action is still done. |
| must(t, e.store.Record(e.ctx, scope, id, Receipt{ID: "r-1", Outcome: OutcomeSuccess, Provider: "fake-a"})) |
| led, _ := e.store.Ledger(e.ctx, scope) |
| - if led.Reserved.Calls != 1 || led.Spent.Calls != 0 { |
| + if led.Reserved.Calls != 0 || led.Spent.Calls != 1 { |
| t.Fatalf("ledger %+v", led) |
| } |
| a, _ := e.store.GetAction(e.ctx, scope, id) |
| if a.State != ActionSucceeded { |
| t.Fatalf("action %s", a.State) |
| } |
| - // Late usage under the same receipt settles exactly once. |
| + // Late usage cannot refund the conservative unknown charge. |
| usage := &Usage{Calls: 1, InputTokens: 80, OutputTokens: 40, CostMicros: 1000} |
| must(t, e.store.Record(e.ctx, scope, id, Receipt{ID: "r-1", Outcome: OutcomeSuccess, Provider: "fake-a", Usage: usage})) |
| must(t, e.store.Record(e.ctx, scope, id, Receipt{ID: "r-1", Outcome: OutcomeSuccess, Provider: "fake-a", Usage: usage})) |
| led, _ = e.store.Ledger(e.ctx, scope) |
| - if led.Reserved.Calls != 0 || led.Spent != *usage { |
| + if led.Reserved.Calls != 0 || led.Spent.InputTokens != 100 || led.Spent.OutputTokens != 50 { |
| t.Fatalf("ledger %+v", led) |
| } |
| other := &Usage{Calls: 1, InputTokens: 81, OutputTokens: 40, CostMicros: 1000} |
| - wantCode(t, e.store.Record(e.ctx, scope, id, Receipt{ID: "r-1", Outcome: OutcomeSuccess, Provider: "fake-a", Usage: other}), CodeReceiptConflict) |
| + must(t, e.store.Record(e.ctx, scope, id, Receipt{ID: "r-1", Outcome: OutcomeSuccess, Provider: "fake-a", Usage: other})) |
| wantCode(t, e.store.Record(e.ctx, scope, id, Receipt{ID: "r-2", Outcome: OutcomeSuccess, Provider: "fake-a", Usage: usage}), CodeReceiptConflict) |
| wantCode(t, e.store.Record(e.ctx, scope, id, Receipt{ID: "r-1", Outcome: OutcomeFailure, Provider: "fake-a"}), CodeReceiptConflict) |
| wantCode(t, e.store.Record(e.ctx, scope, id, Receipt{Outcome: OutcomeSuccess}), CodeInvalid) |
diff --git a/internal/equipo/team/final_period_test.go b/internal/equipo/team/final_period_test.go| new file mode 100644 |
| index 00000000..f2a35d7c |
| --- /dev/null |
| +++ b/internal/equipo/team/final_period_test.go |
| @@ -0,0 +1,72 @@ |
| +package team |
| + |
| +import ( |
| + "database/sql" |
| + "testing" |
| + "time" |
| +) |
| + |
| +func TestUnknownChargesStayInTheirMonth(t *testing.T) { |
| + for _, outcome := range []string{"completed", "lost"} { |
| + t.Run(outcome, func(t *testing.T) { |
| + e := newEnv(t) |
| + must(t, e.store.ConfigureBudgets(e.ctx, acctA, 0, periodSet())) |
| + s, h := runnerJob(e, runnerPolicy(t, "subscription")) |
| + month := e.clock.Now() |
| + id, err := e.store.Intend(e.ctx, s, h, intent("turn", Usage{})) |
| + must(t, err) |
| + _, err = e.store.Admit(e.ctx, s, id) |
| + must(t, err) |
| + if outcome == "lost" { |
| + must(t, e.store.Lost(e.ctx, s, id, "unknown")) |
| + } else { |
| + must(t, e.store.Record(e.ctx, s, id, Receipt{ID: "done", Outcome: OutcomeSuccess})) |
| + } |
| + must(t, e.store.ContainUntrusted(e.ctx, s, h)) |
| + must(t, e.store.Pause(e.ctx, "recovery")) |
| + must(t, e.store.RecordRecoveryCharge(e.ctx, RecoveryCharge{Key: "missing", Account: acctA, Project: 1, Reserved: PeriodLimits{Calls: 2, Seconds: 10}}, "owner", "missing history")) |
| + for _, project := range []ProjectID{0, 1} { |
| + current, err := e.store.PeriodUsage(e.ctx, acctA, project, month) |
| + must(t, err) |
| + if current.Spent.Calls != 3 || current.Spent.InputTokens != 100 || current.Spent.OutputTokens != 50 || current.Spent.Seconds != 1210 || current.Reserved != (PeriodLimits{}) { |
| + t.Errorf("unknown charge not settled in its month: %+v", current) |
| + } |
| + next, err := e.store.PeriodUsage(e.ctx, acctA, project, month.AddDate(0, 1, 0)) |
| + must(t, err) |
| + if next != (PeriodUsage{}) { |
| + t.Errorf("unknown charge leaked into next month: %+v", next) |
| + } |
| + } |
| + must(t, e.store.read(e.ctx, func(tx *sql.Tx) error { |
| + var state, by string |
| + if err := tx.QueryRow(`SELECT state,settled_by FROM reservations`).Scan(&state, &by); err != nil { |
| + return err |
| + } |
| + if state != "settled" || by != "unknown" { |
| + t.Errorf("unknown usage not marked: %s %s", state, by) |
| + } |
| + var unknown int |
| + if err := tx.QueryRow(`SELECT elapsed_unknown FROM time_reservations`).Scan(&unknown); err != nil { |
| + return err |
| + } |
| + if unknown != 1 { |
| + t.Error("elapsed uncertainty erased") |
| + } |
| + return nil |
| + })) |
| + }) |
| + } |
| +} |
| + |
| +func TestOpenChargesStayInTheirMonth(t *testing.T) { |
| + e := newEnv(t) |
| + must(t, e.store.ConfigureBudgets(e.ctx, acctA, 0, periodSet())) |
| + s, h := runnerJob(e, runnerPolicy(t, "subscription")) |
| + _, err := e.store.Intend(e.ctx, s, h, intent("pending", Usage{})) |
| + must(t, err) |
| + next, err := e.store.PeriodUsage(e.ctx, acctA, 0, e.clock.Now().Add(32*24*time.Hour)) |
| + must(t, err) |
| + if next != (PeriodUsage{}) { |
| + t.Fatal("old open reservations reduce new month", next) |
| + } |
| +} |
diff --git a/internal/equipo/team/periodbudget.go b/internal/equipo/team/periodbudget.go| index b78f23e7..0a4c5361 100644 |
| --- a/internal/equipo/team/periodbudget.go |
| +++ b/internal/equipo/team/periodbudget.go |
| @@ -152,8 +152,8 @@ func period(at time.Time) string { return at.UTC().Format("2006-01") } |
| func periodSum(ctx context.Context, tx *sql.Tx, account AccountID, project ProjectID, at time.Time) (PeriodUsage, error) { |
| var sum PeriodUsage |
| - chargeQuery := "SELECT reserved FROM recovery_charges WHERE account=?" |
| - chargeArgs := []any{string(account)} |
| + chargeQuery := "SELECT reserved FROM recovery_charges WHERE account=? AND substr(created_at,1,7)=?" |
| + chargeArgs := []any{string(account), period(at)} |
| if project != 0 { |
| chargeQuery += " AND project_id=?" |
| chargeArgs = append(chargeArgs, project) |
| @@ -175,7 +175,7 @@ func periodSum(ctx context.Context, tx *sql.Tx, account AccountID, project Proje |
| err = fail(CodeInvalid, "negative recovery charge") |
| break |
| } |
| - sum.Reserved, err = sum.Reserved.add(r) |
| + sum.Spent, err = sum.Spent.add(r) |
| if err != nil { |
| break |
| } |
| @@ -246,10 +246,8 @@ func periodQuery(table string, account AccountID, project ProjectID, at time.Tim |
| args = append(args, project) |
| } |
| q += " AND " + states |
| - if settled { |
| - q += " AND period=?" |
| - args = append(args, period(at)) |
| - } |
| + q += " AND period=?" |
| + args = append(args, period(at)) |
| return q, args |
| } |
| @@ -327,7 +325,7 @@ func settleTime(ctx context.Context, tx *sql.Tx, a Attempt, now time.Time) error |
| return fail(CodeState, "attempt has no open time reservation") |
| } |
| if unknown != 0 || now.Before(a.CreatedAt) { |
| - _, err := tx.ExecContext(ctx, `UPDATE time_reservations SET elapsed_unknown=1 WHERE attempt_id=?`, a.ID) |
| + _, err := tx.ExecContext(ctx, `UPDATE time_reservations SET elapsed_unknown=1, settled_seconds=reserved_seconds, state='settled', settled_at=? WHERE attempt_id=?`, ts(now), a.ID) |
| return err |
| } |
| seconds := max(int64(0), now.Unix()-a.CreatedAt.Unix()) |
diff --git a/internal/equipo/team/periodbudget_test.go b/internal/equipo/team/periodbudget_test.go| index b8f18de1..8a362728 100644 |
| --- a/internal/equipo/team/periodbudget_test.go |
| +++ b/internal/equipo/team/periodbudget_test.go |
| @@ -189,8 +189,8 @@ func TestBudgetPeriodBoundary(t *testing.T) { |
| nov := e.clock.Now() |
| e.clock.Advance(13 * time.Hour) |
| u := periodUsage(e, 0) |
| - if u.Reserved.Calls != 1 || u.Spent.Calls != 0 || u.Reserved.Seconds != 1200 { |
| - t.Fatal("period rollover lost unresolved usage", u) |
| + if u != (PeriodUsage{}) { |
| + t.Fatal("period rollover carried unresolved usage", u) |
| } |
| receipt.ID = "late" |
| must(t, e.store.Record(e.ctx, a, ids[1], receipt)) |
diff --git a/internal/equipo/team/periodquery_test.go b/internal/equipo/team/periodquery_test.go| index 399274ff..b133b5f6 100644 |
| --- a/internal/equipo/team/periodquery_test.go |
| +++ b/internal/equipo/team/periodquery_test.go |
| @@ -58,7 +58,7 @@ func TestPeriodQueriesBoundedHistory(t *testing.T) { |
| if err != nil { |
| return err |
| } |
| - if !strings.Contains(plan, "SEARCH") || !strings.Contains(plan, "state=?") || (settled && !strings.Contains(plan, "period=?")) || (project != 0 && !strings.Contains(plan, "project_id=?")) { |
| + if !strings.Contains(plan, "SEARCH") || !strings.Contains(plan, "state=?") || !strings.Contains(plan, "period=?") || (project != 0 && !strings.Contains(plan, "project_id=?")) { |
| t.Fatalf("bounded-history query plan: %s", plan) |
| } |
| var count int |
| @@ -73,8 +73,8 @@ func TestPeriodQueriesBoundedHistory(t *testing.T) { |
| return nil |
| })) |
| u := periodUsage(e, project) |
| - if u.Reserved.Calls != 1 || u.Reserved.InputTokens != 7 || u.Spent.Calls != 1 || u.Spent.InputTokens != 2 || u.Reserved.Seconds != 1200 { |
| - t.Fatal("old open rows lost or old settled rows charged", u) |
| + if u.Reserved != (PeriodLimits{}) || u.Spent.Calls != 1 || u.Spent.InputTokens != 2 { |
| + t.Fatal("old rows charged to current month", u) |
| } |
| } |
| must(t, e.store.tx(e.ctx, func(tx *sql.Tx) error { |
diff --git a/internal/equipo/team/recovery_release_test.go b/internal/equipo/team/recovery_release_test.go| index 18204f56..5e7e56e5 100644 |
| --- a/internal/equipo/team/recovery_release_test.go |
| +++ b/internal/equipo/team/recovery_release_test.go |
| @@ -76,7 +76,7 @@ func TestContainAfterClockRollback(t *testing.T) { |
| t.Fatal("contained handle renewed") |
| } |
| usage := periodUsage(e, 1) |
| - if usage.Reserved.Seconds != int64(testPolicy().AttemptSeconds) { |
| + if usage.Spent.Seconds != int64(testPolicy().AttemptSeconds) { |
| t.Fatalf("rollback refunded unknown elapsed time: %+v", usage) |
| } |
| e.clock.Advance(time.Hour) |
| @@ -201,7 +201,7 @@ func TestContainAfterClockRollbackReopen(t *testing.T) { |
| e.openNoResume() |
| must(t, e.store.StopAttempt(e.ctx, scope, h, "physical cleanup")) |
| must(t, e.store.Contain(e.ctx, scope, h.Attempt, "supervisor")) |
| - if got := periodUsage(e, 1); got.Reserved.Seconds != int64(testPolicy().AttemptSeconds) { |
| + if got := periodUsage(e, 1); got.Spent.Seconds != int64(testPolicy().AttemptSeconds) { |
| t.Fatalf("reopen lost clock high water: %+v", got) |
| } |
| } |
diff --git a/internal/equipo/team/review_regression_test.go b/internal/equipo/team/review_regression_test.go| index ab44cafc..7c110f31 100644 |
| --- a/internal/equipo/team/review_regression_test.go |
| +++ b/internal/equipo/team/review_regression_test.go |
| @@ -66,7 +66,7 @@ func TestEveryReplayClassRetainsUnknownUsage(t *testing.T) { |
| must(t, err) |
| rows, err := e.store.Reservations(e.ctx, scope) |
| must(t, err) |
| - if len(rows) != 1 || rows[0].State != ReservationOpen { |
| + if len(rows) != 1 || rows[0].State != ReservationSettled || rows[0].Settled != rows[0].Reserved { |
| t.Fatalf("unknown usage released: %+v", rows) |
| } |
| }) |
diff --git a/internal/equipo/team/settletime_test.go b/internal/equipo/team/settletime_test.go| index 67305567..291cbed9 100644 |
| --- a/internal/equipo/team/settletime_test.go |
| +++ b/internal/equipo/team/settletime_test.go |
| @@ -24,7 +24,7 @@ func TestContainTimeAfterClockStep(t *testing.T) { |
| usage := periodUsage(e, 1) |
| reserved := int64(0) |
| if tc.elapsed < 0 { |
| - reserved = int64(testPolicy().AttemptSeconds) |
| + tc.seconds = int64(testPolicy().AttemptSeconds) |
| } |
| if usage.Reserved.Seconds != reserved || usage.Spent.Seconds != tc.seconds { |
| t.Fatalf("settled %+v, want %d seconds", usage, tc.seconds) |
| @@ -85,13 +85,13 @@ func TestTimeMigrationAfterClockStep(t *testing.T) { |
| must(t, db.Close()) |
| e.open() |
| must(t, e.store.ConfigureBudgets(e.ctx, acctA, 0, periodSet())) |
| - if usage := periodUsage(e, 0); usage.Reserved.Seconds != int64(testPolicy().AttemptSeconds) || usage.Spent.Seconds != 0 { |
| + if usage := periodUsage(e, 0); usage.Spent.Seconds != int64(testPolicy().AttemptSeconds) || usage.Reserved.Seconds != 0 { |
| t.Fatal("migrated backwards time", usage) |
| } |
| var state string |
| var seconds int64 |
| must(t, e.store.db.QueryRow("SELECT state, settled_seconds FROM time_reservations WHERE attempt_id=?", h.Attempt).Scan(&state, &seconds)) |
| - if state != "open" || seconds != 0 { |
| + if state != "settled" || seconds != int64(testPolicy().AttemptSeconds) { |
| t.Fatal("migrated settlement missing", state, seconds) |
| } |
| must(t, e.store.Contain(e.ctx, scope, h.Attempt, "s")) |
diff --git a/internal/equipo/team/subscription_test.go b/internal/equipo/team/subscription_test.go| index 56c67105..ac6a0aef 100644 |
| --- a/internal/equipo/team/subscription_test.go |
| +++ b/internal/equipo/team/subscription_test.go |
| @@ -136,7 +136,7 @@ func TestUnknownUsageStillCharged(t *testing.T) { |
| must(t, err) |
| sum, err := e.store.Ledger(e.ctx, s) |
| must(t, err) |
| - if sum.Reserved.Calls != 2 || sum.Reserved.InputTokens != 200 || !sum.Charged.CostUnavailable { |
| + if sum.Charged.Calls != 2 || sum.Charged.InputTokens != 200 || !sum.Charged.CostUnavailable { |
| t.Fatal("unknown usage refunded", sum) |
| } |
| } |
diff --git a/internal/equipotest/recovery_test.go b/internal/equipotest/recovery_test.go| index 89231e9a..02f59c1f 100644 |
| --- a/internal/equipotest/recovery_test.go |
| +++ b/internal/equipotest/recovery_test.go |
| @@ -305,7 +305,7 @@ func TestRecoveryReleaseMissingHistoryCharge(t *testing.T) { |
| executionMust(t, s.ReleaseExecution(ctx, owner, snap.Revision, "attest missing history has been conservatively charged", snap.Hash)) |
| usage, err := x.Core.PeriodUsage(ctx, req.Account, req.Project, time.Now()) |
| executionMust(t, err) |
| - if usage.Reserved != charge.Reserved || scalar(t, d, "SELECT count(*) FROM actions WHERE receipt<>''") != 0 { |
| + if usage.Spent != charge.Reserved || scalar(t, d, "SELECT count(*) FROM actions WHERE receipt<>''") != 0 { |
| t.Fatalf("charge lost or fabricated receipt: %+v", usage) |
| } |
| } |
diff --git a/internal/equipotest/runner_events_test.go b/internal/equipotest/runner_events_test.go| index a3a85340..08a477a4 100644 |
| --- a/internal/equipotest/runner_events_test.go |
| +++ b/internal/equipotest/runner_events_test.go |
| @@ -164,7 +164,7 @@ func TestRunnerEventReplayMissingAndLateAfterCancel(t *testing.T) { |
| executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) |
| rows, err := f.x.Core.Reservations(connectionContext, e.Scope) |
| executionMust(t, err) |
| - if rows[0].State != team.ReservationOpen { |
| + if rows[0].State != team.ReservationSettled || rows[0].Settled != rows[0].Reserved { |
| t.Fatal("missing usage refunded") |
| } |
| q := f.request() |
| @@ -186,7 +186,7 @@ func TestRunnerEventReplayMissingAndLateAfterCancel(t *testing.T) { |
| } |
| rows, err = f.x.Core.Reservations(connectionContext, e.Scope) |
| executionMust(t, err) |
| - if rows[0].State != team.ReservationSettled || rows[0].Settled.InputTokens != 13 { |
| + if rows[0].State != team.ReservationSettled || rows[0].Settled.InputTokens != rows[0].Reserved.InputTokens { |
| t.Fatal("late usage did not settle", rows) |
| } |
| } |