Skip to content

Comments

Add unit tests for providers#83

Draft
Dexploarer wants to merge 1 commit intodevelopfrom
unit-tests-providers-5860222823788848613
Draft

Add unit tests for providers#83
Dexploarer wants to merge 1 commit intodevelopfrom
unit-tests-providers-5860222823788848613

Conversation

@Dexploarer
Copy link
Owner

This PR adds unit tests for the providers in src/providers/, specifically session-bridge, workspace, and workspace-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

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.
@google-labs-jules
Copy link

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch unit-tests-providers-5860222823788848613

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • Unit Tests for Session Bridge Provider: Added comprehensive unit tests for session-bridge.js, covering the resolveSessionKeyFromRoom function for various room types (DM, SELF, GROUP, CHANNEL) and metadata scenarios (threadId, groupId, custom channel). Tests also validate the createSessionKeyProvider for handling existing session keys, generating main keys when rooms are not found, and correctly deriving session keys from room information, including metadata.
  • Unit Tests for Workspace Provider: Introduced unit tests for workspace-provider.js, specifically for the truncate, buildContext, and buildCodingAgentSummary utility functions. The tests for createWorkspaceProvider verify its functionality in loading workspace bootstrap files from default or custom directories, filtering files based on session keys, enriching context with coding agent information, and gracefully handling errors during file loading.
  • Unit Tests for Workspace File Filtering: Implemented unit tests for workspace.js, focusing on the filterBootstrapFilesForSession function. These tests ensure that files are correctly filtered based on the session key, specifically allowing only AGENTS.md and TOOLS.md for subagent sessions while returning all files for other session types or when no session key is provided.

🧠 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
  • src/providers/session-bridge.test.ts
    • Added new test file for session-bridge.js.
  • src/providers/workspace-provider.test.ts
    • Added new test file for workspace-provider.js.
  • src/providers/workspace.test.ts
    • Added new test file for workspace.js.
Activity
  • The pull request was automatically created by Jules for task 5860222823788848613, initiated by @Dexploarer.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 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.

Comment on lines +82 to +170
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");
});
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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 createdAt property is missing.
  • connector is missing the required basePath property.
  • interactionMode is set to "auto", which is not a valid value according to InteractionModeSchema.
  • The iterations array contains objects with an id property, but the CodingIterationSchema expects an index property.

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.

Comment on lines +133 to +146
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" },
});
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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" },
    });
  });

Comment on lines +221 to +253
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",
});
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant