Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions internal/storage/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package storage

import (
"context"
"encoding/json"
"errors"
"path/filepath"
"testing"
Expand Down Expand Up @@ -150,6 +151,37 @@ func TestLedgerAndTotals(t *testing.T) {
}
}

func TestLedgerTotalsJSONTags(t *testing.T) {
totals := LedgerTotals{
RunID: "run-3",
Calls: 2,
PromptTokens: 300,
CompletionTokens: 130,
Dollars: 0.036,
}

b, err := json.Marshal(totals)
if err != nil {
t.Fatalf("Marshal: %v", err)
}

var got map[string]any
if err := json.Unmarshal(b, &got); err != nil {
t.Fatalf("Unmarshal: %v", err)
}

for _, key := range []string{"runId", "calls", "promptTokens", "completionTokens", "dollars"} {
if _, ok := got[key]; !ok {
t.Fatalf("JSON key %q missing from %s", key, string(b))
}
}
for _, key := range []string{"RunID", "Calls", "PromptTokens", "CompletionTokens", "Dollars"} {
if _, ok := got[key]; ok {
t.Fatalf("unexpected Go field name %q in %s", key, string(b))
}
}
}

func TestSummarizeLedger(t *testing.T) {
s := openTemp(t)
ctx := context.Background()
Expand Down
10 changes: 5 additions & 5 deletions internal/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ type ApprovalRecord struct {

// LedgerTotals aggregates spend for audit/reporting.
type LedgerTotals struct {
RunID string
Calls int64
PromptTokens int64
CompletionTokens int64
Dollars float64
RunID string `json:"runId"`
Calls int64 `json:"calls"`
PromptTokens int64 `json:"promptTokens"`
CompletionTokens int64 `json:"completionTokens"`
Dollars float64 `json:"dollars"`
}

// UsageGroup is one bucket of aggregated spend — e.g. one team, one provider, or
Expand Down