Skip to content

Commit e2b9037

Browse files
authored
Ensure file paths are not sent in telemetry when running unit tests (#1197)
* 🐛 1st arg of command handlers is {} or Uri based on how invoked * 📝 change log * Fixes #1180
1 parent 3626de2 commit e2b9037

File tree

5 files changed

+38
-39
lines changed

5 files changed

+38
-39
lines changed

news/3 Code Health/1180.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure file paths are not sent in telemetry when running unit tests.

src/client/unittests/codeLenses/testFiles.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

3-
import { CancellationToken, CancellationTokenSource, CodeLens, CodeLensProvider, Event, EventEmitter, Position, Range, SymbolInformation, SymbolKind, TextDocument, workspace } from 'vscode';
4-
import { Uri } from 'vscode';
3+
// tslint:disable:no-object-literal-type-assertion
4+
5+
import { CancellationToken, CancellationTokenSource, CodeLens, CodeLensProvider, Event, EventEmitter, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri, workspace } from 'vscode';
56
import * as constants from '../../common/constants';
67
import { PythonSymbolProvider } from '../../providers/symbolProvider';
78
import { CommandSource } from '../common/constants';
@@ -108,12 +109,12 @@ export class TestFileCodeLensProvider implements CodeLensProvider {
108109
new CodeLens(range, {
109110
title: getTestStatusIcon(cls.status) + constants.Text.CodeLensRunUnitTest,
110111
command: constants.Commands.Tests_Run,
111-
arguments: [CommandSource.codelens, file, <TestsToRun>{ testSuite: [cls] }]
112+
arguments: [undefined, CommandSource.codelens, file, <TestsToRun>{ testSuite: [cls] }]
112113
}),
113114
new CodeLens(range, {
114115
title: getTestStatusIcon(cls.status) + constants.Text.CodeLensDebugUnitTest,
115116
command: constants.Commands.Tests_Debug,
116-
arguments: [CommandSource.codelens, file, <TestsToRun>{ testSuite: [cls] }]
117+
arguments: [undefined, CommandSource.codelens, file, <TestsToRun>{ testSuite: [cls] }]
117118
})
118119
];
119120
}
@@ -182,12 +183,12 @@ function getFunctionCodeLens(file: Uri, functionsAndSuites: FunctionsAndSuites,
182183
new CodeLens(range, {
183184
title: getTestStatusIcon(fn.status) + constants.Text.CodeLensRunUnitTest,
184185
command: constants.Commands.Tests_Run,
185-
arguments: [CommandSource.codelens, file, <TestsToRun>{ testFunction: [fn] }]
186+
arguments: [undefined, CommandSource.codelens, file, <TestsToRun>{ testFunction: [fn] }]
186187
}),
187188
new CodeLens(range, {
188189
title: getTestStatusIcon(fn.status) + constants.Text.CodeLensDebugUnitTest,
189190
command: constants.Commands.Tests_Debug,
190-
arguments: [CommandSource.codelens, file, <TestsToRun>{ testFunction: [fn] }]
191+
arguments: [undefined, CommandSource.codelens, file, <TestsToRun>{ testFunction: [fn] }]
191192
})
192193
];
193194
}
@@ -203,12 +204,12 @@ function getFunctionCodeLens(file: Uri, functionsAndSuites: FunctionsAndSuites,
203204
new CodeLens(range, {
204205
title: constants.Text.CodeLensRunUnitTest,
205206
command: constants.Commands.Tests_Run,
206-
arguments: [CommandSource.codelens, file, <TestsToRun>{ testFunction: functions }]
207+
arguments: [undefined, CommandSource.codelens, file, <TestsToRun>{ testFunction: functions }]
207208
}),
208209
new CodeLens(range, {
209210
title: constants.Text.CodeLensDebugUnitTest,
210211
command: constants.Commands.Tests_Debug,
211-
arguments: [CommandSource.codelens, file, <TestsToRun>{ testFunction: functions }]
212+
arguments: [undefined, CommandSource.codelens, file, <TestsToRun>{ testFunction: functions }]
212213
})
213214
];
214215
}
@@ -218,12 +219,12 @@ function getFunctionCodeLens(file: Uri, functionsAndSuites: FunctionsAndSuites,
218219
new CodeLens(range, {
219220
title: `${getTestStatusIcons(functions)}${constants.Text.CodeLensRunUnitTest} (Multiple)`,
220221
command: constants.Commands.Tests_Picker_UI,
221-
arguments: [CommandSource.codelens, file, functions]
222+
arguments: [undefined, CommandSource.codelens, file, functions]
222223
}),
223224
new CodeLens(range, {
224225
title: `${getTestStatusIcons(functions)}${constants.Text.CodeLensDebugUnitTest} (Multiple)`,
225226
command: constants.Commands.Tests_Picker_UI_Debug,
226-
arguments: [CommandSource.codelens, file, functions]
227+
arguments: [undefined, CommandSource.codelens, file, functions]
227228
})
228229
];
229230
}

src/client/unittests/common/testUtils.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { inject, injectable, named } from 'inversify';
22
import * as path from 'path';
3-
import * as vscode from 'vscode';
4-
import { Uri, workspace } from 'vscode';
5-
import { window } from 'vscode';
3+
import { commands, Uri, window, workspace } from 'vscode';
64
import * as constants from '../../common/constants';
7-
import { IUnitTestSettings } from '../../common/types';
8-
import { Product } from '../../common/types';
5+
import { IUnitTestSettings, Product } from '../../common/types';
96
import { CommandSource } from './constants';
107
import { TestFlatteningVisitor } from './testVisitors/flatteningVisitor';
11-
import { ITestVisitor, TestFile, TestFolder, TestProvider, Tests, TestSettingsPropertyNames, TestsToRun, UnitTestProduct } from './types';
12-
import { ITestsHelper } from './types';
8+
import { ITestsHelper, ITestVisitor, TestFile, TestFolder, TestProvider, Tests, TestSettingsPropertyNames, TestsToRun, UnitTestProduct } from './types';
139

1410
export async function selectTestWorkspace(): Promise<Uri | undefined> {
1511
if (!Array.isArray(workspace.workspaceFolders) || workspace.workspaceFolders.length === 0) {
@@ -24,9 +20,9 @@ export async function selectTestWorkspace(): Promise<Uri | undefined> {
2420
}
2521

2622
export function displayTestErrorMessage(message: string) {
27-
vscode.window.showErrorMessage(message, constants.Button_Text_Tests_View_Output).then(action => {
23+
window.showErrorMessage(message, constants.Button_Text_Tests_View_Output).then(action => {
2824
if (action === constants.Button_Text_Tests_View_Output) {
29-
vscode.commands.executeCommand(constants.Commands.Tests_ViewOutput, CommandSource.ui);
25+
commands.executeCommand(constants.Commands.Tests_ViewOutput, undefined, CommandSource.ui);
3026
}
3127
});
3228

@@ -44,7 +40,7 @@ export function convertFileToPackage(filePath: string): string {
4440

4541
@injectable()
4642
export class TestsHelper implements ITestsHelper {
47-
constructor( @inject(ITestVisitor) @named('TestFlatteningVisitor') private flatteningVisitor: TestFlatteningVisitor) { }
43+
constructor(@inject(ITestVisitor) @named('TestFlatteningVisitor') private flatteningVisitor: TestFlatteningVisitor) { }
4844
public parseProviderName(product: UnitTestProduct): TestProvider {
4945
switch (product) {
5046
case Product.nosetest: return 'nosetest';
@@ -96,6 +92,7 @@ export class TestsHelper implements ITestsHelper {
9692
public flattenTestFiles(testFiles: TestFile[]): Tests {
9793
testFiles.forEach(testFile => this.flatteningVisitor.visitTestFile(testFile));
9894

95+
// tslint:disable-next-line:no-object-literal-type-assertion
9996
const tests = <Tests>{
10097
testFiles: testFiles,
10198
testFunctions: this.flatteningVisitor.flattenedTestFunctions,
@@ -165,6 +162,7 @@ export class TestsHelper implements ITestsHelper {
165162
if (testFns.length > 0) { return { testFunction: testFns }; }
166163

167164
// Just return this as a test file.
165+
// tslint:disable-next-line:no-object-literal-type-assertion
168166
return <TestsToRun>{ testFile: [{ name: name, nameToRun: name, functions: [], suites: [], xmlName: name, fullPath: '', time: 0 }] };
169167
}
170168
}

src/client/unittests/display/picker.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as path from 'path';
2-
import { QuickPickItem, Uri, window } from 'vscode';
3-
import * as vscode from 'vscode';
2+
import { commands, QuickPickItem, Uri, window } from 'vscode';
43
import * as constants from '../../common/constants';
54
import { CommandSource } from '../common/constants';
65
import { FlattenedTestFunction, ITestCollectionStorageService, TestFile, TestFunction, Tests, TestStatus, TestsToRun } from '../common/types';
@@ -10,7 +9,7 @@ export class TestDisplay {
109
public displayStopTestUI(workspace: Uri, message: string) {
1110
window.showQuickPick([message]).then(item => {
1211
if (item === message) {
13-
vscode.commands.executeCommand(constants.Commands.Tests_Stop, workspace);
12+
commands.executeCommand(constants.Commands.Tests_Stop, undefined, workspace);
1413
}
1514
});
1615
}
@@ -194,7 +193,7 @@ function onItemSelected(cmdSource: CommandSource, wkspace: Uri, selection: TestI
194193
}
195194
let cmd = '';
196195
// tslint:disable-next-line:no-any
197-
const args: any[] = [cmdSource, wkspace];
196+
const args: any[] = [undefined, cmdSource, wkspace];
198197
switch (selection.type) {
199198
case Type.Null: {
200199
return;
@@ -221,13 +220,13 @@ function onItemSelected(cmdSource: CommandSource, wkspace: Uri, selection: TestI
221220
}
222221
case Type.RunMethod: {
223222
cmd = constants.Commands.Tests_Run;
224-
// tslint:disable-next-line:prefer-type-cast
223+
// tslint:disable-next-line:prefer-type-cast no-object-literal-type-assertion
225224
args.push({ testFunction: [selection.fn.testFunction] } as TestsToRun);
226225
break;
227226
}
228227
case Type.DebugMethod: {
229228
cmd = constants.Commands.Tests_Debug;
230-
// tslint:disable-next-line:prefer-type-cast
229+
// tslint:disable-next-line:prefer-type-cast no-object-literal-type-assertion
231230
args.push({ testFunction: [selection.fn.testFunction] } as TestsToRun);
232231
args.push(true);
233232
break;
@@ -237,5 +236,5 @@ function onItemSelected(cmdSource: CommandSource, wkspace: Uri, selection: TestI
237236
}
238237
}
239238

240-
vscode.commands.executeCommand(cmd, ...args);
239+
commands.executeCommand(cmd, ...args);
241240
}

src/client/unittests/main.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,34 +87,34 @@ function dispose() {
8787
}
8888
function registerCommands(): vscode.Disposable[] {
8989
const disposables: Disposable[] = [];
90-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Discover, (cmdSource: CommandSource = CommandSource.commandPalette, resource?: Uri) => {
90+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Discover, (_, cmdSource: CommandSource = CommandSource.commandPalette, resource?: Uri) => {
9191
// Ignore the exceptions returned.
9292
// This command will be invoked else where in the extension.
9393
// tslint:disable-next-line:no-empty
9494
discoverTests(cmdSource, resource, true, true).catch(() => { });
9595
}));
96-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Run_Failed, (cmdSource: CommandSource = CommandSource.commandPalette, resource: Uri) => runTestsImpl(cmdSource, resource, undefined, true)));
96+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Run_Failed, (_, cmdSource: CommandSource = CommandSource.commandPalette, resource: Uri) => runTestsImpl(cmdSource, resource, undefined, true)));
9797
// tslint:disable-next-line:no-unnecessary-callback-wrapper
98-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Run, (cmdSource: CommandSource = CommandSource.commandPalette, file: Uri, testToRun?: TestsToRun) => runTestsImpl(cmdSource, file, testToRun)));
99-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Debug, (cmdSource: CommandSource = CommandSource.commandPalette, file: Uri, testToRun: TestsToRun) => runTestsImpl(cmdSource, file, testToRun, false, true)));
98+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Run, (_, cmdSource: CommandSource = CommandSource.commandPalette, file: Uri, testToRun?: TestsToRun) => runTestsImpl(cmdSource, file, testToRun)));
99+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Debug, (_, cmdSource: CommandSource = CommandSource.commandPalette, file: Uri, testToRun: TestsToRun) => runTestsImpl(cmdSource, file, testToRun, false, true)));
100100
// tslint:disable-next-line:no-unnecessary-callback-wrapper
101101
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_View_UI, () => displayUI(CommandSource.commandPalette)));
102102
// tslint:disable-next-line:no-unnecessary-callback-wrapper
103-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Picker_UI, (cmdSource: CommandSource = CommandSource.commandPalette, file: Uri, testFunctions: TestFunction[]) => displayPickerUI(cmdSource, file, testFunctions)));
104-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Picker_UI_Debug, (cmdSource: CommandSource = CommandSource.commandPalette, file: Uri, testFunctions: TestFunction[]) => displayPickerUI(cmdSource, file, testFunctions, true)));
103+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Picker_UI, (_, cmdSource: CommandSource = CommandSource.commandPalette, file: Uri, testFunctions: TestFunction[]) => displayPickerUI(cmdSource, file, testFunctions)));
104+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Picker_UI_Debug, (_, cmdSource: CommandSource = CommandSource.commandPalette, file: Uri, testFunctions: TestFunction[]) => displayPickerUI(cmdSource, file, testFunctions, true)));
105105
// tslint:disable-next-line:no-unnecessary-callback-wrapper
106-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Stop, (resource: Uri) => stopTests(resource)));
106+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Stop, (_, resource: Uri) => stopTests(resource)));
107107
// tslint:disable-next-line:no-unnecessary-callback-wrapper
108-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_ViewOutput, (cmdSource: CommandSource = CommandSource.commandPalette) => viewOutput(cmdSource)));
108+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_ViewOutput, (_, cmdSource: CommandSource = CommandSource.commandPalette) => viewOutput(cmdSource)));
109109
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Ask_To_Stop_Discovery, () => displayStopUI('Stop discovering tests')));
110110
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Ask_To_Stop_Test, () => displayStopUI('Stop running tests')));
111111
// tslint:disable-next-line:no-unnecessary-callback-wrapper
112-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Select_And_Run_Method, (cmdSource: CommandSource = CommandSource.commandPalette, resource: Uri) => selectAndRunTestMethod(cmdSource, resource)));
113-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Select_And_Debug_Method, (cmdSource: CommandSource = CommandSource.commandPalette, resource: Uri) => selectAndRunTestMethod(cmdSource, resource, true)));
112+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Select_And_Run_Method, (_, cmdSource: CommandSource = CommandSource.commandPalette, resource: Uri) => selectAndRunTestMethod(cmdSource, resource)));
113+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Select_And_Debug_Method, (_, cmdSource: CommandSource = CommandSource.commandPalette, resource: Uri) => selectAndRunTestMethod(cmdSource, resource, true)));
114114
// tslint:disable-next-line:no-unnecessary-callback-wrapper
115-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Select_And_Run_File, (cmdSource: CommandSource = CommandSource.commandPalette) => selectAndRunTestFile(cmdSource)));
115+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Select_And_Run_File, (_, cmdSource: CommandSource = CommandSource.commandPalette) => selectAndRunTestFile(cmdSource)));
116116
// tslint:disable-next-line:no-unnecessary-callback-wrapper
117-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Run_Current_File, (cmdSource: CommandSource = CommandSource.commandPalette) => runCurrentTestFile(cmdSource)));
117+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Run_Current_File, (_, cmdSource: CommandSource = CommandSource.commandPalette) => runCurrentTestFile(cmdSource)));
118118

119119
return disposables;
120120
}

0 commit comments

Comments
 (0)