Sync upstream Gemini-CLI v0.8.2 (#838)

This commit is contained in:
tanzhenxin
2025-10-23 09:27:04 +08:00
committed by GitHub
parent 096fabb5d6
commit eb95c131be
644 changed files with 70389 additions and 23709 deletions

View File

@@ -4,8 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
import { detectIde, DetectedIde, getIdeInfo } from './detect-ide.js';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { detectIde, IDE_DEFINITIONS } from './detect-ide.js';
describe('detectIde', () => {
const ideProcessInfo = { pid: 123, command: 'some/path/to/code' };
@@ -35,110 +35,103 @@ describe('detectIde', () => {
it('should detect Devin', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('__COG_BASHRC_SOURCED', '1');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Devin);
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.devin);
});
it('should detect Replit', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('REPLIT_USER', 'testuser');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Replit);
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.replit);
});
it('should detect Cursor', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('CURSOR_TRACE_ID', 'some-id');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Cursor);
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.cursor);
});
it('should detect Codespaces', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('CODESPACES', 'true');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Codespaces);
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.codespaces);
});
it('should detect Cloud Shell via EDITOR_IN_CLOUD_SHELL', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('EDITOR_IN_CLOUD_SHELL', 'true');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.CloudShell);
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.cloudshell);
});
it('should detect Cloud Shell via CLOUD_SHELL', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('CLOUD_SHELL', 'true');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.CloudShell);
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.cloudshell);
});
it('should detect Trae', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('TERM_PRODUCT', 'Trae');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Trae);
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.trae);
});
it('should detect Firebase Studio via MONOSPACE_ENV', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('MONOSPACE_ENV', 'true');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.FirebaseStudio);
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.firebasestudio);
});
it('should detect VSCode when no other IDE is detected and command includes "code"', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('MONOSPACE_ENV', '');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.VSCode);
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.vscode);
});
it('should detect VSCodeFork when no other IDE is detected and command does not include "code"', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('MONOSPACE_ENV', '');
expect(detectIde(ideProcessInfoNoCode)).toBe(DetectedIde.VSCodeFork);
expect(detectIde(ideProcessInfoNoCode)).toBe(IDE_DEFINITIONS.vscodefork);
});
});
describe('detectIde with ideInfoFromFile', () => {
const ideProcessInfo = { pid: 123, command: 'some/path/to/code' };
beforeEach(() => {
vi.stubEnv('__COG_BASHRC_SOURCED', '');
vi.stubEnv('REPLIT_USER', '');
vi.stubEnv('CURSOR_TRACE_ID', '');
vi.stubEnv('CODESPACES', '');
vi.stubEnv('EDITOR_IN_CLOUD_SHELL', '');
vi.stubEnv('CLOUD_SHELL', '');
vi.stubEnv('TERM_PRODUCT', '');
vi.stubEnv('MONOSPACE_ENV', '');
});
it('should prioritize other IDEs over VSCode detection', () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it('should use the name and displayName from the file', () => {
const ideInfoFromFile = {
name: 'custom-ide',
displayName: 'Custom IDE',
};
expect(detectIde(ideProcessInfo, ideInfoFromFile)).toEqual(ideInfoFromFile);
});
it('should fall back to env detection if name is missing', () => {
const ideInfoFromFile = { displayName: 'Custom IDE' };
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('REPLIT_USER', 'testuser');
expect(detectIde(ideProcessInfo)).toBe(DetectedIde.Replit);
});
});
describe('getIdeInfo', () => {
it('should return correct info for Devin', () => {
expect(getIdeInfo(DetectedIde.Devin)).toEqual({ displayName: 'Devin' });
});
it('should return correct info for Replit', () => {
expect(getIdeInfo(DetectedIde.Replit)).toEqual({ displayName: 'Replit' });
});
it('should return correct info for Cursor', () => {
expect(getIdeInfo(DetectedIde.Cursor)).toEqual({ displayName: 'Cursor' });
});
it('should return correct info for CloudShell', () => {
expect(getIdeInfo(DetectedIde.CloudShell)).toEqual({
displayName: 'Cloud Shell',
});
});
it('should return correct info for Codespaces', () => {
expect(getIdeInfo(DetectedIde.Codespaces)).toEqual({
displayName: 'GitHub Codespaces',
});
});
it('should return correct info for FirebaseStudio', () => {
expect(getIdeInfo(DetectedIde.FirebaseStudio)).toEqual({
displayName: 'Firebase Studio',
});
});
it('should return correct info for Trae', () => {
expect(getIdeInfo(DetectedIde.Trae)).toEqual({ displayName: 'Trae' });
});
it('should return correct info for VSCode', () => {
expect(getIdeInfo(DetectedIde.VSCode)).toEqual({ displayName: 'VS Code' });
});
it('should return correct info for VSCodeFork', () => {
expect(getIdeInfo(DetectedIde.VSCodeFork)).toEqual({ displayName: 'IDE' });
expect(detectIde(ideProcessInfo, ideInfoFromFile)).toBe(
IDE_DEFINITIONS.vscode,
);
});
it('should fall back to env detection if displayName is missing', () => {
const ideInfoFromFile = { name: 'custom-ide' };
vi.stubEnv('TERM_PROGRAM', 'vscode');
expect(detectIde(ideProcessInfo, ideInfoFromFile)).toBe(
IDE_DEFINITIONS.vscode,
);
});
});