Skip to content

Fetch active Firebase Project from Studio Workspace when running in Studio #8904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 4, 2025

Conversation

samedson
Copy link
Contributor

@samedson samedson commented Jul 29, 2025

Description

Features:

  • Implements a way to fetch the active Firebase Project when running the CLI inside of Firebase Studio so that they sync up. When Studio and the CLI disagree, implements a way for the user to reconcile them. Note that the --project parameter will still work as an override.
  • Updates firebase use to update the active project in Firebase Studio.

Progress:

  • Fetch the active project from Firebase Studio
  • Give the user a way to reconcile active projects
  • Write the active project to configstore
  • Update firebase use to update the active project
  • Provide a way to signal to Firebase Studio that the active project has been updated (eg. writing to configstore or a separate file)
  • Is it wonky if there's a conflict and you run firebase use <new-project>? You go through conflict resolution and then could set the project to a third project (maybe we skip conflict resolution if you are calling the use command)?

Scenarios Tested

MONOSPACE_ENV=1 WORKSPACE_SLUG="<studio-workspace-id>" firebase apps:list --project <another-project-id>
✔ Preparing the list of your Firebase apps

... list of apps from <another-project-id>

Sample Commands

$ MONOSPACE_ENV=1 WORKSPACE_SLUG="<studio-workspace-id>" firebase apps:list
? Found different active Firebase Projects in the Firebase CLI and your Firebase Studio 
Workspace. Which project would you like to set as your active project?
  Set <studio-project-id> from Firebase Studio as my active project in both places
❯ Set <cli-project-id> from Firebase CLI as my active project in both places
Updating Studio Workspace active project to match Firebase CLI '<cli-project-id>'
✔ Preparing the list of your Firebase apps

... list of apps from <cli-project-id>

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @samedson, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request aims to enhance the Firebase CLI's ability to work seamlessly within the Firebase Studio environment. It introduces the necessary API definitions and logic to fetch project information directly from a Firebase Studio workspace, allowing the CLI to automatically configure itself with the correct Firebase project when running in that specific environment. This is a foundational step towards deeper integration with Firebase Studio.

Highlights

  • Firebase Studio Integration: I've introduced new functionality to integrate the Firebase CLI with Firebase Studio. This allows the CLI to automatically determine the active Firebase project based on a Studio workspace, but only when the MONOSPACE_ENV environment variable is set.
  • New API Endpoint: A new API origin, studioWorkspaceApiOrigin, has been added in src/api.ts to define the base URL for the Firebase Studio Workspace API (https://monospace-pa.googleapis.com). A corresponding Client instance (studioWorkspaceClient) has been set up in src/management/projects.ts to interact with this API.
  • Workspace Project Resolution: A new asynchronous function getStudioWorkspace has been added to src/management/projects.ts. This function fetches details for a given workspace ID from the Studio API. The Command class in src/command.ts now includes an applyStudioWorkspace method that calls getStudioWorkspace (currently with a hardcoded ID studio-74855340 and multiple TODOs for dynamic ID fetching) and, if successful, sets the CLI's active project (options.project) to the firebaseProjectId returned by the Studio workspace.
  • Debugging Aid: A console.log statement has been temporarily added in src/apiv2.ts to output the fetchURL for debugging purposes during API requests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 introduces functionality to fetch project information from Firebase Studio. The changes add a new API endpoint, a client to call it, and logic in the Command class to use this information to set the project context when running inside a Studio environment.

My review has identified a few high-priority issues that should be addressed before merging:

  • There are several console.log and console.error statements that appear to be for debugging. These should be removed or replaced with the project's standard logger.
  • A hardcoded workspace ID is used. This will prevent the feature from being used in any other context and should be replaced with a dynamic method for retrieving the workspace ID.

Copy link
Contributor Author

@samedson samedson left a comment

Choose a reason for hiding this comment

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

LGTM! Just one suggestion

}

async function writeStudioProjectToConfigStore(options: Options, studioProjectId: string) {
if (options.projectRoot) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was curious what the desired behavior should be without a project root. This is when there's no firebase.json in your directory chain?

I did a quick sanity check and noticed there's different behavior when you have a firebase.json and when you don't:

➜  firebase-tools git:(fetch-project-from-studio) MONOSPACE_ENV=1 WORKSPACE_SLUG="studio-48028039" firebase apps:list
✔ Preparing the list of your Firebase apps
No apps found.

➜  firebase-tools git:(fetch-project-from-studio) touch firebase.json

➜  firebase-tools git:(fetch-project-from-studio) ✗ MONOSPACE_ENV=1 WORKSPACE_SLUG="studio-48028039" firebase apps:list
? Found different active Firebase Projects in the Firebase CLI and your Firebase Studio 
Workspace. Which project would you like to set as your active project? (Use arrow keys)
❯ Set greeting-generator-spibe from Firebase Studio as my active project in both places
  Set dumpsterfire-6 from Firebase CLI as my active project in both places
  
  ➜  firebase-tools git:(fetch-project-from-studio) ✗ rm -f firebase.json                      
  
➜  firebase-tools git:(fetch-project-from-studio) MONOSPACE_ENV=1 WORKSPACE_SLUG="studio-48028039" firebase use dumpsterfire-5

Error: firebase use must be run from a Firebase project directory.

Run firebase init to start a project directory in the current folder.

My hunch is a lot of apps won't have a firebase.json for their studio project.

So maybe the user experience is:

  • ✅ If you haven't called firebase use, then we use the studio project, no conflict resolution.
  • ✅ If you have called firebase use, it'll force you through the init flow, which creates a firebase.json

So lots of words to say, this seems fine to me, but what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this was pretty much my thinking as well when I noticed this edge case - if you're not in a Firebase project directory, we can't set your active project, we just pick up your studio project.

@codecov-commenter
Copy link

codecov-commenter commented Aug 1, 2025

Codecov Report

❌ Patch coverage is 85.91549% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.76%. Comparing base (f1c2d21) to head (cedb46b).
⚠️ Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
src/management/studio.ts 89.65% 2 Missing and 4 partials ⚠️
src/command.ts 71.42% 1 Missing and 1 partial ⚠️
src/commands/use.ts 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8904      +/-   ##
==========================================
- Coverage   52.18%   50.76%   -1.42%     
==========================================
  Files         418      497      +79     
  Lines       30694    32947    +2253     
  Branches     6348     6844     +496     
==========================================
+ Hits        16018    16726     +708     
- Misses      13234    14749    +1515     
- Partials     1442     1472      +30     

☔ View full report in Codecov by Sentry.
📢 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.

@samedson samedson force-pushed the fetch-project-from-studio branch from cedb46b to 491cbdb Compare August 4, 2025 13:26
@samedson
Copy link
Contributor Author

samedson commented Aug 4, 2025

Just rebased onto master FYI to see if it fixes the test failures

@samedson samedson merged commit 7e2a6e3 into master Aug 4, 2025
48 of 50 checks passed
@samedson samedson deleted the fetch-project-from-studio branch August 4, 2025 17:36
@github-project-automation github-project-automation bot moved this from Approved [PR] to Done in [Cloud] Extensions + Functions Aug 4, 2025
@samedson samedson changed the title Fetch project from studio Fetch active Firebase Project from Studio Workspace when running in Studio Aug 4, 2025
joehan added a commit that referenced this pull request Aug 5, 2025
* Fix apptesting enablement (#8905)

* Fix an issue with apptesting enablement

Co-authored-by: Joe Hanley <joehanley@google.com>

* Fix issue where login didnt work as expected on studio (#8914)

* Fix issue where login didnt work as expected on studio

* Update src/commands/login.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* 14.11.2

* [firebase-release] Removed change log and reset repo after 14.11.2 release

* Enable FDC API in `firebase init dataconnect` for Spark projects (#8927)

* feat: address pr comments on app-* commands

* Fetch active Firebase Project from Studio Workspace when running in Studio (#8904)

* Disable broken VSCode integration tests (#8934)

* Add userinfo.email scope when in studio (#8935)

* Add userinfo.email scope when in studio

* Update src/requireAuth.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Update src/requireAuth.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* feat: Display Firestore database edition (#8926)

* feat: Display Firestore database edition

Adds the 'Edition' to the output of the `firestore:databases:get` command.

The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table.

The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`.

* feat: Display Firestore database edition

Adds the 'Edition' to the output of the `firestore:databases:get` command.

The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table.

The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`.

* feat: Display Firestore database edition

Adds the 'Edition' to the output of the `firestore:databases:get` command.

The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table.

The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`.

Also refactors the tests for `prettyPrintDatabase` to improve readability and maintainability.

* feat: Display Firestore database edition

Adds the 'Edition' to the output of the `firestore:databases:get` command.

The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table.

The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`.

Also refactors the tests for `prettyPrintDatabase` to improve readability and maintainability and adds a test case for the `STANDARD` edition.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>

* Formatted

---------

Co-authored-by: Jake Ouellette <jakeout@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Google Open Source Bot <firebase-oss-bot@google.com>
Co-authored-by: Fred Zhang <fredzqm@google.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Sam Edson <samedson@google.com>
Co-authored-by: Ehsan <ehsann@google.com>
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.

3 participants