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

This commit is contained in:
Kevin Ramdass
2025-12-12 11:53:07 -08:00
committed by GitHub
parent edbe5480ca
commit 20164ebcda
2 changed files with 45 additions and 1 deletions

View File

@@ -4,13 +4,28 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, afterEach } from 'vitest';
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
import { detectIde, IDE_DEFINITIONS } from './detect-ide.js';
describe('detectIde', () => {
const ideProcessInfo = { pid: 123, command: 'some/path/to/code' };
const ideProcessInfoNoCode = { pid: 123, command: 'some/path/to/fork' };
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', '');
});
afterEach(() => {
vi.unstubAllEnvs();
// Clear Cursor-specific environment variables that might interfere with tests
@@ -103,6 +118,20 @@ describe('detectIde with ideInfoFromFile', () => {
vi.unstubAllEnvs();
});
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', '');
});
it('should use the name and displayName from the file', () => {
const ideInfoFromFile = {
name: 'custom-ide',

View File

@@ -13,6 +13,7 @@ import {
afterEach,
beforeAll,
afterAll,
beforeEach,
} from 'vitest';
import type { LogEvent, LogEventEntry } from './clearcut-logger.js';
import { ClearcutLogger, EventNames, TEST_ONLY } from './clearcut-logger.js';
@@ -131,6 +132,20 @@ describe('ClearcutLogger', () => {
vi.unstubAllEnvs();
});
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', '');
});
function setup({
config = {
experiments: {