Skip to content

fix(app): local-dev Firebase placeholders must be format-valid, not just fake - #11594

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
formed2forge:fix/ios-local-firebase-config-format
Aug 15, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
formed2forge:fix/ios-local-firebase-config-format

Conversation

@formed2forge

@formed2forge formed2forge commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Why

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. 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 a bash setup.sh ios dev 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:

  1. 'Configuration fails. It may be caused by an invalid GOOGLE_APP_ID in GoogleService-Info.plist...' — GOOGLE_APP_ID must look like <project_number>:<number>:<platform>:<hex>; omi-dev-local isn't hex.
  2. After fixing that: 'API Key length must be 39 characters, API Key must start with A.' — the placeholder API key was 37 chars and didn't start with A.

Fixed both in all three sources that describe this same fake identity (iOS plist, Android json, 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 to actually fix it end to end.

Also patches BUNDLE_ID in the copied plist (generate_ios_custom_config in setup.sh) to track the per-hostname-suffixed APP_BUNDLE_IDENTIFIER that dev builds already get, since the placeholder's static BUNDLE_ID never 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_ENABLED stay false, matching the existing posture of this config.

Tests

  • app/test/unit/firebase_local_options_test.dart (new) — asserts the Dart FirebaseOptions consts and the raw plist/json source files match the format Firebase's SDK actually enforces (39-char API key starting with A; \d+:\d+:(ios|android|web):hex app 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 the BUNDLE_ID patch, following the existing setup_app_env_test.sh pattern (sources setup.sh, stubs the machine-dependent generate_device_suffix/detect_apple_team_id helpers, asserts the patched plist's BUNDLE_ID matches the generated APP_BUNDLE_IDENTIFIER).

Both pass locally:

flutter test test/unit/firebase_local_options_test.dart   # 6/6 passed
bash scripts/generate_ios_custom_config_bundle_id_test.sh # passed

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

Review in cubic

…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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 issues found across 6 files

Confidence score: 3/5

  • app/setup.sh patches a BUNDLE_ID that 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 for flutter run --flavor dev — align the patched value with the real dev Debug bundle id source.
  • app/scripts/generate_ios_custom_config_bundle_id_test.sh is 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 dead detect_apple_team_id override and the guaranteed-fail-first cp fallback pattern reduce test hermeticity and can mask genuine fixture/setup errors — remove the unused override and create Runner before copying so failures are meaningful.
  • app/test/unit/firebase_local_options_test.dart currently 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

Comment thread app/setup.sh
# 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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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', () {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kodjima33
kodjima33 merged commit 0304ce3 into BasedHardware:main Aug 15, 2026
30 checks passed
@cursor
cursor Bot deleted the fix/ios-local-firebase-config-format branch September 2, 2026 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants