Skip to content

Detect the Android app module by basename in apps:init - #10864

Merged
joehan merged 3 commits into
firebase:mainfrom
Zuhef:fix/alpha-10863-android-app-basename
Jul 31, 2026
Merged

Detect the Android app module by basename in apps:init#10864
joehan merged 3 commits into
firebase:mainfrom
Zuhef:fix/alpha-10863-android-app-basename

Conversation

@Zuhef

@Zuhef Zuhef commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

findIntelligentPathForAndroid decides whether the user is already inside the Android app module by testing the first segment of the path, when the intent — stated in its own docstring — is the last one:

const paths = appDir.split("/");
// For when app/build.gradle is found
if (paths[0] === "app") {
  return appDir;
}

For any realistic input the first segment is not app: it's android for android/app, and "" for an absolute path like /home/me/proj/android/app. The branch therefore never runs, and correctness falls through to the src heuristic below it.

Root cause

Because the early return never fires, an app module that has no src directory reaches the fallback that appends app a second time, and getSdkOutputPath writes google-services.json into a directory that does not exist:

appDir expected before
android/app (has src/) android/app android/app — but via the src check, not the intended branch
android/app (no src/) android/app android/app/app

split("/") is also separator-dependent, so the check can never match on Windows, where appDir arrives with \ from path.join.

Fix

Use path.basename(appDir) === "app", which expresses the documented intent directly and is correct for relative paths, absolute paths, trailing separators, and both path separators. Behaviour for the existing cases is unchanged — android/app with a src/ directory still returns android/app, just through the branch that was meant to handle it.

Testing

Added the regression case to the existing getAndroidPlatform table. It fails before this change:

1 failing
  Inside app folder without a src directory:
  AssertionError: expected 'android\app\app' to equal 'android/app'

and passes after it.

$ npx mocha "src/management/apps.spec.ts"
46 passing

$ npx mocha "src/management/*.spec.ts"
97 passing

$ npm run test:compile
(clean)

npx eslint and npx prettier --check are clean on both changed files.

One extra thing, same lines of code

Three assertions in apps.spec.ts hardcoded forward slashes while the implementation builds those values with path.join, so apps.spec.ts was red on a Windows checkout before this PR — 42 passing, 3 failing:

AssertionError: expected 'android\app' to equal 'android/app'
AssertionError: expected 'ios\abc' to equal 'ios/abc'

node-test.yml runs unit tests on ubuntu-latest and macos-latest only (Windows is integration-only), so CI never showed this. I switched those three expectations to path.join(...), which is a no-op on Linux and macOS and makes the suite pass on Windows. The two cases where the function returns appDir verbatim keep their literal values, since that string is echoed back unchanged. Happy to split this into its own PR if you'd rather keep the fix isolated.

Fixes #10863

findIntelligentPathForAndroid checked appDir.split('/')[0] === 'app', so the branch its own docstring describes never ran: the first segment is 'android' for 'android/app' and '' for an absolute path. Correctness fell through to the 'src' heuristic, and a module without a src directory got 'app' appended twice, so google-services.json was written to a path that does not exist. split('/') also never matches on Windows.

Use path.basename(appDir) instead, and make the spec assertions that compare against path.join output platform-independent so the suite is green on a Windows checkout.
@google-cla

google-cla Bot commented Jul 29, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where apps:init writes google-services.json to an incorrect app/app path when the Android module lacks a src directory. This is resolved by using path.basename(appDir) instead of splitting the path string to detect the module directory. Additionally, unit tests in src/management/apps.spec.ts have been updated to use platform-independent path joining and a new test case has been added to cover this scenario. There are no review comments, so I have no feedback to provide.

@Zuhef Zuhef closed this Jul 30, 2026
@Zuhef Zuhef reopened this Jul 30, 2026
@Zuhef

Zuhef commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

…roid-app-basename

# Conflicts:
#	CHANGELOG.md
@joehan
joehan requested a review from maneesht July 30, 2026 22:54
@joehan
joehan merged commit e3b7ca3 into firebase:main Jul 31, 2026
49 checks passed
@joehan

joehan commented Jul 31, 2026

Copy link
Copy Markdown
Member

Thanks for the contirbution!

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@3fc2d76). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10864   +/-   ##
=======================================
  Coverage        ?   58.64%           
=======================================
  Files           ?      621           
  Lines           ?    40731           
  Branches        ?     8280           
=======================================
  Hits            ?    23888           
  Misses          ?    14853           
  Partials        ?     1990           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

apps:init: Android module detected by first path segment instead of basename, producing app/app output path

5 participants