2025-07-07 16:45:44 -04:00
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
2025-08-04 09:53:50 -07:00
import { describe , it , expect , vi , beforeEach , afterEach } from 'vitest' ;
2025-07-07 16:45:44 -04:00
import { helpCommand } from './helpCommand.js' ;
2026-03-11 23:20:42 +05:30
import { CommandKind , type CommandContext } from './types.js' ;
2025-08-04 09:53:50 -07:00
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js' ;
import { MessageType } from '../types.js' ;
2025-07-07 16:45:44 -04:00
describe ( 'helpCommand' , ( ) = > {
let mockContext : CommandContext ;
2026-06-09 21:00:26 +00:00
const originalPlatform = process . platform ;
const action = helpCommand . action ;
if ( ! action ) {
throw new Error ( 'Help command has no action' ) ;
}
2025-07-07 16:45:44 -04:00
beforeEach ( ( ) = > {
2025-08-04 09:53:50 -07:00
mockContext = createMockCommandContext ( {
ui : {
addItem : vi.fn ( ) ,
} ,
} as unknown as CommandContext ) ;
2025-07-07 16:45:44 -04:00
} ) ;
2025-08-04 09:53:50 -07:00
afterEach ( ( ) = > {
2026-06-09 21:00:26 +00:00
Object . defineProperty ( process , 'platform' , { value : originalPlatform } ) ;
vi . unstubAllEnvs ( ) ;
2025-08-04 09:53:50 -07:00
vi . clearAllMocks ( ) ;
} ) ;
2026-06-09 21:00:26 +00:00
it ( 'should add a help message to the UI history by default' , async ( ) = > {
await action ( mockContext , '' ) ;
2025-08-04 09:53:50 -07:00
expect ( mockContext . ui . addItem ) . toHaveBeenCalledWith (
expect . objectContaining ( {
type : MessageType . HELP ,
timestamp : expect.any ( Date ) ,
} ) ,
) ;
2025-07-07 16:45:44 -04:00
} ) ;
2025-08-04 09:53:50 -07:00
it ( 'should have the correct command properties' , ( ) = > {
expect ( helpCommand . name ) . toBe ( 'help' ) ;
expect ( helpCommand . kind ) . toBe ( CommandKind . BUILT_IN ) ;
2025-10-17 13:20:15 -07:00
expect ( helpCommand . description ) . toBe ( 'For help on gemini-cli' ) ;
2025-07-07 16:45:44 -04:00
} ) ;
2026-06-09 21:00:26 +00:00
describe ( 'Antigravity installer commands help' , ( ) = > {
it ( 'should output macOS installation command on darwin platform' , async ( ) = > {
Object . defineProperty ( process , 'platform' , { value : 'darwin' } ) ;
await action ( mockContext , 'install antigravity cli' ) ;
expect ( mockContext . ui . addItem ) . toHaveBeenCalledWith (
expect . objectContaining ( {
type : MessageType . INFO ,
text : ` To install the Antigravity CLI on macOS, run the following command: \ n \ n'curl -fsSL https://antigravity.google/cli/install.sh | bash' ` ,
} ) ,
) ;
} ) ;
it ( 'should output Linux installation command on linux platform' , async ( ) = > {
Object . defineProperty ( process , 'platform' , { value : 'linux' } ) ;
await action ( mockContext , 'how do I install antigravity CLI' ) ;
expect ( mockContext . ui . addItem ) . toHaveBeenCalledWith (
expect . objectContaining ( {
type : MessageType . INFO ,
text : ` To install the Antigravity CLI on Linux, run the following command: \ n \ n'curl -fsSL https://antigravity.google/cli/install.sh | bash' ` ,
} ) ,
) ;
} ) ;
it ( 'should output Windows PowerShell installation command on win32 when PSModulePath is set' , async ( ) = > {
Object . defineProperty ( process , 'platform' , { value : 'win32' } ) ;
vi . stubEnv ( 'PSModulePath' , 'C:\\some\\path' ) ;
await action ( mockContext , 'how do I migrate to antigravity CLI' ) ;
expect ( mockContext . ui . addItem ) . toHaveBeenCalledWith (
expect . objectContaining ( {
type : MessageType . INFO ,
text : ` To install the Antigravity CLI on Windows (PowerShell), run the following command: \ n \ n'irm https://antigravity.google/cli/install.ps1 | iex' ` ,
} ) ,
) ;
} ) ;
it ( 'should output Windows CMD installation command on win32 when PSModulePath is not set' , async ( ) = > {
Object . defineProperty ( process , 'platform' , { value : 'win32' } ) ;
vi . stubEnv ( 'PSModulePath' , '' ) ;
await action ( mockContext , 'install antigravity cli' ) ;
expect ( mockContext . ui . addItem ) . toHaveBeenCalledWith (
expect . objectContaining ( {
type : MessageType . INFO ,
text : ` To install the Antigravity CLI on Windows (Command Prompt), run the following command: \ n \ n'curl -fsSL https://antigravity.google/cli/install.cmd -o install.cmd && install.cmd && del install.cmd' ` ,
} ) ,
) ;
} ) ;
it ( 'should learn more message on unsupported platform' , async ( ) = > {
Object . defineProperty ( process , 'platform' , { value : 'freebsd' } ) ;
await action ( mockContext , 'install antigravity cli' ) ;
expect ( mockContext . ui . addItem ) . toHaveBeenCalledWith (
expect . objectContaining ( {
type : MessageType . INFO ,
text : 'Learn more about Antigravity CLI at https://antigravity.google/docs/cli-getting-started' ,
} ) ,
) ;
} ) ;
it ( 'should fall back to default help if query does not contain install or migrate' , async ( ) = > {
Object . defineProperty ( process , 'platform' , { value : 'darwin' } ) ;
await action ( mockContext , 'antigravity cli' ) ;
expect ( mockContext . ui . addItem ) . toHaveBeenCalledWith (
expect . objectContaining ( {
type : MessageType . HELP ,
} ) ,
) ;
} ) ;
} ) ;
2025-07-07 16:45:44 -04:00
} ) ;