Skip to content

test: update ide detection tests to make them more robust when run in an ide#15008

Merged
kevin-ramdass merged 2 commits intomainfrom
kevin-ramdass/ide
Dec 12, 2025
Merged

test: update ide detection tests to make them more robust when run in an ide#15008
kevin-ramdass merged 2 commits intomainfrom
kevin-ramdass/ide

Conversation

@kevin-ramdass
Copy link
Copy Markdown
Contributor

Summary

Resets/mocks the env variable per test.

Details

Related Issues

How to Validate

npm run test from within an ide.

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
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @kevin-ramdass, 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 stability and reliability of the test suite by implementing robust environment isolation. It introduces beforeEach hooks in key test files to systematically clear or mock various environment variables. This proactive measure prevents external environment configurations, particularly those from an Integrated Development Environment (IDE), from inadvertently influencing test outcomes, thereby ensuring more consistent and predictable test results across all execution contexts.

Highlights

  • Test Robustness: Introduced beforeEach hooks in test files to reset and mock environment variables, preventing leakage from the host environment into test runs.
  • Environment Variable Isolation: Explicitly stubbed out a comprehensive list of environment variables (e.g., TERM_PROGRAM, CODESPACES, VSCODE_IPC_HOOK_CLI) to ensure tests run in a clean, predictable state.
  • Consistent Test Execution: Improved the reliability of IDE detection and telemetry logging tests by ensuring they produce consistent results regardless of whether they are executed within an IDE or a CI environment.
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
Copy Markdown
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 improves the robustness of IDE detection tests by resetting relevant environment variables before each test run. This prevents the host environment from interfering with test outcomes, especially when tests are run from within an IDE. The changes are correct and achieve the stated goal. I've added a couple of suggestions to address code duplication in the test setup, which will improve long-term maintainability.

Comment on lines +14 to +27
beforeEach(() => {
// Ensure these env vars don't leak from the host environment
vi.stubEnv('ANTIGRAVITY_CLI_ALIAS', '');
vi.stubEnv('TERM_PROGRAM', '');
vi.stubEnv('CURSOR_TRACE_ID', '');
vi.stubEnv('CODESPACES', '');
vi.stubEnv('VSCODE_IPC_HOOK_CLI', '');
vi.stubEnv('EDITOR_IN_CLOUD_SHELL', '');
vi.stubEnv('CLOUD_SHELL', '');
vi.stubEnv('TERM_PRODUCT', '');
vi.stubEnv('MONOSPACE_ENV', '');
vi.stubEnv('REPLIT_USER', '');
vi.stubEnv('__COG_BASHRC_SOURCED', '');
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

This beforeEach block is duplicated later in this file (lines 121-133) and also in packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts. To improve maintainability and avoid future inconsistencies, consider extracting this logic into a shared test utility function. For now, we can at least improve this block by defining the environment variables in an array and iterating over them. This makes the list easier to manage and the code more concise.

  beforeEach(() => {
    // Ensure these env vars don't leak from the host environment
    const ideEnvVars = [
      'ANTIGRAVITY_CLI_ALIAS',
      'TERM_PROGRAM',
      'CURSOR_TRACE_ID',
      'CODESPACES',
      'VSCODE_IPC_HOOK_CLI',
      'EDITOR_IN_CLOUD_SHELL',
      'CLOUD_SHELL',
      'TERM_PRODUCT',
      'MONOSPACE_ENV',
      'REPLIT_USER',
      '__COG_BASHRC_SOURCED',
    ];
    for (const envVar of ideEnvVars) {
      vi.stubEnv(envVar, '');
    }
  });

Comment on lines +135 to +147
beforeEach(() => {
vi.stubEnv('ANTIGRAVITY_CLI_ALIAS', '');
vi.stubEnv('TERM_PROGRAM', '');
vi.stubEnv('CURSOR_TRACE_ID', '');
vi.stubEnv('CODESPACES', '');
vi.stubEnv('VSCODE_IPC_HOOK_CLI', '');
vi.stubEnv('EDITOR_IN_CLOUD_SHELL', '');
vi.stubEnv('CLOUD_SHELL', '');
vi.stubEnv('TERM_PRODUCT', '');
vi.stubEnv('MONOSPACE_ENV', '');
vi.stubEnv('REPLIT_USER', '');
vi.stubEnv('__COG_BASHRC_SOURCED', '');
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

This beforeEach block is duplicated in packages/core/src/ide/detect-ide.test.ts. To improve maintainability and prevent future inconsistencies where one file is updated but not the other, this logic should be extracted to a shared test utility. For now, refactoring to use an array of variables makes it more concise and easier to manage.

  beforeEach(() => {
    const ideEnvVars = [
      'ANTIGRAVITY_CLI_ALIAS',
      'TERM_PROGRAM',
      'CURSOR_TRACE_ID',
      'CODESPACES',
      'VSCODE_IPC_HOOK_CLI',
      'EDITOR_IN_CLOUD_SHELL',
      'CLOUD_SHELL',
      'TERM_PRODUCT',
      'MONOSPACE_ENV',
      'REPLIT_USER',
      '__COG_BASHRC_SOURCED',
    ];
    for (const envVar of ideEnvVars) {
      vi.stubEnv(envVar, '');
    }
  });

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 12, 2025

Size Change: -2 B (0%)

Total Size: 21.6 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 21.6 MB -2 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 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-closed.sb 3.29 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

compressed-size-action

@kevin-ramdass kevin-ramdass marked this pull request as ready for review December 12, 2025 19:35
@kevin-ramdass kevin-ramdass requested a review from a team as a code owner December 12, 2025 19:35
@kevin-ramdass kevin-ramdass added this pull request to the merge queue Dec 12, 2025
Merged via the queue into main with commit 20164eb Dec 12, 2025
20 checks passed
@kevin-ramdass kevin-ramdass deleted the kevin-ramdass/ide branch December 12, 2025 20:06
thacio added a commit to thacio/auditaria that referenced this pull request Dec 13, 2025
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