fix(ccusage): accept period key from current ccusage#2732
Conversation
|
Automatic message from CI checks : It seems like this branch is targeting the wrong branch, any contribution should target develop branch. See CONTRIBUTING.md for details. |
|
Automatic message from CI checks : It seems like this branch is targeting the wrong branch, any contribution should target develop branch. See CONTRIBUTING.md for details. |
ccusage renamed the per-record key from month/date/week to `period`, so the deserializer's required old field names no longer match and `rtk cc-economics` fails with "missing field `month`". Add `#[serde(alias = "period")]` to the daily/weekly/monthly key fields so both legacy and current ccusage output parse. Adds period-shape tests for all three granularities; existing legacy-key tests stay green.
07d1e0d to
d0a77cd
Compare
|
Hey @mvanhorn , could you please provide related docs ? Cannot find anything about period key in ccusage : https://ccusage.com/guide/all-reports |
|
I guess |
|
Hey @mvanhorn Tested locally, issue is fixed. Thanks for contributing to RTK ! |
|
Appreciate it, @aeppling - rtk reads the new ccusage period key cleanly now. |
ccusage silently renamed month/date/week to period upstream (rtk-ai/rtk#2732), breaking rtk's deserializer with no graceful path. requireField() had the same exposure: any renamed field from Cursor or Anthropic would hard-fail with SchemaDriftError and no fallback. requireField now accepts an optional list of legacy/alternate field names to check before giving up, and SchemaDriftError reports which aliases were tried when the field is still missing. No adapter opts in yet since neither vendor has renamed anything, but the mechanism is now real and tested.
|
Thanks @aeppling! Accepting the period key keeps rtk compatible with current ccusage output. |
Summary
rtk cc-economicscurrently fails withmissing field month(serde: missing fieldmonth) because ccusage renamed its per-record key frommonth/date/weektoperiod. The deserializer insrc/analytics/ccusage.rsstill required the old names, so every record fails to parse and the feature is unusable.Changes
#[serde(alias = "period")]to the key field ofDailyEntry,WeeklyEntry, andMonthlyEntry. This accepts the currentperiodkey while staying backward-compatible with older ccusage output that still emitsmonth/date/week. No other behavior changes.Tests
cargo fmt --all,cargo clippy --all-targets, andcargo test --allall clean (2290 passed).cargo run -- cc-economicsnow renders against live ccusage with no parse error.Closes #2731