Wire spatial adapter into repository and test RPC integration
epic-geographic-peer-mentor-map-data-infrastructure-task-011 — Integrate the PostgisSpatialAdapter into MentorLocationRepository.findMentorsInBounds() replacing any stub implementations. Write integration tests against a local Supabase instance (supabase start) that seed mentor_location rows, call findMentorsInBounds with known bounding boxes, and assert correct results are returned and cross-org rows are excluded by RLS.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 6 - 158 tasks
Can start after Tier 5 completes
Implementation Notes
Replace stub in MentorLocationRepository with: final response = await supabase.rpc('mentors_in_bounds', params: {'min_lng': bounds.west, 'min_lat': bounds.south, 'max_lng': bounds.east, 'max_lat': bounds.north}). Map the RPC response list to List
Wrap the RPC call in a try/catch mapping PostgrestException to a domain-level SpatialQueryException. In CI, add a docker-compose step that runs supabase start before the integration test step.
Testing Requirements
Integration tests using flutter_test with supabase_flutter and a locally running supabase start instance. Test setup: (1) create two organisations, two authenticated users (one per org); (2) seed mentor_location rows with known coordinates; (3) call findMentorsInBounds with a bounding box that includes some rows and excludes others. Assertions: correct rows returned, cross-org rows absent, empty bounding box returns empty list, malformed bounding box throws typed exception. All tests must clean up seeded data via afterAll.
Tag tests as 'integration' to allow exclusion from unit test CI step. No mocking of the Supabase client in integration tests — the real client must be used.
Supabase's hosted PostGIS extension behaviour may differ from the local emulator for spatial RPC functions, causing bounding-box queries to return incorrect results or fail in production while passing locally.
Mitigation & Contingency
Mitigation: Write integration tests against the Supabase emulator from the start and run the same test suite against a staging Supabase project before merging. Use ST_DWithin and ST_MakeEnvelope in plain SQL first, validate with psql, then wrap as RPC.
Contingency: If PostGIS RPC proves unreliable, fall back to client-side bounding box filtering on a full fetch of consented mentor locations (acceptable for up to ~200 mentors per chapter) until the spatial query is stabilised.
OpenStreetMap tile usage may require attribution handling and rate limiting. Switching to Google Maps Flutter plugin mid-implementation would require significant rework of the map-provider-integration abstraction.
Mitigation & Contingency
Mitigation: Define the map-provider-integration abstraction interface before selecting the SDK so that the concrete implementation is swappable. Implement OSM first with correct attribution. Document Google Maps as the alternate with its API key setup steps.
Contingency: If OSM tiles are rejected by stakeholders or tile server limits are hit, activate the Google Maps Flutter plugin implementation behind the same interface without touching any UI or service code.
Incorrect RLS configuration could allow a coordinator to query mentor locations from a different organisation, constituting a GDPR data breach.
Mitigation & Contingency
Mitigation: Write dedicated RLS integration tests with two isolated test organisations and assert that cross-organisation queries return zero rows. Include these tests in CI. Have a second developer review all RLS policy SQL before migration is applied.
Contingency: If a cross-organisation data leak is discovered post-deployment, immediately disable the map feature via the organisation feature flag, revoke the affected Supabase RLS policy, and notify the data protection officer per the organisation's GDPR incident response procedure.