Skip to content

Commit 8b4078c

Browse files
committed
test(codex): reuse the shared replay fixture builders
`keeps_child_usage_matching_parent_event_after_fork` carried its own copies of the session_meta and token_count builders, so a change to the fixture schema would have to be made in two places.
1 parent 7bdc537 commit 8b4078c

1 file changed

Lines changed: 6 additions & 38 deletions

File tree

  • rust/crates/ccusage/src/adapter/codex

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

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,52 +1553,20 @@ mod tests {
15531553

15541554
#[test]
15551555
fn keeps_child_usage_matching_parent_event_after_fork() {
1556-
fn metadata(timestamp: &str, id: &str, parent: Option<&str>) -> String {
1557-
json!({
1558-
"timestamp": timestamp,
1559-
"type": "session_meta",
1560-
"payload": {"id": id, "forked_from_id": parent},
1561-
})
1562-
.to_string()
1563-
}
1564-
1565-
fn token_count(timestamp: &str, input_tokens: u64) -> String {
1566-
json!({
1567-
"timestamp": timestamp,
1568-
"type": "event_msg",
1569-
"payload": {
1570-
"type": "token_count",
1571-
"info": {
1572-
"last_token_usage": {
1573-
"input_tokens": input_tokens,
1574-
"output_tokens": 1,
1575-
"total_tokens": input_tokens + 1,
1576-
},
1577-
"model": "gpt-5.2",
1578-
},
1579-
},
1580-
})
1581-
.to_string()
1582-
}
1583-
15841556
let fixture = fs_fixture!({
15851557
"parent.jsonl": [
1586-
metadata("2026-05-12T08:00:00.000Z", "parent", None),
1587-
token_count("2026-05-12T08:01:00.000Z", 100),
1558+
replay_metadata("2026-05-12T08:00:00.000Z", "parent", None),
1559+
replay_token_count("2026-05-12T08:01:00.000Z", 100),
15881560
// Written after the child forked.
1589-
token_count("2026-05-12T08:03:00.000Z", 50),
1561+
replay_token_count("2026-05-12T08:03:00.000Z", 50),
15901562
]
15911563
.join("\n"),
15921564
"child.jsonl": [
1593-
metadata(
1594-
"2026-05-12T08:02:00.000Z",
1595-
"child",
1596-
Some("parent"),
1597-
),
1565+
replay_metadata("2026-05-12T08:02:00.000Z", "child", Some("parent")),
15981566
// Replayed parent state at the fork.
1599-
token_count("2026-05-12T08:02:00.000Z", 100),
1567+
replay_token_count("2026-05-12T08:02:00.000Z", 100),
16001568
// Real child usage that happens to equal the parent's next event.
1601-
token_count("2026-05-12T08:04:00.000Z", 50),
1569+
replay_token_count("2026-05-12T08:04:00.000Z", 50),
16021570
]
16031571
.join("\n"),
16041572
});

0 commit comments

Comments
 (0)