Skip to content

fix(ev): stop a manual scraper run from undoing the Spain EV handover - #124

Merged
GeiserX merged 1 commit into
mainfrom
fix/spain-ev-source-single-rule
Aug 22, 2026
Merged

fix(ev): stop a manual scraper run from undoing the Spain EV handover#124
GeiserX merged 1 commit into
mainfrom
fix/spain-ev-source-single-rule

Conversation

@GeiserX

@GeiserX GeiserX commented Aug 22, 2026

Copy link
Copy Markdown
Owner

Follow-up to #122, closing a foot-gun that PR left behind.

The rule that Spain must use exactly one EV source — REVE or Open Charge Map, never both — was implemented only in the scheduler (instrumentation.ts). The manual CLI never got it. So npm run scraper:run -- --country=all would happily run the Open Charge Map scraper for Spain alongside REVE, and once REVE has retired those ~19,000 rows, one such run puts every one of them straight back.

The obvious fix is to copy the rule into cli.ts. That is the wrong fix: two copies drift, and this particular drift is silent — nothing errors, the map just quietly fills back up with duplicate Spanish chargers, which is exactly the failure #122 existed to prevent.

So the rule now lives in one place, scrapers/spain-ev-source.ts, and both the scheduler and the CLI call it. The scheduler's inline copy is gone.

Naming EV_ES explicitly on the CLI still runs it — the CLI is a manual override, and an operator asking for it by name means it. Only --country=all is collapsed.

Verification

  • 5 new tests covering both key states, the all case, the no-Spain-EV case, and that other countries are untouched.
  • I checked the tests can fail: mutating the helper to forget dropping the superseded source — the exact bug this prevents — turned 2 of the 5 red, and restoring it made all 5 pass.
  • Type check clean, lint clean, and the existing registry-alignment guard in cli.test.ts still passes.

No behaviour change for the running deployment: the scheduler path already had this rule, so production has been correct since v1.12.0. This only affects the manual CLI and removes the duplication.

Summary by CodeRabbit

  • New Features
    • Spain’s electric vehicle data source is now selected automatically based on available configuration.
    • “All countries” mode prevents duplicate Spain EV sources and preserves other selections.
  • Bug Fixes
    • Added a fallback to the standard Spain EV source when the alternative source is unavailable.
    • Configurations without Spain EV scraping remain unchanged.
  • Tests
    • Added coverage for source selection, fallback behavior, deduplication, and non-Spain configurations.

The rule that Spain must use exactly one EV source lived only in the
scheduler. The manual CLI did not have it, so `scraper:run --country=all`
would run OpenChargeMap for Spain alongside REVE - and after REVE retires
those rows, a single such run puts all ~19k of them straight back.

Rather than copy the rule into the CLI, both now call one function. Two
copies would drift, and the drift is silent: the map just quietly fills up
with duplicate Spanish chargers again.

Naming EV_ES explicitly on the CLI still runs it. The CLI is a manual
override and an operator asking for it by name means it.
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 297ac790-b0af-4bc3-861c-86170db13bab

📥 Commits

Reviewing files that changed from the base of the PR and between 6d9598d and fddabe1.

📒 Files selected for processing (4)
  • src/instrumentation.ts
  • src/scrapers/cli.ts
  • src/scrapers/spain-ev-source.test.ts
  • src/scrapers/spain-ev-source.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Spain EV source selection

Layer / File(s) Summary
Shared resolver and coverage
src/scrapers/spain-ev-source.ts, src/scrapers/spain-ev-source.test.ts
Adds resolveSpainEvSource, which selects one Spain EV source based on PUMPERLY_REVE_API_KEY and preserves other sources. Tests cover fallback, deduplication, and disabled configurations.
Runtime and CLI integration
src/instrumentation.ts, src/scrapers/cli.ts
Uses the resolver in instrumentation and for --country=all. Explicit country selections remain unchanged.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to fddab

This change centralizes Spain’s EV-source selection rule and applies it consistently to scheduled and manual runs, preventing the manual all-country command from restoring retired duplicate chargers. No actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preventing manual scraper runs from reversing the Spain EV source handover.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/spain-ev-source-single-rule

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@GeiserX

GeiserX commented Aug 22, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@GeiserX
GeiserX merged commit 5637b27 into main Aug 22, 2026
8 checks passed
@GeiserX
GeiserX deleted the fix/spain-ev-source-single-rule branch August 22, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant