Skip to content

Conversation

@rm-hull
Copy link
Owner

@rm-hull rm-hull commented Nov 8, 2025

Introduce comprehensive unit tests for the main Bubbletea model (internal/ui/Model), ensuring correct state transitions and command generation upon receiving various messages.

Includes mock implementations for:

  • Git client interaction
  • LLM provider API calls
  • Sub-models (CommitView, PromptView)

The dependency github.com/stretchr/objx was added to support the test utilities.

Introduce comprehensive unit tests for the main Bubbletea
model (`internal/ui/Model`), ensuring correct state
transitions and command generation upon receiving various
messages.

Includes mock implementations for:
* Git client interaction
* LLM provider API calls
* Sub-models (`CommitView`, `PromptView`)

The dependency `github.com/stretchr/objx` was added to
support the test utilities.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rm-hull, 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 application's core UI model. By introducing a new suite of unit tests, it validates the model's behavior across various states and message types, ensuring the robustness and predictability of the user interface. The use of mocks for external services and sub-components allows for focused testing of the model's internal logic without relying on actual external interactions.

Highlights

  • New Unit Tests: Comprehensive unit tests have been added for the main Bubbletea UI model (internal/ui/Model), specifically targeting its Update logic to ensure correct state transitions and command generation.
  • Mock Implementations: The tests utilize mock implementations for external dependencies such as Git client interaction and LLM provider API calls, as well as for internal sub-models like CommitView and PromptView, to ensure isolated and reliable testing.
  • Dependency Addition: The github.com/stretchr/objx library was introduced as a new dependency to support the test utilities.
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.

@github-actions
Copy link

github-actions bot commented Nov 8, 2025

TestsPassed ✅SkippedFailed
JUnit Test Report33 ran33 passed0 skipped0 failed
TestResult
JUnit Test Report
com/rm-hull/git-commit-summary/internal/config.TestLoad/Defaults✅ passed
com/rm-hull/git-commit-summary/internal/config.TestLoad/WithEnvironmentVariables✅ passed
com/rm-hull/git-commit-summary/internal/config.TestLoad✅ passed
com/rm-hull/git-commit-summary/internal/llm_provider.TestNewProvider/GoogleProvider✅ passed
com/rm-hull/git-commit-summary/internal/llm_provider.TestNewProvider/OpenAIProvider✅ passed
com/rm-hull/git-commit-summary/internal/llm_provider.TestNewProvider/UnknownProvider✅ passed
com/rm-hull/git-commit-summary/internal/llm_provider.TestNewProvider✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/NewHistory✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Add_and_Value✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Undo✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Redo✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Undo_at_beginning✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Redo_at_end✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Add_truncates_future_history✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory/Multiple_Undos_and_Redos✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestHistory✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/tea.KeyMsg_-_CtrlC_in_showSpinner_state✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/tea.KeyMsg_-_CtrlC_in_other_states✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/gitCheckMsg_-_empty_(no_staged_changes)✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/gitCheckMsg_-_non-empty_(staged_changes)✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/gitDiffMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/llmResultMsg_-_with_user_message✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/llmResultMsg_-_without_user_message✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/commitMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/regenerateMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/userResponseMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/cancelRegenPromptMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/errMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/abortMsg✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/spinner.Update_for_showSpinner_state✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/commitView.Update_for_showCommitView_state✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update/promptView.Update_for_showRegeneratePrompt_state✅ passed
com/rm-hull/git-commit-summary/internal/ui.TestModel_Update✅ passed

gemini-code-assist[bot]

This comment was marked as outdated.

Updates the assertion in the `TestModel_Update` for the
`regenerateMsg` handler to verify that the command returned
is the expected `textinput.Blink()` initialization command.
The tests for `Model.Update` handling `llmResultMsg` no longer
require setting up and asserting calls on a mocked commit
view.

Instead, we now assert directly that the resulting command is
of type `textarea.Blink()`, which confirms the state
transition and command generation correctly occurred. This
simplifies the test implementation.
@rm-hull
Copy link
Owner Author

rm-hull commented Nov 9, 2025

/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 introduces a comprehensive set of unit tests for the UI Model's update logic, which is a fantastic addition for ensuring the correctness of state transitions and command handling. The use of mocks for dependencies is well-implemented. I've provided a few suggestions to enhance the test structure for better isolation and maintainability, improve the robustness of the test mocks, and increase the precision of some assertions. Overall, this is a solid contribution to the project's test coverage.

Comment on lines +59 to +70
func TestModel_Update(t *testing.T) {
ctx := context.Background()
mockLLM := new(MockLLMProvider)
mockGit := new(MockGitClient)

// Common setup for InitialModel
initialModel := func() *Model {
// Explicitly use the types to avoid "imported and not used" warnings
var _ interfaces.GitClient = mockGit
var _ llmprovider.Provider = mockLLM
return InitialModel(ctx, mockLLM, mockGit, "system prompt", "user message")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The TestModel_Update function is quite long and contains repetitive setup code. Additionally, the mock instances (mockLLM, mockGit) are created once and shared across all sub-tests, which can lead to test interdependence and flaky tests.

A great way to solve both issues is to refactor this into a table-driven test. This would:

  1. Improve Readability & Maintainability: Consolidate test cases into a single, easy-to-scan table.
  2. Ensure Test Isolation: Allow for fresh mocks to be created for each test case within the t.Run loop.

Here is an example of how you could structure it:

func TestModel_Update(t *testing.T) {
    testCases := []struct {
        name          string
        // ... setup fields
    }{ /* ... test cases ... */ }

    for _, tc := range testCases {
        t.Run(tc.name, func(t *testing.T) {
            // Create fresh mocks here
            mockLLM := new(MockLLMProvider)
            mockGit := new(MockGitClient)
            
            // Setup model and mocks based on tc fields
            
            // Run test and assert
        })
    }
}

Updates tests within `internal/ui/model_test.go`:

*   Makes the mocked `commitView` update expectation explicit
    when testing `Ctrl+C` handling.
*   Removes redundant assertion on the updated model within
    the spinner tick message test, focusing solely on validating
    that a command is returned.
Refactor the `mockTeaModel` methods to safely retrieve return
values from the underlying mocking framework (`m.Called`).

This ensures the mock does not panic if expected arguments are
missing or of the incorrect type, defaulting to `nil` or the
mock receiver itself where appropriate.
@rm-hull rm-hull merged commit 8114e9f into main Nov 9, 2025
3 checks passed
@rm-hull rm-hull deleted the chore/add-tests branch November 9, 2025 14:54
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