Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(chatRuntimeSlice): add tests for chat runtime slice

Steven Enamakel086aa8f95217
diff --git a/app/src/store/chatRuntimeSlice.test.ts b/app/src/store/chatRuntimeSlice.test.ts
index 56552edd14..aba8eddb7d 100644
--- a/app/src/store/chatRuntimeSlice.test.ts
+++ b/app/src/store/chatRuntimeSlice.test.ts
@@ -150,6 +150,24 @@ describe('chatRuntimeSlice recordChatTurnUsage', () => {
expect(store.getState().chatRuntime.sessionTokenUsage.lastTurnContextUsed).toBe(920);
});
+ it('fills the gauge from the final call, not the summed spend of a many-call turn', () => {
+ const store = makeStore();
+ // A 72-call tool loop: 5.7M input summed across calls, ~104k in the last one.
+ store.dispatch(
+ recordChatTurnUsage({
+ inputTokens: 5_710_657,
+ outputTokens: 30_790,
+ contextWindow: 1_048_576,
+ contextTokens: 103_900,
+ })
+ );
+ const usage = store.getState().chatRuntime.sessionTokenUsage;
+ expect(usage.lastTurnContextUsed).toBe(103_900);
+ // Spend is untouched: the turn still cost what it cost.
+ expect(usage.lastTurnInputTokens).toBe(5_710_657);
+ expect(usage.inputTokens).toBe(5_710_657);
+ });
+
it('clamps the gauge numerator to zero when sub-agents exceed the turn total (#4271)', () => {
const store = makeStore();
store.dispatch(