fix(codex): record app-server token usage in session accounting
This commit is contained in:
@@ -196,6 +196,40 @@ class TestRunTurn:
|
||||
# turn_id propagated for downstream session-DB linkage
|
||||
assert r.turn_id == "turn-fake-001"
|
||||
|
||||
def test_token_usage_notification_is_captured(self):
|
||||
client = FakeClient()
|
||||
client.queue_notification(
|
||||
"thread/tokenUsage/updated",
|
||||
threadId="thread-fake-001",
|
||||
turnId="turn-fake-001",
|
||||
tokenUsage={
|
||||
"last": {
|
||||
"totalTokens": 130,
|
||||
"inputTokens": 80,
|
||||
"cachedInputTokens": 20,
|
||||
"outputTokens": 25,
|
||||
"reasoningOutputTokens": 5,
|
||||
},
|
||||
"total": {
|
||||
"totalTokens": 500,
|
||||
"inputTokens": 300,
|
||||
"cachedInputTokens": 75,
|
||||
"outputTokens": 100,
|
||||
"reasoningOutputTokens": 25,
|
||||
},
|
||||
"modelContextWindow": 200000,
|
||||
},
|
||||
)
|
||||
client.queue_notification(
|
||||
"turn/completed",
|
||||
threadId="t",
|
||||
turn={"id": "tu1", "status": "completed", "error": None},
|
||||
)
|
||||
r = make_session(client).run_turn("hi", turn_timeout=2.0)
|
||||
assert r.token_usage_last["totalTokens"] == 130
|
||||
assert r.token_usage_total["totalTokens"] == 500
|
||||
assert r.model_context_window == 200000
|
||||
|
||||
def test_rich_content_turn_is_collapsed_to_text_payload(self):
|
||||
client = FakeClient()
|
||||
client.queue_notification(
|
||||
|
||||
Reference in New Issue
Block a user