Unit test LabelKeyRegistry and LabelKeyResolver
epic-dynamic-terminology-and-labels-foundation-task-008 — Write comprehensive flutter_test unit tests covering: all domain groups in LabelKeyRegistry have non-empty, dot-notation string values; LabelKeyResolver.resolve returns org label when present; falls back to default when org label missing; falls back to formatted key when neither present; parameterized substitution replaces all {{param}} occurrences; validateKey throws assertion in debug for unknown keys; and validateKey returns formatted fallback for unknown keys in release mode.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
The most robust way to test all LabelKeyRegistry constants is to use a static list or map of all defined keys (e.g. LabelKeyRegistry.allKeys getter returning a List
For parameterized substitution tests, ensure the test covers: single param, multiple params, same param used twice in the string, and no params provided when string has placeholders.
Testing Requirements
Use flutter_test exclusively. Organize tests into two top-level groups: 'LabelKeyRegistry' and 'LabelKeyResolver'. For LabelKeyRegistry, use reflection or a manual list to iterate all constants and assert format. For LabelKeyResolver, use table-driven tests (parameterized with a list of input/output pairs) for the resolution and substitution scenarios.
For debug vs release mode testing: extract the validateKey logic into a pure function that accepts a `bool isDebug` parameter to avoid needing actual build-mode switching. Minimum coverage: 100% lines and branches for both classes. Run with `flutter test test/label_key_resolver_test.dart --coverage`.
The labels JSONB column in organization_configs may lack a consistent schema across organizations, causing deserialization failures or silent missing keys when a new organization is onboarded with a differently structured map.
Mitigation & Contingency
Mitigation: Define and enforce a canonical JSONB schema via a Supabase check constraint and a migration script. Validate the schema in TerminologyRepository at parse time and emit structured errors for any key-type mismatches.
Contingency: If schema drift is discovered post-deployment, LabelKeyResolver's fallback logic ensures the app continues to function with English defaults while a data migration is prepared to normalize the offending organization's config.
Device local storage corruption or platform-specific SharedPreferences serialization bugs could render a cached terminology map unreadable, causing the app to fall back to English defaults unexpectedly for an organization with custom terminology.
Mitigation & Contingency
Mitigation: Wrap all cache reads in try/catch, validate the deserialized map against a minimum-required-keys check, and evict corrupted entries automatically before re-fetching from Supabase.
Contingency: Surface a non-blocking in-app warning to the coordinator that terminology may be in default English until the next sync completes; trigger an immediate background sync.