high priority high complexity testing pending testing specialist Tier 5

Acceptance Criteria

Tests connect to the Supabase test instance using credentials supplied via CI environment variables (not hardcoded)
setUp() seeds the required scenario_rules and scenario_prompt_history rows before each test
tearDown() removes all seeded rows after each test to ensure isolation
evaluate() returns the highest-priority matching rule when multiple rules match the context
evaluate() enforces cooldown: if scenario_prompt_history has a recent entry within the cooldown window, the rule is not selected
evaluate() returns EvaluationResult with reason code NO_MATCHING_RULE when no rule's trigger_conditions are met
evaluate() returns EvaluationResult with reason code COOLDOWN_ACTIVE when the best match is blocked by cooldown
evaluate() returns EvaluationResult with reason code RULE_INACTIVE when only inactive rules exist for the chapter
All assertions use the EvaluationResult enum values (not raw strings) for reason codes
Tests pass reliably in CI (no flakiness from network timing) — use retry logic or explicit await for Supabase operations
Integration test file is clearly separated from unit tests (e.g., in test/integration/ subdirectory)

Technical Requirements

frameworks
Flutter
flutter_test
Supabase Flutter SDK
Riverpod
apis
Supabase REST API
Supabase PostgREST
scenario_rules table
scenario_prompt_history table
data models
ScenarioRule
ScenarioPromptHistory
EvaluationResult
ScenarioRuleEngine
ScenarioRuleRepository
PromptHistoryRepository
performance requirements
Each integration test must complete within 10 seconds (accounting for network latency)
Seed and teardown operations must use batch inserts/deletes to minimize round-trips
security requirements
Supabase credentials must be read from environment variables (SUPABASE_TEST_URL, SUPABASE_TEST_ANON_KEY) — never hardcoded
Test instance must be a dedicated non-production Supabase project
Seeded data must use synthetic IDs that cannot conflict with production data

Execution Context

Execution Tier
Tier 5

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) and teardownRules(List ruleIds) to keep test bodies readable. Ensure ScenarioRuleEngine is instantiated with real repository instances (not mocks) for this integration test.

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/).

Component
Scenario Rule Engine
service high
Epic Risks (2)
high impact medium prob scope

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.

medium impact medium prob technical

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.