Conversation
Summary of ChangesHello, 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 introduces support for automatically configuring a Dart Multi-Client Protocol (MCP) server for Flutter projects during the migration process. This enhancement aims to simplify the setup for Flutter developers by ensuring that the appropriate Dart MCP server is added to the Antigravity configuration when a Flutter application is detected and Dart is available on the system. It also provides helpful feedback if Dart is not found, guiding users to install Flutter. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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 by creating a comment using either
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. 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
|
There was a problem hiding this comment.
Code Review
This pull request adds support for configuring the Dart MCP server for Flutter projects. The implementation looks good, but I have a few suggestions for improvement.
In migrate.ts, I've suggested a refactoring to reduce nesting, in line with the repository's style guide.
In migrate.spec.ts, I've found a test that will fail due to an incorrect assertion on a warning message and provided a fix. I've also pointed out significant code duplication in the new tests and suggested a refactoring to improve maintainability.
src/firebase_studio/migrate.spec.ts
Outdated
| expect(logWarningStub.calledWith("Dart is not available. You should install Flutter.")).to.be | ||
| .true; |
There was a problem hiding this comment.
The warning message asserted in this test does not match the one in the implementation. This will cause the test to fail.
The implementation in migrate.ts logs:
"Couldn't find Dart/Flutter on PATH. Install Flutter by following the instruction at https://docs.flutter.dev/install."
Please update the expectation to match the actual warning message.
expect(logWarningStub.calledWith("Couldn't find Dart/Flutter on PATH. Install Flutter by following the instruction at https://docs.flutter.dev/install.")).to.be.true;| if (appType === "FLUTTER") { | ||
| if (utils.commandExistsSync("dart")) { | ||
| if (!mcpConfig.mcpServers["dart"]) { | ||
| mcpConfig.mcpServers["dart"] = { | ||
| command: "dart", | ||
| args: ["mcp-server"], | ||
| }; | ||
| updated = true; | ||
| logger.info(`✅ Configured Dart MCP server in ${mcpConfigPath}`); | ||
| } else { | ||
| logger.info("ℹ️ Dart MCP server already configured in Antigravity, skipping."); | ||
| } | ||
| } else { | ||
| utils.logWarning( | ||
| "Couldn't find Dart/Flutter on PATH. Install Flutter by following the instruction at https://docs.flutter.dev/install.", | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
The nesting for configuring the Dart MCP server is a bit deep. According to the repository's style guide, we should aim to reduce nesting.
You could refactor this logic into a helper function to improve readability and reduce nesting. For example:
function configureDartMcp(mcpConfig: McpConfig, mcpConfigPath: string): boolean {
if (!utils.commandExistsSync("dart")) {
utils.logWarning(
"Couldn't find Dart/Flutter on PATH. Install Flutter by following the instruction at https://docs.flutter.dev/install.",
);
return false;
}
if (mcpConfig.mcpServers["dart"]) {
logger.info("ℹ️ Dart MCP server already configured in Antigravity, skipping.");
return false;
}
mcpConfig.mcpServers["dart"] = {
command: "dart",
args: ["mcp-server"],
};
logger.info(`✅ Configured Dart MCP server in ${mcpConfigPath}`);
return true;
}Then you can call it like this:
if (appType === "FLUTTER") {
if (configureDartMcp(mcpConfig, mcpConfigPath)) {
updated = true;
}
}This encapsulates the branching logic as suggested in the style guide.
References
- The style guide recommends reducing code nesting and considering helper functions to encapsulate branching logic for better maintainability. (link)
| it("should configure Dart MCP server for Flutter apps if dart is available", async () => { | ||
| accessStub.withArgs(sinon.match("pubspec.yaml")).resolves(); | ||
| commandStub.withArgs("dart").returns(true); | ||
|
|
||
| readFileStub.callsFake(async (p: any) => { | ||
| const pStr = p.toString(); | ||
| if (pStr.endsWith("metadata.json")) | ||
| return JSON.stringify({ projectId: "test-project", appName: "Test App" }); | ||
| if (pStr.endsWith("readme_template.md")) | ||
| return "# ${appName}\nRun ${startCommand} at ${localUrl}"; | ||
| if (pStr.endsWith("system_instructions_template.md")) return "Project: ${appName}"; | ||
| if (pStr.endsWith("startup_workflow.md")) return "Step 1: Build"; | ||
| if (pStr.endsWith(".firebaserc")) | ||
| return JSON.stringify({ projects: { default: "test-project" } }); | ||
| if (pStr.endsWith("blueprint.md")) return "# **App Name**: Test App"; | ||
| if (pStr.endsWith("package.json")) return "{}"; | ||
| if (pStr.endsWith("mcp_config.json")) | ||
| throw Object.assign(new Error("File not found"), { code: "ENOENT" }); | ||
| throw new Error(`Unexpected readFile: ${pStr}`); | ||
| }); | ||
|
|
||
| await migrate(testRoot); | ||
|
|
||
| const mcpConfigDir = path.join(require("os").homedir(), ".gemini", "antigravity"); | ||
| const mcpConfigPath = path.join(mcpConfigDir, "mcp_config.json"); | ||
|
|
||
| expect(writeFileStub.calledWith(mcpConfigPath, sinon.match(/"dart":/))).to.be.true; | ||
| }); | ||
|
|
||
| it("should NOT configure Dart MCP server for Flutter apps if dart is NOT available, and log warning", async () => { | ||
| accessStub.withArgs(sinon.match("pubspec.yaml")).resolves(); | ||
| commandStub.withArgs("dart").returns(false); | ||
|
|
||
| const logWarningStub = sandbox.stub(utils, "logWarning"); | ||
|
|
||
| readFileStub.callsFake(async (p: any) => { | ||
| const pStr = p.toString(); | ||
| if (pStr.endsWith("metadata.json")) | ||
| return JSON.stringify({ projectId: "test-project", appName: "Test App" }); | ||
| if (pStr.endsWith("readme_template.md")) | ||
| return "# ${appName}\nRun ${startCommand} at ${localUrl}"; | ||
| if (pStr.endsWith("system_instructions_template.md")) return "Project: ${appName}"; | ||
| if (pStr.endsWith("startup_workflow.md")) return "Step 1: Build"; | ||
| if (pStr.endsWith(".firebaserc")) | ||
| return JSON.stringify({ projects: { default: "test-project" } }); | ||
| if (pStr.endsWith("blueprint.md")) return "# **App Name**: Test App"; | ||
| if (pStr.endsWith("package.json")) return "{}"; | ||
| if (pStr.endsWith("mcp_config.json")) | ||
| throw Object.assign(new Error("File not found"), { code: "ENOENT" }); | ||
| throw new Error(`Unexpected readFile: ${pStr}`); | ||
| }); | ||
|
|
||
| await migrate(testRoot); | ||
|
|
||
| const mcpConfigDir = path.join(require("os").homedir(), ".gemini", "antigravity"); | ||
| const mcpConfigPath = path.join(mcpConfigDir, "mcp_config.json"); | ||
|
|
||
| expect(writeFileStub.calledWith(mcpConfigPath, sinon.match(/"dart"/))).to.be.false; | ||
| expect(logWarningStub.calledWith("Dart is not available. You should install Flutter.")).to.be | ||
| .true; | ||
| }); | ||
|
|
||
| it("should NOT configure Dart MCP server if app is not Flutter", async () => { | ||
| accessStub.withArgs(sinon.match("pubspec.yaml")).rejects({ code: "ENOENT" }); | ||
| commandStub.withArgs("dart").returns(true); | ||
|
|
||
| readFileStub.callsFake(async (p: any) => { | ||
| const pStr = p.toString(); | ||
| if (pStr.endsWith("metadata.json")) | ||
| return JSON.stringify({ projectId: "test-project", appName: "Test App" }); | ||
| if (pStr.endsWith("readme_template.md")) | ||
| return "# ${appName}\nRun ${startCommand} at ${localUrl}"; | ||
| if (pStr.endsWith("system_instructions_template.md")) return "Project: ${appName}"; | ||
| if (pStr.endsWith("startup_workflow.md")) return "Step 1: Build"; | ||
| if (pStr.endsWith(".firebaserc")) | ||
| return JSON.stringify({ projects: { default: "test-project" } }); | ||
| if (pStr.endsWith("blueprint.md")) return "# **App Name**: Test App"; | ||
| if (pStr.endsWith("package.json")) return "{}"; | ||
| if (pStr.endsWith("mcp_config.json")) | ||
| throw Object.assign(new Error("File not found"), { code: "ENOENT" }); | ||
| throw new Error(`Unexpected readFile: ${pStr}`); | ||
| }); | ||
|
|
||
| await migrate(testRoot); | ||
|
|
||
| const mcpConfigDir = path.join(require("os").homedir(), ".gemini", "antigravity"); | ||
| const mcpConfigPath = path.join(mcpConfigDir, "mcp_config.json"); | ||
|
|
||
| expect(writeFileStub.calledWith(mcpConfigPath, sinon.match(/"dart"/))).to.be.false; | ||
| }); |
There was a problem hiding this comment.
There's a significant amount of duplicated code across the three new tests for Dart MCP server configuration. Specifically, the readFileStub.callsFake implementation is nearly identical in all three tests.
To improve maintainability and reduce redundancy, consider extracting this common setup into a beforeEach block within a new nested describe block for these related tests. This will make the tests cleaner and easier to manage.
For example:
describe("Dart MCP server configuration", () => {
beforeEach(() => {
readFileStub.callsFake(async (p: any) => {
const pStr = p.toString();
if (pStr.endsWith("metadata.json"))
return JSON.stringify({ projectId: "test-project", appName: "Test App" });
if (pStr.endsWith("readme_template.md"))
return "# ${appName}\nRun ${startCommand} at ${localUrl}";
if (pStr.endsWith("system_instructions_template.md")) return "Project: ${appName}";
if (pStr.endsWith("startup_workflow.md")) return "Step 1: Build";
if (pStr.endsWith(".firebaserc"))
return JSON.stringify({ projects: { default: "test-project" } });
if (pStr.endsWith("blueprint.md")) return "# **App Name**: Test App";
if (pStr.endsWith("package.json")) return "{}";
if (pStr.endsWith("mcp_config.json"))
throw Object.assign(new Error("File not found"), { code: "ENOENT" });
throw new Error(`Unexpected readFile: ${pStr}`);
});
});
it("should configure Dart MCP server for Flutter apps if dart is available", ...);
it("should NOT configure Dart MCP server for Flutter apps if dart is NOT available, and log warning", ...);
it("should NOT configure Dart MCP server if app is not Flutter", ...);
});
Description
b/492452409