summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks
diff options
context:
space:
mode:
authorDaniel Lee <[email protected]>2025-07-24 10:13:00 -0700
committerGitHub <[email protected]>2025-07-24 17:13:00 +0000
commit3dd6e431df057af47b96990d0c9c6477ccfbe452 (patch)
tree8a75c928b0c558d82a5470a504ff57f48002f801 /packages/cli/src/ui/hooks
parent52980510c92deb4af4c9012ae23bd67f169c1a32 (diff)
feat: add GEMINI_CLI environment variable to spawned shell commands (#4791)
Diffstat (limited to 'packages/cli/src/ui/hooks')
-rw-r--r--packages/cli/src/ui/hooks/shellCommandProcessor.test.ts19
-rw-r--r--packages/cli/src/ui/hooks/shellCommandProcessor.ts4
2 files changed, 20 insertions, 3 deletions
diff --git a/packages/cli/src/ui/hooks/shellCommandProcessor.test.ts b/packages/cli/src/ui/hooks/shellCommandProcessor.test.ts
index 5ebf2b1d..1b268502 100644
--- a/packages/cli/src/ui/hooks/shellCommandProcessor.test.ts
+++ b/packages/cli/src/ui/hooks/shellCommandProcessor.test.ts
@@ -6,6 +6,8 @@
import { act, renderHook } from '@testing-library/react';
import { vi } from 'vitest';
+import { spawn } from 'child_process';
+import type { ChildProcessWithoutNullStreams } from 'child_process';
import { useShellCommandProcessor } from './shellCommandProcessor';
import { Config, GeminiClient } from '@google/gemini-cli-core';
import * as fs from 'fs';
@@ -39,12 +41,13 @@ describe('useShellCommandProcessor', () => {
let configMock: Config;
let geminiClientMock: GeminiClient;
- beforeEach(async () => {
- const { spawn } = await import('child_process');
+ beforeEach(() => {
spawnEmitter = new EventEmitter();
spawnEmitter.stdout = new EventEmitter();
spawnEmitter.stderr = new EventEmitter();
- (spawn as vi.Mock).mockReturnValue(spawnEmitter);
+ vi.mocked(spawn).mockReturnValue(
+ spawnEmitter as ChildProcessWithoutNullStreams,
+ );
vi.spyOn(fs, 'existsSync').mockReturnValue(false);
vi.spyOn(fs, 'readFileSync').mockReturnValue('');
@@ -88,6 +91,16 @@ describe('useShellCommandProcessor', () => {
result.current.handleShellCommand('ls -l', abortController.signal);
});
+ expect(spawn).toHaveBeenCalledWith(
+ 'bash',
+ ['-c', expect.any(String)],
+ expect.objectContaining({
+ env: expect.objectContaining({
+ GEMINI_CLI: '1',
+ }),
+ }),
+ );
+
expect(onExecMock).toHaveBeenCalledTimes(1);
const execPromise = onExecMock.mock.calls[0][0];
diff --git a/packages/cli/src/ui/hooks/shellCommandProcessor.ts b/packages/cli/src/ui/hooks/shellCommandProcessor.ts
index 5d2b3166..9e343f90 100644
--- a/packages/cli/src/ui/hooks/shellCommandProcessor.ts
+++ b/packages/cli/src/ui/hooks/shellCommandProcessor.ts
@@ -72,6 +72,10 @@ function executeShellCommand(
cwd,
stdio: ['ignore', 'pipe', 'pipe'],
detached: !isWindows, // Use process groups on non-Windows for robust killing
+ env: {
+ ...process.env,
+ GEMINI_CLI: '1',
+ },
});
// Use decoders to handle multi-byte characters safely (for streaming output).