Skip to content

fix(cli): reset themeManager between tests to ensure isolation#20598

Merged
NTaylorMullen merged 3 commits intomainfrom
fix/theme-manager-test-isolation
Feb 28, 2026
Merged

fix(cli): reset themeManager between tests to ensure isolation#20598
NTaylorMullen merged 3 commits intomainfrom
fix/theme-manager-test-isolation

Conversation

@NTaylorMullen
Copy link
Collaborator

@NTaylorMullen NTaylorMullen commented Feb 27, 2026

Summary

Fixes non-deterministic SVG snapshot failures in the CLI package by ensuring that themeManager state (active theme and terminal background) is reset between every test run.

Details

Commit f9f916e1d enabled 24-bit color in tests and introduced SVG snapshots via toMatchSvgSnapshot. Since themeManager is a global singleton and Vitest reuses worker processes, state from one test (e.g., setting a terminal background or active theme) would leak into subsequent tests. This led to non-deterministic hex code mismatches in SVG snapshots (e.g., #3d3f51 vs #45475a).

This PR adds a beforeEach hook to packages/cli/test-setup.ts to reset themeManager to its default state before every test.

Related Issues

Fixes the failures reported in the Gemini CLI Maintainers chat thread.

How to Validate

  1. Created a reproduction test file packages/cli/src/ui/themes/leak.test.ts that explicitly modified themeManager in one test and verified the leak in the next.
  2. Confirmed the leak existed before the fix.
  3. Confirmed the leak was eliminated after applying the fix to test-setup.ts.
  4. Verified that all existing CLI tests (npm test -w @google/gemini-cli) continue to pass (barring pre-existing failures on main).

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run

Update: Added themeManager.clearFileThemes() and ensured all theme clearing methods (clearExtensionThemes, clearFileThemes, loadCustomThemes({})) are called in test-setup.ts for complete isolation, per code review feedback.

@NTaylorMullen NTaylorMullen requested a review from a team as a code owner February 27, 2026 19:21
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 resolves an issue where test state was leaking between runs, leading to non-deterministic SVG snapshot failures. By introducing a reset mechanism for the themeManager before each test, it ensures proper test isolation and reliability, preventing color mismatches in visual tests.

Highlights

  • Test Isolation: Implemented a beforeEach hook in packages/cli/test-setup.ts to reset the themeManager's state, including custom themes, active theme, and terminal background, before each test run.
  • Fix for Non-Deterministic Failures: Addressed non-deterministic SVG snapshot failures in the CLI package caused by state leakage from the global themeManager singleton between Vitest worker processes.
Changelog
  • packages/cli/test-setup.ts
    • Imported themeManager and DEFAULT_THEME to enable state management.
    • Added a beforeEach hook to reset themeManager's state to its defaults before each test.
Activity
  • A reproduction test file (packages/cli/src/ui/themes/leak.test.ts) was created to explicitly demonstrate the themeManager state leak.
  • The existence of the leak was confirmed prior to the fix.
  • The leak was verified to be eliminated after applying the fix in test-setup.ts.
  • All existing CLI tests were validated to ensure they continue to pass.
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 addresses non-deterministic test failures by resetting the themeManager state in a beforeEach hook. The change is correct in principle, but it's incomplete as it misses resetting themes loaded from extensions, which could lead to continued state leakage between tests. I've added a suggestion to call themeManager.clearExtensionThemes() to ensure complete test isolation.

@github-actions
Copy link

github-actions bot commented Feb 27, 2026

Size Change: +900 B (0%)

Total Size: 25.8 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.3 MB +900 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 27, 2026
@NTaylorMullen NTaylorMullen force-pushed the fix/theme-manager-test-isolation branch from a0bf29a to b3741de Compare February 27, 2026 20:24
@NTaylorMullen NTaylorMullen reopened this Feb 27, 2026
@NTaylorMullen NTaylorMullen force-pushed the fix/theme-manager-test-isolation branch 3 times, most recently from 13b5ec2 to adb9fa9 Compare February 28, 2026 18:14
@NTaylorMullen NTaylorMullen force-pushed the fix/theme-manager-test-isolation branch from adb9fa9 to 627423a Compare February 28, 2026 19:19
@NTaylorMullen NTaylorMullen added this pull request to the merge queue Feb 28, 2026
Merged via the queue into main with commit cd3a8c3 Feb 28, 2026
27 checks passed
@NTaylorMullen NTaylorMullen deleted the fix/theme-manager-test-isolation branch February 28, 2026 19:56
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants