Skip to content

Commit 6e48ae6

Browse files
committed
test(codex): use fixture macro for branch history
Use the existing fs_fixture macro for the copied branch-history regression while still exercising both single-threaded and parallel Codex loaders.
1 parent 0107c2e commit 6e48ae6

3 files changed

Lines changed: 56 additions & 15 deletions

File tree

‎apps/ccusage/test/fixtures/codex/sessions/branch-history/2026-05-12T08-00-00-parent.jsonl‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎apps/ccusage/test/fixtures/codex/sessions/branch-history/2026-05-12T08-02-00-branch.jsonl‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎rust/crates/ccusage/src/adapter/codex/loader.rs‎

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ mod tests {
125125
time::{SystemTime, UNIX_EPOCH},
126126
};
127127

128+
use ccusage_test_support::fs_fixture;
128129
use serde_json::json;
129130

130131
fn codex_event(session_id: &str) -> CodexTokenUsageEvent {
@@ -153,12 +154,62 @@ mod tests {
153154

154155
#[test]
155156
fn dedupes_copied_branch_history_across_session_files() {
157+
let parent_history = [
158+
json!({
159+
"timestamp": "2026-05-12T08:00:00.000Z",
160+
"type": "turn_context",
161+
"payload": {
162+
"model": "gpt-5.2",
163+
},
164+
})
165+
.to_string(),
166+
json!({
167+
"timestamp": "2026-05-12T08:01:00.000Z",
168+
"type": "event_msg",
169+
"payload": {
170+
"type": "token_count",
171+
"info": {
172+
"total_token_usage": {
173+
"input_tokens": 1_000,
174+
"cached_input_tokens": 100,
175+
"output_tokens": 200,
176+
"reasoning_output_tokens": 20,
177+
"total_tokens": 1_200,
178+
},
179+
},
180+
},
181+
})
182+
.to_string(),
183+
]
184+
.join("\n");
185+
let branch_history = [
186+
parent_history.as_str(),
187+
&json!({
188+
"timestamp": "2026-05-12T08:02:00.000Z",
189+
"type": "event_msg",
190+
"payload": {
191+
"type": "token_count",
192+
"info": {
193+
"total_token_usage": {
194+
"input_tokens": 1_600,
195+
"cached_input_tokens": 300,
196+
"output_tokens": 450,
197+
"reasoning_output_tokens": 40,
198+
"total_tokens": 2_050,
199+
},
200+
},
201+
},
202+
})
203+
.to_string(),
204+
]
205+
.join("\n");
206+
let fixture = fs_fixture!({
207+
"2026-05-12T08-00-00-parent.jsonl": &parent_history,
208+
"2026-05-12T08-02-00-branch.jsonl": branch_history,
209+
});
210+
156211
for single_thread in [true, false] {
157-
let events = load_codex_events_from_directory(
158-
&codex_branch_history_fixture_dir(),
159-
single_thread,
160-
)
161-
.unwrap();
212+
let events = load_codex_events_from_directory(fixture.root(), single_thread).unwrap();
162213

163214
assert_eq!(events.len(), 2);
164215
assert_eq!(events[0].session_id, "2026-05-12T08-00-00-parent");
@@ -186,11 +237,6 @@ mod tests {
186237
dir
187238
}
188239

189-
fn codex_branch_history_fixture_dir() -> PathBuf {
190-
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
191-
.join("../../../apps/ccusage/test/fixtures/codex/sessions/branch-history")
192-
}
193-
194240
#[test]
195241
fn loads_saved_codex_exec_json_usage() {
196242
let dir = temp_dir("json-usage");

0 commit comments

Comments
 (0)