-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(mcp): AI Logic Init Feature (CLI Command and MCP Firebase Init Tool) #9185
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
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2b87a86
Add Firebase App provisioning API integration
TrCaM 74f3687
Firebase MCP init tool schema change to support provisioning
TrCaM 6c2b93a
Add methods to detect existing local apps from directories
TrCaM 31e6327
Add methods to ensure local file locations for app provisioning
TrCaM b68727f
Wire up provisioning logic with fake API service - Verify logic first…
TrCaM 1c2cc10
Archive mock provisioning service for future reference
TrCaM d411761
Complete first working version of revamped firebase init MCP tool
TrCaM a1cd048
Merge master into feature branch
TrCaM 647eb87
Fix lint/formating - Add unit test for new firebase init tool
TrCaM 3309d71
Fix lint/formating - Add unit test for new firebase init tool
TrCaM 0a0af59
Minor pr fixes
joehan 193d196
Adding missing files
joehan 5f3a6b9
Merge branch 'master' into jh-provisioning
joehan e3afdee
Merge branch 'master' into jh-provisioning
joehan 9814ef9
Merge branch 'master' into jh-provisioning
joehan 6bedcaf
Reduce provisioning integration scope for only AI Logic
TrCaM 265d339
Complete orchestration API provisioning to AI Logic feature (Both CLI…
TrCaM 8b0ff79
Merge remote-tracking branch 'origin/master' into caot/mcp/ailogic
TrCaM d032ff7
Fix lint and unit tests
TrCaM 82d5443
Address Gemini code assist comments
TrCaM c3b33c6
Simplify ailogic init feature to only use existing project and app
TrCaM a7de790
Merge remote-tracking branch 'origin/master' into caot-mcp-ailogic
TrCaM ade68ce
Fix linting
TrCaM f1906de
Addresses comments
TrCaM 671cec2
Merge remote-tracking branch 'origin/master' into caot-mcp-ailogic
TrCaM 9dc2299
Check projectId is non-empty for ailogic feature (MCP tool)
TrCaM c8c02ae
Merge branch 'master' into caot-mcp-ailogic
joehan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,300 @@ | ||
import * as prompt from "../../../prompt"; | ||
import { expect } from "chai"; | ||
import * as sinon from "sinon"; | ||
import * as init from "./index"; | ||
import * as utils from "./utils"; | ||
import * as projects from "../../../management/projects"; | ||
import { Setup } from "../.."; | ||
|
||
describe("init ailogic", () => { | ||
let sandbox: sinon.SinonSandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe("askQuestions", () => { | ||
let inputStub: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
inputStub = sandbox.stub(prompt, "input"); | ||
}); | ||
|
||
it("should populate ailogic featureInfo with valid app ID", async () => { | ||
inputStub.resolves("1:123456789:android:abcdef123456"); // Valid Android app ID | ||
const mockSetup = {} as Setup; | ||
await init.askQuestions(mockSetup); | ||
|
||
expect(mockSetup.featureInfo).to.have.property("ailogic"); | ||
expect(mockSetup.featureInfo?.ailogic).to.deep.equal({ | ||
appId: "1:123456789:android:abcdef123456", | ||
}); | ||
}); | ||
|
||
it("should validate app ID format and reject invalid format", async () => { | ||
// Mock the input function to simulate user input and validation | ||
let validationFunction: ((input: string) => string | boolean) | undefined; | ||
inputStub.callsFake(async (options: { validate?: (input: string) => string | boolean }) => { | ||
validationFunction = options.validate; | ||
return "1:123456789:web:abcdef123456"; // Return valid app ID after validation | ||
}); | ||
|
||
const mockSetup = {} as Setup; | ||
await init.askQuestions(mockSetup); | ||
|
||
// Test the validation function directly | ||
if (validationFunction) { | ||
expect(validationFunction("")).to.equal("Please enter a Firebase app ID"); | ||
expect(validationFunction("invalid-format")).to.equal( | ||
"Invalid app ID format. Expected: 1:PROJECT_NUMBER:PLATFORM:APP_ID (e.g., 1:123456789:web:abcdef123456)", | ||
); | ||
expect(validationFunction("1:123456789:flutter:abcdef")).to.equal( | ||
"Invalid app ID format. Expected: 1:PROJECT_NUMBER:PLATFORM:APP_ID (e.g., 1:123456789:web:abcdef123456)", | ||
); | ||
expect(validationFunction("1:123456789:web:abcdef123456")).to.equal(true); | ||
} | ||
}); | ||
}); | ||
|
||
describe("actuate", () => { | ||
let setup: Setup; | ||
let parseAppIdStub: sinon.SinonStub; | ||
let getFirebaseProjectStub: sinon.SinonStub; | ||
let validateProjectNumberMatchStub: sinon.SinonStub; | ||
let validateAppExistsStub: sinon.SinonStub; | ||
let buildProvisionOptionsStub: sinon.SinonStub; | ||
let provisionAiLogicAppStub: sinon.SinonStub; | ||
let getConfigFileNameStub: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
setup = { | ||
config: {}, | ||
rcfile: { projects: {}, targets: {}, etags: {} }, | ||
featureInfo: { | ||
ailogic: { | ||
appId: "1:123456789:android:abcdef123456", | ||
}, | ||
}, | ||
projectId: "test-project", | ||
instructions: [], | ||
} as Setup; | ||
|
||
// Stub all utility functions | ||
parseAppIdStub = sandbox.stub(utils, "parseAppId"); | ||
getFirebaseProjectStub = sandbox.stub(projects, "getFirebaseProject"); | ||
validateProjectNumberMatchStub = sandbox.stub(utils, "validateProjectNumberMatch"); | ||
validateAppExistsStub = sandbox.stub(utils, "validateAppExists"); | ||
buildProvisionOptionsStub = sandbox.stub(utils, "buildProvisionOptions"); | ||
provisionAiLogicAppStub = sandbox.stub(utils, "provisionAiLogicApp"); | ||
getConfigFileNameStub = sandbox.stub(utils, "getConfigFileName"); | ||
}); | ||
|
||
it("should return early if no ailogic feature info", async () => { | ||
setup.featureInfo = {}; | ||
|
||
await init.actuate(setup); | ||
|
||
// No stubs should be called | ||
sinon.assert.notCalled(parseAppIdStub); | ||
sinon.assert.notCalled(provisionAiLogicAppStub); | ||
}); | ||
|
||
it("should validate and provision existing app successfully", async () => { | ||
const mockAppInfo = { | ||
projectNumber: "123456789", | ||
appId: "1:123456789:android:abcdef123456", | ||
platform: "android" as const, | ||
}; | ||
const mockProjectInfo = { | ||
projectNumber: "123456789", | ||
projectId: "test-project", | ||
name: "projects/test-project", | ||
displayName: "Test Project", | ||
}; | ||
const mockConfigContent = '{"config": "content"}'; | ||
const base64Config = Buffer.from(mockConfigContent).toString("base64"); | ||
|
||
parseAppIdStub.returns(mockAppInfo); | ||
getFirebaseProjectStub.resolves(mockProjectInfo); | ||
validateAppExistsStub.resolves(); | ||
buildProvisionOptionsStub.returns({ mock: "options" }); | ||
provisionAiLogicAppStub.resolves({ configData: base64Config }); | ||
getConfigFileNameStub.returns("google-services.json"); | ||
|
||
await init.actuate(setup); | ||
|
||
sinon.assert.calledWith(parseAppIdStub, "1:123456789:android:abcdef123456"); | ||
sinon.assert.calledWith(getFirebaseProjectStub, "test-project"); | ||
sinon.assert.calledWith(validateProjectNumberMatchStub, mockAppInfo, mockProjectInfo); | ||
sinon.assert.calledWith(validateAppExistsStub, mockAppInfo); | ||
sinon.assert.calledWith( | ||
buildProvisionOptionsStub, | ||
"test-project", | ||
"android", | ||
"1:123456789:android:abcdef123456", | ||
); | ||
|
||
expect(setup.instructions).to.include( | ||
"Firebase AI Logic has been enabled for existing android app: 1:123456789:android:abcdef123456", | ||
); | ||
expect(setup.instructions).to.include( | ||
"Save the following content as google-services.json in your app's root directory:", | ||
); | ||
expect(setup.instructions).to.include(mockConfigContent); | ||
}); | ||
|
||
it("should throw error if no project ID found", async () => { | ||
setup.projectId = undefined; | ||
|
||
await expect(init.actuate(setup)).to.be.rejectedWith( | ||
"AI Logic setup failed: No project ID found. Please ensure you are in a Firebase project directory or specify a project.", | ||
); | ||
|
||
sinon.assert.calledOnce(parseAppIdStub); | ||
sinon.assert.notCalled(getFirebaseProjectStub); | ||
}); | ||
|
||
it("should handle project number mismatch error", async () => { | ||
const mockAppInfo = { | ||
projectNumber: "123456789", | ||
appId: "1:123456789:android:abcdef123456", | ||
platform: "android" as const, | ||
}; | ||
const mockProjectInfo = { | ||
projectNumber: "987654321", | ||
projectId: "test-project", | ||
name: "projects/test-project", | ||
displayName: "Test Project", | ||
}; | ||
|
||
parseAppIdStub.returns(mockAppInfo); | ||
getFirebaseProjectStub.resolves(mockProjectInfo); | ||
validateProjectNumberMatchStub.throws(new Error("Project number mismatch")); | ||
|
||
await expect(init.actuate(setup)).to.be.rejectedWith( | ||
"AI Logic setup failed: Project number mismatch", | ||
); | ||
|
||
sinon.assert.calledWith(validateProjectNumberMatchStub, mockAppInfo, mockProjectInfo); | ||
sinon.assert.notCalled(validateAppExistsStub); | ||
}); | ||
|
||
it("should handle app validation error", async () => { | ||
const mockAppInfo = { | ||
projectNumber: "123456789", | ||
appId: "1:123456789:android:abcdef123456", | ||
platform: "android" as const, | ||
}; | ||
const mockProjectInfo = { | ||
projectNumber: "123456789", | ||
projectId: "test-project", | ||
name: "projects/test-project", | ||
displayName: "Test Project", | ||
}; | ||
|
||
parseAppIdStub.returns(mockAppInfo); | ||
getFirebaseProjectStub.resolves(mockProjectInfo); | ||
validateAppExistsStub.throws(new Error("App does not exist")); | ||
|
||
await expect(init.actuate(setup)).to.be.rejectedWith( | ||
"AI Logic setup failed: App does not exist", | ||
); | ||
|
||
sinon.assert.calledWith(validateAppExistsStub, mockAppInfo); | ||
sinon.assert.notCalled(buildProvisionOptionsStub); | ||
}); | ||
|
||
it("should handle provisioning errors gracefully", async () => { | ||
const mockAppInfo = { | ||
projectNumber: "123456789", | ||
appId: "1:123456789:android:abcdef123456", | ||
platform: "android" as const, | ||
}; | ||
const mockProjectInfo = { | ||
projectNumber: "123456789", | ||
projectId: "test-project", | ||
name: "projects/test-project", | ||
displayName: "Test Project", | ||
}; | ||
|
||
parseAppIdStub.returns(mockAppInfo); | ||
getFirebaseProjectStub.resolves(mockProjectInfo); | ||
validateAppExistsStub.resolves(); | ||
buildProvisionOptionsStub.returns({ mock: "options" }); | ||
provisionAiLogicAppStub.throws(new Error("Provisioning API failed")); | ||
|
||
await expect(init.actuate(setup)).to.be.rejectedWith( | ||
"AI Logic setup failed: Provisioning API failed", | ||
); | ||
}); | ||
|
||
it("should include config file content in instructions for iOS", async () => { | ||
if (setup.featureInfo?.ailogic) { | ||
setup.featureInfo.ailogic.appId = "1:123456789:ios:abcdef123456"; | ||
} | ||
const mockAppInfo = { | ||
projectNumber: "123456789", | ||
appId: "1:123456789:ios:abcdef123456", | ||
platform: "ios" as const, | ||
}; | ||
const mockProjectInfo = { | ||
projectNumber: "123456789", | ||
projectId: "test-project", | ||
name: "projects/test-project", | ||
displayName: "Test Project", | ||
}; | ||
const mockConfigContent = '<?xml version="1.0" encoding="UTF-8"?>'; | ||
const base64Config = Buffer.from(mockConfigContent).toString("base64"); | ||
|
||
parseAppIdStub.returns(mockAppInfo); | ||
getFirebaseProjectStub.resolves(mockProjectInfo); | ||
validateAppExistsStub.resolves(); | ||
buildProvisionOptionsStub.returns({ mock: "options" }); | ||
provisionAiLogicAppStub.resolves({ configData: base64Config }); | ||
getConfigFileNameStub.returns("GoogleService-Info.plist"); | ||
|
||
await init.actuate(setup); | ||
|
||
expect(setup.instructions).to.include( | ||
"Firebase AI Logic has been enabled for existing ios app: 1:123456789:ios:abcdef123456", | ||
); | ||
expect(setup.instructions).to.include( | ||
"Save the following content as GoogleService-Info.plist in your app's root directory:", | ||
); | ||
expect(setup.instructions).to.include(mockConfigContent); | ||
}); | ||
|
||
it("should include platform placement guidance in instructions", async () => { | ||
const mockAppInfo = { | ||
projectNumber: "123456789", | ||
appId: "1:123456789:android:abcdef123456", | ||
platform: "android" as const, | ||
}; | ||
const mockProjectInfo = { | ||
projectNumber: "123456789", | ||
projectId: "test-project", | ||
name: "projects/test-project", | ||
displayName: "Test Project", | ||
}; | ||
const mockConfigContent = '{"config": "content"}'; | ||
const base64Config = Buffer.from(mockConfigContent).toString("base64"); | ||
|
||
parseAppIdStub.returns(mockAppInfo); | ||
getFirebaseProjectStub.resolves(mockProjectInfo); | ||
validateAppExistsStub.resolves(); | ||
buildProvisionOptionsStub.returns({ mock: "options" }); | ||
provisionAiLogicAppStub.resolves({ configData: base64Config }); | ||
getConfigFileNameStub.returns("google-services.json"); | ||
|
||
await init.actuate(setup); | ||
|
||
expect(setup.instructions).to.include( | ||
"Place this config file in the appropriate location for your platform.", | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.