44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7- import { describe , it , expect , vi , beforeEach , afterEach } from 'vitest' ;
87import {
8+ describe ,
9+ it ,
10+ expect ,
11+ vi ,
12+ beforeEach ,
13+ afterEach ,
14+ type MockInstance ,
15+ } from 'vitest' ;
16+ import {
17+ main ,
918 setupUnhandledRejectionHandler ,
1019 validateDnsResolutionOrder ,
1120 startInteractiveUI ,
@@ -33,14 +42,10 @@ vi.mock('./config/settings.js', async (importOriginal) => {
3342
3443vi . mock ( './config/config.js' , ( ) => ( {
3544 loadCliConfig : vi . fn ( ) . mockResolvedValue ( {
36- config : {
37- getSandbox : vi . fn ( ( ) => false ) ,
38- getQuestion : vi . fn ( ( ) => '' ) ,
39- } ,
40- modelWasSwitched : false ,
41- originalModelBeforeSwitch : null ,
42- finalModel : 'test-model' ,
43- } ) ,
45+ getSandbox : vi . fn ( ( ) => false ) ,
46+ getQuestion : vi . fn ( ( ) => '' ) ,
47+ } as unknown as Config ) ,
48+ parseArguments : vi . fn ( ) . mockResolvedValue ( { sessionSummary : null } ) ,
4449} ) ) ;
4550
4651vi . mock ( 'read-package-up' , ( ) => ( {
@@ -157,6 +162,87 @@ describe('gemini.tsx main function', () => {
157162 } ) ;
158163} ) ;
159164
165+ describe ( 'gemini.tsx main function kitty protocol' , ( ) => {
166+ let setRawModeSpy : MockInstance <
167+ ( mode : boolean ) => NodeJS . ReadStream & { fd : 0 }
168+ > ;
169+
170+ beforeEach ( ( ) => {
171+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
172+ if ( ! ( process . stdin as any ) . setRawMode ) {
173+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
174+ ( process . stdin as any ) . setRawMode = vi . fn ( ) ;
175+ }
176+ setRawModeSpy = vi . spyOn ( process . stdin , 'setRawMode' ) ;
177+ } ) ;
178+
179+ it ( 'should call setRawMode and detectAndEnableKittyProtocol when isInteractive is true' , async ( ) => {
180+ const { detectAndEnableKittyProtocol } = await import (
181+ './ui/utils/kittyProtocolDetector.js'
182+ ) ;
183+ const { loadCliConfig, parseArguments } = await import (
184+ './config/config.js'
185+ ) ;
186+ const { loadSettings } = await import ( './config/settings.js' ) ;
187+ vi . mocked ( loadCliConfig ) . mockResolvedValue ( {
188+ isInteractive : ( ) => true ,
189+ getQuestion : ( ) => '' ,
190+ getSandbox : ( ) => false ,
191+ getDebugMode : ( ) => false ,
192+ getListExtensions : ( ) => false ,
193+ getMcpServers : ( ) => ( { } ) ,
194+ initialize : vi . fn ( ) ,
195+ getIdeMode : ( ) => false ,
196+ getExperimentalZedIntegration : ( ) => false ,
197+ getScreenReader : ( ) => false ,
198+ } as unknown as Config ) ;
199+ vi . mocked ( loadSettings ) . mockReturnValue ( {
200+ errors : [ ] ,
201+ merged : {
202+ advanced : { } ,
203+ security : { auth : { } } ,
204+ ui : { } ,
205+ } ,
206+ setValue : vi . fn ( ) ,
207+ } as never ) ;
208+ vi . mocked ( parseArguments ) . mockResolvedValue ( {
209+ model : undefined ,
210+ sandbox : undefined ,
211+ sandboxImage : undefined ,
212+ debug : undefined ,
213+ prompt : undefined ,
214+ promptInteractive : undefined ,
215+ allFiles : undefined ,
216+ showMemoryUsage : undefined ,
217+ yolo : undefined ,
218+ approvalMode : undefined ,
219+ telemetry : undefined ,
220+ checkpointing : undefined ,
221+ telemetryTarget : undefined ,
222+ telemetryOtlpEndpoint : undefined ,
223+ telemetryOtlpProtocol : undefined ,
224+ telemetryLogPrompts : undefined ,
225+ telemetryOutfile : undefined ,
226+ allowedMcpServerNames : undefined ,
227+ allowedTools : undefined ,
228+ experimentalAcp : undefined ,
229+ extensions : undefined ,
230+ listExtensions : undefined ,
231+ proxy : undefined ,
232+ includeDirectories : undefined ,
233+ screenReader : undefined ,
234+ useSmartEdit : undefined ,
235+ sessionSummary : undefined ,
236+ promptWords : undefined ,
237+ } ) ;
238+
239+ await main ( ) ;
240+
241+ expect ( setRawModeSpy ) . toHaveBeenCalledWith ( true ) ;
242+ expect ( detectAndEnableKittyProtocol ) . toHaveBeenCalledTimes ( 1 ) ;
243+ } ) ;
244+ } ) ;
245+
160246describe ( 'validateDnsResolutionOrder' , ( ) => {
161247 let consoleWarnSpy : ReturnType < typeof vi . spyOn > ;
162248
@@ -213,7 +299,7 @@ describe('startInteractiveUI', () => {
213299 } ) ) ;
214300
215301 vi . mock ( './ui/utils/kittyProtocolDetector.js' , ( ) => ( {
216- detectAndEnableKittyProtocol : vi . fn ( ( ) => Promise . resolve ( ) ) ,
302+ detectAndEnableKittyProtocol : vi . fn ( ( ) => Promise . resolve ( true ) ) ,
217303 } ) ) ;
218304
219305 vi . mock ( './ui/utils/updateCheck.js' , ( ) => ( {
@@ -260,9 +346,6 @@ describe('startInteractiveUI', () => {
260346
261347 it ( 'should perform all startup tasks in correct order' , async ( ) => {
262348 const { getCliVersion } = await import ( './utils/version.js' ) ;
263- const { detectAndEnableKittyProtocol } = await import (
264- './ui/utils/kittyProtocolDetector.js'
265- ) ;
266349 const { checkForUpdates } = await import ( './ui/utils/updateCheck.js' ) ;
267350 const { registerCleanup } = await import ( './utils/cleanup.js' ) ;
268351
@@ -275,7 +358,6 @@ describe('startInteractiveUI', () => {
275358
276359 // Verify all startup tasks were called
277360 expect ( getCliVersion ) . toHaveBeenCalledTimes ( 1 ) ;
278- expect ( detectAndEnableKittyProtocol ) . toHaveBeenCalledTimes ( 1 ) ;
279361 expect ( registerCleanup ) . toHaveBeenCalledTimes ( 1 ) ;
280362
281363 // Verify cleanup handler is registered with unmount function
0 commit comments