high priority high complexity testing pending testing specialist Tier 11

Acceptance Criteria

Test seeds Supabase test instance with a test user, one activity within the scheduler date window, and one matching scenario rule
Calling runScheduler() against the seeded data inserts exactly one prompt_delivery record in the test database
Navigating to the notifications tab shows exactly one ScenarioPromptNotificationCard with the seeded scenario title
Tapping the card opens ScenarioPromptDetailBottomSheet displaying the correct scenario context and wellbeing flags from the seed data
Tapping the CTA button navigates to the activity wizard screen (verify by finding the wizard's first-step widget or route name)
Test teardown deletes all seeded rows and delivery records — no state leaks between test runs
The full flow completes without throwing any exceptions or error-state widgets appearing
Test runs successfully in CI using a dedicated Supabase test project (not production)
Total test execution time is under 60 seconds

Technical Requirements

frameworks
Flutter
flutter_test
integration_test
Supabase Flutter SDK
apis
Supabase REST API (test project)
Supabase Auth (test credentials)
data models
Activity
ScenarioPrompt
PromptDeliveryRecord
ScenarioRule
WellbeingFlag
performance requirements
Full integration test must complete in under 60 seconds
Supabase seed and teardown operations must complete in under 5 seconds each
security requirements
Test project credentials (URL, anon key) must be stored in environment variables, never hardcoded
Test Supabase project must be isolated from production — separate project URL
RLS policies on the test project must mirror production policies
ui components
ScenarioPromptNotificationCard
ScenarioPromptDetailBottomSheet
ActivityWizard (first step)
NotificationsTab

Execution Context

Execution Tier
Tier 11

Tier 11 - 5 tasks

Can start after Tier 10 completes

Implementation Notes

Expose a testable hook on the Scheduler Service (e.g., a public runNow() method or a VisibleForTesting annotation) so the integration test can trigger it synchronously without waiting for a background timer. For Supabase seeding, create a TestDataSeeder helper class that encapsulates all insert/delete operations — this keeps the test body readable. Use meaningful test UUIDs (e.g., 'test-activity-e2e-001') prefixed consistently so teardown can use .delete().like('id', 'test-%') as a safety net. Ensure the test Supabase project has the same schema migrations as production — include a CI step that runs migrations against the test project before running integration tests.

For deep link routing, the activity wizard screen should be identifiable by a unique Key or route name — assert using find.byKey(Key('activity-wizard-step-1')) or find.byType(ActivityWizardScreen). If the scheduler runs on a background isolate in production, add a Flutter test mode that runs it on the main isolate to avoid isolate communication complexity in tests.

Testing Requirements

Use the Flutter integration_test package with IntegrationTestWidgetsFlutterBinding.ensureInitialized(). Structure: (1) setUp — authenticate test user against Supabase test project, insert seed rows via supabase.from('activities').insert(); (2) act — pump full app, trigger scheduler manually via exposed test hook or by navigating to notifications tab which triggers scheduler; (3) assert UI state step by step with pumpAndSettle between each interaction; (4) tearDown — delete all inserted rows by test-user ID. Run on a physical device or emulator via flutter test integration_test/ --dart-define=SUPABASE_TEST_URL=... --dart-define=SUPABASE_TEST_KEY=....

CI pipeline must set these env vars as secrets. Do not run against the production Supabase project.

Component
Scenario Prompt Scheduler Service
service high
Epic Risks (2)
high impact medium prob technical

If the scheduler runs concurrently (e.g., two overlapping cron invocations due to edge function retry), duplicate prompts could be dispatched before the first run's history records are committed, breaking the deduplication guarantee.

Mitigation & Contingency

Mitigation: Use a Postgres advisory lock or unique constraint on (user_id, scenario_id, activity_ref) in the prompt history table to make concurrent writes idempotent; design the scheduler to check history inside a transaction.

Contingency: If concurrency issues persist in production, add a distributed lock via Supabase Edge Function concurrency limit (max_instances=1) for the evaluation function as a hard guard.

medium impact medium prob scope

Coordinators may find scenario configuration unclear if trigger conditions are expressed as raw JSON or technical terminology, leading to misconfiguration and irrelevant prompts being sent to peer mentors.

Mitigation & Contingency

Mitigation: Design the ScenarioConfigurationScreen to display human-readable descriptions of each template's trigger condition (e.g., 'Send 3 days after first contact if wellbeing concern was flagged') rather than raw rule properties; validate with an HLF coordinator in a design review before implementation.

Contingency: If coordinators still misconfigure rules after launch, add a preview mode that shows a simulated prompt based on a test activity before the rule is enabled.