-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathbugCommand.test.ts
More file actions
208 lines (190 loc) · 6.39 KB
/
Copy pathbugCommand.test.ts
File metadata and controls
208 lines (190 loc) · 6.39 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { bugCommand } from './bugCommand.js';
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
import { AuthType } from '@qwen-code/qwen-code-core';
import * as systemInfoUtils from '../../utils/systemInfo.js';
const mockOpenBrowserSecurely = vi.hoisted(() => vi.fn());
// Mock dependencies
vi.mock('@qwen-code/qwen-code-core', async (importOriginal) => {
const actual =
await importOriginal<typeof import('@qwen-code/qwen-code-core')>();
return {
...actual,
openBrowserSecurely: mockOpenBrowserSecurely,
};
});
vi.mock('../../utils/systemInfo.js');
describe('bugCommand', () => {
beforeEach(() => {
vi.mocked(systemInfoUtils.getExtendedSystemInfo).mockResolvedValue({
cliVersion: '0.1.0',
osPlatform: 'test-platform',
osArch: 'x64',
osRelease: '22.0.0',
nodeVersion: 'v20.0.0',
npmVersion: '10.0.0',
sandboxEnv: 'test',
modelVersion: 'qwen3-coder-plus',
selectedAuthType: '',
ideClient: 'VSCode',
sessionId: 'test-session-id',
memoryUsage: '100 MB',
gitCommit:
GIT_COMMIT_INFO && !['N/A'].includes(GIT_COMMIT_INFO)
? GIT_COMMIT_INFO
: undefined,
});
mockOpenBrowserSecurely.mockClear();
mockOpenBrowserSecurely.mockResolvedValue(undefined);
vi.stubEnv('SANDBOX', 'qwen-test');
});
afterEach(() => {
vi.unstubAllEnvs();
vi.clearAllMocks();
});
it('should generate the default GitHub issue URL', async () => {
const mockContext = createMockCommandContext({
services: {
config: {
getBugCommand: () => undefined,
},
},
});
if (!bugCommand.action) throw new Error('Action is not defined');
await bugCommand.action(mockContext, 'A test bug');
const qwenCodeLine =
GIT_COMMIT_INFO && !['N/A'].includes(GIT_COMMIT_INFO)
? `Qwen Code: 0.1.0 (${GIT_COMMIT_INFO})`
: 'Qwen Code: 0.1.0';
const expectedInfo = `${qwenCodeLine}
Runtime: Node.js v20.0.0 / npm 10.0.0
IDE Client: VSCode
OS: test-platform x64 (22.0.0)
Model: qwen3-coder-plus
Fast Model: qwen3-coder-plus
Session ID: test-session-id
Sandbox: test
Proxy: no proxy
Memory Usage: 100 MB`;
const expectedUrl =
'https://github.com/QwenLM/qwen-code/issues/new?template=bug_report.yml&title=A%20test%20bug&info=%0A' +
encodeURIComponent(expectedInfo) +
'%0A';
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{
type: 'info',
text: 'To submit your bug report, please open the following URL in your browser:',
linkUrl: expectedUrl,
linkText: 'Open GitHub bug report form',
},
expect.any(Number),
);
expect(mockOpenBrowserSecurely).toHaveBeenCalledWith(expectedUrl);
});
it('should use a custom URL template from config if provided', async () => {
const customTemplate =
'https://internal.bug-tracker.com/new?desc={title}&details={info}';
const mockContext = createMockCommandContext({
services: {
config: {
getBugCommand: () => ({ urlTemplate: customTemplate }),
},
},
});
if (!bugCommand.action) throw new Error('Action is not defined');
await bugCommand.action(mockContext, 'A custom bug');
const qwenCodeLine =
GIT_COMMIT_INFO && !['N/A'].includes(GIT_COMMIT_INFO)
? `Qwen Code: 0.1.0 (${GIT_COMMIT_INFO})`
: 'Qwen Code: 0.1.0';
const expectedInfo = `${qwenCodeLine}
Runtime: Node.js v20.0.0 / npm 10.0.0
IDE Client: VSCode
OS: test-platform x64 (22.0.0)
Model: qwen3-coder-plus
Fast Model: qwen3-coder-plus
Session ID: test-session-id
Sandbox: test
Proxy: no proxy
Memory Usage: 100 MB`;
const expectedUrl = customTemplate
.replace('{title}', encodeURIComponent('A custom bug'))
.replace('{info}', encodeURIComponent(`\n${expectedInfo}\n`));
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{
type: 'info',
text: 'To submit your bug report, please open the following URL in your browser:',
linkUrl: expectedUrl,
linkText: 'Open GitHub bug report form',
},
expect.any(Number),
);
expect(mockOpenBrowserSecurely).toHaveBeenCalledWith(expectedUrl);
});
it('should include Base URL when auth type is OpenAI', async () => {
vi.mocked(systemInfoUtils.getExtendedSystemInfo).mockResolvedValue({
cliVersion: '0.1.0',
osPlatform: 'test-platform',
osArch: 'x64',
osRelease: '22.0.0',
nodeVersion: 'v20.0.0',
npmVersion: '10.0.0',
sandboxEnv: 'test',
modelVersion: 'qwen3-coder-plus',
selectedAuthType: AuthType.USE_OPENAI,
ideClient: 'VSCode',
sessionId: 'test-session-id',
memoryUsage: '100 MB',
baseUrl: 'https://api.openai.com/v1',
gitCommit:
GIT_COMMIT_INFO && !['N/A'].includes(GIT_COMMIT_INFO)
? GIT_COMMIT_INFO
: undefined,
});
const mockContext = createMockCommandContext({
services: {
config: {
getBugCommand: () => undefined,
},
},
});
if (!bugCommand.action) throw new Error('Action is not defined');
await bugCommand.action(mockContext, 'OpenAI bug');
const qwenCodeLine =
GIT_COMMIT_INFO && !['N/A'].includes(GIT_COMMIT_INFO)
? `Qwen Code: 0.1.0 (${GIT_COMMIT_INFO})`
: 'Qwen Code: 0.1.0';
const expectedInfo = `${qwenCodeLine}
Runtime: Node.js v20.0.0 / npm 10.0.0
IDE Client: VSCode
OS: test-platform x64 (22.0.0)
Auth: API Key - ${AuthType.USE_OPENAI}
Base URL: https://api.openai.com/v1
Model: qwen3-coder-plus
Fast Model: qwen3-coder-plus
Session ID: test-session-id
Sandbox: test
Proxy: no proxy
Memory Usage: 100 MB`;
const expectedUrl =
'https://github.com/QwenLM/qwen-code/issues/new?template=bug_report.yml&title=OpenAI%20bug&info=%0A' +
encodeURIComponent(expectedInfo) +
'%0A';
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{
type: 'info',
text: 'To submit your bug report, please open the following URL in your browser:',
linkUrl: expectedUrl,
linkText: 'Open GitHub bug report form',
},
expect.any(Number),
);
expect(mockOpenBrowserSecurely).toHaveBeenCalledWith(expectedUrl);
});
});