Skip to content

Commit eccd732

Browse files
cursoragentjgorres
andcommitted
test(all): cover start-of-week in unified weekly loaders
Assert that load_rows and load_sections bucket weekly rows by the requested start day, document that commands.weekly.startOfWeek sets the default with the flag taking precedence, and fix the weekly-reports example that paired a claude weekly comment with a ccusage weekly command. Co-authored-by: jgorres <[email protected]>
1 parent 4fda612 commit eccd732

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎docs/guide/cli-options.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ccusage daily --last 7
4242
ccusage monthly --last 3
4343
```
4444

45-
The count is inclusive of the current period, so `--last 2` on a daily report covers yesterday and today. Weeks start on the same day the report buckets by: Monday by default and Sunday for `ccusage claude weekly`, unless `--start-of-week` on `ccusage weekly` or `ccusage claude weekly` sets another day.
45+
The count is inclusive of the current period, so `--last 2` on a daily report covers yesterday and today. Weeks start on the same day the report buckets by: Monday by default and Sunday for `ccusage claude weekly`, unless `commands.weekly.startOfWeek` in a [configuration file](/guide/config-files) or `--start-of-week` on `ccusage weekly` or `ccusage claude weekly` sets another day, with the flag taking precedence.
4646

4747
`--last` works on every daily, weekly, and monthly report, including the per-agent ones such as `ccusage codex daily --last 1`. It is not available on `session`, `blocks`, or `statusline`, which have no calendar period, and it cannot be combined with `--since`, `--until`, or `--sections`.
4848

‎docs/guide/weekly-reports.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ Configure which day starts the week:
5151
ccusage weekly --start-of-week monday
5252
ccusage weekly -w monday
5353

54-
# Start week on Sunday (default for ccusage claude weekly)
54+
# Start week on Sunday
5555
ccusage weekly --start-of-week sunday
5656

57+
# ccusage claude weekly starts on Sunday by default
58+
ccusage claude weekly
59+
5760
# Other options: tuesday, wednesday, thursday, friday, saturday
5861
```
5962

‎rust/crates/ccusage-adapter-all/src/tests.rs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,39 @@ fn unified_session_rows_use_grok_home() {
10781078
assert_unified_rows_use_grok_home(AgentReportKind::Session);
10791079
}
10801080

1081+
#[test]
1082+
fn unified_weekly_rows_and_sections_honor_start_of_week() {
1083+
let line = r#"{"timestamp":1750000000,"params":{"sessionId":"sess-grok","update":{"sessionUpdate":"turn_completed","usage":{"inputTokens":100,"outputTokens":20,"modelUsage":{"grok-4.5-build":{"inputTokens":100,"outputTokens":20}}}},"_meta":{"eventId":"evt-grok"}}}"#;
1084+
let fixture = fs_fixture!({
1085+
"grok/sessions/proj/sess-grok/updates.jsonl": line,
1086+
});
1087+
let _env = isolated_agent_env(&fixture, "GROK_HOME", fixture.path("grok").into_os_string());
1088+
let shared = fixture_shared("20250615", "20250615");
1089+
1090+
for (start_of_week, week) in [
1091+
(WeekDay::Sunday, "2025-06-15"),
1092+
(WeekDay::Monday, "2025-06-09"),
1093+
] {
1094+
let rows = load_rows(AgentReportKind::Weekly, &shared, start_of_week).unwrap();
1095+
let periods: Vec<_> = rows.rows.iter().map(|row| row.period.as_str()).collect();
1096+
assert_eq!(periods, [week], "{start_of_week:?} load_rows");
1097+
1098+
let sections = load_sections(
1099+
&[AgentReportKind::Daily, AgentReportKind::Weekly],
1100+
&shared,
1101+
start_of_week,
1102+
)
1103+
.unwrap();
1104+
let (_, weekly) = sections
1105+
.sections
1106+
.iter()
1107+
.find(|(kind, _)| *kind == AgentReportKind::Weekly)
1108+
.unwrap();
1109+
let periods: Vec<_> = weekly.iter().map(|row| row.period.as_str()).collect();
1110+
assert_eq!(periods, [week], "{start_of_week:?} load_sections");
1111+
}
1112+
}
1113+
10811114
fn assert_daily_family_and_session_sections_match_standalone(shared: &SharedArgs) {
10821115
for command_kind in [AgentReportKind::Daily, AgentReportKind::Session] {
10831116
let sections = match command_kind {

0 commit comments

Comments
 (0)