Skip to content

Commit 52aac82

Browse files
committed
Fix for incorrect tmux detection logic.
1 parent 8ac560d commit 52aac82

2 files changed

Lines changed: 77 additions & 24 deletions

File tree

packages/cli/src/gemini.test.tsx

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ import {
5151
import { act } from 'react';
5252
import { type InitializationResult } from './core/initializer.js';
5353
import { runNonInteractive } from './nonInteractiveCli.js';
54+
import * as userStartupWarningsModule from './utils/userStartupWarnings.js';
55+
5456
// Hoisted constants and mocks
5557
const performance = vi.hoisted(() => ({
5658
now: vi.fn(),
@@ -645,13 +647,11 @@ describe('gemini.tsx main function kitty protocol', () => {
645647
.spyOn(debugLogger, 'log')
646648
.mockImplementation(() => {});
647649

648-
process.env['GEMINI_API_KEY'] = 'test-key';
650+
vi.stubEnv('GEMINI_API_KEY', 'test-key');
649651
try {
650652
await main();
651653
} catch (e) {
652654
if (!(e instanceof MockProcessExitError)) throw e;
653-
} finally {
654-
delete process.env['GEMINI_API_KEY'];
655655
}
656656

657657
if (flag === 'listExtensions') {
@@ -710,13 +710,11 @@ describe('gemini.tsx main function kitty protocol', () => {
710710
}),
711711
);
712712

713-
process.env['GEMINI_API_KEY'] = 'test-key';
713+
vi.stubEnv('GEMINI_API_KEY', 'test-key');
714714
try {
715715
await main();
716716
} catch (e) {
717717
if (!(e instanceof MockProcessExitError)) throw e;
718-
} finally {
719-
delete process.env['GEMINI_API_KEY'];
720718
}
721719

722720
expect(start_sandbox).toHaveBeenCalled();
@@ -764,13 +762,11 @@ describe('gemini.tsx main function kitty protocol', () => {
764762

765763
vi.spyOn(themeManager, 'setActiveTheme').mockReturnValue(false);
766764

767-
process.env['GEMINI_API_KEY'] = 'test-key';
765+
vi.stubEnv('GEMINI_API_KEY', 'test-key');
768766
try {
769767
await main();
770768
} catch (e) {
771769
if (!(e instanceof MockProcessExitError)) throw e;
772-
} finally {
773-
delete process.env['GEMINI_API_KEY'];
774770
}
775771

776772
expect(debugLoggerWarnSpy).toHaveBeenCalledWith(
@@ -989,13 +985,11 @@ describe('gemini.tsx main function kitty protocol', () => {
989985
// eslint-disable-next-line @typescript-eslint/no-explicit-any
990986
(process.stdin as any).isTTY = false;
991987

992-
process.env['GEMINI_API_KEY'] = 'test-key';
988+
vi.stubEnv('GEMINI_API_KEY', 'test-key');
993989
try {
994990
await main();
995991
} catch (e) {
996992
if (!(e instanceof MockProcessExitError)) throw e;
997-
} finally {
998-
delete process.env['GEMINI_API_KEY'];
999993
}
1000994

1001995
expect(readStdinSpy).toHaveBeenCalled();
@@ -1012,6 +1006,71 @@ describe('gemini.tsx main function kitty protocol', () => {
10121006
expect(processExitSpy).toHaveBeenCalledWith(0);
10131007
processExitSpy.mockRestore();
10141008
});
1009+
1010+
it.each([
1011+
{
1012+
useAlternateBuffer: false,
1013+
description:
1014+
'false when useAlternateBuffer is false (even if terminal buffer is true)',
1015+
},
1016+
{
1017+
useAlternateBuffer: true,
1018+
description: 'true when useAlternateBuffer is true',
1019+
},
1020+
])(
1021+
'should use getUseAlternateBuffer to evaluate isAlternateBuffer for startup warnings: $description',
1022+
async ({ useAlternateBuffer }) => {
1023+
const getUserStartupWarningsSpy = vi
1024+
.spyOn(userStartupWarningsModule, 'getUserStartupWarnings')
1025+
.mockResolvedValue([]);
1026+
1027+
vi.mocked(parseArguments).mockResolvedValue({
1028+
enabled: true,
1029+
allowedPaths: [],
1030+
networkAccess: false,
1031+
promptInteractive: false,
1032+
} as unknown as CliArgs);
1033+
1034+
vi.mocked(loadSettings).mockReturnValue(
1035+
createMockSettings({
1036+
merged: {
1037+
advanced: {},
1038+
security: { auth: {} },
1039+
ui: {},
1040+
},
1041+
workspace: { settings: {} },
1042+
setValue: vi.fn(),
1043+
forScope: () => ({ settings: {}, originalSettings: {}, path: '' }),
1044+
}),
1045+
);
1046+
1047+
const mockConfig = createMockConfig({
1048+
isInteractive: () => true,
1049+
getQuestion: () => '',
1050+
getSandbox: () => undefined,
1051+
getUseAlternateBuffer: () => useAlternateBuffer,
1052+
getUseTerminalBuffer: () => true, // Ensure we differentiate from isAlternateBufferEnabled
1053+
getScreenReader: () => false,
1054+
});
1055+
1056+
vi.mocked(loadCliConfig).mockResolvedValue(mockConfig);
1057+
1058+
vi.stubEnv('GEMINI_API_KEY', 'test-key');
1059+
try {
1060+
await main();
1061+
} catch (e) {
1062+
if (!(e instanceof MockProcessExitError)) throw e;
1063+
}
1064+
1065+
expect(getUserStartupWarningsSpy).toHaveBeenCalledWith(
1066+
expect.anything(),
1067+
undefined,
1068+
expect.objectContaining({ isAlternateBuffer: useAlternateBuffer }),
1069+
);
1070+
1071+
getUserStartupWarningsSpy.mockRestore();
1072+
},
1073+
);
10151074
});
10161075

10171076
describe('gemini.tsx main function exit codes', () => {
@@ -1132,15 +1191,13 @@ describe('gemini.tsx main function exit codes', () => {
11321191
};
11331192
});
11341193

1135-
process.env['GEMINI_API_KEY'] = 'test-key';
1194+
vi.stubEnv('GEMINI_API_KEY', 'test-key');
11361195
try {
11371196
await main();
11381197
expect.fail('Should have thrown MockProcessExitError');
11391198
} catch (e) {
11401199
expect(e).toBeInstanceOf(MockProcessExitError);
11411200
expect((e as MockProcessExitError).code).toBe(42);
1142-
} finally {
1143-
delete process.env['GEMINI_API_KEY'];
11441201
}
11451202
});
11461203

@@ -1165,15 +1222,13 @@ describe('gemini.tsx main function exit codes', () => {
11651222
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11661223
(process.stdin as any).isTTY = true;
11671224

1168-
process.env['GEMINI_API_KEY'] = 'test-key';
1225+
vi.stubEnv('GEMINI_API_KEY', 'test-key');
11691226
try {
11701227
await main();
11711228
expect.fail('Should have thrown MockProcessExitError');
11721229
} catch (e) {
11731230
expect(e).toBeInstanceOf(MockProcessExitError);
11741231
expect((e as MockProcessExitError).code).toBe(42);
1175-
} finally {
1176-
delete process.env['GEMINI_API_KEY'];
11771232
}
11781233
});
11791234

@@ -1210,13 +1265,12 @@ describe('gemini.tsx main function exit codes', () => {
12101265
throw new MockProcessExitError(code);
12111266
});
12121267

1213-
process.env['GEMINI_API_KEY'] = 'test-key';
1268+
vi.stubEnv('GEMINI_API_KEY', 'test-key');
12141269
try {
12151270
await main();
12161271
} catch (e) {
12171272
if (!(e instanceof MockProcessExitError)) throw e;
12181273
} finally {
1219-
delete process.env['GEMINI_API_KEY'];
12201274
processExitSpy.mockRestore();
12211275
}
12221276

packages/cli/src/gemini.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ import {
8787
import { loadSandboxConfig } from './config/sandboxConfig.js';
8888
import { deleteSession, listSessions } from './utils/sessions.js';
8989
import { createPolicyUpdater } from './config/policy.js';
90-
import { isAlternateBufferEnabled } from './ui/hooks/useAlternateBuffer.js';
9190

9291
import { setupTerminalAndTheme } from './utils/terminalTheme.js';
9392
import { runDeferredCommand } from './deferred.js';
@@ -562,8 +561,8 @@ export async function main() {
562561
}
563562

564563
let input = config.getQuestion();
565-
const useAlternateBuffer = shouldEnterAlternateScreen(
566-
isAlternateBufferEnabled(config),
564+
const isRealAlternateBuffer = shouldEnterAlternateScreen(
565+
config.getUseAlternateBuffer(),
567566
config.getScreenReader(),
568567
);
569568
const rawStartupWarnings = await rawStartupWarningsPromise;
@@ -574,7 +573,7 @@ export async function main() {
574573
priority: WarningPriority.High,
575574
})),
576575
...(await getUserStartupWarnings(settings.merged, undefined, {
577-
isAlternateBuffer: useAlternateBuffer,
576+
isAlternateBuffer: isRealAlternateBuffer,
578577
})),
579578
];
580579

0 commit comments

Comments
 (0)