Skip to content

Conversation

@danielfs
Copy link

Tests included

  • project and API key are mutually exclusive in the client initializer
  • generate with empty model name
  • maybe append user content when length is zero
  • maybe append user content when there is no user role
  • Name() method

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @danielfs, 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 the Gemini model integration by introducing several new unit tests. These tests specifically target various error conditions and edge cases related to model initialization, content generation, and the logic for appending user content. The primary goal is to improve the robustness and reliability of the gemini-model package, ensuring it behaves correctly and handles invalid configurations or content states gracefully.

Highlights

  • Model Name Verification: A new unit test has been added to verify that the Name() method of the Gemini model correctly returns its assigned name.
  • Client Initialization Error Handling: A test case was introduced for NewModel to ensure an error is returned when both Project and APIKey are provided in the client configuration, as these parameters are mutually exclusive.
  • Empty Model Name Generation: A test now confirms that GenerateContent properly handles an empty model name by returning an error, preventing generation with an invalid model.
  • User Content Appending (Empty List): A test for maybeAppendUserContent verifies its behavior when the content list is initially empty, ensuring a user role is correctly appended in such scenarios.
  • User Content Appending (No User Role): Another test for maybeAppendUserContent checks that a user role is appended when the last content entry does not have a user role, maintaining proper conversation flow.
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
Contributor

@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 valuable set of unit tests covering several error conditions and edge cases for the Gemini model, such as initialization with conflicting parameters and handling of empty model names. The tests are well-structured and align with the goals outlined in the description. I have provided a few suggestions to enhance the robustness of the tests by making error assertions more specific and ensuring consistent failure handling to prevent potential panics.

@danielfs danielfs force-pushed the danielfs/test-model-gemini branch 2 times, most recently from 35344cf to e023ec9 Compare November 13, 2025 00:59
@danielfs
Copy link
Author

/gemini review

Copy link
Contributor

@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 valuable unit tests covering several error and edge cases for the Gemini model implementation. The tests are clear and correctly validate the intended behavior. I have one suggestion to refactor two tests for maybeAppendUserContent into a single, table-driven test. This improves the test structure by following common Go idioms, reduces code duplication, and allows for adding another relevant test case for better coverage.

@danielfs danielfs force-pushed the danielfs/test-model-gemini branch from e023ec9 to 12644d7 Compare November 13, 2025 01:10
@danielfs
Copy link
Author

/gemini review

Copy link
Contributor

@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 covering several error conditions and edge cases for the Gemini model implementation. The tests are well-written and improve the overall test coverage. I have one suggestion to make the test for maybeAppendUserContent more thorough by also verifying the content of the appended messages.

@danielfs danielfs force-pushed the danielfs/test-model-gemini branch from 12644d7 to 53d4da3 Compare November 13, 2025 01:16
@danielfs
Copy link
Author

/gemini review

Copy link
Contributor

@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 covering several error paths and edge cases for the Gemini model, such as client initialization with mutually exclusive parameters, handling of an empty model name, and the logic for appending user content. The tests are well-structured and improve the overall test coverage. I have a couple of suggestions to enhance the robustness and maintainability of the new tests.

- project and API key are mutually exclusive in the client initializer
- generate with empty model name
- maybe append user content when length is zero
- maybe append user content when there is no user role
- Name() method
@danielfs danielfs force-pushed the danielfs/test-model-gemini branch from 53d4da3 to b474d5a Compare November 13, 2025 01:22
@danielfs
Copy link
Author

/gemini review

Copy link
Contributor

@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 covering several important error conditions and edge cases for the Gemini model, such as client initialization errors, empty model names, and content generation logic. My review includes suggestions to improve the maintainability of these new tests by centralizing constants to avoid duplication and by simplifying the error-checking logic in one of the tests to make it more concise and readable.

Comment on lines +35 to +38
const (
systemInstructionText = "Handle the requests as specified in the System Instruction."
continueProcessingText = "Continue processing previous requests as instructed. Exit or provide a summary if no more outputs are needed."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

These constants duplicate strings that are hardcoded in the maybeAppendUserContent function in gemini.go. This makes the tests brittle because if the strings in the implementation change, these tests will fail without a clear link to the cause. To improve maintainability, it would be better to define these constants in the gemini package, export them, and then reuse them in this test file. This would create a single source of truth for these strings.

Choose a reason for hiding this comment

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

Comment on lines +231 to +246
var errs []error
for _, err := range newModel.GenerateContent(t.Context(), req, false) {
errs = append(errs, err)
}

if len(errs) != 1 {
t.Fatalf("expected 1 error, got %d", len(errs))
}

err = errs[0]
if err == nil {
t.Fatal("Model.Generate() expected error due to empty model name, got nil")
}
if want := "model is empty"; !strings.Contains(err.Error(), want) {
t.Fatalf("Model.Generate() error = %q, want to contain %q", err, want)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for retrieving and checking the error can be simplified. Since a non-streaming GenerateContent call is designed to yield exactly one result, you don't need to collect errors in a slice and then check its length. You can simplify the code by iterating once and checking the error directly. This makes the test's intent clearer and more concise.

 var err error
 for _, e := range newModel.GenerateContent(t.Context(), req, false) {
  err = e
 }

 if err == nil {
  t.Fatal("Model.Generate() expected error due to empty model name, got nil")
 }
 if want := "model is empty"; !strings.Contains(err.Error(), want) {
  t.Fatalf("Model.Generate() error = %q, want to contain %q", err, want)
 }

Choose a reason for hiding this comment

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

medium

The logic for retrieving and checking the error can be simplified. Since a non-streaming GenerateContent call is designed to yield exactly one result, you don't need to collect errors in a slice and then check its length. You can simplify the code by iterating once and checking the error directly. This makes the test's intent clearer and more concise.

 var err error
 for _, e := range newModel.GenerateContent(t.Context(), req, false) {
  err = e
 }

 if err == nil {
  t.Fatal("Model.Generate() expected error due to empty model name, got nil")
 }
 if want := "model is empty"; !strings.Contains(err.Error(), want) {
  t.Fatalf("Model.Generate() error = %q, want to contain %q", err, want)
 }

@danielfs

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.

2 participants