-
Notifications
You must be signed in to change notification settings - Fork 260
test(gemini-model): add unit tests to cover some errors #269
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: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @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 Highlights
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.
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.
35344cf to
e023ec9
Compare
|
/gemini review |
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 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.
e023ec9 to
12644d7
Compare
|
/gemini review |
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 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.
12644d7 to
53d4da3
Compare
|
/gemini review |
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 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
53d4da3 to
b474d5a
Compare
|
/gemini review |
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 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.
| 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." | ||
| ) |
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.
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.
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.
| 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) | ||
| } |
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 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)
}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 logic for retrieving and checking the error can be simplified. Since a non-streaming
GenerateContentcall 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) }
Tests included