high priority high complexity testing pending testing specialist Tier 5

Acceptance Criteria

E2E test: Edge Function receives a valid dispatch request, retrieves credentials from Vault mock, routes to a mock adapter, and returns a structured result with status 200 and expected payload shape
E2E test: Sync Scheduler reads cron config from database, creates a run_log entry with status 'running', invokes the Edge Function, and updates run_log status to 'completed' on success
E2E test: Health Monitor executes checks against mock endpoints, stores health_check results in database, and transitions integration status from 'unknown' to 'healthy' or 'degraded' correctly
Negative-path test: Auth failure from Vault returns structured error response with code AUTH_FAILURE and does not expose credential details in logs
Negative-path test: Adapter timeout (simulated via mock delay > threshold) triggers retry logic, exhausts retries, and records status 'failed' with timeout reason in run_log
Negative-path test: Invalid dispatch payload returns 400 with field-level validation errors before any Vault or adapter calls are made
All tests are isolated using mock adapters and do not require live Xledger, Dynamics, Cornerstone, Consio, or Bufdir endpoints
Test suite completes in under 60 seconds in CI environment
All tests pass in Supabase local dev environment via supabase test db

Technical Requirements

frameworks
flutter_test
Supabase Edge Functions (Deno)
supabase local CLI for test DB
apis
Supabase Edge Function invoke API
Supabase RPC for run_log and health_check tables
Mock adapter HTTP endpoints
data models
integration_run_log
health_check_result
integration_config
vault_credential
performance requirements
Full E2E test suite must complete within 60 seconds
Each individual test case must complete within 10 seconds including mock network round-trips
Mock adapter response latency capped at 200ms to simulate realistic conditions
security requirements
No real credentials must appear in test fixtures or logs
Vault mock must simulate encrypted retrieval without exposing plaintext secrets
Auth failure paths must not leak internal error details in response bodies

Execution Context

Execution Tier
Tier 5

Tier 5 - 253 tasks

Can start after Tier 4 completes

Integration Task

Handles integration between different epics or system components. Requires coordination across multiple development streams.

Implementation Notes

Start by setting up the mock adapter registry — a simple in-memory map from integration type key to a mock handler that returns configurable responses. Use Supabase's local CLI (`supabase start`) to spin up a local Postgres instance for run_log and health_check tables. For Vault mock, create a simple key-value store seeded with test credentials keyed by org_id + integration_type. Structure tests so each suite is independently runnable.

Pay special attention to the status machine in HealthMonitor — tests must cover every valid transition (unknown→healthy, healthy→degraded, degraded→failed) and invalid transitions must be asserted to be no-ops. For timeout simulation, use a configurable delay in the mock adapter and set the Edge Function's timeout threshold to a low value (e.g., 500ms) in the test config. Avoid sharing mutable state between test cases to prevent flakiness.

Testing Requirements

This task IS the testing task. Write integration tests using Deno's built-in test runner for Edge Functions and flutter_test for any Dart-side invocation layers. Structure tests in three suites: (1) EdgeFunctionSuite — dispatch, credential retrieval, adapter routing, and response shape; (2) SyncSchedulerSuite — cron config read, run_log lifecycle, Edge Function invocation, status update; (3) HealthMonitorSuite — endpoint check, result storage, status transition. Each suite must have at least one happy-path and two negative-path tests.

Use beforeEach/afterEach hooks to reset mock state and database rows. Target 100% coverage of all public Edge Function handler branches. Mock all external HTTP calls using a local mock server (e.g., Deno's built-in fetch mock or a lightweight HTTP mock library).

Component
Integration Edge Functions
infrastructure high
Dependencies (3)
Epic Risks (3)
medium impact medium prob technical

Supabase Edge Functions have cold start latency that can cause the first sync invocation after idle periods to fail or timeout when the external API has a short connection window, leading to missed scheduled syncs that go undetected.

Mitigation & Contingency

Mitigation: Configure Edge Function memory and implement a warm-up ping mechanism before heavy sync invocations. Set generous timeout values on the external API calls. Log all cold-start incidents for monitoring.

Contingency: If cold starts cause consistent sync failures, migrate the sync scheduler to a persistent Supabase cron job that pre-warms the function 30 seconds before the scheduled sync time.

high impact low prob technical

The sync scheduler must execute jobs at predictable times for financial reporting accuracy. Drift in cron execution timing (due to Supabase infrastructure delays) could cause syncs to run at wrong times, leading to missing data in accounting exports or duplicate exports across reporting periods.

Mitigation & Contingency

Mitigation: Implement idempotency keys based on integration ID + scheduled period, so re-runs of a delayed sync cannot create duplicate exports. Log actual execution timestamps vs scheduled timestamps and alert on drift exceeding 5 minutes.

Contingency: If scheduler reliability is insufficient, integrate with a dedicated cron service (e.g., pg_cron on Supabase) for millisecond-precise scheduling, replacing the application-level scheduler.

high impact medium prob integration

Aggressive health monitoring ping frequency could trigger rate limiting on external APIs (especially Xledger and Dynamics), causing legitimate export calls to fail after the monitor exhausts the API's request quota.

Mitigation & Contingency

Mitigation: Use lightweight health check endpoints (HEAD requests or vendor-specific ping/status endpoints) rather than data requests. Set health check frequency to once per 15 minutes minimum. Implement exponential backoff after consecutive failures.

Contingency: If rate limiting occurs, disable active health monitoring for the affected integration type and switch to passive health detection (mark unhealthy only when a scheduled sync fails).