-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Expand file tree
/
Copy pathhelpCommand.test.ts
More file actions
133 lines (107 loc) · 4.61 KB
/
Copy pathhelpCommand.test.ts
File metadata and controls
133 lines (107 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { helpCommand } from './helpCommand.js';
import { CommandKind, type CommandContext } from './types.js';
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
import { MessageType } from '../types.js';
describe('helpCommand', () => {
let mockContext: CommandContext;
const originalPlatform = process.platform;
const action = helpCommand.action;
if (!action) {
throw new Error('Help command has no action');
}
beforeEach(() => {
mockContext = createMockCommandContext({
ui: {
addItem: vi.fn(),
},
} as unknown as CommandContext);
});
afterEach(() => {
Object.defineProperty(process, 'platform', { value: originalPlatform });
vi.unstubAllEnvs();
vi.clearAllMocks();
});
it('should add a help message to the UI history by default', async () => {
await action(mockContext, '');
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({
type: MessageType.HELP,
timestamp: expect.any(Date),
}),
);
});
it('should have the correct command properties', () => {
expect(helpCommand.name).toBe('help');
expect(helpCommand.kind).toBe(CommandKind.BUILT_IN);
expect(helpCommand.description).toBe('For help on gemini-cli');
});
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,
}),
);
});
});
});