Skip to content

Commit 193b72e

Browse files
committed
test updates
1 parent 42b36d0 commit 193b72e

File tree

2 files changed

+35
-50
lines changed

2 files changed

+35
-50
lines changed

src/features/copilotTools.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,20 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
132132

133133
function BuildEnvironmentInfoContent(envInfo: EnvironmentInfo): LanguageModelTextPart {
134134
// Create a formatted string that looks like JSON but preserves comments
135-
let envTypeStr: string = `This environment is managed by ${envInfo.type} environment manager. Use the install tool to install packages into this environment.`;
135+
let envTypeDescriptor: string = `This environment is managed by ${envInfo.type} environment manager. Use the install tool to install packages into this environment.`;
136136

137137
if (envInfo.type === 'system') {
138-
envTypeStr =
139-
'System pythons are pythons that ship with the OS or are installed globally. These python installs may be used by the OS for running services and core functionality. Confirm with the user before installing packages into this environment, as it can lead to issues with any services on the OS';
138+
envTypeDescriptor =
139+
'System pythons are pythons that ship with the OS or are installed globally. These python installs may be used by the OS for running services and core functionality. Confirm with the user before installing packages into this environment, as it can lead to issues with any services on the OS.';
140140
}
141141
const content = `{
142-
"environmentType": ${JSON.stringify(envTypeStr)},
143-
// python version of the environment
142+
// ${JSON.stringify(envTypeDescriptor)}
143+
"environmentType": ${JSON.stringify(envInfo.type)},
144+
// Python version of the environment
144145
"pythonVersion": ${JSON.stringify(envInfo.version)},
145-
// Use this command to run python script or code in the terminal.
146+
// Use this command to run Python script or code in the terminal.
146147
"runCommand": ${JSON.stringify(envInfo.runCommand)},
147-
// installed python packages and their versions if know in the format <name> (<version>), empty array is returned if no packages are installed.
148+
// Installed Python packages, each in the format <name> or <name> (<version>). The version may be omitted if unknown. Returns an empty array if no packages are installed.
148149
"packages": ${JSON.stringify(Array.isArray(envInfo.packages) ? envInfo.packages : envInfo.packages, null, 2)}
149150
}`;
150151

src/test/copilotTools.unit.test.ts

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ suite('InstallPackageTool Tests', () => {
186186
const content = result.content as vscode.LanguageModelTextPart[];
187187
const firstPart = content[0] as vscode.MarkdownString;
188188

189-
console.log('result', firstPart.value);
190189
assert.strictEqual(
191190
firstPart.value.includes('An error occurred while installing packages'),
192191
true,
@@ -243,7 +242,7 @@ suite('GetEnvironmentInfoTool Tests', () => {
243242
let mockApi: typeMoq.IMock<PythonProjectEnvironmentApi & PythonPackageGetterApi & PythonPackageManagementApi>;
244243
let mockEnvironment: typeMoq.IMock<PythonEnvironment>;
245244
let em: typeMoq.IMock<EnvironmentManagers>;
246-
let manager: typeMoq.IMock<InternalEnvironmentManager>;
245+
let managerSys: typeMoq.IMock<InternalEnvironmentManager>;
247246

248247
setup(() => {
249248
// Create mock functions
@@ -255,42 +254,11 @@ suite('GetEnvironmentInfoTool Tests', () => {
255254
// eslint-disable-next-line @typescript-eslint/no-explicit-any
256255
mockEnvironment.setup((x: any) => x.then).returns(() => undefined);
257256

258-
// Create an instance of GetEnvironmentInfoTool with the mock functions
259-
manager = typeMoq.Mock.ofType<InternalEnvironmentManager>();
260-
manager.setup((m) => m.id).returns(() => 'ms-python.python:venv');
261-
manager.setup((m) => m.name).returns(() => 'venv');
262-
manager.setup((m) => m.displayName).returns(() => 'Test Manager');
263-
264257
em = typeMoq.Mock.ofType<EnvironmentManagers>();
265-
em.setup((e) => e.managers).returns(() => [manager.object]);
266-
em.setup((e) => e.getEnvironmentManager(typeMoq.It.isAnyString())).returns(() => manager.object);
258+
em.setup((e) => e.managers).returns(() => [managerSys.object]);
259+
em.setup((e) => e.getEnvironmentManager(typeMoq.It.isAnyString())).returns(() => managerSys.object);
267260

268261
getEnvironmentInfoTool = new GetEnvironmentInfoTool(mockApi.object, em.object);
269-
270-
// runConfig valid / not valid
271-
// const runConfigValid: PythonCommandRunConfiguration = {
272-
// executable: 'conda',
273-
// args: ['run', '-n', 'env_name', 'python'],
274-
// };
275-
// const runConfigValidString = 'conda run -n env_name python';
276-
// const runConfigNoArgs: PythonCommandRunConfiguration = {
277-
// executable: '.venv/bin/python',
278-
// args: [],
279-
// };
280-
// const runConfigNoArgsString = '.venv/bin/python';
281-
282-
// // managerId valid / not valid
283-
// const managerIdValid = `'ms-python.python:venv'`;
284-
// const typeValidString = 'venv';
285-
// const managerIdInvalid = `vscode-python, there is no such manager`;
286-
287-
// // environment valid
288-
// const envInfoVersion = '3.9.1';
289-
290-
// //package valid / not valid
291-
// const installedPackagesValid = [{ name: 'package1', version: '1.0.0' }, { name: 'package2' }];
292-
// const installedPackagesValidString = 'package1 1.0.0\npackage2 2.0.0';
293-
// const installedPackagesInvalid = undefined;
294262
});
295263

296264
teardown(() => {
@@ -324,11 +292,19 @@ suite('GetEnvironmentInfoTool Tests', () => {
324292
assert.strictEqual(firstPart.value.includes('An error occurred while fetching environment information'), true);
325293
});
326294
test('should return successful with environment info', async () => {
295+
// Create an instance of GetEnvironmentInfoTool with the mock functions
296+
managerSys = typeMoq.Mock.ofType<InternalEnvironmentManager>();
297+
managerSys.setup((m) => m.id).returns(() => 'ms-python.python:venv');
298+
managerSys.setup((m) => m.name).returns(() => 'venv');
299+
managerSys.setup((m) => m.displayName).returns(() => 'Test Manager');
300+
301+
em = typeMoq.Mock.ofType<EnvironmentManagers>();
302+
em.setup((e) => e.managers).returns(() => [managerSys.object]);
303+
em.setup((e) => e.getEnvironmentManager(typeMoq.It.isAnyString())).returns(() => managerSys.object);
327304
// create mock of PythonEnvironment
328305
const mockEnvironmentSuccess = typeMoq.Mock.ofType<PythonEnvironment>();
329-
// mockEnvironment = typeMoq.Mock.ofType<PythonEnvironment>();
330306

331-
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
307+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
332308
mockEnvironmentSuccess.setup((x: any) => x.then).returns(() => undefined);
333309
mockEnvironmentSuccess.setup((x) => x.version).returns(() => '3.9.1');
334310
const mockEnvId = typeMoq.Mock.ofType<PythonEnvironmentId>();
@@ -378,7 +354,6 @@ suite('GetEnvironmentInfoTool Tests', () => {
378354
// assert
379355
const content = result.content as vscode.LanguageModelTextPart[];
380356
const firstPart = content[0] as vscode.MarkdownString;
381-
console.log('result', firstPart.value);
382357
assert.strictEqual(firstPart.value.includes('3.9.1'), true);
383358
assert.strictEqual(firstPart.value.includes('package1 (1.0.0)'), true);
384359
assert.strictEqual(firstPart.value.includes('package2 (2.0.0)'), true);
@@ -388,14 +363,24 @@ suite('GetEnvironmentInfoTool Tests', () => {
388363
test('should return successful with weird environment info', async () => {
389364
// create mock of PythonEnvironment
390365
const mockEnvironmentSuccess = typeMoq.Mock.ofType<PythonEnvironment>();
391-
// mockEnvironment = typeMoq.Mock.ofType<PythonEnvironment>();
392366

393-
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
367+
// Create an instance of GetEnvironmentInfoTool with the mock functions
368+
let managerSys = typeMoq.Mock.ofType<InternalEnvironmentManager>();
369+
managerSys.setup((m) => m.id).returns(() => 'ms-python.python:system');
370+
managerSys.setup((m) => m.name).returns(() => 'system');
371+
managerSys.setup((m) => m.displayName).returns(() => 'Test Manager');
372+
373+
let emSys = typeMoq.Mock.ofType<EnvironmentManagers>();
374+
emSys.setup((e) => e.managers).returns(() => [managerSys.object]);
375+
emSys.setup((e) => e.getEnvironmentManager(typeMoq.It.isAnyString())).returns(() => managerSys.object);
376+
getEnvironmentInfoTool = new GetEnvironmentInfoTool(mockApi.object, emSys.object);
377+
378+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
394379
mockEnvironmentSuccess.setup((x: any) => x.then).returns(() => undefined);
395380
mockEnvironmentSuccess.setup((x) => x.version).returns(() => '3.12.1');
396381
const mockEnvId = typeMoq.Mock.ofType<PythonEnvironmentId>();
397382
mockEnvId.setup((x) => x.managerId).returns(() => 'ms-python.python:system');
398-
manager.setup((m) => m.name).returns(() => 'system');
383+
managerSys.setup((m) => m.name).returns(() => 'system');
399384
mockEnvironmentSuccess.setup((x) => x.envId).returns(() => mockEnvId.object);
400385
mockEnvironmentSuccess
401386
.setup((x) => x.execInfo)
@@ -429,10 +414,9 @@ suite('GetEnvironmentInfoTool Tests', () => {
429414
// assert
430415
const content = result.content as vscode.LanguageModelTextPart[];
431416
const firstPart = content[0] as vscode.MarkdownString;
432-
console.log('result', firstPart.value);
433417
assert.strictEqual(firstPart.value.includes('3.12.1'), true);
434418
assert.strictEqual(firstPart.value.includes('"packages": []'), true);
435419
assert.strictEqual(firstPart.value.includes(`"path/to/venv/bin/python"`), true);
436-
assert.strictEqual(firstPart.value.includes('sys'), true);
420+
assert.strictEqual(firstPart.value.includes('system'), true);
437421
});
438422
});

0 commit comments

Comments
 (0)