Conversation
Added comprehensive unit tests for `src/providers/` to improve code coverage and reliability. - Added `src/providers/session-bridge.test.ts` covering `resolveSessionKeyFromRoom` and `createSessionKeyProvider`. - Added `src/providers/workspace.test.ts` covering `filterBootstrapFilesForSession`. - Added `src/providers/workspace-provider.test.ts` covering `createWorkspaceProvider` and internal helpers. - Mocked `@elizaos/core` and internal file system operations to ensure isolated and deterministic tests.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @Dexploarer, 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 significantly enhances the test coverage for core provider modules by introducing dedicated unit tests. The new tests ensure the reliability and correctness of session key resolution, workspace context generation, and bootstrap file filtering, contributing to a more robust and maintainable codebase. 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 a good set of unit tests for the providers in src/providers/. The tests cover the main functionalities of session-bridge, workspace, and workspace-provider. The use of mocks for external dependencies is well-implemented.
I've found a few areas for improvement, mainly concerning the correctness of mock data objects in workspace-provider.test.ts. Some test objects do not conform to their TypeScript types, which can make tests brittle. I've also suggested an additional test case in session-bridge.test.ts to improve coverage.
Overall, this is a valuable addition that increases the project's test coverage and reliability.
| describe("buildCodingAgentSummary", () => { | ||
| it("builds summary from context", () => { | ||
| const ctx: CodingAgentContext = { | ||
| sessionId: "session-1", | ||
| taskDescription: "Do something", | ||
| workingDirectory: "/work", | ||
| connector: { type: "local", available: true }, | ||
| interactionMode: "auto", | ||
| iterations: [ | ||
| { | ||
| id: 1, | ||
| startedAt: 1000, | ||
| errors: [], | ||
| commandResults: [], | ||
| }, | ||
| ], | ||
| maxIterations: 5, | ||
| active: true, | ||
| allFeedback: [], | ||
| filesModified: [], | ||
| filesRead: [], | ||
| }; | ||
|
|
||
| const summary = buildCodingAgentSummary(ctx); | ||
| expect(summary).toContain("## Coding Agent Session"); | ||
| expect(summary).toContain("**Task:** Do something"); | ||
| expect(summary).toContain("**Iterations:** 1 / 5"); | ||
| }); | ||
|
|
||
| it("includes errors from last iteration", () => { | ||
| const ctx: CodingAgentContext = { | ||
| sessionId: "session-1", | ||
| taskDescription: "Task", | ||
| workingDirectory: "/work", | ||
| connector: { type: "local", available: true }, | ||
| interactionMode: "auto", | ||
| iterations: [ | ||
| { | ||
| id: 1, | ||
| startedAt: 1000, | ||
| errors: [{ category: "lint", message: "Lint error", filePath: "file.ts", line: 10 }], | ||
| commandResults: [], | ||
| }, | ||
| ], | ||
| maxIterations: 5, | ||
| active: true, | ||
| allFeedback: [], | ||
| filesModified: [], | ||
| filesRead: [], | ||
| }; | ||
|
|
||
| const summary = buildCodingAgentSummary(ctx); | ||
| expect(summary).toContain("Errors to Resolve"); | ||
| expect(summary).toContain("[lint]"); | ||
| expect(summary).toContain("file.ts:10"); | ||
| expect(summary).toContain("Lint error"); | ||
| }); | ||
|
|
||
| it("includes pending feedback", () => { | ||
| const ctx: CodingAgentContext = { | ||
| sessionId: "session-1", | ||
| taskDescription: "Task", | ||
| workingDirectory: "/work", | ||
| connector: { type: "local", available: true }, | ||
| interactionMode: "auto", | ||
| iterations: [ | ||
| { | ||
| id: 1, | ||
| startedAt: 1000, | ||
| errors: [], | ||
| commandResults: [], | ||
| }, | ||
| ], | ||
| maxIterations: 5, | ||
| active: true, | ||
| allFeedback: [ | ||
| { timestamp: 2000, type: "user", text: "Fix this" }, // After iteration start (1000) | ||
| { timestamp: 500, type: "user", text: "Old feedback" }, // Before iteration start | ||
| ], | ||
| filesModified: [], | ||
| filesRead: [], | ||
| }; | ||
|
|
||
| const summary = buildCodingAgentSummary(ctx); | ||
| expect(summary).toContain("Human Feedback"); | ||
| expect(summary).toContain("Fix this"); | ||
| expect(summary).not.toContain("Old feedback"); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
The CodingAgentContext objects created in these tests do not conform to the CodingAgentContext type definition from src/services/coding-agent-context.ts. For example:
- The required
createdAtproperty is missing. connectoris missing the requiredbasePathproperty.interactionModeis set to"auto", which is not a valid value according toInteractionModeSchema.- The
iterationsarray contains objects with anidproperty, but theCodingIterationSchemaexpects anindexproperty.
While the tests may pass because the function under test (buildCodingAgentSummary) doesn't use all of these properties, using improperly typed mock data can lead to brittle tests and hide potential bugs. The test data should be updated to be fully compliant with the CodingAgentContext and CodingIteration types.
| it("returns existing session key from metadata if present", async () => { | ||
| const provider = createSessionKeyProvider({ defaultAgentId: agentId }); | ||
| const message = { | ||
| metadata: { sessionKey: "existing-key" }, | ||
| } as unknown as Memory; | ||
|
|
||
| const result = await provider.get(runtime, message, state); | ||
|
|
||
| expect(result).toEqual({ | ||
| text: "Session: existing-key", | ||
| values: { sessionKey: "existing-key", agentId }, // mocked parseAgentSessionKey returns null, so it falls back to defaultAgentId | ||
| data: { sessionKey: "existing-key" }, | ||
| }); | ||
| }); |
There was a problem hiding this comment.
The current test for existing session keys only covers the fallback case where parseAgentSessionKey returns null. To ensure full coverage of the logic, it's important to also test the successful path where a valid session key is provided and an agentId is successfully parsed. I've suggested adding a new test case for this scenario.
it("returns existing session key and parsed agentId from metadata", async () => {
const provider = createSessionKeyProvider({ defaultAgentId: agentId });
const message = {
metadata: { sessionKey: "agent:parsed-agent:main" },
} as unknown as Memory;
const result = await provider.get(runtime, message, state);
expect(result).toEqual({
text: "Session: agent:parsed-agent:main",
values: { sessionKey: "agent:parsed-agent:main", agentId: "parsed-agent" },
data: { sessionKey: "agent:parsed-agent:main" },
});
});
it("returns existing session key from metadata if present", async () => {
const provider = createSessionKeyProvider({ defaultAgentId: agentId });
const message = {
metadata: { sessionKey: "existing-key" },
} as unknown as Memory;
const result = await provider.get(runtime, message, state);
expect(result).toEqual({
text: "Session: existing-key",
values: { sessionKey: "existing-key", agentId }, // mocked parseAgentSessionKey returns null, so it falls back to defaultAgentId
data: { sessionKey: "existing-key" },
});
});| it("get() enriches with coding agent context if present", async () => { | ||
| const provider = createWorkspaceProvider(); | ||
| const codingCtx = { | ||
| sessionId: "session-1", | ||
| taskDescription: "Code something", | ||
| // Add required fields to pass duck-typing | ||
| workingDirectory: "/", | ||
| connector: { type: "local", available: true }, | ||
| interactionMode: "auto", | ||
| iterations: [], | ||
| maxIterations: 1, | ||
| active: true, | ||
| allFeedback: [], | ||
| filesModified: [], | ||
| filesRead: [], | ||
| }; | ||
| const message = { | ||
| metadata: { | ||
| codingAgentContext: codingCtx, | ||
| }, | ||
| } as unknown as Memory; | ||
|
|
||
| (loadWorkspaceBootstrapFiles as any).mockResolvedValue([]); | ||
|
|
||
| const result = await provider.get(runtime, message, state); | ||
|
|
||
| expect(result?.text).toContain("Coding Agent Session"); | ||
| expect(result?.text).toContain("Code something"); | ||
| expect(result?.data).toEqual({ | ||
| workspaceDir: "/default/workspace", | ||
| codingSession: "session-1", | ||
| }); | ||
| }); |
There was a problem hiding this comment.
The codingCtx object used in this test is not a valid CodingAgentContext object (e.g., it's missing createdAt, connector.basePath, and has an invalid interactionMode). While extractCodingAgentContext performs a minimal duck-typing check, it then performs an unsafe cast to CodingAgentContext. This can be risky if buildCodingAgentSummary or other downstream functions rely on properties not covered by the duck-typing. Consider making the mock codingCtx object fully compliant with CodingAgentContext to make the test more robust and representative of real-world data.
This PR adds unit tests for the providers in
src/providers/, specificallysession-bridge,workspace, andworkspace-provider. These tests cover key functionality such as session key resolution, bootstrap file filtering, and workspace context generation. Mocks were used for external dependencies and file system operations to ensuring robust and fast tests.PR created automatically by Jules for task 5860222823788848613 started by @Dexploarer