Skip to content

Tests for app-* commands #8909

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Tests for app-* commands #8909

wants to merge 6 commits into from

Conversation

joehan
Copy link
Contributor

@joehan joehan commented Jul 29, 2025

Description

Experimenting with making Gemini write tests for some of the less loved areas of our codebase - in this case, the apps-* commands

Scenarios Tested

No behavior changes here, just passing tests.

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 @joehan, 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 significantly enhances the test coverage for various apps-* commands within the codebase. The primary intent is to improve the reliability and maintainability of these command-line functionalities by adding robust unit tests, as part of an experiment to use Gemini for test generation. No functional changes are introduced; the focus is purely on ensuring the correctness of existing behavior through automated testing.

Highlights

  • New Test Coverage: Introduced comprehensive unit tests for several apps-* commands, including apps:android:sha:create, apps:android:sha:delete, apps:android:sha:list, apps:create, apps:list, and apps:sdkconfig.
  • Improved Testability: Exported several internal utility functions (getCertHashType, logCertificatesList, logCertificatesCount, logPostAppCreationInformation, logAppsList, logAppCount) from their respective command files to enable direct unit testing.
  • Type Definition Refinement: Adjusted the AppAndroidShaData interface in src/management/apps.ts to generalize the certType property from a specific SHA_1 enum value to the broader ShaCertificateType, accommodating different SHA certificate types.
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 adds tests for the app-* commands. I've left suggestions to make the tests more robust by verifying that stubbed functions are called with the correct arguments and asserting that the correct messages are logged for logging functions. I also suggested a change to the type definition for certType in src/management/apps.ts.

await command.runner()("test-app-id", shaHash, {});

expect(needProjectIdStub).to.have.been.calledOnce;
expect(createAppAndroidShaStub).to.have.been.calledOnce;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test checks that createAppAndroidShaStub is called, but it could be more robust by also verifying that it's called with the correct arguments. This ensures the command is correctly interpreting its inputs and passing them to the management API.

      expect(createAppAndroidShaStub).to.have.been.calledOnceWith("test-project-id", "test-app-id", {
        shaHash: shaHash,
        certType: ShaCertificateType.SHA_1
      });

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we address this ^?

await command.runner()("test-app-id", "test-sha-id", {});

expect(needProjectIdStub).to.have.been.calledOnce;
expect(deleteAppAndroidShaStub).to.have.been.calledOnce;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To make this test more specific, consider asserting that deleteAppAndroidShaStub is called with the expected arguments (projectId, appId, and shaId). This will ensure the command is correctly parsing and passing its arguments.

Suggested change
expect(deleteAppAndroidShaStub).to.have.been.calledOnce;
expect(deleteAppAndroidShaStub).to.have.been.calledOnceWith("test-project-id", "test-app-id", "test-sha-id");

Copy link
Contributor

Choose a reason for hiding this comment

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

^ can we address this as well?

Comment on lines 44 to 47
promiseWithSpinnerStub.resolves(certificates);

await command.runner()("test-app-id", {});

Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test stubs promiseWithSpinner directly, which prevents the actual logic inside the action (the call to listAppAndroidSha) from being executed. A more effective test would be to let promiseWithSpinner execute (using callThrough) and stub listAppAndroidSha instead. This would allow you to verify that listAppAndroidSha is called with the correct arguments, which is the primary responsibility of this command's action.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with this!

Comment on lines 53 to 59
it('should display "No SHA certificate hashes found." if no certificates exist', async () => {
promiseWithSpinnerStub.resolves([]);

await command.runner()("test-app-id", {});

// No assertion needed here, we are just checking that it does not throw.
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test only checks that the command doesn't throw an error when no certificates are found. A stronger assertion would be to verify that the correct message is logged to the user. You can achieve this by spying on logger.info and checking that it's called with a message including "No SHA certificate hashes found.".

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we address this?

platform: AppPlatform.WEB,
displayName: "test-display-name",
};
logPostAppCreationInformation(appMetadata, AppPlatform.WEB);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The tests in this describe block only check that the logging function doesn't throw an error, which is a very weak assertion. To make them more valuable, you should assert that the correct information is being logged.

Comment on lines +65 to +72
it('should display "No apps found." if no apps exist', async () => {
listFirebaseAppsStub.resolves([]);
getAppPlatformStub.returns(AppPlatform.ANY);

await command.runner()(undefined, {});

// No assertion needed here, we are just checking that it does not throw.
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test only verifies that the command doesn't throw when no apps are found. A more robust test would assert that the expected "No apps found." message is logged. You can achieve this by spying on logger.info and checking its arguments.

Comment on lines +98 to +108
describe("logAppCount", () => {
it("should print the total number of apps", () => {
logAppCount(5);
// No assertion needed here, we are just checking that it does not throw.
});

it("should not print if count is 0", () => {
logAppCount(0);
// No assertion needed here, we are just checking that it does not throw.
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

These tests for logAppCount only check that the function doesn't throw. To make them more effective, you could spy on logger.info and assert that it's called with the correct count message when the count is greater than 0, and not called when the count is 0.

@joehan joehan requested a review from maneesht July 30, 2025 15:35

expect(promiseWithSpinnerStub).to.have.been.calledOnce;
const spinnerText = promiseWithSpinnerStub.getCall(0).args[1];
expect(spinnerText).to.include("Preparing the list");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also check that the logger logged the list that you stubbed above?

});

it("should prompt for platform if not provided in interactive mode", async () => {
getAppPlatformStub.withArgs("").returns(AppPlatform.ANY);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be here?

});

it("should get config for the only app when no app id is provided", async () => {
needProjectIdStub.returns("test-project-id");
Copy link
Contributor

Choose a reason for hiding this comment

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

This one line appears in most of the tests. Should it be moved into the beforeEach block?

@github-project-automation github-project-automation bot moved this to Changes Requested [PR] in [Cloud] Extensions + Functions Aug 1, 2025
joehan and others added 2 commits August 5, 2025 09:31
* 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>
@joehan joehan requested a review from maneesht August 5, 2025 16:56
@joehan joehan marked this pull request as ready for review August 5, 2025 17:16
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