fix token profile API-call-only usage · Entire

fix token profile API-call-only usage

Sessions

Changes

2

108 unmodified lines

109
110
111
112
112
113
114
115

108 unmodified lines

\t}
\tdefer repo.Close()
\n\tstore := checkpoint.NewCommittedReadStore(ctx, repo)
\tstore := checkpoint.NewGitStore(repo, checkpoint.ResolveCommittedRefs(ctx))
\tstore.SetBlobFetcher(FetchBlobsByHash)
\tinfos, err := store.ListCommitted(ctx)
\tif 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) {
\trepo, _ := runExplainAutoTestRepo(t)
\tctx := context.Background()
\tstore := checkpoint.NewGitStore(repo)
\tstore := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())

\twriteProfileTokenCheckpoint(ctx, t, store, "100aaa000001", "profile-cache-hotspot", &agent.TokenUsage{
\t\tInputTokens:         100,
63 unmodified lines

func TestTokensProfileCmd_JSONOutput(t *testing.T) {
\trepo, _ := runExplainAutoTestRepo(t)
\tctx := context.Background()
\tstore := checkpoint.NewGitStore(repo)
\tstore := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())

\twriteProfileTokenCheckpoint(ctx, t, store, "200bbb000001", "profile-json-cache", &agent.TokenUsage{
\t\tInputTokens:     100,
39 unmodified lines

\t}
}

func TestTokensProfileCmd_JSONOutputReportsAPICallOnlyCheckpoints(t *testing.T) {
\trepo, _ := runExplainAutoTestRepo(t)
\tctx := context.Background()
\tstore := checkpoint.NewGitStore(repo)
\tstore := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())

\twriteProfileTokenCheckpoint(ctx, t, store, "250bbb000001", "profile-json-api-only", &agent.TokenUsage{
\t\tAPICallCount: 25,
\t})

\tcmd := newTokensGroupCmd()
\tvar stdout bytes.Buffer
\tcmd.SetOut(&stdout)
\tcmd.SetArgs([]string{"profile", "--json"})

\tif err := cmd.ExecuteContext(ctx); err != nil {
\t\tt.Fatalf("expected no error, got: %%v", err)
\t}

\tvar result tokensProfileReport
\tif err := json.Unmarshal(stdout.Bytes(), &result); err != nil {
\t\tt.Fatalf("expected valid JSON, got parse error: %%v\noutput: %%s", err, stdout.String())
\t}
\tif result.CheckpointsWithTokenData != 1 {
\t\tt.Fatalf("checkpoints_with_token_data = %%d, want 1", result.CheckpointsWithTokenData)
\t}
\tif result.MissingTokenData != 0 {
\t\tt.Fatalf("missing_token_data = %%d, want 0", result.MissingTokenData)
\t}
\tif result.Tokens == nil || result.Tokens.Total != 0 || result.Tokens.APICalls != 25 {
\t\tt.Fatalf("unexpected token usage: %%+v", result.Tokens)
\t}
\tif got := signalCount(result.Signals, "api-call-amplification"); got != 1 {
\t\tt.Fatalf("api-call-amplification signal count = %%d, want 1", got)
\t}
}

func TestTokensProfileCmd_LimitScopesAnalyzedCheckpoints(t *testing.T) {
\trepo, _ := runExplainAutoTestRepo(t)
\tctx := context.Background()
\tstore := checkpoint.NewGitStore(repo)
\tstore := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())

\twriteProfileTokenCheckpoint(ctx, t, store, "300ccc000001", "profile-limit-one", &agent.TokenUsage{
\t\tInputTokens:  100,