Integration test: rule evaluation against Supabase data
epic-scenario-based-follow-up-prompts-core-logic-task-012 — Write integration tests that exercise the full evaluation path against a real Supabase test instance: seed scenario_rules and scenario_prompt_history records, call ScenarioRuleEngine.evaluate() via ScenarioRuleRepository and PromptHistoryRepository, assert correct rule selection including cooldown enforcement, assert EvaluationResult reason codes for non-match cases. Use flutter_test with Supabase test project credentials from CI environment.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Implementation Notes
Supabase RLS policies on the test instance must allow the test service role key to insert and delete rows in scenario_rules and scenario_prompt_history. If the test project uses the anon key, ensure RLS policies are relaxed for the test tables or use the service role key exclusively for seeding/teardown. Use unique test-run prefixes (e.g., UUID-based chapter_id) to prevent parallel CI runs from interfering with each other. Cooldown window testing requires inserting scenario_prompt_history rows with specific created_at timestamps — use Supabase's ability to insert with explicit timestamp values.
Define a helper function seedRules(List
Testing Requirements
Integration tests using flutter_test connecting to a real Supabase test project. Place tests in test/integration/scenario_rule_engine_integration_test.dart. Use setUpAll() to initialize Supabase.initialize() once with env-var credentials. Use setUp()/tearDown() for per-test data seeding and cleanup.
Test scenarios must include: (1) single matching rule returns correct result; (2) multiple rules, highest priority wins; (3) cooldown active blocks best match, lower-priority non-blocked rule selected instead; (4) cooldown active, no alternative rule → COOLDOWN_ACTIVE reason code; (5) no rules for chapter → NO_MATCHING_RULE; (6) rules exist but all inactive → RULE_INACTIVE; (7) trigger_conditions partially met → NO_MATCHING_RULE with correct partial-match metadata. Run integration tests separately from unit tests via a dedicated test command (e.g., flutter test test/integration/).
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.