mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-26 13:04:49 -07:00
chore(compiler): Enable strict property access TS compiler flag. (#6255)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -15,19 +15,22 @@ export function shouldAttemptBrowserLaunch(): boolean {
|
||||
// A list of browser names that indicate we should not attempt to open a
|
||||
// web browser for the user.
|
||||
const browserBlocklist = ['www-browser'];
|
||||
const browserEnv = process.env.BROWSER;
|
||||
const browserEnv = process.env['BROWSER'];
|
||||
if (browserEnv && browserBlocklist.includes(browserEnv)) {
|
||||
return false;
|
||||
}
|
||||
// Common environment variables used in CI/CD or other non-interactive shells.
|
||||
if (process.env.CI || process.env.DEBIAN_FRONTEND === 'noninteractive') {
|
||||
if (
|
||||
process.env['CI'] ||
|
||||
process.env['DEBIAN_FRONTEND'] === 'noninteractive'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The presence of SSH_CONNECTION indicates a remote session.
|
||||
// We should not attempt to launch a browser unless a display is explicitly available
|
||||
// (checked below for Linux).
|
||||
const isSSH = !!process.env.SSH_CONNECTION;
|
||||
const isSSH = !!process.env['SSH_CONNECTION'];
|
||||
|
||||
// On Linux, the presence of a display server is a strong indicator of a GUI.
|
||||
if (process.platform === 'linux') {
|
||||
|
||||
@@ -119,7 +119,7 @@ async function findLastEditTimestamp(
|
||||
const { response } = part.functionResponse;
|
||||
if (response && !('error' in response) && 'output' in response) {
|
||||
id = part.functionResponse.id;
|
||||
content = response.output;
|
||||
content = response['output'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,10 +411,10 @@ Return ONLY the corrected target snippet in the specified JSON format with the k
|
||||
|
||||
if (
|
||||
result &&
|
||||
typeof result.corrected_target_snippet === 'string' &&
|
||||
result.corrected_target_snippet.length > 0
|
||||
typeof result['corrected_target_snippet'] === 'string' &&
|
||||
result['corrected_target_snippet'].length > 0
|
||||
) {
|
||||
return result.corrected_target_snippet;
|
||||
return result['corrected_target_snippet'];
|
||||
} else {
|
||||
return problematicSnippet;
|
||||
}
|
||||
@@ -499,10 +499,10 @@ Return ONLY the corrected string in the specified JSON format with the key 'corr
|
||||
|
||||
if (
|
||||
result &&
|
||||
typeof result.corrected_new_string === 'string' &&
|
||||
result.corrected_new_string.length > 0
|
||||
typeof result['corrected_new_string'] === 'string' &&
|
||||
result['corrected_new_string'].length > 0
|
||||
) {
|
||||
return result.corrected_new_string;
|
||||
return result['corrected_new_string'];
|
||||
} else {
|
||||
return originalNewString;
|
||||
}
|
||||
@@ -568,10 +568,10 @@ Return ONLY the corrected string in the specified JSON format with the key 'corr
|
||||
|
||||
if (
|
||||
result &&
|
||||
typeof result.corrected_new_string_escaping === 'string' &&
|
||||
result.corrected_new_string_escaping.length > 0
|
||||
typeof result['corrected_new_string_escaping'] === 'string' &&
|
||||
result['corrected_new_string_escaping'].length > 0
|
||||
) {
|
||||
return result.corrected_new_string_escaping;
|
||||
return result['corrected_new_string_escaping'];
|
||||
} else {
|
||||
return potentiallyProblematicNewString;
|
||||
}
|
||||
@@ -634,10 +634,10 @@ Return ONLY the corrected string in the specified JSON format with the key 'corr
|
||||
|
||||
if (
|
||||
result &&
|
||||
typeof result.corrected_string_escaping === 'string' &&
|
||||
result.corrected_string_escaping.length > 0
|
||||
typeof result['corrected_string_escaping'] === 'string' &&
|
||||
result['corrected_string_escaping'].length > 0
|
||||
) {
|
||||
return result.corrected_string_escaping;
|
||||
return result['corrected_string_escaping'];
|
||||
} else {
|
||||
return potentiallyProblematicString;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ const originalPlatform = process.platform;
|
||||
describe('editor utils', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
delete process.env.SANDBOX;
|
||||
vi.unstubAllEnvs();
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
writable: true,
|
||||
@@ -42,7 +42,7 @@ describe('editor utils', () => {
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
delete process.env.SANDBOX;
|
||||
vi.unstubAllEnvs();
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
writable: true,
|
||||
@@ -461,7 +461,7 @@ describe('editor utils', () => {
|
||||
|
||||
describe('allowEditorTypeInSandbox', () => {
|
||||
it('should allow vim in sandbox mode', () => {
|
||||
process.env.SANDBOX = 'sandbox';
|
||||
vi.stubEnv('SANDBOX', 'sandbox');
|
||||
expect(allowEditorTypeInSandbox('vim')).toBe(true);
|
||||
});
|
||||
|
||||
@@ -470,7 +470,7 @@ describe('editor utils', () => {
|
||||
});
|
||||
|
||||
it('should allow emacs in sandbox mode', () => {
|
||||
process.env.SANDBOX = 'sandbox';
|
||||
vi.stubEnv('SANDBOX', 'sandbox');
|
||||
expect(allowEditorTypeInSandbox('emacs')).toBe(true);
|
||||
});
|
||||
|
||||
@@ -479,7 +479,7 @@ describe('editor utils', () => {
|
||||
});
|
||||
|
||||
it('should allow neovim in sandbox mode', () => {
|
||||
process.env.SANDBOX = 'sandbox';
|
||||
vi.stubEnv('SANDBOX', 'sandbox');
|
||||
expect(allowEditorTypeInSandbox('neovim')).toBe(true);
|
||||
});
|
||||
|
||||
@@ -496,7 +496,7 @@ describe('editor utils', () => {
|
||||
];
|
||||
for (const editor of guiEditors) {
|
||||
it(`should not allow ${editor} in sandbox mode`, () => {
|
||||
process.env.SANDBOX = 'sandbox';
|
||||
vi.stubEnv('SANDBOX', 'sandbox');
|
||||
expect(allowEditorTypeInSandbox(editor)).toBe(false);
|
||||
});
|
||||
|
||||
@@ -533,25 +533,25 @@ describe('editor utils', () => {
|
||||
|
||||
it('should return false for vscode when installed and in sandbox mode', () => {
|
||||
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/code'));
|
||||
process.env.SANDBOX = 'sandbox';
|
||||
vi.stubEnv('SANDBOX', 'sandbox');
|
||||
expect(isEditorAvailable('vscode')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true for vim when installed and in sandbox mode', () => {
|
||||
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/vim'));
|
||||
process.env.SANDBOX = 'sandbox';
|
||||
vi.stubEnv('SANDBOX', 'sandbox');
|
||||
expect(isEditorAvailable('vim')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for emacs when installed and in sandbox mode', () => {
|
||||
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/emacs'));
|
||||
process.env.SANDBOX = 'sandbox';
|
||||
vi.stubEnv('SANDBOX', 'sandbox');
|
||||
expect(isEditorAvailable('emacs')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for neovim when installed and in sandbox mode', () => {
|
||||
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/nvim'));
|
||||
process.env.SANDBOX = 'sandbox';
|
||||
vi.stubEnv('SANDBOX', 'sandbox');
|
||||
expect(isEditorAvailable('neovim')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,7 +72,7 @@ export function checkHasEditorType(editor: EditorType): boolean {
|
||||
}
|
||||
|
||||
export function allowEditorTypeInSandbox(editor: EditorType): boolean {
|
||||
const notUsingSandbox = !process.env.SANDBOX;
|
||||
const notUsingSandbox = !process.env['SANDBOX'];
|
||||
if (['vscode', 'vscodium', 'windsurf', 'cursor', 'zed'].includes(editor)) {
|
||||
return notUsingSandbox;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ describe('loadServerHierarchicalMemory', () => {
|
||||
|
||||
vi.resetAllMocks();
|
||||
// Set environment variables to indicate test environment
|
||||
process.env.NODE_ENV = 'test';
|
||||
process.env.VITEST = 'true';
|
||||
vi.stubEnv('NODE_ENV', 'test');
|
||||
vi.stubEnv('VITEST', 'true');
|
||||
|
||||
projectRoot = await createEmptyDir(path.join(testRootDir, 'project'));
|
||||
cwd = await createEmptyDir(path.join(projectRoot, 'src'));
|
||||
@@ -58,6 +58,7 @@ describe('loadServerHierarchicalMemory', () => {
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
vi.unstubAllEnvs();
|
||||
// Some tests set this to a different value.
|
||||
setGeminiMdFilename(DEFAULT_CONTEXT_FILENAME);
|
||||
// Clean up the temporary directory to prevent resource leaks.
|
||||
|
||||
@@ -57,8 +57,9 @@ async function findProjectRoot(startDir: string): Promise<string | null> {
|
||||
(error as { code: string }).code === 'ENOENT';
|
||||
|
||||
// Only log unexpected errors in non-test environments
|
||||
// process.env.NODE_ENV === 'test' or VITEST are common test indicators
|
||||
const isTestEnv = process.env.NODE_ENV === 'test' || process.env.VITEST;
|
||||
// process.env['NODE_ENV'] === 'test' or VITEST are common test indicators
|
||||
const isTestEnv =
|
||||
process.env['NODE_ENV'] === 'test' || process.env['VITEST'];
|
||||
|
||||
if (!isENOENT && !isTestEnv) {
|
||||
if (typeof error === 'object' && error !== null && 'code' in error) {
|
||||
@@ -246,7 +247,8 @@ async function readGeminiMdFiles(
|
||||
`Successfully read and processed imports: ${filePath} (Length: ${processedResult.content.length})`,
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
const isTestEnv = process.env.NODE_ENV === 'test' || process.env.VITEST;
|
||||
const isTestEnv =
|
||||
process.env['NODE_ENV'] === 'test' || process.env['VITEST'];
|
||||
if (!isTestEnv) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
logger.warn(
|
||||
|
||||
@@ -151,20 +151,23 @@ export function shouldLaunchBrowser(): boolean {
|
||||
// A list of browser names that indicate we should not attempt to open a
|
||||
// web browser for the user.
|
||||
const browserBlocklist = ['www-browser'];
|
||||
const browserEnv = process.env.BROWSER;
|
||||
const browserEnv = process.env['BROWSER'];
|
||||
if (browserEnv && browserBlocklist.includes(browserEnv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common environment variables used in CI/CD or other non-interactive shells.
|
||||
if (process.env.CI || process.env.DEBIAN_FRONTEND === 'noninteractive') {
|
||||
if (
|
||||
process.env['CI'] ||
|
||||
process.env['DEBIAN_FRONTEND'] === 'noninteractive'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The presence of SSH_CONNECTION indicates a remote session.
|
||||
// We should not attempt to launch a browser unless a display is explicitly available
|
||||
// (checked below for Linux).
|
||||
const isSSH = !!process.env.SSH_CONNECTION;
|
||||
const isSSH = !!process.env['SSH_CONNECTION'];
|
||||
|
||||
// On Linux, the presence of a display server is a strong indicator of a GUI.
|
||||
if (platform() === 'linux') {
|
||||
|
||||
@@ -388,7 +388,7 @@ describe('getShellConfiguration', () => {
|
||||
});
|
||||
|
||||
it('should return cmd.exe configuration by default', () => {
|
||||
delete process.env.ComSpec;
|
||||
delete process.env['ComSpec'];
|
||||
const config = getShellConfiguration();
|
||||
expect(config.executable).toBe('cmd.exe');
|
||||
expect(config.argsPrefix).toEqual(['/d', '/s', '/c']);
|
||||
@@ -397,7 +397,7 @@ describe('getShellConfiguration', () => {
|
||||
|
||||
it('should respect ComSpec for cmd.exe', () => {
|
||||
const cmdPath = 'C:\\WINDOWS\\system32\\cmd.exe';
|
||||
process.env.ComSpec = cmdPath;
|
||||
process.env['ComSpec'] = cmdPath;
|
||||
const config = getShellConfiguration();
|
||||
expect(config.executable).toBe(cmdPath);
|
||||
expect(config.argsPrefix).toEqual(['/d', '/s', '/c']);
|
||||
@@ -407,7 +407,7 @@ describe('getShellConfiguration', () => {
|
||||
it('should return PowerShell configuration if ComSpec points to powershell.exe', () => {
|
||||
const psPath =
|
||||
'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe';
|
||||
process.env.ComSpec = psPath;
|
||||
process.env['ComSpec'] = psPath;
|
||||
const config = getShellConfiguration();
|
||||
expect(config.executable).toBe(psPath);
|
||||
expect(config.argsPrefix).toEqual(['-NoProfile', '-Command']);
|
||||
@@ -416,7 +416,7 @@ describe('getShellConfiguration', () => {
|
||||
|
||||
it('should return PowerShell configuration if ComSpec points to pwsh.exe', () => {
|
||||
const pwshPath = 'C:\\Program Files\\PowerShell\\7\\pwsh.exe';
|
||||
process.env.ComSpec = pwshPath;
|
||||
process.env['ComSpec'] = pwshPath;
|
||||
const config = getShellConfiguration();
|
||||
expect(config.executable).toBe(pwshPath);
|
||||
expect(config.argsPrefix).toEqual(['-NoProfile', '-Command']);
|
||||
@@ -424,7 +424,7 @@ describe('getShellConfiguration', () => {
|
||||
});
|
||||
|
||||
it('should be case-insensitive when checking ComSpec', () => {
|
||||
process.env.ComSpec = 'C:\\Path\\To\\POWERSHELL.EXE';
|
||||
process.env['ComSpec'] = 'C:\\Path\\To\\POWERSHELL.EXE';
|
||||
const config = getShellConfiguration();
|
||||
expect(config.executable).toBe('C:\\Path\\To\\POWERSHELL.EXE');
|
||||
expect(config.argsPrefix).toEqual(['-NoProfile', '-Command']);
|
||||
|
||||
@@ -37,7 +37,7 @@ export interface ShellConfiguration {
|
||||
*/
|
||||
export function getShellConfiguration(): ShellConfiguration {
|
||||
if (isWindows()) {
|
||||
const comSpec = process.env.ComSpec || 'cmd.exe';
|
||||
const comSpec = process.env['ComSpec'] || 'cmd.exe';
|
||||
const executable = comSpec.toLowerCase();
|
||||
|
||||
if (
|
||||
|
||||
@@ -39,9 +39,9 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
resetEncodingCache();
|
||||
|
||||
// Clear environment variables that might affect tests
|
||||
delete process.env.LC_ALL;
|
||||
delete process.env.LC_CTYPE;
|
||||
delete process.env.LANG;
|
||||
delete process.env['LC_ALL'];
|
||||
delete process.env['LC_CTYPE'];
|
||||
delete process.env['LANG'];
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -218,21 +218,21 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
});
|
||||
|
||||
it('should parse locale from LC_ALL environment variable', () => {
|
||||
process.env.LC_ALL = 'en_US.UTF-8';
|
||||
process.env['LC_ALL'] = 'en_US.UTF-8';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('utf-8');
|
||||
});
|
||||
|
||||
it('should parse locale from LC_CTYPE when LC_ALL is not set', () => {
|
||||
process.env.LC_CTYPE = 'fr_FR.ISO-8859-1';
|
||||
process.env['LC_CTYPE'] = 'fr_FR.ISO-8859-1';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('iso-8859-1');
|
||||
});
|
||||
|
||||
it('should parse locale from LANG when LC_ALL and LC_CTYPE are not set', () => {
|
||||
process.env.LANG = 'de_DE.UTF-8';
|
||||
process.env['LANG'] = 'de_DE.UTF-8';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('utf-8');
|
||||
@@ -268,16 +268,16 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
});
|
||||
|
||||
it('should handle locale without encoding (no dot)', () => {
|
||||
process.env.LANG = 'C';
|
||||
process.env['LANG'] = 'C';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('c');
|
||||
});
|
||||
|
||||
it('should handle empty locale environment variables', () => {
|
||||
process.env.LC_ALL = '';
|
||||
process.env.LC_CTYPE = '';
|
||||
process.env.LANG = '';
|
||||
process.env['LC_ALL'] = '';
|
||||
process.env['LC_CTYPE'] = '';
|
||||
process.env['LANG'] = '';
|
||||
mockedExecSync.mockReturnValue('UTF-8');
|
||||
|
||||
const result = getSystemEncoding();
|
||||
@@ -285,24 +285,24 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
});
|
||||
|
||||
it('should return locale as-is when locale format has no dot', () => {
|
||||
process.env.LANG = 'invalid_format';
|
||||
process.env['LANG'] = 'invalid_format';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('invalid_format');
|
||||
});
|
||||
|
||||
it('should prioritize LC_ALL over other environment variables', () => {
|
||||
process.env.LC_ALL = 'en_US.UTF-8';
|
||||
process.env.LC_CTYPE = 'fr_FR.ISO-8859-1';
|
||||
process.env.LANG = 'de_DE.CP1252';
|
||||
process.env['LC_ALL'] = 'en_US.UTF-8';
|
||||
process.env['LC_CTYPE'] = 'fr_FR.ISO-8859-1';
|
||||
process.env['LANG'] = 'de_DE.CP1252';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('utf-8');
|
||||
});
|
||||
|
||||
it('should prioritize LC_CTYPE over LANG', () => {
|
||||
process.env.LC_CTYPE = 'fr_FR.ISO-8859-1';
|
||||
process.env.LANG = 'de_DE.CP1252';
|
||||
process.env['LC_CTYPE'] = 'fr_FR.ISO-8859-1';
|
||||
process.env['LANG'] = 'de_DE.CP1252';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('iso-8859-1');
|
||||
@@ -315,7 +315,7 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
});
|
||||
|
||||
it('should use cached system encoding on subsequent calls', () => {
|
||||
process.env.LANG = 'en_US.UTF-8';
|
||||
process.env['LANG'] = 'en_US.UTF-8';
|
||||
const buffer = Buffer.from('test');
|
||||
|
||||
// First call
|
||||
@@ -323,7 +323,7 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
expect(result1).toBe('utf-8');
|
||||
|
||||
// Change environment (should not affect cached result)
|
||||
process.env.LANG = 'fr_FR.ISO-8859-1';
|
||||
process.env['LANG'] = 'fr_FR.ISO-8859-1';
|
||||
|
||||
// Second call should use cached value
|
||||
const result2 = getCachedEncodingForBuffer(buffer);
|
||||
@@ -435,7 +435,7 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
describe('Cross-platform behavior', () => {
|
||||
it('should work correctly on macOS', () => {
|
||||
mockedOsPlatform.mockReturnValue('darwin');
|
||||
process.env.LANG = 'en_US.UTF-8';
|
||||
process.env['LANG'] = 'en_US.UTF-8';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('utf-8');
|
||||
@@ -443,7 +443,7 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
|
||||
it('should work correctly on other Unix-like systems', () => {
|
||||
mockedOsPlatform.mockReturnValue('freebsd');
|
||||
process.env.LANG = 'en_US.UTF-8';
|
||||
process.env['LANG'] = 'en_US.UTF-8';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('utf-8');
|
||||
@@ -451,7 +451,7 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
|
||||
it('should handle unknown platforms as Unix-like', () => {
|
||||
mockedOsPlatform.mockReturnValue('unknown' as NodeJS.Platform);
|
||||
process.env.LANG = 'en_US.UTF-8';
|
||||
process.env['LANG'] = 'en_US.UTF-8';
|
||||
|
||||
const result = getSystemEncoding();
|
||||
expect(result).toBe('utf-8');
|
||||
@@ -461,7 +461,7 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
describe('Edge cases and error handling', () => {
|
||||
it('should handle empty buffer gracefully', () => {
|
||||
mockedOsPlatform.mockReturnValue('linux');
|
||||
process.env.LANG = 'en_US.UTF-8';
|
||||
process.env['LANG'] = 'en_US.UTF-8';
|
||||
|
||||
const buffer = Buffer.alloc(0);
|
||||
const result = getCachedEncodingForBuffer(buffer);
|
||||
@@ -470,7 +470,7 @@ describe('Shell Command Processor - Encoding Functions', () => {
|
||||
|
||||
it('should handle very large buffers', () => {
|
||||
mockedOsPlatform.mockReturnValue('linux');
|
||||
process.env.LANG = 'en_US.UTF-8';
|
||||
process.env['LANG'] = 'en_US.UTF-8';
|
||||
|
||||
const buffer = Buffer.alloc(1024 * 1024, 'a');
|
||||
const result = getCachedEncodingForBuffer(buffer);
|
||||
|
||||
@@ -79,7 +79,7 @@ export function getSystemEncoding(): string | null {
|
||||
// system encoding. However, these environment variables might not always
|
||||
// be set or accurate. Handle cases where none of these variables are set.
|
||||
const env = process.env;
|
||||
let locale = env.LC_ALL || env.LC_CTYPE || env.LANG || '';
|
||||
let locale = env['LC_ALL'] || env['LC_CTYPE'] || env['LANG'] || '';
|
||||
|
||||
// Fallback to querying the system directly when environment variables are missing
|
||||
if (!locale) {
|
||||
|
||||
Reference in New Issue
Block a user