Tier 0 data layer integration and green-light verification
epic-bufdir-report-export-foundation-task-018 — Perform end-to-end integration verification of all Tier 0 components together: GeneratedReportsRepository creates an audit record, OrgHierarchyResolver expands the scope, ExportDataQueryBuilder fetches correctly joined data, BufdirCategoryMapper transforms categories, ExportStorageBucket client writes the file, FileDownloadHandler retrieves and triggers share sheet, and ExportPeriodPicker, ExportConfirmationDialog, and ExportProgressIndicator render correctly in a test harness screen. All components must be green-lit before any Tier 1 epic work begins.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Create a `test/integration/tier0_green_light_test.dart` file as the canonical sign-off artifact. Structure the test with a setUp that seeds the test database and a tearDown that removes all seeded data and deletes test storage files. Use a TestHarnessScreen widget that renders ExportPeriodPicker, ExportConfirmationDialog, and ExportProgressIndicator in a Column for widget testing. For the data layer components (repository, resolver, query builder, mapper, storage), write sequential integration test steps that assert on intermediate state, not just the final output.
Document the green-light checklist as a markdown table in `docs/tier0-green-light-checklist.md` and update it with actual test run timestamps and results. This task is a blocking gate — do not mark complete until every check is genuinely green in CI.
Testing Requirements
Write a dedicated integration test harness screen (not shown in production navigation) that wires all Tier 0 components together. Use flutter_test WidgetTester for UI components. Write a structured green-light checklist test that runs each component check as a named test case using group() and test() blocks. Each check must produce a clear PASS/FAIL with a descriptive message.
Run the full suite in CI as a required check before any Tier 1 branch can merge. Include a smoke test that runs the entire export flow from scope selection through to file download in one test case. Ensure all tests are idempotent (can be re-run multiple times without leftover state).
NHF's three-level hierarchy (national / region / chapter) with 1,400 chapters may have edge cases such as chapters belonging to multiple regions, orphaned nodes, or missing parent links in the database. Incorrect scope expansion would silently under- or over-report activities, which could invalidate a Bufdir submission.
Mitigation & Contingency
Mitigation: Obtain a full hierarchy fixture export from NHF before implementation begins. Write exhaustive unit tests covering boundary cases: single chapter, full national roll-up, chapters with no activities, and chapters assigned to multiple regions. Validate resolver output against a known-good manual count.
Contingency: If hierarchy data quality is too poor for automated resolution at launch, implement a manual scope override in the coordinator UI that allows the coordinator to explicitly select org units from a tree picker, bypassing the resolver.
The activity_type_configuration table may not cover all activity types currently in use, leaving a subset unmapped at launch. Bufdir submissions with unmapped categories will be incomplete and may be rejected by Bufdir.
Mitigation & Contingency
Mitigation: Run a query against production activity data before implementation to enumerate all distinct activity type IDs. Cross-reference with Bufdir's published category schema (request from Norse Digital Products). Flag every gap as a known issue and build the warning surface into the preview panel.
Contingency: Implement a fallback 'Other' category bucket for unmapped types and surface a prominent warning in the export preview requiring coordinator acknowledgement before proceeding. Log unmapped types for post-launch cleanup.
Supabase RLS policies on generated_reports and the storage bucket must enforce strict org isolation. A misconfigured policy could allow a coordinator from one organisation to read another organisation's export files, creating a serious data breach with GDPR implications.
Mitigation & Contingency
Mitigation: Write RLS integration tests that attempt cross-org reads with explicitly different JWT tokens and assert that all attempts return empty sets or 403 errors. Include RLS policy review in the pull request checklist. Use Supabase's built-in policy tester during development.
Contingency: If a policy gap is discovered post-deployment, immediately revoke all signed URLs for affected exports, audit the access log for unauthorised reads, and issue a coordinated disclosure to affected organisations per GDPR breach notification requirements.