high priority medium complexity testing pending testing specialist Tier 21

Acceptance Criteria

Test suite contains at minimum 8 named integration test cases covering: (1) successful run logs status='success', (2) failed run logs status='failed' with error_message, (3) concurrent second run logs status='skipped', (4) advisory lock is released after successful run, (5) advisory lock is released after failed run, (6) activity insert updates last_contact_date, (7) consecutive failure counter increments to 2 and triggers alert, (8) successful run resets consecutive failure counter to 0
All tests use isolated Supabase test database state — each test sets up its own seed data and tears it down after completion
Tests do not depend on shared global state — each test can run in any order independently
Test suite completes in under 60 seconds for CI/CD pipeline suitability
All 8 test cases pass with 0 failures in the test Supabase environment
Test output clearly identifies which scenario each test covers using descriptive test names
Alert dispatch in failure tests is validated using a mock/stub webhook endpoint — no real alerting channels are hit during test runs
Tests are added to CI pipeline and block merges on failure

Technical Requirements

frameworks
flutter_test
Supabase test client (service_role)
Deno test utilities for Edge Function testing
apis
Supabase Edge Function invoke API
Supabase Database REST API for state assertions
data models
cron_execution_logs
assignments
activities
performance requirements
Each individual test must complete in under 10 seconds
Concurrency test for advisory lock must use actual parallel invocations, not sequential mocks
security requirements
Test database must use a separate Supabase project or branch — never run destructive integration tests against the production database
Service role key for test environment must be stored in CI secrets, not in source code

Execution Context

Execution Tier
Tier 21

Tier 21 - 1 tasks

Can start after Tier 20 completes

Implementation Notes

Organize tests in a file named `cron_trigger_integration_test.dart` under the `integration_test/` directory. Use a `CronTestHelpers` utility class to encapsulate common setup patterns (seeding an assignment, inserting an activity, reading log rows). For the advisory lock concurrency test, insert a deliberate 2-second delay into the Edge Function via a test-mode flag to make the race condition reliably observable — remove this flag from production builds. Use Supabase's `supabase_flutter` client with the test project's URL and service role key, loaded from environment variables in test setup.

Consider using Supabase's branching feature (if available) to create a clean database branch per test run for maximum isolation.

Testing Requirements

This task IS the testing deliverable. Each of the 8 acceptance criteria test cases must be implemented as a named test in flutter_test or a Deno test file (depending on where the Edge Function logic is tested). Use `setUp` and `tearDown` hooks to isolate test state. For the concurrency test, use Dart's `Future.wait` to invoke the cron function twice simultaneously.

For the activity reset test, use the Supabase test client to insert an activity row directly and then assert the assignments table state. Mock the alerting webhook using a local HTTP server spun up in the test (e.g., using Dart's `HttpServer`). Assert both the HTTP call was received AND the payload matches the expected structure.

Component
Assignment Reminder Cron Trigger
infrastructure medium
Epic Risks (2)
high impact low prob technical

If the daily cron job takes longer than 24 hours to complete (due to a large dataset or a slow query), a second instance will start while the first is still running, causing duplicate reminder dispatch for assignments processed twice.

Mitigation & Contingency

Mitigation: Implement an advisory lock that prevents a second run from starting if the first is still active. Monitor run duration via the execution log table and alert if any run exceeds 30 minutes. The 10,000-assignment load test should verify the run completes in under 5 minutes.

Contingency: If a double-run occurs, the idempotency guard in ReminderDispatchService prevents duplicate notifications from being sent. The execution log identifies the overlap and allows the ops team to investigate the root cause.

high impact medium prob integration

If the activity registration hook that resets last_contact_date is implemented incorrectly or not triggered for all activity types (e.g., proxy registrations, bulk registrations), peer mentors will continue receiving reminders even after logging contact, damaging user trust.

Mitigation & Contingency

Mitigation: Audit all code paths that create activity records (direct registration, proxy registration, bulk registration, coordinator proxy) and ensure each path calls the assignment contact update. Write integration tests for each registration path asserting that last_contact_date is updated.

Contingency: Provide an authenticated admin endpoint that allows manual correction of last_contact_date for a specific assignment, enabling ops to resolve individual cases while the bug is fixed and deployed.