Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request addresses a Crashlytics API issue where requests fail when using user credentials by adding the required 'x-goog-user-project' header to all relevant API calls. A new unit test file was added to verify that this header is correctly included in requests. The review feedback highlights the need to use the existing 'GOOG_USER_PROJECT_HEADER' constant from 'src/apiv2.ts' instead of hardcoding the string literal, ensuring consistency and adherence to the repository's style guide.
| method: "GET", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "x-goog-user-project": requestProjectNumber, |
There was a problem hiding this comment.
The header name "x-goog-user-project" is a repeated string that is already defined as a constant GOOG_USER_PROJECT_HEADER in src/apiv2.ts. To adhere to the repository style guide regarding extracting repeated strings and reusing existing utilities, please import and use GOOG_USER_PROJECT_HEADER instead of hardcoding the string literal here and in other Crashlytics API files.
References
- Define static IDs, default timeouts, millisecond offsets, and repeated strings as top-level constants (UPPER_SNAKE_CASE) instead of inlining magic values inside functions. (link)
- Reuse or extend existing utilities: Check imported modules, the immediate subsystem, and src/utils.ts first; reuse or extend existing helpers rather than writing bespoke inline logic. (link)
| import { expect } from "chai"; | ||
| import * as sinon from "sinon"; | ||
|
|
||
| import { ClientRequestOptions } from "../apiv2"; |
There was a problem hiding this comment.
Import GOOG_USER_PROJECT_HEADER from ../apiv2 to avoid hardcoding the "x-goog-user-project" header string, adhering to the repository style guide.
| import { ClientRequestOptions } from "../apiv2"; | |
| import { ClientRequestOptions, GOOG_USER_PROJECT_HEADER } from "../apiv2"; |
References
- Define static IDs, default timeouts, millisecond offsets, and repeated strings as top-level constants (UPPER_SNAKE_CASE) instead of inlining magic values inside functions. (link)
| expect(requestStub).to.have.been.calledOnce; | ||
| const options = requestStub.firstCall.args[0] as ClientRequestOptions<unknown>; | ||
| const headers = options.headers; | ||
| expect(headers).to.include({ "x-goog-user-project": projectNumber }); |
There was a problem hiding this comment.
Use the imported GOOG_USER_PROJECT_HEADER constant instead of the hardcoded "x-goog-user-project" string.
| expect(headers).to.include({ "x-goog-user-project": projectNumber }); | |
| expect(headers).to.include({ [GOOG_USER_PROJECT_HEADER]: projectNumber }); |
References
- Define static IDs, default timeouts, millisecond offsets, and repeated strings as top-level constants (UPPER_SNAKE_CASE) instead of inlining magic values inside functions. (link)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11547 +/- ##
=======================================
Coverage ? 61.05%
=======================================
Files ? 870
Lines ? 51015
Branches ? 10285
=======================================
Hits ? 31145
Misses ? 18750
Partials ? 1120 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The Crashlytics API rejects user credentials without a quota project, so every Crashlytics MCP tool failed with "requires a quota project". Send the app's project number as x-goog-user-project on all Crashlytics requests, as generateAlertPolicy already does. GOOGLE_CLOUD_QUOTA_PROJECT still overrides it. Fixes firebase#11545
1a5243b to
19c66be
Compare
Description
Fixes #11545.
The Crashlytics API needs a quota project when called with user credentials, but only
generateAlertPolicysentx-goog-user-project(from #11382). So every other Crashlytics call failed with a 403 that said "requires a quota project". That includes the MCP tools and things likegetIssueandlistEvents.This adds the header, set to the project number from the app ID, to the rest of the Crashlytics requests in
issues.ts,events.ts,notes.tsandreports.ts.GOOGLE_CLOUD_QUOTA_PROJECTstill wins if it's set, sinceapiv2applies it afterwards.Scenarios Tested
New
src/crashlytics/quotaProject.spec.tsstubsCRASHLYTICS_API_CLIENT.requestand checks the header on all nine calls. It fails onmainand passes with this change. All Crashlytics and MCP specs pass.I checked the request options directly because the test
nockhelper'smatchHeaderis a no-op (src/test/helpers/nock.ts), so header checks written with it, including the one inalerts.spec.ts, pass no matter what's sent. Happy to open a separate issue about that.Sample Commands
With
firebase loginand noGOOGLE_CLOUD_QUOTA_PROJECT,crashlytics_get_issueand the other Crashlytics MCP tools no longer return 403.I used an AI coding assistant for this and reviewed it myself.
🤖 Generated with Claude Code