//go:build integration package integration import ( "context" "testing" "github.com/missionworkforce/missionmatch/internal/platform/missionclass" ) // TestMissionAreasMatchInCodeVocabulary reads mission_areas from the live DB ordered by sort_order and // asserts the resulting code slice equals missionclass.Codes in both membership and order. This is the // drift guard between the database controlled vocabulary (migration 0025) and the in code list the // deterministic classifier keys on, so the two can never silently diverge. // // The read uses the migrator pool (BYPASSRLS) because mission_areas is global reference data outside // RLS with SELECT granted to missionmatch_app; no tenant setup or org context is needed. func TestMissionAreasMatchInCodeVocabulary(t *testing.T) { ctx := context.Background() rows, err := migrator.Query(ctx, "SELECT code FROM mission_areas ORDER BY sort_order, code") if err != nil { t.Fatalf("query mission_areas: %v", err) } defer rows.Close() var got []string for rows.Next() { var code string if err := rows.Scan(&code); err != nil { t.Fatalf("scan mission_areas row: %v", err) } got = append(got, code) } if err := rows.Err(); err != nil { t.Fatalf("mission_areas rows error: %v", err) } if len(got) != len(missionclass.Codes) { t.Fatalf("mission_areas has %d rows, missionclass.Codes has %d", len(got), len(missionclass.Codes)) } for i := range got { if got[i] != missionclass.Codes[i] { t.Fatalf("mission code drift at position %d: DB %q != missionclass.Codes %q", i, got[i], missionclass.Codes[i]) } } }