Skip to content

Commit eb8bb63

Browse files
committed
test(ccusage): spread the 1h cache split fixture over two days
CodeRabbit noted that every fixture record fell on one date, so weekly, monthly and session reports never merged two rows and a merge that dropped cacheCreation1hTokens would still pass. Add records on the next day, keep daily reports on the first day with --until, and assert the summed counts for the merged reports.
1 parent 19e58e2 commit eb8bb63

1 file changed

Lines changed: 50 additions & 12 deletions

File tree

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

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -915,27 +915,56 @@ fn breakdowns_report_one_hour_cache_creation_tokens_only_for_models_with_a_split
915915
r#"{"timestamp":"2026-09-15T12:00:00.000Z","sessionId":"session-a","requestId":"request-a","message":{"id":"message-a","model":"claude-sonnet-4-20250514","usage":{"input_tokens":10,"output_tokens":2,"cache_creation_input_tokens":400,"cache_creation":{"ephemeral_5m_input_tokens":100,"ephemeral_1h_input_tokens":300}}}}"#,
916916
r#"{"timestamp":"2026-09-15T12:01:00.000Z","sessionId":"session-a","requestId":"request-b","message":{"id":"message-b","model":"claude-sonnet-4-20250514","usage":{"input_tokens":10,"output_tokens":2,"cache_creation_input_tokens":50}}}"#,
917917
r#"{"timestamp":"2026-09-15T12:02:00.000Z","sessionId":"session-a","requestId":"request-c","message":{"id":"message-c","model":"claude-haiku-4-5-20251001","usage":{"input_tokens":10,"output_tokens":2,"cache_creation_input_tokens":70}}}"#,
918+
r#"{"timestamp":"2026-09-16T12:00:00.000Z","sessionId":"session-a","requestId":"request-d","message":{"id":"message-d","model":"claude-sonnet-4-20250514","usage":{"input_tokens":10,"output_tokens":2,"cache_creation_input_tokens":100,"cache_creation":{"ephemeral_5m_input_tokens":20,"ephemeral_1h_input_tokens":80}}}}"#,
919+
r#"{"timestamp":"2026-09-16T12:01:00.000Z","sessionId":"session-a","requestId":"request-e","message":{"id":"message-e","model":"claude-haiku-4-5-20251001","usage":{"input_tokens":10,"output_tokens":2,"cache_creation_input_tokens":30}}}"#,
918920
];
919921
let _ = fixture.write_file("projects/project-a/session-a/chat.jsonl", lines.join("\n"));
920922

923+
// Daily rows stop at 2026-09-15; weekly, monthly and session rows merge
924+
// both days.
925+
let first_day = (450, 300, 70);
926+
let both_days = (550, 380, 100);
921927
let reports = [
922-
(&["claude", "daily"][..], "/daily/0/modelBreakdowns"),
923-
(&["claude", "weekly"][..], "/weekly/0/modelBreakdowns"),
924-
(&["claude", "monthly"][..], "/monthly/0/modelBreakdowns"),
925-
(&["claude", "session"][..], "/sessions/0/modelBreakdowns"),
926-
(&["daily"][..], "/daily/0/modelBreakdowns"),
927-
(&["weekly"][..], "/weekly/0/modelBreakdowns"),
928-
(&["monthly"][..], "/monthly/0/modelBreakdowns"),
929-
(&["session"][..], "/session/0/modelBreakdowns"),
928+
(
929+
&["claude", "daily"][..],
930+
"/daily/0/modelBreakdowns",
931+
first_day,
932+
),
933+
(
934+
&["claude", "weekly"][..],
935+
"/weekly/0/modelBreakdowns",
936+
both_days,
937+
),
938+
(
939+
&["claude", "monthly"][..],
940+
"/monthly/0/modelBreakdowns",
941+
both_days,
942+
),
943+
(
944+
&["claude", "session"][..],
945+
"/sessions/0/modelBreakdowns",
946+
both_days,
947+
),
948+
(&["daily"][..], "/daily/0/modelBreakdowns", first_day),
949+
(&["weekly"][..], "/weekly/0/modelBreakdowns", both_days),
950+
(&["monthly"][..], "/monthly/0/modelBreakdowns", both_days),
951+
(&["session"][..], "/session/0/modelBreakdowns", both_days),
930952
(
931953
&["daily", "--by-agent"][..],
932954
"/daily/0/agents/0/modelBreakdowns",
955+
first_day,
933956
),
934957
];
935-
for (args, pointer) in reports {
958+
for (args, pointer, (sonnet_cache, sonnet_1h, haiku_cache)) in reports {
959+
let until: &[&str] = if pointer.starts_with("/daily") {
960+
&["--until", "2026-09-15"]
961+
} else {
962+
&[]
963+
};
936964
let args = args
937965
.iter()
938966
.chain(&["--json", "--offline", "--timezone", "UTC"])
967+
.chain(until)
939968
.copied()
940969
.collect::<Vec<_>>();
941970
let json: serde_json::Value =
@@ -949,11 +978,20 @@ fn breakdowns_report_one_hour_cache_creation_tokens_only_for_models_with_a_split
949978
};
950979

951980
let sonnet = model("claude-sonnet-4-20250514");
952-
assert_eq!(sonnet["cacheCreationTokens"], 450, "{args:?}: {sonnet}");
953-
assert_eq!(sonnet["cacheCreation1hTokens"], 300, "{args:?}: {sonnet}");
981+
assert_eq!(
982+
sonnet["cacheCreationTokens"], sonnet_cache,
983+
"{args:?}: {sonnet}"
984+
);
985+
assert_eq!(
986+
sonnet["cacheCreation1hTokens"], sonnet_1h,
987+
"{args:?}: {sonnet}"
988+
);
954989

955990
let haiku = model("claude-haiku-4-5-20251001");
956-
assert_eq!(haiku["cacheCreationTokens"], 70, "{args:?}: {haiku}");
991+
assert_eq!(
992+
haiku["cacheCreationTokens"], haiku_cache,
993+
"{args:?}: {haiku}"
994+
);
957995
assert!(
958996
haiku.get("cacheCreation1hTokens").is_none(),
959997
"{args:?}: {haiku}"

0 commit comments

Comments
 (0)