Repository navigation
feat(fetcher): add calendar_holidays — Nager.Date-backed public holidays - #155
Conversation
…Date Single fetcher under the new `calendar_*` family that emits Calendar / Text / TextBlock from one underlying API read. Replaces the planned `holiday_today` + `holiday_upcoming` checkboxes (#68) with one widget covering today's holiday, upcoming list, and a month grid with holiday days flagged as event_days. Safety::Safe — host `date.nager.at` is hardcoded; only the ISO 3166-1 alpha-2 country code is config-driven and is sanitised locally. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #155 +/- ##
==========================================
+ Coverage 78.08% 78.25% +0.16%
==========================================
Files 112 115 +3
Lines 21018 21690 +672
==========================================
+ Hits 16412 16973 +561
- Misses 4606 4717 +111
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/fetcher/calendar/holidays.rs (2)
477-487: Nit: live test runs deserialization but not formatting end-to-end.The ignored live test only prints the raw rows. Since the whole point of the smoke test is "does my pipeline still work against real Nager.Date data," consider also running
render_body(&holidays, Shape::TextBlock, today, Language::Local, 5)and asserting non-empty lines. Optional.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/fetcher/calendar/holidays.rs` around lines 477 - 487, Update the live smoke test live_jp_returns_holidays_for_current_year to exercise end-to-end formatting: after calling fetch_year(today.year(), "JP") and asserting non-empty holidays, call render_body(&holidays, Shape::TextBlock, today, Language::Local, 5) and assert that the returned lines (or rendered string) are non-empty; this ensures the pipeline covers deserialization and formatting (referenced symbols: fetch_year, render_body, Shape::TextBlock, Language::Local).
56-72: Minor:languagefield isOption<Language>but the enum derivesDefault.Since
Languagealready implementsDefault(=Local),language: Languagewith#[serde(default)]is equivalent and removes one unwrap site at line 116. Pure ergonomics; not blocking.♻️ Sketch
pub struct Options { pub country: Option<String>, #[serde(default)] - pub language: Option<Language>, + pub language: Language, #[serde(default)] pub limit: Option<u32>, }…and at line 116:
- let language = opts.language.unwrap_or_default(); + let language = opts.language;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/fetcher/calendar/holidays.rs` around lines 56 - 72, Change Options.language from Option<Language> to Language with #[serde(default)] and remove the Option wrapper so serde supplies Language::Local when absent; update any code that currently does .language.unwrap() (the usage site that unwraps Options.language) to use the field directly (or adjust to .language if binding changed), and ensure imports/derives remain the same for the Language enum which already implements Default.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/fetcher/calendar/holidays.rs`:
- Around line 88-95: The cache key generation in fn cache_key(&self, ctx:
&FetchContext) omits the current year, allowing stale cross-year reads; modify
cache_key to incorporate the current UTC year (e.g., obtain Utc::now().year())
into the extra string used when calling cache_key(self.name(), ctx, &extra) so
the key becomes unique per year; ensure you still include the existing
toml-serialized ctx.options and fall back to the same default behavior when
options are None.
- Around line 113-127: The fetch function in holidays.rs currently only calls
fetch_year(today.year()) which causes TextBlock/upcoming_lines to run dry at
year-end; modify fetch to also retrieve the next year (fetch_year(today.year() +
1)) when the cursor is within ~limit days of year-end or unconditionally, merge
the two holiday vectors into the holidays variable before any
filtering/rendering, and ensure shape (ctx.shape / Shape::Calendar) is bound
before the fetches so you can decide conditional fetching by shape; update the
call sites using holidays (e.g., render_body) to use the merged list and keep
the existing >= today filtering logic.
---
Nitpick comments:
In `@src/fetcher/calendar/holidays.rs`:
- Around line 477-487: Update the live smoke test
live_jp_returns_holidays_for_current_year to exercise end-to-end formatting:
after calling fetch_year(today.year(), "JP") and asserting non-empty holidays,
call render_body(&holidays, Shape::TextBlock, today, Language::Local, 5) and
assert that the returned lines (or rendered string) are non-empty; this ensures
the pipeline covers deserialization and formatting (referenced symbols:
fetch_year, render_body, Shape::TextBlock, Language::Local).
- Around line 56-72: Change Options.language from Option<Language> to Language
with #[serde(default)] and remove the Option wrapper so serde supplies
Language::Local when absent; update any code that currently does
.language.unwrap() (the usage site that unwraps Options.language) to use the
field directly (or adjust to .language if binding changed), and ensure
imports/derives remain the same for the Language enum which already implements
Default.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 322de3ab-ee3c-4725-b176-b7b15e494210
📒 Files selected for processing (3)
src/fetcher/calendar/holidays.rssrc/fetcher/calendar/mod.rssrc/fetcher/mod.rs
| fn cache_key(&self, ctx: &FetchContext) -> String { | ||
| let extra = ctx | ||
| .options | ||
| .as_ref() | ||
| .and_then(|v| toml::to_string(v).ok()) | ||
| .unwrap_or_default(); | ||
| cache_key(self.name(), ctx, &extra) | ||
| } |
There was a problem hiding this comment.
Cache key omits the year — risk of stale cross-year reads.
cache_key mixes in name + shape + format + options but not today.year(). If the cache TTL outlives Jan 1 00:00 UTC, a January read can hit the previous year's cached payload and upcoming_lines will yield nothing until the entry expires. Folding Utc::now().year() into the extra string makes the boundary deterministic.
♻️ Suggested fix
fn cache_key(&self, ctx: &FetchContext) -> String {
- let extra = ctx
- .options
- .as_ref()
- .and_then(|v| toml::to_string(v).ok())
- .unwrap_or_default();
- cache_key(self.name(), ctx, &extra)
+ let opts = ctx
+ .options
+ .as_ref()
+ .and_then(|v| toml::to_string(v).ok())
+ .unwrap_or_default();
+ let year = chrono::Utc::now().date_naive().year();
+ cache_key(self.name(), ctx, &format!("{year}|{opts}"))
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| fn cache_key(&self, ctx: &FetchContext) -> String { | |
| let extra = ctx | |
| .options | |
| .as_ref() | |
| .and_then(|v| toml::to_string(v).ok()) | |
| .unwrap_or_default(); | |
| cache_key(self.name(), ctx, &extra) | |
| } | |
| fn cache_key(&self, ctx: &FetchContext) -> String { | |
| let opts = ctx | |
| .options | |
| .as_ref() | |
| .and_then(|v| toml::to_string(v).ok()) | |
| .unwrap_or_default(); | |
| let year = chrono::Utc::now().date_naive().year(); | |
| cache_key(self.name(), ctx, &format!("{year}|{opts}")) | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/fetcher/calendar/holidays.rs` around lines 88 - 95, The cache key
generation in fn cache_key(&self, ctx: &FetchContext) omits the current year,
allowing stale cross-year reads; modify cache_key to incorporate the current UTC
year (e.g., obtain Utc::now().year()) into the extra string used when calling
cache_key(self.name(), ctx, &extra) so the key becomes unique per year; ensure
you still include the existing toml-serialized ctx.options and fall back to the
same default behavior when options are None.
| async fn fetch(&self, ctx: &FetchContext) -> Result<Payload, FetchError> { | ||
| let opts: Options = parse_options(ctx.options.as_ref()).map_err(FetchError::Failed)?; | ||
| let country = require_country(opts.country.as_deref())?; | ||
| let language = opts.language.unwrap_or_default(); | ||
| let limit = opts | ||
| .limit | ||
| .unwrap_or(DEFAULT_LIMIT) | ||
| .clamp(MIN_LIMIT, MAX_LIMIT) as usize; | ||
| let today = Utc::now().date_naive(); | ||
| let holidays = fetch_year(today.year(), &country).await?; | ||
| let shape = ctx.shape.unwrap_or(Shape::Calendar); | ||
| Ok(payload(render_body( | ||
| &holidays, shape, today, language, limit, | ||
| ))) | ||
| } |
There was a problem hiding this comment.
Year-boundary blind spot: TextBlock will dry up at year-end.
fetch_year(today.year(), …) only ever asks Nager.Date for the current calendar year. In late December, upcoming_lines will return zero or one entries even though early-January holidays are publicly available from the same endpoint (/api/v3/PublicHolidays/{year+1}/{country}). This silently degrades the home-feed morning briefing for ~weeks every year-end. Today/Calendar shapes are unaffected, but the TextBlock shape is the one most likely to surface the gap.
Consider fetching the next year too whenever the cursor is within ~limit holiday-days of year-end (or unconditionally — it's one extra cached request per year), then merging before filtering by >= today.
♻️ Sketch
- let today = Utc::now().date_naive();
- let holidays = fetch_year(today.year(), &country).await?;
+ let today = Utc::now().date_naive();
+ let mut holidays = fetch_year(today.year(), &country).await?;
+ if matches!(shape, Shape::TextBlock) {
+ // Carry over next year's data so December → January upcoming lists keep working.
+ if let Ok(next) = fetch_year(today.year() + 1, &country).await {
+ holidays.extend(next);
+ }
+ }
let shape = ctx.shape.unwrap_or(Shape::Calendar);(Move the shape binding above the fetch.)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/fetcher/calendar/holidays.rs` around lines 113 - 127, The fetch function
in holidays.rs currently only calls fetch_year(today.year()) which causes
TextBlock/upcoming_lines to run dry at year-end; modify fetch to also retrieve
the next year (fetch_year(today.year() + 1)) when the cursor is within ~limit
days of year-end or unconditionally, merge the two holiday vectors into the
holidays variable before any filtering/rendering, and ensure shape (ctx.shape /
Shape::Calendar) is bound before the fetches so you can decide conditional
fetching by shape; update the call sites using holidays (e.g., render_body) to
use the merged list and keep the existing >= today filtering logic.
Summary
Adds
calendar_holidays, a single fetcher under the newcalendar_*family that emits Calendar / Text / TextBlock from one Nager.Date API call. Collapses the plannedholiday_today+holiday_upcomingcheckboxes (#68) into one widget — same underlying read, three shapes:events🎌 Showa Day), or empty (renders as the shared "nothing here yet" placeholder)04/29 — Showa Day)Targets the
home_feedmorning-briefing preset (#150) ambient slot. Updates#68post-merge: drop theholiday_*section, addcalendar_holidaystocalendar_*.Reference
Safe— hostdate.nager.athardcoded; only ISO 3166-1 alpha-2 country code is config-driven and validated locally (filter to letters → uppercase → require length 2)calendar,text,text_blockOptions
country\"JP\"/\"US\")language\"local\"|\"english\"\"local\"localuses the country's localized name;englishuses the English label.limitCompatible renderers
calendargrid_calendar+ animated familiestexttext_plain,text_ascii+ animated familiestext_blocklist_plain,text_plain+ animated familiesTest plan
cargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo test— 765 tests green (21 new infetcher::calendar::holidays::tests)#[ignore]test againstdate.nager.at) returns 16 JP holidays for 2026languagetoggle — renders correctly (today empty → placeholder, upcoming sorted, calendar marks 04/29 as event day)🤖 Generated with Claude Code
Summary by CodeRabbit