forked from getagentseal/codeburn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel-efficiency.test.ts
More file actions
141 lines (127 loc) · 4.22 KB
/
Copy pathmodel-efficiency.test.ts
File metadata and controls
141 lines (127 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { describe, expect, it } from 'vitest'
import { aggregateModelEfficiency } from '../src/model-efficiency.js'
import type { ClassifiedTurn, ParsedApiCall, ProjectSummary, SessionSummary } from '../src/types.js'
function call(model: string, costUSD = 1): ParsedApiCall {
return {
provider: 'claude',
model,
usage: {
inputTokens: 100,
outputTokens: 50,
cacheCreationInputTokens: 0,
cacheReadInputTokens: 0,
cachedInputTokens: 0,
reasoningTokens: 0,
webSearchRequests: 0,
},
costUSD,
tools: ['Edit'],
mcpTools: [],
skills: [],
hasAgentSpawn: false,
hasPlanMode: false,
speed: 'standard',
timestamp: '2026-05-05T00:00:00Z',
bashCommands: [],
deduplicationKey: `${model}-${costUSD}`,
}
}
function turn(model: string, opts: { hasEdits?: boolean; retries?: number; costUSD?: number } = {}): ClassifiedTurn {
return {
userMessage: '',
assistantCalls: [call(model, opts.costUSD ?? 1)],
timestamp: '2026-05-05T00:00:00Z',
sessionId: 's1',
category: 'coding',
retries: opts.retries ?? 0,
hasEdits: opts.hasEdits ?? true,
}
}
function multiModelTurn(calls: ParsedApiCall[], opts: { retries?: number; hasEdits?: boolean } = {}): ClassifiedTurn {
return {
userMessage: '',
assistantCalls: calls,
timestamp: '2026-05-05T00:00:00Z',
sessionId: 's1',
category: 'coding',
retries: opts.retries ?? 0,
hasEdits: opts.hasEdits ?? true,
}
}
function project(turns: ClassifiedTurn[]): ProjectSummary {
const session: SessionSummary = {
sessionId: 's1',
project: 'app',
firstTimestamp: '2026-05-05T00:00:00Z',
lastTimestamp: '2026-05-05T00:00:00Z',
totalCostUSD: turns.reduce((sum, t) => sum + t.assistantCalls.reduce((s, c) => s + c.costUSD, 0), 0),
totalInputTokens: 0,
totalOutputTokens: 0,
totalCacheReadTokens: 0,
totalCacheWriteTokens: 0,
apiCalls: turns.reduce((sum, t) => sum + t.assistantCalls.length, 0),
turns,
modelBreakdown: {},
toolBreakdown: {},
mcpBreakdown: {},
bashBreakdown: {},
categoryBreakdown: {} as SessionSummary['categoryBreakdown'],
skillBreakdown: {},
}
return {
project: 'app',
projectPath: '/app',
sessions: [session],
totalCostUSD: session.totalCostUSD,
totalApiCalls: session.apiCalls,
}
}
describe('aggregateModelEfficiency', () => {
it('computes one-shot, retry, and cost-per-edit metrics by display model', () => {
const stats = aggregateModelEfficiency([project([
turn('claude-sonnet-4-5', { hasEdits: true, retries: 0, costUSD: 2 }),
turn('claude-sonnet-4-5', { hasEdits: true, retries: 2, costUSD: 4 }),
turn('claude-opus-4-6', { hasEdits: true, retries: 0, costUSD: 10 }),
turn('claude-sonnet-4-5', { hasEdits: false, retries: 0, costUSD: 3 }),
])])
const sonnet = stats.get('Sonnet 4.5')
expect(sonnet?.editTurns).toBe(2)
expect(sonnet?.oneShotTurns).toBe(1)
expect(sonnet?.oneShotRate).toBe(50)
expect(sonnet?.retriesPerEdit).toBe(1)
expect(sonnet?.costPerEditUSD).toBe(3)
const opus = stats.get('Opus 4.6')
expect(opus?.oneShotRate).toBe(100)
})
it('returns no stats for non-edit turns', () => {
const stats = aggregateModelEfficiency([project([
turn('claude-sonnet-4-5', { hasEdits: false }),
])])
expect(stats.size).toBe(0)
})
it('attributes a multi-model turn to the first non-synthetic model', () => {
const stats = aggregateModelEfficiency([project([
multiModelTurn([
call('<synthetic>', 0),
call('claude-opus-4-6', 2),
call('claude-sonnet-4-5', 1),
], { retries: 0, hasEdits: true }),
])])
expect(stats.has('Opus 4.6')).toBe(true)
expect(stats.has('Sonnet 4.5')).toBe(false)
expect(stats.has('<synthetic>')).toBe(false)
const opus = stats.get('Opus 4.6')!
expect(opus.editTurns).toBe(1)
expect(opus.oneShotTurns).toBe(1)
expect(opus.costPerEditUSD).toBe(3)
})
it('skips a turn whose calls are all synthetic', () => {
const stats = aggregateModelEfficiency([project([
multiModelTurn([
call('<synthetic>', 0),
call('<synthetic>', 0),
], { retries: 0, hasEdits: true }),
])])
expect(stats.size).toBe(0)
})
})