-
Notifications
You must be signed in to change notification settings - Fork 1k
Jules unit tests for apphosting MCP tools #9030
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 @joehan, 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 PR introduces comprehensive unit tests for the apphosting tools within the mcp directory, specifically for the fetch_logs and list_backends functionalities. These tests ensure the reliability and correctness of these tools by covering various operational scenarios and error conditions.
Highlights
- New unit tests for fetch_logs tool: Verifies log fetching for both service and build logs, including cases where service names or build IDs cannot be determined.
- New unit tests for list_backends tool: Confirms correct listing of backends, handling scenarios with no backends, and ensuring proper retrieval of associated traffic and domain information.
- Comprehensive test coverage: Tests include successful operations, edge cases, and expected error handling using chai for assertions and sinon for mocking dependencies.
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. 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
-
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. ↩
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 unit tests for the fetch_logs
and list_backends
App Hosting MCP tools. The tests are comprehensive and cover various scenarios, including success cases, failure cases, and edge cases. The test structure is clear and uses sinon
for mocking dependencies effectively.
I've identified a couple of areas in fetch_logs.spec.ts
where test setup code is duplicated across multiple tests within the same context. I've suggested refactoring this repeated setup into beforeEach
blocks to improve maintainability and reduce redundancy. The tests for list_backends.spec.ts
are well-written with no major issues.
context("when buildLogs is false", () => { | ||
it("should fetch service logs successfully", async () => { | ||
const backend = { | ||
name: `projects/${projectId}/locations/${location}/backends/${backendId}`, | ||
managedResources: [ | ||
{ | ||
runService: { | ||
service: `projects/${projectId}/locations/${location}/services/service-id`, | ||
}, | ||
}, | ||
], | ||
}; | ||
const traffic = { | ||
name: `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`, | ||
}; | ||
const logs = ["log entry 1", "log entry 2"]; | ||
|
||
getBackendStub.resolves(backend); | ||
getTrafficStub.resolves(traffic); | ||
fetchServiceLogsStub.resolves(logs); | ||
|
||
const result = await fetch_logs.fn({ backendId, location }, { projectId } as any); | ||
|
||
expect(getBackendStub).to.be.calledWith(projectId, location, backendId); | ||
expect(getTrafficStub).to.be.calledWith(projectId, location, backendId); | ||
expect(fetchServiceLogsStub).to.be.calledWith(projectId, "service-id"); | ||
expect(result).to.deep.equal(toContent(logs)); | ||
}); | ||
|
||
it("should throw FirebaseError if service name cannot be determined", async () => { | ||
const backend = { | ||
name: `projects/${projectId}/locations/${location}/backends/${backendId}`, | ||
managedResources: [], | ||
}; | ||
const traffic = { | ||
name: `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`, | ||
}; | ||
|
||
getBackendStub.resolves(backend); | ||
getTrafficStub.resolves(traffic); | ||
|
||
await expect(fetch_logs.fn({ backendId, location }, { projectId } as any)).to.be.rejectedWith( | ||
FirebaseError, | ||
"Unable to get service name from managedResources.", | ||
); | ||
}); | ||
}); |
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 test setup for traffic
and getTrafficStub
is repeated in both tests within this context. You can move this common setup into a beforeEach
block to reduce duplication and improve maintainability.
context("when buildLogs is false", () => {
const traffic = {
name: `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`,
};
beforeEach(() => {
getTrafficStub.resolves(traffic);
});
it("should fetch service logs successfully", async () => {
const backend = {
name: `projects/${projectId}/locations/${location}/backends/${backendId}`,
managedResources: [
{
runService: {
service: `projects/${projectId}/locations/${location}/services/service-id`,
},
},
],
};
const logs = ["log entry 1", "log entry 2"];
getBackendStub.resolves(backend);
fetchServiceLogsStub.resolves(logs);
const result = await fetch_logs.fn({ backendId, location }, { projectId } as any);
expect(getBackendStub).to.be.calledWith(projectId, location, backendId);
expect(getTrafficStub).to.be.calledWith(projectId, location, backendId);
expect(fetchServiceLogsStub).to.be.calledWith(projectId, "service-id");
expect(result).to.deep.equal(toContent(logs));
});
it("should throw FirebaseError if service name cannot be determined", async () => {
const backend = {
name: `projects/${projectId}/locations/${location}/backends/${backendId}`,
managedResources: [],
};
getBackendStub.resolves(backend);
await expect(fetch_logs.fn({ backendId, location }, { projectId } as any)).to.be.rejectedWith(
FirebaseError,
"Unable to get service name from managedResources.",
);
});
});
context("when buildLogs is true", () => { | ||
const buildLogsUri = `https://console.cloud.google.com/build/region=${location}/12345`; | ||
const build = { createTime: new Date().toISOString(), buildLogsUri }; | ||
const builds = { builds: [build] }; | ||
|
||
it("should fetch build logs successfully", async () => { | ||
const backend = { name: `projects/${projectId}/locations/${location}/backends/${backendId}` }; | ||
const traffic = { | ||
name: `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`, | ||
}; | ||
const logEntries = [{ textPayload: "build log 1" }]; | ||
|
||
getBackendStub.resolves(backend); | ||
getTrafficStub.resolves(traffic); | ||
listBuildsStub.resolves(builds); | ||
listEntriesStub.resolves(logEntries); | ||
|
||
const result = await fetch_logs.fn({ buildLogs: true, backendId, location }, { | ||
projectId, | ||
} as any); | ||
|
||
expect(listBuildsStub).to.be.calledWith(projectId, location, backendId); | ||
expect(listEntriesStub).to.be.calledOnce; | ||
expect(listEntriesStub.args[0][1]).to.include('resource.labels.build_id="12345"'); | ||
expect(result).to.deep.equal(toContent(logEntries)); | ||
}); | ||
|
||
it("should return 'No logs found.' if no build logs are available", async () => { | ||
const backend = { name: `projects/${projectId}/locations/${location}/backends/${backendId}` }; | ||
const traffic = { | ||
name: `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`, | ||
}; | ||
|
||
getBackendStub.resolves(backend); | ||
getTrafficStub.resolves(traffic); | ||
listBuildsStub.resolves(builds); | ||
listEntriesStub.resolves([]); | ||
|
||
const result = await fetch_logs.fn({ buildLogs: true, backendId, location }, { | ||
projectId, | ||
} as any); | ||
expect(result).to.deep.equal(toContent("No logs found.")); | ||
}); | ||
|
||
it("should throw FirebaseError if build ID cannot be determined from buildLogsUri", async () => { | ||
const buildWithInvalidUri = { | ||
createTime: new Date().toISOString(), | ||
buildLogsUri: "invalid-uri", | ||
}; | ||
const buildsWithInvalidUri = { builds: [buildWithInvalidUri] }; | ||
const backend = { name: `projects/${projectId}/locations/${location}/backends/${backendId}` }; | ||
const traffic = { | ||
name: `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`, | ||
}; | ||
|
||
getBackendStub.resolves(backend); | ||
getTrafficStub.resolves(traffic); | ||
listBuildsStub.resolves(buildsWithInvalidUri); | ||
|
||
await expect( | ||
fetch_logs.fn({ buildLogs: true, backendId, location }, { projectId } as any), | ||
).to.be.rejectedWith(FirebaseError, "Unable to determine the build ID."); | ||
}); | ||
}); |
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 setup for backend
, traffic
, and their corresponding stubs (getBackendStub
, getTrafficStub
) is repeated across all tests in this context. To improve code clarity and reduce duplication, you can extract this common setup into a beforeEach
block within the context.
context("when buildLogs is true", () => {
const buildLogsUri = `https://console.cloud.google.com/build/region=${location}/12345`;
const build = { createTime: new Date().toISOString(), buildLogsUri };
const builds = { builds: [build] };
const backend = { name: `projects/${projectId}/locations/${location}/backends/${backendId}` };
const traffic = {
name: `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`,
};
beforeEach(() => {
getBackendStub.resolves(backend);
getTrafficStub.resolves(traffic);
});
it("should fetch build logs successfully", async () => {
const logEntries = [{ textPayload: "build log 1" }];
listBuildsStub.resolves(builds);
listEntriesStub.resolves(logEntries);
const result = await fetch_logs.fn({ buildLogs: true, backendId, location }, {
projectId,
} as any);
expect(listBuildsStub).to.be.calledWith(projectId, location, backendId);
expect(listEntriesStub).to.be.calledOnce;
expect(listEntriesStub.args[0][1]).to.include('resource.labels.build_id="12345"');
expect(result).to.deep.equal(toContent(logEntries));
});
it("should return 'No logs found.' if no build logs are available", async () => {
listBuildsStub.resolves(builds);
listEntriesStub.resolves([]);
const result = await fetch_logs.fn({ buildLogs: true, backendId, location }, {
projectId,
} as any);
expect(result).to.deep.equal(toContent("No logs found."));
});
it("should throw FirebaseError if build ID cannot be determined from buildLogsUri", async () => {
const buildWithInvalidUri = {
createTime: new Date().toISOString(),
buildLogsUri: "invalid-uri",
};
const buildsWithInvalidUri = { builds: [buildWithInvalidUri] };
listBuildsStub.resolves(buildsWithInvalidUri);
await expect(
fetch_logs.fn({ buildLogs: true, backendId, location }, { projectId } as any),
).to.be.rejectedWith(FirebaseError, "Unable to determine the build ID.");
});
});
Description
From Jules - unit tests for the app_hosting tools.