MCPcopy Create free account
hub / github.com/github/gh-aw / TestExtractJSONTokenUsage

Function TestExtractJSONTokenUsage

pkg/workflow/metrics_test.go:121–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func TestExtractJSONTokenUsage(t *testing.T) {
122 tests := []struct {
123 name string
124 data map[string]any
125 expected int
126 }{
127 {
128 name: "Direct tokens field",
129 data: map[string]any{
130 "tokens": 500,
131 },
132 expected: 500,
133 },
134 {
135 name: "Token count field",
136 data: map[string]any{
137 "token_count": 300,
138 },
139 expected: 300,
140 },
141 {
142 name: "Usage object with input/output tokens",
143 data: map[string]any{
144 "usage": map[string]any{
145 "input_tokens": 100,
146 "output_tokens": 50,
147 },
148 },
149 expected: 150,
150 },
151 {
152 name: "Usage object with cache tokens",
153 data: map[string]any{
154 "usage": map[string]any{
155 "input_tokens": 100,
156 "output_tokens": 50,
157 "cache_creation_input_tokens": 200,
158 "cache_read_input_tokens": 75,
159 },
160 },
161 expected: 425,
162 },
163 {
164 name: "Delta format",
165 data: map[string]any{
166 "delta": map[string]any{
167 "usage": map[string]any{
168 "input_tokens": 25,
169 "output_tokens": 35,
170 },
171 },
172 },
173 expected: 60,
174 },
175 {
176 name: "String token count",
177 data: map[string]any{
178 "tokens": "750",

Callers

nothing calls this directly

Calls 3

ExtractJSONTokenUsageFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected