Fix dashboard CSV loading: use absolute /cia-data/ URLs so /dashboards/* pages stop 404'ing local CSVs#2403
Conversation
Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/147e836d-692f-4336-b3ea-5a905d128d78 Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
🏷️ Automatic Labeling SummaryThis PR has been automatically labeled based on the files changed and PR metadata. Applied Labels: testing,size-m Label Categories
For more information, see |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
There was a problem hiding this comment.
Pull request overview
This PR fixes dashboard CSV loading for pages under /dashboards/* by switching local-first CSV URLs from relative cia-data/... paths (which resolve to /dashboards/cia-data/... and 404) to root-relative /cia-data/... paths, aligning with the deployed artifact location in dist/cia-data/.
Changes:
- Updated multiple dashboard loaders to fetch local CSVs via absolute root-relative
/cia-data/...URLs. - Updated
CIADataLoader’scsvBaseURLto/cia-data/to make orchestrated loads depth-independent. - Added/updated Vitest coverage to prevent regressions (new “no relative cia-data literals” test + updated orchestrator expectation).
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/dashboard-cia-data-absolute-paths.test.ts | New regression test scanning key modules to ensure no relative cia-data/... (or ../cia-data/...) string literals remain. |
| tests/cia-data-loader-orchestrator.test.ts | Updates expectation to match the new /cia-data/foo.csv base URL behavior. |
| src/browser/dashboards/stats-loader.ts | Switches stats hero local CSV to /cia-data/extraction_summary_report.csv so it works from any page depth. |
| src/browser/dashboards/seasonal-patterns.ts | Updates seasonal local CSV URL to /cia-data/... for /dashboards/seasonal-patterns.html. |
| src/browser/dashboards/risk-dashboard.ts | Updates risk dashboard local CSV URL to /cia-data/... for /dashboards/risk.html. |
| src/browser/dashboards/pre-election.ts | Updates pre-election local CSV URLs to /cia-data/... for /dashboards/pre-election.html. |
| src/browser/dashboards/politician-dashboard.ts | Sets LOCAL_DATA_BASE to /cia-data so local-first URLs work from any document depth. |
| src/browser/dashboards/party-dashboard.ts | Updates party dashboard local fetch URL to /cia-data/party/${filename} for /dashboards/parties.html. |
| src/browser/dashboards/ministry-dashboard.ts | Updates ministry dashboard local base URL to /cia-data/ministry/ (preserving trailing slash behavior). |
| src/browser/dashboards/election-cycle.ts | Updates election-cycle local CSV URLs to /cia-data/... for /dashboards/election-cycle.html. |
| src/browser/dashboards/committees-dashboard.ts | Updates committees dashboard local CSV URLs to /cia-data/... for /dashboards/committees.html. |
| src/browser/dashboards/coalition-dashboard.ts | Updates coalition dashboard local CSV URLs to /cia-data/... for /dashboards/coalitions.html. |
| src/browser/dashboards/anomaly-detection.ts | Updates anomaly-detection local CSV URL to /cia-data/... for /dashboards/anomaly-detection.html. |
| src/browser/cia/data-loader.ts | Changes csvBaseURL to /cia-data/ so orchestrated loads aren’t dependent on the importing page’s directory depth. |
🔎 Investigation
The task asked three questions:
D3, Chart.js and PapaParse are bundled via
register-globalsincia-entry.ts/main.tsand load fine.vite buildcompiles everysrc/browser/dashboards/*.tsmodule, andpostbuild(inpackage.json) copiescia-data/intodist/cia-data/.s3-deploy.yml(scripts/deploy-s3.sh) uploadsdist/**andaws s3 syncauto-detectstext/csvfor.csvfiles. ✅cia-datacorrectly available where the loaders expect?It is — at
/cia-data/...on both GitHub Pages and S3.They do eventually, but only via the GitHub-raw fallback because eleven loaders built relative
cia-data/…URLs. From/dashboards/parties.htmlthose resolved to/dashboards/cia-data/…→ 404, so the local CSV (and the SW cache) was bypassed on every visit.✅ Fix
Switch every dashboard loader to absolute, root-relative
/cia-data/…URLs so the local-first hop succeeds from any document depth (/,/dashboards/<slug>.html,/dashboard/index*.html,/politician-dashboard.html).Loaders updated
dashboards/stats-loader.tscia-data/extraction_summary_report.csv/cia-data/extraction_summary_report.csvdashboards/party-dashboard.tscia-data/party/${file}/cia-data/party/${file}dashboards/election-cycle.tscia-data/election-cycle/…× 4/cia-data/election-cycle/…× 4dashboards/committees-dashboard.tscia-data/…× 5/cia-data/…× 5dashboards/coalition-dashboard.tscia-data/…× 7/cia-data/…× 7dashboards/seasonal-patterns.tscia-data/seasonal/…/cia-data/seasonal/…dashboards/pre-election.tscia-data/pre-election/…× 2/cia-data/pre-election/…× 2dashboards/anomaly-detection.tscia-data/seasonal/…/cia-data/seasonal/…dashboards/ministry-dashboard.tscia-data/ministry/(config base)/cia-data/ministry/dashboards/risk-dashboard.tscia-data/politician/…/cia-data/politician/…dashboards/politician-dashboard.tsLOCAL_DATA_BASE = 'cia-data'LOCAL_DATA_BASE = '/cia-data'cia/data-loader.tscsvBaseURL = '../cia-data/'csvBaseURL = '/cia-data/'coalition-loader.tsalready used/cia-data/, so no change needed.🧪 Tests
tests/dashboard-cia-data-absolute-paths.test.ts— strips comments from each dashboard module's source and asserts no remaining barecia-data/…(or'../cia-data/') string literal.tests/cia-data-loader-orchestrator.test.ts— expects the new/cia-data/foo.csvbase URL (the one test that pinned the old'../cia-data/'prefix).tsc -p tsconfig.browser.json --noEmit: clean.tests/coalition-dashboard.test.js&tests/committees-dashboard.test.jsare unaffected (they verify hand-rolled arrays, not the dashboard config).📈 Expected impact
/\/cia-data\/.*\.csv$/i) starts hitting on dashboard pages; previously the SW's runtime cache kept missing because the request URL contained/dashboards/cia-data/…and the origin returned 404 before the SW could store anything useful./dashboards/*pages (no fallback waterfall).🔒 Security & compliance
Pure URL string-prefix change in client-side
fetch()URLs (relative → root-absolute). No new sinks/sources, no auth/crypto/SSRF surface. CodeQL declared trivial; Code Review passed with no comments.