Implement deep link argument validation and fallback routing
epic-scenario-based-follow-up-prompts-core-logic-task-008 — Extend ScenarioDeepLinkHandler to validate all route arguments before navigation: verify activityId exists and belongs to the current user, confirm contactId is accessible, validate prefill values are within acceptable ranges. On validation failure, implement graceful fallback to the activity list screen with a contextual toast message rather than crashing or showing an error screen.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Add validateDeepLinkArgs(ScenarioContext context) as an async method on ScenarioDeepLinkHandler that returns Future
Map each DeepLinkFailureReason to a localized string via a dedicated DeepLinkErrorMessages class using the app's existing localization infrastructure. Never show raw exception messages to the user.
Testing Requirements
Write unit tests using flutter_test with mocked Supabase repository. Test cases: (1) all fields valid → isValid=true, (2) activityId not found in DB → ACTIVITY_NOT_FOUND, (3) activityId found but wrong user_id → ACTIVITY_NOT_OWNED (verify the user-facing message is identical to ACTIVITY_NOT_FOUND for security), (4) contactId not accessible → CONTACT_NOT_ACCESSIBLE, (5) prefillDate 91 days in the past → PREFILL_DATE_OUT_OF_RANGE, (6) prefillDate in the future → PREFILL_DATE_OUT_OF_RANGE, (7) prefillDuration = 0 → PREFILL_DURATION_OUT_OF_RANGE, (8) prefillDuration = 481 → PREFILL_DURATION_OUT_OF_RANGE, (9) Supabase throws exception → NETWORK_ERROR. Widget test: verify that fallbackToActivityList() triggers a SnackBar with non-empty text and that router.go() was called with the activity list route. Verify analytics mock received a call with failureReason and no PII.
The Rule Engine must support a flexible JSON rule schema that can express compound conditions (e.g., contact_type AND wellbeing_flag AND delay_days). Underestimating schema expressiveness may require breaking changes to the rule format after coordinators have already configured rules.
Mitigation & Contingency
Mitigation: Define and freeze the rule JSON schema (trigger_type enum, metadata_conditions structure, delay logic) before any implementation begins; validate schema against all known HLF scenarios documented in the feature spec.
Contingency: If schema changes are needed after deployment, implement a schema version field and a migration utility that upgrades stored rules to the new format without coordinator intervention.
Deep-link navigation to the activity wizard with pre-filled arguments may fail if the user's session has expired or if the wizard route is not yet mounted in the navigator stack, causing unhandled navigation exceptions.
Mitigation & Contingency
Mitigation: Implement session state check before navigation; if session is expired, redirect to biometric/login screen and store the pending deep-link URI for post-auth redirect using go_router's redirect mechanism.
Contingency: If post-auth redirect proves unreliable, fall back to navigating to the home screen with a visible action banner that re-triggers the wizard with pre-filled arguments.