Repository navigation
fix(app): local-dev Firebase placeholders must be format-valid, not just fake - #11594
Conversation
…ust fake Firebase's native SDK format-validates GOOGLE_APP_ID and API_KEY at Firebase.initializeApp() time, before any network call and before Auth is routed to the local emulator — so a syntactically invalid placeholder crashes the app on launch even though the values are never meant to reach a real backend. Measured on iPhone 17 Pro / iOS 27.0 while verifying an unrelated iOS UIScene fix: a dev-flavor build using the local-harness placeholder configs crashed with `'Configuration fails. It may be caused by an invalid GOOGLE_APP_ID...'`, then (after fixing that) with `API Key length must be 39 characters, API Key must start with 'A'`. GOOGLE_APP_ID was "1:000000000000:ios:omi-dev-local" (a human-readable string where Firebase expects a hex-like token) and API_KEY was "local-firebase-auth-emulator-api-key" (37 chars, doesn't start with 'A'). Both are now syntactically valid-looking but still fake — no real Firebase project is reachable with them, matching the existing IS_ANALYTICS_ENABLED=false / IS_GCM_ENABLED=false posture of this placeholder config. Fixed in all three sources that describe this same fake identity: the iOS plist, the Android json, and the Dart FirebaseOptions consts — main.dart selects the Dart consts explicitly for OMI_APP_PROFILE=local_dev, but the crash traced to native Firebase plugin registration reading the bundled plist even earlier, before Dart's main() runs, so both had to change. Also patches BUNDLE_ID in the copied plist to track the per-hostname-suffixed APP_BUNDLE_IDENTIFIER dev builds already get (generate_ios_custom_config), since the placeholder's static BUNDLE_ID never matched it. This one turned out not to be the actual crash trigger — Firebase's error message named the wrong field — but it's still a real mismatch and cheap to fix alongside it. Failure-Class: none
There was a problem hiding this comment.
6 issues found across 6 files
Confidence score: 3/5
app/setup.shpatches aBUNDLE_IDthat appears to differ from the actual dev Debug identifier, which can point iOS flavor runs at the wrong plist/config and cause confusing build/run behavior forflutter run --flavor dev— align the patched value with the real dev Debug bundle id source.app/scripts/generate_ios_custom_config_bundle_id_test.shis currently not exercised by normal app test commands/CI, so the key bundle-id regression this PR tries to guard can still slip through unnoticed — wire this script into an existing macOS CI/test target.- In
app/scripts/generate_ios_custom_config_bundle_id_test.sh, the deaddetect_apple_team_idoverride and the guaranteed-fail-firstcpfallback pattern reduce test hermeticity and can mask genuine fixture/setup errors — remove the unused override and createRunnerbefore copying so failures are meaningful. app/test/unit/firebase_local_options_test.dartcurrently validates formats but not cross-source consistency, and it uses working-directory-dependent relative paths; this can produce false confidence or flaky failures across environments — add explicit plist/json value sync assertions and use stable repo-root-aware path resolution.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/scripts/generate_ios_custom_config_bundle_id_test.sh">
<violation number="1" location="app/scripts/generate_ios_custom_config_bundle_id_test.sh:1">
P2: This regression script is never run by the app test commands or CI, so a future BUNDLE_ID regression can pass all checks undetected. Wire it into a macOS test job or an existing app test target.</violation>
<violation number="2" location="app/scripts/generate_ios_custom_config_bundle_id_test.sh:21">
P3: `detect_apple_team_id` is not defined or called by `setup.sh`, so this override never runs and cannot make the test hermetic. Remove the dead override and update the surrounding comment to describe the actual dependency.</violation>
<violation number="3" location="app/scripts/generate_ios_custom_config_bundle_id_test.sh:29">
P3: The first cp to Runner always fails because the mkdir on line 26 never creates '$fixture_dir/ios/Runner', so the '||' fallback branch runs on every pass. This is a guaranteed-fail-first pattern that obscures intent. Create the Runner directory up front and copy once.</violation>
</file>
<file name="app/test/unit/firebase_local_options_test.dart">
<violation number="1" location="app/test/unit/firebase_local_options_test.dart:36">
P3: The group named "setup/prebuilt Firebase config sources stay in sync" doesn't actually assert any consistency between sources — the plist and json tests each only verify that their individual values are format-valid, and neither compares them against the Dart DefaultFirebaseOptions values in the first group. If a future edit changes the Dart appId/apiKey while leaving the prebuilt files valid, or changes one prebuilt file but not the other, all of these tests still pass and the drift goes undetected despite the group's stated purpose. Either add cross-source equality assertions (apiKey/appId/messagingSenderId/projectId) against the Dart options, or rename the group to match what it checks (e.g. "prebuilt Firebase config sources are format-valid").</violation>
<violation number="2" location="app/test/unit/firebase_local_options_test.dart:38">
P3: The new test reads `setup/prebuilt/...` with package-root-relative paths (`File('setup/prebuilt/GoogleService-Info-Local.plist')` and `google-services-local.json`). These only resolve when the test's working directory is `app/`; from any other CWD they throw `FileSystemException`. The repo already has a robust package-root resolver in `test/unit/limitless_golden_test.dart` that walks up from `Directory.current` looking for `pubspec.yaml`. Consider reusing that pattern so the test is hermetic to its invocation directory rather than depending on the caller's CWD.</violation>
</file>
<file name="app/setup.sh">
<violation number="1" location="app/setup.sh:88">
P1: The patched BUNDLE_ID (`com.friend-app-with-wearable.ios12-${suffix}`, taken from Custom.xcconfig) does not match the bundle identifier the dev Debug build actually uses, so the plist/`flutter run --flavor dev` mismatch this aims to fix remains. devDebug.xcconfig (base config of the "Debug-dev" configuration) overrides APP_BUNDLE_IDENTIFIER to `com.friend-app-with-wearable.ios12.development` after including Custom.xcconfig, so the running app's bundle id is `.development`, not the suffixed value. Patch the plist to the `.development` id (the value the prebuilt plist already targeted) instead.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| # Xcode actually bundles (project.pbxproj references that path directly, not | ||
| # Config/Dev/); patch both so on-disk copies stay consistent. | ||
| local suffixed_bundle_id="com.friend-app-with-wearable.ios12-${suffix}" | ||
| /usr/libexec/PlistBuddy -c "Set :BUNDLE_ID ${suffixed_bundle_id}" "ios/Config/${config_name}/GoogleService-Info.plist" |
There was a problem hiding this comment.
P1: The patched BUNDLE_ID (com.friend-app-with-wearable.ios12-${suffix}, taken from Custom.xcconfig) does not match the bundle identifier the dev Debug build actually uses, so the plist/flutter run --flavor dev mismatch this aims to fix remains. devDebug.xcconfig (base config of the "Debug-dev" configuration) overrides APP_BUNDLE_IDENTIFIER to com.friend-app-with-wearable.ios12.development after including Custom.xcconfig, so the running app's bundle id is .development, not the suffixed value. Patch the plist to the .development id (the value the prebuilt plist already targeted) instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/setup.sh, line 88:
<comment>The patched BUNDLE_ID (`com.friend-app-with-wearable.ios12-${suffix}`, taken from Custom.xcconfig) does not match the bundle identifier the dev Debug build actually uses, so the plist/`flutter run --flavor dev` mismatch this aims to fix remains. devDebug.xcconfig (base config of the "Debug-dev" configuration) overrides APP_BUNDLE_IDENTIFIER to `com.friend-app-with-wearable.ios12.development` after including Custom.xcconfig, so the running app's bundle id is `.development`, not the suffixed value. Patch the plist to the `.development` id (the value the prebuilt plist already targeted) instead.</comment>
<file context>
@@ -78,6 +78,15 @@ function generate_ios_custom_config() {
+ # Xcode actually bundles (project.pbxproj references that path directly, not
+ # Config/Dev/); patch both so on-disk copies stay consistent.
+ local suffixed_bundle_id="com.friend-app-with-wearable.ios12-${suffix}"
+ /usr/libexec/PlistBuddy -c "Set :BUNDLE_ID ${suffixed_bundle_id}" "ios/Config/${config_name}/GoogleService-Info.plist"
+ /usr/libexec/PlistBuddy -c "Set :BUNDLE_ID ${suffixed_bundle_id}" ios/Runner/GoogleService-Info.plist
else
</file context>
| @@ -0,0 +1,48 @@ | |||
| #!/usr/bin/env bash | |||
There was a problem hiding this comment.
P2: This regression script is never run by the app test commands or CI, so a future BUNDLE_ID regression can pass all checks undetected. Wire it into a macOS test job or an existing app test target.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/scripts/generate_ios_custom_config_bundle_id_test.sh, line 1:
<comment>This regression script is never run by the app test commands or CI, so a future BUNDLE_ID regression can pass all checks undetected. Wire it into a macOS test job or an existing app test target.</comment>
<file context>
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
</file context>
| # generate_device_suffix reads the local hostname, and detect_apple_team_id inspects | ||
| # this machine's signing identities (and prompts interactively as a last resort). | ||
| generate_device_suffix() { echo "testhost"; } | ||
| detect_apple_team_id() { echo "TESTTEAM01"; } |
There was a problem hiding this comment.
P3: detect_apple_team_id is not defined or called by setup.sh, so this override never runs and cannot make the test hermetic. Remove the dead override and update the surrounding comment to describe the actual dependency.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/scripts/generate_ios_custom_config_bundle_id_test.sh, line 21:
<comment>`detect_apple_team_id` is not defined or called by `setup.sh`, so this override never runs and cannot make the test hermetic. Remove the dead override and update the surrounding comment to describe the actual dependency.</comment>
<file context>
@@ -0,0 +1,48 @@
+# generate_device_suffix reads the local hostname, and detect_apple_team_id inspects
+# this machine's signing identities (and prompts interactively as a last resort).
+generate_device_suffix() { echo "testhost"; }
+detect_apple_team_id() { echo "TESTTEAM01"; }
+
+fixture_dir="$(mktemp -d "${TMPDIR:-/tmp}/omi-ios-custom-config.XXXXXX")"
</file context>
| } | ||
| }); | ||
|
|
||
| group('setup/prebuilt Firebase config sources stay in sync', () { |
There was a problem hiding this comment.
P3: The group named "setup/prebuilt Firebase config sources stay in sync" doesn't actually assert any consistency between sources — the plist and json tests each only verify that their individual values are format-valid, and neither compares them against the Dart DefaultFirebaseOptions values in the first group. If a future edit changes the Dart appId/apiKey while leaving the prebuilt files valid, or changes one prebuilt file but not the other, all of these tests still pass and the drift goes undetected despite the group's stated purpose. Either add cross-source equality assertions (apiKey/appId/messagingSenderId/projectId) against the Dart options, or rename the group to match what it checks (e.g. "prebuilt Firebase config sources are format-valid").
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/test/unit/firebase_local_options_test.dart, line 36:
<comment>The group named "setup/prebuilt Firebase config sources stay in sync" doesn't actually assert any consistency between sources — the plist and json tests each only verify that their individual values are format-valid, and neither compares them against the Dart DefaultFirebaseOptions values in the first group. If a future edit changes the Dart appId/apiKey while leaving the prebuilt files valid, or changes one prebuilt file but not the other, all of these tests still pass and the drift goes undetected despite the group's stated purpose. Either add cross-source equality assertions (apiKey/appId/messagingSenderId/projectId) against the Dart options, or rename the group to match what it checks (e.g. "prebuilt Firebase config sources are format-valid").</comment>
<file context>
@@ -0,0 +1,54 @@
+ }
+ });
+
+ group('setup/prebuilt Firebase config sources stay in sync', () {
+ test('GoogleService-Info-Local.plist API_KEY and GOOGLE_APP_ID are format-valid', () {
+ final plist = File('setup/prebuilt/GoogleService-Info-Local.plist').readAsStringSync();
</file context>
| mkdir -p "$fixture_dir/ios/Config/Dev" "$fixture_dir/ios/Flutter" "$fixture_dir/scripts" | ||
| cp scripts/generate_ios_custom_config.sh "$fixture_dir/scripts/generate_ios_custom_config.sh" | ||
| cp setup/prebuilt/GoogleService-Info-Local.plist "$fixture_dir/ios/Config/Dev/GoogleService-Info.plist" | ||
| cp setup/prebuilt/GoogleService-Info-Local.plist "$fixture_dir/ios/Runner/GoogleService-Info.plist" 2>/dev/null \ |
There was a problem hiding this comment.
P3: The first cp to Runner always fails because the mkdir on line 26 never creates '$fixture_dir/ios/Runner', so the '||' fallback branch runs on every pass. This is a guaranteed-fail-first pattern that obscures intent. Create the Runner directory up front and copy once.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/scripts/generate_ios_custom_config_bundle_id_test.sh, line 29:
<comment>The first cp to Runner always fails because the mkdir on line 26 never creates '$fixture_dir/ios/Runner', so the '||' fallback branch runs on every pass. This is a guaranteed-fail-first pattern that obscures intent. Create the Runner directory up front and copy once.</comment>
<file context>
@@ -0,0 +1,48 @@
+mkdir -p "$fixture_dir/ios/Config/Dev" "$fixture_dir/ios/Flutter" "$fixture_dir/scripts"
+cp scripts/generate_ios_custom_config.sh "$fixture_dir/scripts/generate_ios_custom_config.sh"
+cp setup/prebuilt/GoogleService-Info-Local.plist "$fixture_dir/ios/Config/Dev/GoogleService-Info.plist"
+cp setup/prebuilt/GoogleService-Info-Local.plist "$fixture_dir/ios/Runner/GoogleService-Info.plist" 2>/dev/null \
+ || { mkdir -p "$fixture_dir/ios/Runner"; cp setup/prebuilt/GoogleService-Info-Local.plist "$fixture_dir/ios/Runner/GoogleService-Info.plist"; }
+
</file context>
|
|
||
| group('setup/prebuilt Firebase config sources stay in sync', () { | ||
| test('GoogleService-Info-Local.plist API_KEY and GOOGLE_APP_ID are format-valid', () { | ||
| final plist = File('setup/prebuilt/GoogleService-Info-Local.plist').readAsStringSync(); |
There was a problem hiding this comment.
P3: The new test reads setup/prebuilt/... with package-root-relative paths (File('setup/prebuilt/GoogleService-Info-Local.plist') and google-services-local.json). These only resolve when the test's working directory is app/; from any other CWD they throw FileSystemException. The repo already has a robust package-root resolver in test/unit/limitless_golden_test.dart that walks up from Directory.current looking for pubspec.yaml. Consider reusing that pattern so the test is hermetic to its invocation directory rather than depending on the caller's CWD.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/test/unit/firebase_local_options_test.dart, line 38:
<comment>The new test reads `setup/prebuilt/...` with package-root-relative paths (`File('setup/prebuilt/GoogleService-Info-Local.plist')` and `google-services-local.json`). These only resolve when the test's working directory is `app/`; from any other CWD they throw `FileSystemException`. The repo already has a robust package-root resolver in `test/unit/limitless_golden_test.dart` that walks up from `Directory.current` looking for `pubspec.yaml`. Consider reusing that pattern so the test is hermetic to its invocation directory rather than depending on the caller's CWD.</comment>
<file context>
@@ -0,0 +1,54 @@
+
+ group('setup/prebuilt Firebase config sources stay in sync', () {
+ test('GoogleService-Info-Local.plist API_KEY and GOOGLE_APP_ID are format-valid', () {
+ final plist = File('setup/prebuilt/GoogleService-Info-Local.plist').readAsStringSync();
+ final apiKey = RegExp(r'<key>API_KEY</key>\s*<string>([^<]+)</string>').firstMatch(plist)!.group(1)!;
+ final appId = RegExp(r'<key>GOOGLE_APP_ID</key>\s*<string>([^<]+)</string>').firstMatch(plist)!.group(1)!;
</file context>
kodjima33
left a comment
There was a problem hiding this comment.
Local-dev-only Firebase placeholders were format-invalid so the native SDK crashed at initializeApp before reaching the emulator; values stay fake, and the new format tests lock it in.
Why
Firebase's native SDK format-validates
GOOGLE_APP_IDandAPI_KEYatFirebase.initializeApp()time — before any network call, and before Auth is routed to the local emulator. The local-harness placeholder Firebase configs (setup/prebuilt/GoogleService-Info-Local.plist,google-services-local.json,lib/firebase_options_local.dart) used syntactically invalid values (GOOGLE_APP_ID = "1:000000000000:ios:omi-dev-local",API_KEY = "local-firebase-auth-emulator-api-key"), so abash setup.sh iosdev build crashes on launch — never gets anywhere near the local emulator it's supposed to talk to.What changed
Measured directly on iPhone 17 Pro / iOS 27.0 while verifying an unrelated iOS UIScene fix:
'Configuration fails. It may be caused by an invalid GOOGLE_APP_ID in GoogleService-Info.plist...'—GOOGLE_APP_IDmust look like<project_number>:<number>:<platform>:<hex>;omi-dev-localisn't hex.'API Key length must be 39 characters, API Key must start withA.'— the placeholder API key was 37 chars and didn't start withA.Fixed both in all three sources that describe this same fake identity (iOS plist, Android json, Dart
FirebaseOptionsconsts) —main.dartselects the Dart consts explicitly forOMI_APP_PROFILE=local_dev, but the crash traced to native Firebase plugin registration reading the bundled plist even earlier, before Dart'smain()runs, so both had to change to actually fix it end to end.Also patches
BUNDLE_IDin the copied plist (generate_ios_custom_configinsetup.sh) to track the per-hostname-suffixedAPP_BUNDLE_IDENTIFIERthat dev builds already get, since the placeholder's staticBUNDLE_IDnever matched it. This turned out not to be the actual crash trigger for the two errors above — Firebase's error message named the wrong field both times — but it's a real mismatch, cheap to fix alongside this, and could plausibly bite some other Firebase code path that does check bundle identity.Values remain non-secret placeholders that reach no real Firebase project —
IS_ANALYTICS_ENABLED/IS_GCM_ENABLED/IS_APPINVITE_ENABLED/IS_ADS_ENABLEDstayfalse, matching the existing posture of this config.Tests
app/test/unit/firebase_local_options_test.dart(new) — asserts the DartFirebaseOptionsconsts and the raw plist/json source files match the format Firebase's SDK actually enforces (39-char API key starting withA;\d+:\d+:(ios|android|web):hexapp ID), so a future edit can't reintroduce a human-readable placeholder in either field without a red test.app/scripts/generate_ios_custom_config_bundle_id_test.sh(new) — hermetic shell test for theBUNDLE_IDpatch, following the existingsetup_app_env_test.shpattern (sourcessetup.sh, stubs the machine-dependentgenerate_device_suffix/detect_apple_team_idhelpers, asserts the patched plist'sBUNDLE_IDmatches the generatedAPP_BUNDLE_IDENTIFIER).Both pass locally:
Manually re-verified the actual crash-to-fix progression on-device (iPhone 17 Pro / iOS 27.0) by patching the built app's config file at each step and relaunching via
devicectl, before committing the same fix to the source files here.Failure-Class: none