Skip to content

Add Statskontoret data integration support#1993

Merged
pethers merged 16 commits intomainfrom
copilot/add-data-support-for-statskontoret
Apr 25, 2026
Merged

Add Statskontoret data integration support#1993
pethers merged 16 commits intomainfrom
copilot/add-data-support-for-statskontoret

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 25, 2026

  • Pass configurable baseURL into assertStatskontoretFetchTarget from StatskontoretClient.fetchWithTimeout
  • Wrap fetch network/timeout failures in typed StatskontoretError with kind: 'http' and preserve cause
  • Align buildBudgetTimeSeries JSDoc with actual annual-row ordering
  • Reformat analysis/statskontoret/indicators-inventory.json to repository-standard 2-space indentation
  • Fix analysis/statskontoret/use-cases.md example import path
  • Add targeted Vitest coverage for custom baseURL and network typed-error behavior
  • Validate targeted Statskontoret tests: 53/53 passed
  • Validate targeted ESLint: clean
  • Validate npm run build:lib: passed
  • Run final parallel validation: Code Review 0 comments, CodeQL 0 alerts
  • Reply to new PR comment 4319188330 with commit 1068acb

Copilot AI and others added 4 commits April 25, 2026 08:12
Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/dc62517a-f53c-423f-b327-3d2856b258f8

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
@github-actions github-actions Bot added documentation Documentation updates dependencies Dependency updates testing Test coverage refactor Code refactoring size-xl Extra large change (> 1000 lines) labels Apr 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🏷️ Automatic Labeling Summary

This PR has been automatically labeled based on the files changed and PR metadata.

Applied Labels: documentation,dependencies,testing,refactor,size-xl

Label Categories

  • 🗳️ Content: news, dashboard, visualization, intelligence
  • 💻 Technology: html-css, javascript, workflow, security
  • 📊 Data: cia-data, riksdag-data, data-pipeline, schema
  • 🌍 I18n: i18n, translation, rtl
  • 🔒 ISMS: isms, iso-27001, nist-csf, cis-controls
  • 🏗️ Infrastructure: ci-cd, deployment, performance, monitoring
  • 🔄 Quality: testing, accessibility, documentation, refactor
  • 🤖 AI: agent, skill, agentic-workflow

For more information, see .github/labeler.yml.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@github-actions github-actions Bot added security Security improvements isms ISMS compliance changes iso-27001 ISO 27001 controls nist-csf NIST CSF compliance cis-controls CIS Controls labels Apr 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 25, 2026

@copilot apply changes based on the comments in this thread

Addressed in b064b08:

  • Densified sparse worksheet rows via Array.from({ length: row.length }, (_, i) => row[i] ?? '') so cells with explicit refs that skip columns no longer leave holes that misalign rowsToRecords.
  • Removed the unused 'page' member from StatskontoretResourceType (the classifier returns 'unknown' for plain HTML pages).
  • Aligned analysis/statskontoret/README.md to Public / High Integrity / Medium-High Availability to match THREAT_MODEL.md and SECURITY_ARCHITECTURE.md.
  • Added a Vitest case covering sparse-row densification.

20/20 targeted tests pass, ESLint clean, build:lib green, parallel_validation green (Code Review: 0 comments, CodeQL: 0 alerts).

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@pethers pethers requested a review from Copilot April 25, 2026 10:41
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class Statskontoret open-data integration (client + CLI + persistence + docs/tests) to complement existing IMF/SCB/World Bank provider tiers.

Changes:

  • Introduces scripts/statskontoret-client.ts (discovery, XLSX/ZIP parsing, headcount + budget outturn helpers, typed errors) and scripts/statskontoret-fetch.ts CLI wrapper for workflows.
  • Extends persistence layer with persistStatskontoretData() and adds jszip dependency for workbook/ZIP parsing.
  • Adds comprehensive Vitest coverage and a new analysis/statskontoret/ documentation hub (inventory, data dictionary, use cases) plus architecture/threat-model updates.

Reviewed changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/statskontoret-inventory.test.ts Validates the new Statskontoret inventory JSON matches the in-code source catalogue and decision matrix.
tests/statskontoret-fetch.test.ts Covers CLI argument parsing + guards (including allowlist enforcement and typed CLI errors).
tests/statskontoret-client.test.ts Covers discovery parsing, XLSX/ZIP parsing, aggregation helpers, and typed error surfaces.
scripts/statskontoret-fetch.ts Adds workflow-friendly CLI to discover/download/parse Statskontoret artifacts with optional persistence.
scripts/statskontoret-client.ts Adds the core Statskontoret client, parsers, aggregators, allowlist guard, and typed error type.
scripts/parliamentary-data/data-persistence.ts Adds statskontoret documentType + persistStatskontoretData() for cache/provenance sidecars.
package.json Adds jszip for XLSX/ZIP parsing.
package-lock.json Locks jszip and transitive dependencies.
analysis/statskontoret/use-cases.md Documents canonical use cases (headcount, budget execution, outturn summaries).
analysis/statskontoret/indicators-inventory.json Introduces a machine-readable Statskontoret dataset inventory + provider decision matrix.
analysis/statskontoret/data-dictionary.md Documents field mappings, inference rules, freshness discipline, and persistence layout.
analysis/statskontoret/README.md Adds the Statskontoret integration hub and CLI quick reference.
THREAT_MODEL.md Adds STRIDE threat assessment section for Statskontoret ingestion.
TESTING.md Documents Statskontoret test suites and expectations (no live network).
SECURITY_ARCHITECTURE.md Adds security architecture notes/controls for the new integration.
README.md Adds top-level documentation entry for Statskontoret integration and quick commands.
MINDMAP.md Adds current-state mindmap branch for Statskontoret integration.
FLOWCHART.md Adds current-state data-flow diagram for Statskontoret ingestion/persistence.
DATA_MODEL.md Adds data-model extension notes for Statskontoret entities and persisted artifacts.
ARCHITECTURE.md Adds current-architecture section describing how Statskontoret fits into the provider tiering and workflows.

Comment thread scripts/statskontoret-client.ts Outdated

private async fetchWithTimeout(url: string): Promise<Response> {
const resolved = resolveStatskontoretUrl(url, this.baseURL);
assertStatskontoretFetchTarget(resolved);
Comment thread scripts/statskontoret-client.ts Outdated
if (!response.ok) {
throw new StatskontoretError(`Statskontoret API error: ${response.status} ${response.statusText} for ${response.url}`, 'http');
}
return response;
Comment thread scripts/statskontoret-client.ts Outdated
Comment on lines +460 to +463
* typed rows sorted by year ascending, then month ascending (NaN last for
* annual rows), then documentType alphabetically. For single-type workbooks
* (e.g. a file explicitly downloaded as "Inkomst"), pass
* `options.documentType` to set the label uniformly.
Comment on lines +2 to +76
"version": "1.1",
"description": "Machine-readable inventory of Statskontoret open datasets used by Riksdagsmonitor for Swedish government-body and central-government budget context. Complements IMF (primary economic projections), SCB (Swedish official statistics), World Bank (non-economic global context), and Riksdag/Regering data.",
"lastUpdated": "2026-04-25",
"effectiveDate": "2026-04-25",
"source": "Statskontoret open data (www.statskontoret.se)",
"classification": "Public",
"clients": {
"cli": "tsx scripts/statskontoret-fetch.ts (commands: list-sources, discover, headcount, budget-outturn)",
"library": "scripts/statskontoret-client.ts (StatskontoretClient class)",
"persistence": "scripts/parliamentary-data/data-persistence.ts (persistStatskontoretData)"
},
"notes": {
"firewallAllowlist": "www.statskontoret.se",
"noMcp": "Statskontoret is not an MCP server. Agentic workflows invoke the TypeScript CLI via the bash tool, mirroring IMF's no-MCP client pattern.",
"formats": "Myndighetsförteckningen is published as Excel. Årsutfall and Månadsutfall expose both Excel and CSV ZIP downloads. Budget time-series pages link to annual official-statistics publications and related open-data tables.",
"privacy": "Public authority/agency data and aggregate budget data only; no private-person data. Authority names and agency-level budget lines are public administrative records."
},
"datasets": {
"myndighetsforteckning": {
"title": "Myndighetsförteckning – öppna data",
"url": "https://www.statskontoret.se/analys-och-statistik/oppna-data/myndighetsforteckning/",
"cadence": "Annual snapshot; source page metadata observed as last-modified 2026-02-06 for the 2025 workbook.",
"coverage": "Summerande statistik 2025; tidsserier 2007–2025; förteckning 2025; förteckning 2007–2025.",
"format": [
"xlsx"
],
"primaryUse": "Headcount of government bodies, grouped by department, leadership form and special organs; department headcount over time from 2007 onward.",
"keyFields": [
"År",
"Myndighet",
"Departement / departementstillhörighet",
"Årsarbetskrafter",
"Ledningsform",
"Särskilda organ"
],
"derivedArtifacts": [
{
"id": "headcount-by-department",
"description": "Sum årsarbetskrafter by year and department, with authority count per group.",
"script": "tsx scripts/statskontoret-fetch.ts headcount --url <xlsx-url> --persist",
"storage": "analysis/data/statskontoret/myndighetsforteckning/headcount-by-department.json"
}
],
"committees": [
"KU",
"FiU",
"AU"
],
"admiralty": "A1"
},
"budget-time-series": {
"title": "Tidsserier, statens budget m.m.",
"url": "https://www.statskontoret.se/analys-och-statistik/officiell-statistik/tidsserier-statens-budget-m.m",
"cadence": "Annual official statistics release.",
"coverage": "Final outcomes for central-government revenue, expenditure, balance and related public-finance tables, generally from 1995.",
"format": [
"html-publication",
"linked-open-data"
],
"primaryUse": "Long-run Swedish central-government budget context for finance, tax and public-administration analysis.",
"committees": [
"FiU",
"SkU",
"KU"
],
"admiralty": "A1",
"derivedArtifacts": [
{
"id": "budget-outturn",
"description": "Long-run central-government budget time series (revenue and expenditure) from 1995 onward parsed into StatskontoretBudgetRow objects.",
"script": "tsx scripts/statskontoret-fetch.ts budget-outturn --source budget-time-series --url <xlsx-url> --persist",
"storage": "analysis/data/statskontoret/budget-time-series/budget-outturn.json"
}
]
},
Comment on lines +25 to +31
```ts
import { parseBudgetRows, summarizeBudgetOutturn } from '../scripts/statskontoret-client.js';

const rows = parseBudgetRows(records, { documentType: 'Inkomst' });
const summary = summarizeBudgetOutturn(rows);
// summary[0] → { year: 2024, documentType: 'Inkomst', totalOutturn: 700000, totalBudget: 670000, variance: 30000, rowCount: 2 }
```
@pethers
Copy link
Copy Markdown
Member

pethers commented Apr 25, 2026

@copilot apply changes based on the comments in this thread

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 25, 2026

@copilot apply changes based on the comments in this thread

Addressed in 1068acb: configurable Statskontoret baseURL now feeds the fetch allowlist guard, network/timeout failures are wrapped as typed StatskontoretError(kind='http') with cause preserved, the JSDoc and use-case import path are corrected, and the Statskontoret inventory JSON is reformatted to 2-space indentation. Added targeted tests; 53/53 Statskontoret tests pass, ESLint/build pass, and parallel validation is clean.

@pethers pethers merged commit 7246c68 into main Apr 25, 2026
17 checks passed
@pethers pethers deleted the copilot/add-data-support-for-statskontoret branch April 25, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cis-controls CIS Controls dependencies Dependency updates documentation Documentation updates isms ISMS compliance changes iso-27001 ISO 27001 controls nist-csf NIST CSF compliance refactor Code refactoring security Security improvements size-xl Extra large change (> 1000 lines) testing Test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants