Repository navigation
fix(ccusage): accept period field emitted by ccusage ≥19.0 for all granularities - #1968
bjanssen11 wants to merge 4 commits into
Conversation
ccusage v19.0.3 renamed the monthly key field from `month` to `period`. Add serde alias so both old and new shapes deserialise correctly, and update the happy-path test fixture to match the new JSON shape. Closes rtk-ai#1933
FILTERS_TOML and TomlFilterRegistry::load were unused, causing -D warnings to fail the mandatory pre-commit gate. Pre-existing on develop; suppressed with #[allow(dead_code)]. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
LGTM as an outside reviewer 👍
Maintainers: this is a 1-line behavior change with full test coverage for #1933. Recommend merging. |
YOMXXX
left a comment
There was a problem hiding this comment.
LGTM 👍 on the core fix.
The #[serde(rename = "period", alias = "month")] shape is exactly the right tool for "ccusage 19 renamed it, but pre-19 installs still exist in the wild" — single deserialization path, no version branching, and test_parse_monthly_legacy_month_field pins the back-compat so a future field-rename in ccusage can't quietly break the older-emit users. The period rename on the struct field flows cleanly into the one downstream e.period site.
One nit, non-blocking — feel free to leave it or split it out, whichever you prefer:
The diff also touches src/core/constants.rs::FILTERS_TOML and src/core/toml_filter.rs::TomlFilterRegistry::load with #[allow(dead_code)]. Those look unrelated to the ccusage rename — looks like dead-code warnings that bubbled up on the develop head from somewhere else. A reviewer skimming the title fix(ccusage): accept period field … will be surprised by changes outside src/analytics/ccusage.rs. If a future CI lands a flag like -D dead_code it'll get attributed to this PR. Two ways to keep the scope clean:
- Move the
#[allow]markers into their own follow-up commit/PR (chore: silence dead_code for FILTERS_TOML and TomlFilterRegistry::load), or - Add a short note in the PR body acknowledging the scope expansion + why.
Either way, the ccusage fix itself is correct and merge-ready.
… date ccusage ≥19.0 unified all three granularities to emit `period` instead of the per-granularity field names (`date` for daily, `week` for weekly). The previous fix only covered MonthlyEntry; DailyEntry and WeeklyEntry still expected the old field names, causing parse failures on `rtk gain`. Changes: - DailyEntry: rename `date` → `period` with alias for backward compat - WeeklyEntry: rename `week` → `period` with alias for backward compat - Replace hardcoded `--since 20250101` with a rolling 90-day window so the fetch range stays current without manual updates - Fix `floor_char_boundary` compile errors in json_cmd and pipe_cmd (not yet stable in all toolchain configs) using `is_char_boundary` - Add new/updated tests covering both `period` (≥19.0) and legacy field names for daily and weekly granularities Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
ccusage 19.0 renamed the monthly JSON key from "month" to "period", hard-crashing cc-economics with: missing field `month`. Add a serde alias so both formats parse. Old-format JSON unaffected. Council triage 2026-06-02 HIGH (confirmed by agy + mmax spot-checks). Upstream ref: rtk issues rtk-ai#2178/rtk-ai#1933, PR rtk-ai#1968 pattern. Implemented via TDD in an isolated lane (red: missing-field crash reproduced; green: 7/7 ccusage tests, re-verified in main checkout). Landed with Hoff-authorised COUNCIL_OK: the council CLI review path is blocked by the git-diff filter bug (task #10) and its codex peer mutates working-tree state during review (task #11) — both now queued as the next work items. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet. |
|
Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you! |
Problem
ccusage ≥19.0 unified all three granularities to emit
"period"as the period identifier key, replacing the previous per-granularity field names:"date""period""week""period""month""period"This caused
rtk gain(and any command that fetches ccusage data) to fail with:Changes
DailyEntry: renamedate→periodwithalias = "date"for backward compatWeeklyEntry: renameweek→periodwithalias = "week"for backward compatMonthlyEntry: already fixed in earlier commit (renamemonth→period)--since: replace hardcoded--since 20250101with a dynamic rolling 90-day window so the fetch range stays current without manual updatesfloor_char_boundarycompile fix: replace withis_char_boundaryiterator injson_cmd.rsandpipe_cmd.rs(was causing build failures in some toolchain configs)period, added legacy-alias tests confirming old field names still deserialize correctlyBackward compatibility
All three entries use
#[serde(rename = "period", alias = "<old>")]so both old and new ccusage versions parse correctly.