Skip to content

Commit 5b94131

Browse files
committed
test(codex): cover the #2046 rollout in every Codex report mode
The adapter tests drive the event loader and the session aggregation, but each Codex report mode groups usage on its own path, and the copy dedupe runs inside that aggregation. A regression in how one mode keys or groups the two identical requests would pass the adapter tests. Run the issue's exact rollout through the CLI for daily, monthly, and session (Codex has no weekly report). Assert JSON rows and totals at 16,000 input, 4,000 cache read, and 200 output, and snapshot each table.
1 parent 12d5264 commit 5b94131

5 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎rust/crates/ccusage/tests/codex_cli.rs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,35 @@ fn prices_issue_1987_recorded_ultrafast_requests_at_ultrafast_rates() {
248248
}
249249
}
250250

251+
#[test]
252+
fn reports_issue_2046_identical_fork_instant_requests_in_every_report_mode() {
253+
let fixture = fs_fixture!({
254+
"codex/sessions/2026/11/01/rollout-2026-11-01T09-42-09-01a1967c-0000-7000-8000-00000000000a.jsonl":
255+
include_str!("fixtures/codex/issue_2046.jsonl"),
256+
});
257+
258+
for (mode, rows) in [
259+
("daily", "daily"),
260+
("monthly", "monthly"),
261+
("session", "sessions"),
262+
] {
263+
let report: Value =
264+
serde_json::from_str(&run_cli(&fixture, &["codex", mode, "--json"])).unwrap();
265+
let rows = report[rows].as_array().unwrap();
266+
assert_eq!(rows.len(), 1, "{mode}");
267+
for usage in [&rows[0], &report["totals"]] {
268+
assert_eq!(usage["inputTokens"], 16_000, "{mode}");
269+
assert_eq!(usage["cacheReadTokens"], 4_000, "{mode}");
270+
assert_eq!(usage["outputTokens"], 200, "{mode}");
271+
}
272+
273+
insta::assert_snapshot!(
274+
format!("issue_2046_{mode}_table"),
275+
run_cli(&fixture, &["codex", mode])
276+
);
277+
}
278+
}
279+
251280
fn issue_1970_codex_fixture() -> Fixture {
252281
fs_fixture!({
253282
"codex/sessions/2026/01/05/child.jsonl":
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{"timestamp":"2026-11-01T09:42:09.923Z","type":"session_meta","payload":{"id":"01a1967c-0000-7000-8000-00000000000a","forked_from_id":"01a1967b-0000-7000-8000-000000000001","timestamp":"2026-11-01T09:42:09.923Z","originator":"codex_vscode","cli_version":"0.164.0-alpha.11.1","source":{"subagent":{"thread_spawn":{"parent_thread_id":"01a1967b-0000-7000-8000-000000000001","depth":1}}},"model_provider":"openai"}}
2+
{"timestamp":"2026-11-01T09:42:09.923Z","type":"compacted","payload":{"message":"","replacement_history":[]}}
3+
{"timestamp":"2026-11-01T09:42:09.923Z","type":"turn_context","payload":{"model":"gpt-6-astra"}}
4+
{"timestamp":"2026-11-01T09:42:09.923Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":990000,"cached_input_tokens":0,"output_tokens":10000,"reasoning_output_tokens":0,"total_tokens":1000000},"last_token_usage":{"input_tokens":990000,"cached_input_tokens":0,"output_tokens":10000,"reasoning_output_tokens":0,"total_tokens":1000000}}}}
5+
{"timestamp":"2026-11-01T09:42:09.923Z","type":"token_usage_record","payload":{"response_id":"resp_child_1","usage":{"input_tokens":10000,"cached_input_tokens":2000,"output_tokens":100,"reasoning_output_tokens":0,"total_tokens":10100}}}
6+
{"timestamp":"2026-11-01T09:42:09.923Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":1000000,"cached_input_tokens":2000,"output_tokens":10100,"reasoning_output_tokens":0,"total_tokens":1010100},"last_token_usage":{"input_tokens":10000,"cached_input_tokens":2000,"output_tokens":100,"reasoning_output_tokens":0,"total_tokens":10100}}}}
7+
{"timestamp":"2026-11-01T09:42:09.923Z","type":"token_usage_record","payload":{"response_id":"resp_child_2","usage":{"input_tokens":10000,"cached_input_tokens":2000,"output_tokens":100,"reasoning_output_tokens":0,"total_tokens":10100}}}
8+
{"timestamp":"2026-11-01T09:42:09.923Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":1010000,"cached_input_tokens":4000,"output_tokens":10200,"reasoning_output_tokens":0,"total_tokens":1020200},"last_token_usage":{"input_tokens":10000,"cached_input_tokens":2000,"output_tokens":100,"reasoning_output_tokens":0,"total_tokens":10100}}}}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/ccusage/tests/codex_cli.rs
3+
expression: "run_cli(&fixture, &[\"codex\", mode])"
4+
---
5+
┌────────────┬───────────────┬───────────┬───────────┬────────────┬───────────────┬─────────────┬───────────────┬─────────────┐
6+
│ Date │ Models │ Input │ Output │ Reasoning │ Cache Create │ Cache Read │ Total Tokens │ Cost (USD) │
7+
├────────────┼───────────────┼───────────┼───────────┼────────────┼───────────────┼─────────────┼───────────────┼─────────────┤
8+
│ 2026-11-01 │ - gpt-6-astra │ 16,000 │ 200 │ 0 │ 0 │ 4,000 │ 20,200 │ $0.17 │
9+
├────────────┼───────────────┼───────────┼───────────┼────────────┼───────────────┼─────────────┼───────────────┼─────────────┤
10+
│ Total │ │ 16,000 │ 200 │ 0 │ 0 │ 4,000 │ 20,200 │ $0.17 │
11+
└────────────┴───────────────┴───────────┴───────────┴────────────┴───────────────┴─────────────┴───────────────┴─────────────┘
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/ccusage/tests/codex_cli.rs
3+
expression: "run_cli(&fixture, &[\"codex\", mode])"
4+
---
5+
┌──────────┬───────────────┬───────────┬───────────┬────────────┬───────────────┬─────────────┬───────────────┬─────────────┐
6+
│ Month │ Models │ Input │ Output │ Reasoning │ Cache Create │ Cache Read │ Total Tokens │ Cost (USD) │
7+
├──────────┼───────────────┼───────────┼───────────┼────────────┼───────────────┼─────────────┼───────────────┼─────────────┤
8+
│ 2026-11 │ - gpt-6-astra │ 16,000 │ 200 │ 0 │ 0 │ 4,000 │ 20,200 │ $0.17 │
9+
├──────────┼───────────────┼───────────┼───────────┼────────────┼───────────────┼─────────────┼───────────────┼─────────────┤
10+
│ Total │ │ 16,000 │ 200 │ 0 │ 0 │ 4,000 │ 20,200 │ $0.17 │
11+
└──────────┴───────────────┴───────────┴───────────┴────────────┴───────────────┴─────────────┴───────────────┴─────────────┘
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/ccusage/tests/codex_cli.rs
3+
expression: "run_cli(&fixture, &[\"codex\", mode])"
4+
---
5+
┌─────────────────────────────────────────────────────────────────────────────┬───────────────┬───────────┬───────────┬────────────┬───────────────┬─────────────┬───────────────┬─────────────┐
6+
│ Session │ Models │ Input │ Output │ Reasoning │ Cache Create │ Cache Read │ Total Tokens │ Cost (USD) │
7+
├─────────────────────────────────────────────────────────────────────────────┼───────────────┼───────────┼───────────┼────────────┼───────────────┼─────────────┼───────────────┼─────────────┤
8+
│ 2026/11/01/rollout-2026-11-01T09-42-09-01a1967c-0000-7000-8000-00000000000a │ - gpt-6-astra │ 16,000 │ 200 │ 0 │ 0 │ 4,000 │ 20,200 │ $0.17 │
9+
├─────────────────────────────────────────────────────────────────────────────┼───────────────┼───────────┼───────────┼────────────┼───────────────┼─────────────┼───────────────┼─────────────┤
10+
│ Total │ │ 16,000 │ 200 │ 0 │ 0 │ 4,000 │ 20,200 │ $0.17 │
11+
└─────────────────────────────────────────────────────────────────────────────┴───────────────┴───────────┴───────────┴────────────┴───────────────┴─────────────┴───────────────┴─────────────┘

0 commit comments

Comments
 (0)