test: update ide detection tests to make them more robust when run in an ide#15008
test: update ide detection tests to make them more robust when run in an ide#15008kevin-ramdass merged 2 commits intomainfrom
Conversation
Summary of ChangesHello @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 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.
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.
| 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', ''); | ||
| }); |
There was a problem hiding this comment.
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, '');
}
});| 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', ''); | ||
| }); |
There was a problem hiding this comment.
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, '');
}
});|
Size Change: -2 B (0%) Total Size: 21.6 MB ℹ️ View Unchanged
|
…em more robust when run in an ide (google-gemini#15008)
Summary
Resets/mocks the env variable per test.
Details
Related Issues
How to Validate
npm run testfrom within an ide.Pre-Merge Checklist