-
Notifications
You must be signed in to change notification settings - Fork 213
@invertase/rebased v2 integration tests #1718
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 @cabljac, 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!
I've undertaken a substantial overhaul of our integration test suite. The primary goal was to modernize the testing infrastructure by migrating from our custom shell-script-based runner to a more robust and standard Node.js/TypeScript environment leveraging Jest. This change not only streamlines our testing process but also enables comprehensive integration testing for Firebase Functions v2, ensuring their stability and correctness.
Highlights
- Test Infrastructure Modernization: The entire integration test infrastructure has been migrated from a custom shell script (run_tests.sh) and in-function test runner to a modern Node.js/TypeScript setup utilizing Jest for test execution. This provides a more standardized and maintainable testing environment.
- New Test Orchestration Script: A new run.ts script has been introduced to orchestrate the entire integration test lifecycle, including environment setup, dynamic function discovery, deployment of functions with unique identifiers, execution of Jest tests, and comprehensive cleanup of deployed resources.
- Firebase Functions v2 Integration Tests: Comprehensive integration tests have been added for Firebase Functions v2, covering various trigger types such as Database, Firestore, Eventarc, Identity, Pub/Sub, Remote Config, Scheduler, Storage, and Tasks. This significantly expands our test coverage for the latest functions version.
- Firebase Functions v1 Test Refactoring: Existing Firebase Functions v1 tests have been refactored to align with the new Jest-based framework. Instead of in-function assertions, test results are now logged to Firestore collections, which are then verified by the Jest test files.
- Improved Environment and Configuration Management: The test suite now includes .env.example and utils.ts for better environment variable handling, tsconfig.json files for TypeScript configuration, and a jest.config.js for Jest, streamlining the setup and execution process.
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
-
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. ↩
|
||
it("should have a correct ref url", () => { | ||
expect(loggedContext?.url).toMatch( | ||
new RegExp(`^https://${projectId}(-default-rtdb)*.firebaseio.com/dbTests/${testId}/start$`) |
Check failure
Code scanning / CodeQL
Regular expression injection High test
environment variable
This regular expression is constructed from a
environment variable
it("should have refs resources", () => { | ||
expect(loggedContext?.resource.name).toMatch( | ||
new RegExp( | ||
`^projects/_/instances/${projectId}(-default-rtdb)*/refs/dbTests/${testId}/start` |
Check failure
Code scanning / CodeQL
Regular expression injection High test
environment variable
This regular expression is constructed from a
environment variable
|
||
it("should have a correct ref url", () => { | ||
expect(loggedContext?.url).toMatch( | ||
new RegExp(`^https://${projectId}(-default-rtdb)*.firebaseio.com/dbTests/${testId}/start$`) |
Check failure
Code scanning / CodeQL
Regular expression injection High test
environment variable
This regular expression is constructed from a
environment variable
it("should have refs resources", () => { | ||
expect(loggedContext?.resource.name).toMatch( | ||
new RegExp( | ||
`^projects/_/instances/${projectId}(-default-rtdb)*/refs/dbTests/${testId}/start$` |
Check failure
Code scanning / CodeQL
Regular expression injection High test
environment variable
This regular expression is constructed from a
environment variable
|
||
it("should have a correct ref url", () => { | ||
expect(loggedContext?.url).toMatch( | ||
new RegExp(`^https://${projectId}(-default-rtdb)*.firebaseio.com/dbTests/${testId}/start$`) |
Check failure
Code scanning / CodeQL
Regular expression injection High test
environment variable
This regular expression is constructed from a
environment variable
it("should have refs resources", () => { | ||
expect(loggedContext?.resource.name).toMatch( | ||
new RegExp( | ||
`^projects/_/instances/${projectId}(-default-rtdb)*/refs/dbTests/${testId}/start$` |
Check failure
Code scanning / CodeQL
Regular expression injection High test
environment variable
This regular expression is constructed from a
environment variable
|
||
it("should have a correct ref url", () => { | ||
expect(loggedContext?.url).toMatch( | ||
new RegExp(`^https://${projectId}(-default-rtdb)*.firebaseio.com/dbTests/${testId}/start$`) |
Check failure
Code scanning / CodeQL
Regular expression injection High test
environment variable
This regular expression is constructed from a
environment variable
it("should have refs resources", () => { | ||
expect(loggedContext?.resource.name).toMatch( | ||
new RegExp( | ||
`^projects/_/instances/${projectId}(-default-rtdb)*/refs/dbTests/${testId}/start$` |
Check failure
Code scanning / CodeQL
Regular expression injection High test
environment variable
This regular expression is constructed from a
environment variable
There was a problem hiding this 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 a major and impressive overhaul of the integration test suite, migrating from a custom shell script-based runner to a more robust and maintainable framework using TypeScript, Jest, and firebase-tools
. The changes are extensive, well-structured, and significantly improve the development experience for testing. My review focuses on ensuring correctness and maintainability in the new implementation. I've found a critical issue related to potential runtime errors from unsafe regex parsing, a few high-severity copy-paste errors in commented-out code, and several medium-severity suggestions to improve type safety, use modern APIs, and handle data serialization more effectively. Overall, this is a fantastic contribution.
.it("should trigger when the scheduler fires", () => success()) | ||
.run(testId, null); | ||
.onRun(async (context) => { | ||
const topicName = /\/topics\/([a-zA-Z0-9\-\_]+)/gi.exec(context.resource.name)[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code directly accesses index [1]
of the result of ...exec(...)
. If the regex doesn't find a match, exec
will return null
, and accessing null[1]
will cause a TypeError
at runtime, crashing the function. You should check if the match is successful before accessing its parts.
const topicName = /\/topics\/([a-zA-Z0-9\-\_]+)/gi.exec(context.resource.name)[1]; | |
const match = /\/topics\/([a-zA-Z0-9\-\_]+)/gi.exec(context.resource.name); | |
const topicName = match ? match[1] : undefined; |
export const alertsOnNewNonFatalIssuePublishedTests = onNewNonfatalIssuePublished(async (event) => { | ||
// const testId = event.data.payload.issue.title; | ||
// await admin | ||
// .firestore() | ||
// .collection("alertsOnNewFatalIssuePublishedTests") | ||
// .doc(testId) | ||
// .set({ | ||
// event: JSON.stringify(event), | ||
// }); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a copy-paste error in this commented-out function. The function alertsOnNewNonFatalIssuePublishedTests
is writing to the alertsOnNewFatalIssuePublishedTests
collection in Firestore. If this code is uncommented in the future, it will lead to incorrect behavior.
The collection name should be alertsOnNewNonFatalIssuePublishedTests
.
export const alertsOnStabilityDigestPublishedTests = onStabilityDigestPublished(async (event) => { | ||
// const testId = event.data.payload.trendingIssues[0].issue.title; | ||
// await admin | ||
// .firestore() | ||
// .collection("alertsOnRegressionAlertPublishedTests") | ||
// .doc(testId) | ||
// .set({ | ||
// event: JSON.stringify(event), | ||
// }); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a copy-paste error in this commented-out function. The function alertsOnStabilityDigestPublishedTests
is writing to the alertsOnRegressionAlertPublishedTests
collection in Firestore. If this code is uncommented in the future, it will lead to incorrect behavior.
The collection name should be alertsOnStabilityDigestPublishedTests
.
export const sanitizeData = (data: any) => | ||
Object.entries(data).reduce((acc, [key, value]) => { | ||
if (value !== undefined) { | ||
acc[key] = value; | ||
} | ||
return acc; | ||
}, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sanitizeData
function uses any
for its parameter and has an inferred return type. For better type safety and maintainability, it's recommended to use more specific types like Record<string, unknown>
.
export const sanitizeData = (data: any) => | |
Object.entries(data).reduce((acc, [key, value]) => { | |
if (value !== undefined) { | |
acc[key] = value; | |
} | |
return acc; | |
}, {}); | |
export const sanitizeData = (data: Record<string, unknown>): Record<string, unknown> => | |
Object.entries(data).reduce((acc: Record<string, unknown>, [key, value]) => { | |
if (value !== undefined) { | |
acc[key] = value; | |
} | |
return acc; | |
}, {}); |
export const analyticsEventTests: any = functions | ||
.region(REGION) | ||
.analytics.event("in_app_purchase") | ||
.onLog(async () => {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exported function analyticsEventTests
is typed as any
. It's a good practice to provide explicit types for exported Cloud Functions to improve type safety and code clarity. You can import the specific event type from the firebase-functions
package. This applies to other new and modified function definitions in this PR as well.
export const analyticsEventTests: any = functions | |
.region(REGION) | |
.analytics.event("in_app_purchase") | |
.onLog(async () => {}); | |
export const analyticsEventTests: functions.CloudFunction<functions.analytics.AnalyticsEvent> = functions | |
.region(REGION) | |
.analytics.event("in_app_purchase") | |
.onLog(async () => {}); |
type: event.type, | ||
time: event.time, | ||
source: event.source, | ||
data: JSON.stringify(event.data), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The event.data
object is being stringified before being saved to Firestore. Firestore can store nested objects directly, and doing so preserves the data structure, making it easier to query and inspect in the Firebase console. Storing it as a string should be avoided unless necessary.
data: JSON.stringify(event.data), | |
data: event.data, |
subject: event.subject, | ||
time: event.time, | ||
type: event.type, | ||
message: JSON.stringify(event.data.message), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
it("should have pubsub data", () => { | ||
const decodedMessage = JSON.parse(loggedContext?.message); | ||
const decoded = new Buffer(decodedMessage.data, "base64").toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new Buffer()
constructor is deprecated due to security and usability issues. It's recommended to use Buffer.from()
, Buffer.alloc()
, or Buffer.allocUnsafe()
instead.
const decoded = new Buffer(decodedMessage.data, "base64").toString(); | |
const decoded = Buffer.from(decodedMessage.data, "base64").toString(); |
Description
Code sample