Unit test ReportFieldValidator and integration smoke test
epic-structured-post-session-report-foundation-task-011 — Write exhaustive unit tests for ReportFieldValidator covering every validation rule type (required, length, pattern, numeric range, select options, date range), edge cases (null values, empty strings, boundary values), and multi-field parallel validation. Write a lightweight integration smoke test that exercises the full data layer chain: OrgFieldConfigLoader → ReportSchemaCache → PostSessionReportRepository → WayForwardItemRepository against a Supabase test project to confirm all contracts are satisfied end-to-end.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
The integration smoke test is the safety net that catches contract mismatches between the data layer components — it is valuable precisely because it tests the real Supabase schema, RLS policies, and Dart serialisation together. Keep it lightweight (one happy-path per component + one RLS failure path) to avoid long CI times. Do NOT add business logic assertions here — those belong in unit tests. For the parallel validation edge case, the simplest implementation is to call `validateAll` 100 times with the same input on a `List.generate` and assert all results are identical — this catches any accidental static mutation.
If the project uses Riverpod, consider whether any integration test should exercise the provider layer; for this task, test the repository classes directly to keep scope narrow.
Testing Requirements
Split into two test files: `report_field_validator_test.dart` (pure unit, no network) and `data_layer_integration_test.dart` (tagged integration). For the unit tests, use a test table driven approach: define a list of `(FieldConfig, dynamic value, bool expectedValid, String? expectedErrorContains)` tuples and iterate with `for (final tc in cases) { test(...) }` to keep the file concise. For the integration test, use `setUpAll` to initialise the Supabase client from env vars and `tearDownAll` to close it.
Use `addTearDown` within each test to register cleanup immediately after creation, so cleanup runs even if the test fails mid-way.
Supabase RLS policies for multi-org report access may be more complex than anticipated — coordinators need cross-peer-mentor access within their org but not across orgs, and draft reports should be invisible to coordinators until submitted. Misconfigured RLS could expose sensitive health data or block legitimate access.
Mitigation & Contingency
Mitigation: Define and test RLS policies in isolation before writing repository code. Create a dedicated SQL migration file with policy definitions and an automated integration test suite that verifies each role's access boundaries using real Supabase auth tokens.
Contingency: If RLS proves too complex to express declaratively, implement application-level access control in the repository layer with explicit org and role checks, and add a security audit task before the feature goes to production.
The org field config JSON stored in Supabase may lack a stable, versioned schema contract. If different organisations have drifted to different field-definition formats, org-field-config-loader will fail silently or crash, breaking form rendering for those orgs.
Mitigation & Contingency
Mitigation: Define a canonical JSON Schema for field config and validate all existing org configs against it before implementation begins. Store a schema version field in every config record and handle version migrations explicitly in the loader.
Contingency: If existing configs are too heterogeneous, implement a config normalisation pass in org-field-config-loader that coerces known variants to the canonical format, logging warnings for fields that cannot be normalised so operations can fix them in the admin console.
TTL-based schema cache invalidation may cause peer mentors to use stale field definitions for up to the TTL window after an admin updates the org config, potentially collecting data against outdated field structures.
Mitigation & Contingency
Mitigation: Set a conservative TTL (e.g. 15 minutes) and expose a manual cache-bust mechanism triggered on app foreground-resume. Document the maximum staleness window in the admin console so org admins know to plan config changes outside active reporting windows.
Contingency: If stale schema causes a data quality incident, add a Supabase Realtime subscription to the org config table that invalidates the cache immediately on any config update.