Skip to content

Commit 0ed3c6a

Browse files
committed
Merge remote-tracking branch 'origin/main' into codex/extract-cli-crate
# Conflicts: # rust/crates/ccusage/src/cli.rs
2 parents cee4d2f + 63cf17e commit 0ed3c6a

4 files changed

Lines changed: 61 additions & 9 deletions

File tree

‎rust/crates/ccusage-cli/src/lib.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ impl SharedArgs {
6161
}
6262
}
6363

64+
pub fn normalize_date_bound(value: &str) -> String {
65+
value.replace('-', "")
66+
}
67+
6468
#[derive(Clone)]
6569
pub struct DailyArgs {
6670
pub shared: SharedArgs,
@@ -783,8 +787,12 @@ fn parse_shared_arg_for_command(
783787

784788
fn parse_shared_arg(parser: &mut ArgParser, shared: &mut SharedArgs) -> Result<(), String> {
785789
match parser.next_flag()?.as_str() {
786-
"-s" | "--since" => shared.since = Some(parser.value_for("--since")?),
787-
"-u" | "--until" => shared.until = Some(parser.value_for("--until")?),
790+
"-s" | "--since" => {
791+
shared.since = Some(normalize_date_bound(&parser.value_for("--since")?))
792+
}
793+
"-u" | "--until" => {
794+
shared.until = Some(normalize_date_bound(&parser.value_for("--until")?))
795+
}
788796
"-j" | "--json" => shared.json = true,
789797
"-m" | "--mode" => shared.mode = parse_cost_mode(&parser.value_for("--mode")?)?,
790798
"-d" | "--debug" => shared.debug = true,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(crate) fn load_codex_events_from_directory(
1818
) -> Result<Vec<CodexTokenUsageEvent>> {
1919
let mut files = Vec::new();
2020
collect_usage_files(sessions_dir, &mut files);
21+
files.sort_by_cached_key(|path| path.to_string_lossy().into_owned());
2122
let mut events = if single_thread {
2223
files
2324
.iter()

‎rust/crates/ccusage/src/config.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use serde_json::{Map, Value};
77

88
use crate::{
99
cli::{
10-
BlocksArgs, CodexSpeed, CostMode, CostSource, DailyArgs, SharedArgs, SortOrder,
11-
StatuslineArgs, VisualBurnRate, WeekDay, WeeklyArgs,
10+
normalize_date_bound, BlocksArgs, CodexSpeed, CostMode, CostSource, DailyArgs, SharedArgs,
11+
SortOrder, StatuslineArgs, VisualBurnRate, WeekDay, WeeklyArgs,
1212
},
1313
config_schema::{
1414
BlocksSpecificOptions, CodexOptions, ConfigCodexSpeed, ConfigCostMode, ConfigCostSource,
@@ -407,10 +407,10 @@ impl crate::cli::CliConfig for ConfigContext {
407407

408408
fn apply_shared_options(shared: &mut SharedArgs, options: SharedOptions) {
409409
if let Some(since) = options.since {
410-
shared.since = Some(since);
410+
shared.since = Some(normalize_date_bound(&since));
411411
}
412412
if let Some(until) = options.until {
413-
shared.until = Some(until);
413+
shared.until = Some(normalize_date_bound(&until));
414414
}
415415
if let Some(json) = options.json {
416416
shared.json = json;
@@ -565,8 +565,8 @@ mod tests {
565565

566566
apply_config_to_shared(&mut shared, &config);
567567

568-
assert_eq!(shared.since.as_deref(), Some("2026-01-01"));
569-
assert_eq!(shared.until.as_deref(), Some("2026-01-31"));
568+
assert_eq!(shared.since.as_deref(), Some("20260101"));
569+
assert_eq!(shared.until.as_deref(), Some("20260131"));
570570
assert!(shared.json);
571571
assert_eq!(shared.mode, CostMode::Calculate);
572572
assert!(shared.debug);

‎rust/crates/ccusage/src/summary.rs‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ mod tests {
300300

301301
use super::*;
302302
use crate::{
303-
cli::{SharedArgs, SortOrder},
303+
cli::{normalize_date_bound, SharedArgs, SortOrder},
304304
format_rfc3339_millis, ModelBreakdown, TokenUsageRaw, UsageEntry, UsageMessage,
305305
};
306306

@@ -495,6 +495,49 @@ mod tests {
495495
insta::assert_json_snapshot!(rows);
496496
}
497497

498+
#[test]
499+
fn filter_and_sort_summaries_treats_dashed_and_compact_bounds_equally() {
500+
fn filtered_models(since: &str) -> Vec<String> {
501+
let mut rows = vec![
502+
summary_row(SummaryFixture {
503+
date: Some("2026-01-24"),
504+
model: "before",
505+
cost: 0.125,
506+
input_tokens: 1,
507+
}),
508+
summary_row(SummaryFixture {
509+
date: Some("2026-04-22"),
510+
model: "on-boundary",
511+
cost: 0.25,
512+
input_tokens: 2,
513+
}),
514+
summary_row(SummaryFixture {
515+
date: Some("2026-04-23"),
516+
model: "after",
517+
cost: 0.5,
518+
input_tokens: 3,
519+
}),
520+
];
521+
let shared = SharedArgs {
522+
since: Some(normalize_date_bound(since)),
523+
order: SortOrder::Asc,
524+
..SharedArgs::default()
525+
};
526+
527+
filter_and_sort_summaries(&mut rows, &shared, |row| row.date.as_deref().unwrap_or(""));
528+
529+
rows.into_iter()
530+
.map(|row| row.models_used.into_iter().next().unwrap())
531+
.collect()
532+
}
533+
534+
let dashed = filtered_models("2026-04-22");
535+
let compact = filtered_models("20260422");
536+
537+
assert_eq!(dashed, compact);
538+
assert_eq!(dashed, vec!["on-boundary", "after"]);
539+
}
540+
498541
struct LoadedEntryFixture {
499542
date: &'static str,
500543
timestamp: i64,

0 commit comments

Comments
 (0)