fix token profile API-call-only usage · Entire
fix token profile API-call-only usage
fcfc307·
peyton-alt·3w ago·2 files·+40 added/-4 removed
Sessions
c04a3bb165a4View transcript
Changes
2
cmd/entire/cli
- Mtokens_profile.go+1/-1
Mtokens_profile_test.go+39/-3
108 unmodified lines
109
110
111
112
112
113
114
115
108 unmodified lines
}
d
repo.Close()
store := checkpoint.NewCommittedReadStore(ctx, repo)
store := checkpoint.NewGitStore(repo, checkpoint.ResolveCommittedRefs(ctx))
store.SetBlobFetcher(FetchBlobsByHash)
infos, err := store.ListCommitted(ctx)
if err != nil {
Mcmd/entire/cli/tokens_profile.go+1/-1
16 unmodified lines
17
18
19
20
20
21
22
23
63 unmodified lines
87
88
89
90
90
91
92
93
39 unmodified lines
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
139
175
176
177
178
16 unmodified lines
func TestTokensProfileCmd_TextOutputAggregatesCommittedCheckpoints(t *testing.T) {
repo, _ := runExplainAutoTestRepo(t)
ctx := context.Background()
store := checkpoint.NewGitStore(repo)
store := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())
writeProfileTokenCheckpoint(ctx, t, store, "100aaa000001", "profile-cache-hotspot", &agent.TokenUsage{
InputTokens: 100,
63 unmodified lines
func TestTokensProfileCmd_JSONOutput(t *testing.T) {
repo, _ := runExplainAutoTestRepo(t)
ctx := context.Background()
store := checkpoint.NewGitStore(repo)
store := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())
writeProfileTokenCheckpoint(ctx, t, store, "200bbb000001", "profile-json-cache", &agent.TokenUsage{
InputTokens: 100,
39 unmodified lines
}
}
func TestTokensProfileCmd_JSONOutputReportsAPICallOnlyCheckpoints(t *testing.T) {
repo, _ := runExplainAutoTestRepo(t)
ctx := context.Background()
store := checkpoint.NewGitStore(repo)
store := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())
writeProfileTokenCheckpoint(ctx, t, store, "250bbb000001", "profile-json-api-only", &agent.TokenUsage{
APICallCount: 25,
})
cmd := newTokensGroupCmd()
var stdout bytes.Buffer
cmd.SetOut(&stdout)
cmd.SetArgs([]string{"profile", "--json"})
if err := cmd.ExecuteContext(ctx); err != nil {
t.Fatalf("expected no error, got: %v", err)
}
var result tokensProfileReport
if err := json.Unmarshal(stdout.Bytes(), &result); err != nil {
t.Fatalf("expected valid JSON, got parse error: %v\noutput: %s", err, stdout.String())
}
if result.CheckpointsWithTokenData != 1 {
t.Fatalf("checkpoints_with_token_data = %d, want 1", result.CheckpointsWithTokenData)
}
if result.MissingTokenData != 0 {
t.Fatalf("missing_token_data = %d, want 0", result.MissingTokenData)
}
if result.Tokens == nil || result.Tokens.Total != 0 || result.Tokens.APICalls != 25 {
t.Fatalf("unexpected token usage: %+v", result.Tokens)
}
if got := signalCount(result.Signals, "api-call-amplification"); got != 1 {
t.Fatalf("api-call-amplification signal count = %d, want 1", got)
}
}
func TestTokensProfileCmd_LimitScopesAnalyzedCheckpoints(t *testing.T) {
repo, _ := runExplainAutoTestRepo(t)
ctx := context.Background()
store := checkpoint.NewGitStore(repo)
store := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())
writeProfileTokenCheckpoint(ctx, t, store, "300ccc000001", "profile-limit-one", &agent.TokenUsage{
InputTokens: 100,