Skip to content
Merged
Show file tree
Hide file tree
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 Sep 19, 2025
74f3687
Firebase MCP init tool schema change to support provisioning
TrCaM Sep 22, 2025
6c2b93a
Add methods to detect existing local apps from directories
TrCaM Sep 22, 2025
31e6327
Add methods to ensure local file locations for app provisioning
TrCaM Sep 22, 2025
b68727f
Wire up provisioning logic with fake API service - Verify logic first…
TrCaM Sep 22, 2025
1c2cc10
Archive mock provisioning service for future reference
TrCaM Sep 24, 2025
d411761
Complete first working version of revamped firebase init MCP tool
TrCaM Sep 24, 2025
a1cd048
Merge master into feature branch
TrCaM Sep 24, 2025
647eb87
Fix lint/formating - Add unit test for new firebase init tool
TrCaM Sep 24, 2025
3309d71
Fix lint/formating - Add unit test for new firebase init tool
TrCaM Sep 24, 2025
0a0af59
Minor pr fixes
joehan Sep 24, 2025
193d196
Adding missing files
joehan Sep 24, 2025
5f3a6b9
Merge branch 'master' into jh-provisioning
joehan Sep 24, 2025
e3afdee
Merge branch 'master' into jh-provisioning
joehan Sep 24, 2025
9814ef9
Merge branch 'master' into jh-provisioning
joehan Sep 24, 2025
6bedcaf
Reduce provisioning integration scope for only AI Logic
TrCaM Sep 25, 2025
265d339
Complete orchestration API provisioning to AI Logic feature (Both CLI…
TrCaM Sep 25, 2025
8b0ff79
Merge remote-tracking branch 'origin/master' into caot/mcp/ailogic
TrCaM Sep 25, 2025
d032ff7
Fix lint and unit tests
TrCaM Sep 25, 2025
82d5443
Address Gemini code assist comments
TrCaM Sep 25, 2025
c3b33c6
Simplify ailogic init feature to only use existing project and app
TrCaM Sep 27, 2025
a7de790
Merge remote-tracking branch 'origin/master' into caot-mcp-ailogic
TrCaM Sep 27, 2025
ade68ce
Fix linting
TrCaM Sep 27, 2025
f1906de
Addresses comments
TrCaM Sep 30, 2025
671cec2
Merge remote-tracking branch 'origin/master' into caot-mcp-ailogic
TrCaM Sep 30, 2025
9dc2299
Check projectId is non-empty for ailogic feature (MCP tool)
TrCaM Sep 30, 2025
c8c02ae
Merge branch 'master' into caot-mcp-ailogic
joehan Oct 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
});
}

choices.push({
value: "ailogic",
name: "AI Logic: Set up Firebase AI Logic with app provisioning",
checked: false,
});

choices.push({
value: "aitools",
name: "AI Tools: Configure AI coding assistants to work with your Firebase project",
Expand Down Expand Up @@ -194,7 +200,7 @@

const setup: Setup = {
config: config.src,
rcfile: config.readProjectFile(".firebaserc", {

Check warning on line 203 in src/commands/init.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
json: true,
fallback: {},
}),
Expand Down
300 changes: 300 additions & 0 deletions src/init/features/ailogic/index.spec.ts
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.",
);
});
});
});
Loading
Loading