From 154a3e2d32bd5001662b1d4a9e4d83ca79b633ad Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 28 Oct 2024 15:16:39 -0700 Subject: [PATCH 01/46] dont automatically inject pystartup --- src/client/common/terminal/service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 511135fa8b2f..d3cd1cdef9b2 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -136,7 +136,7 @@ export class TerminalService implements ITerminalService, Disposable { this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal); this.terminal = this.terminalManager.createTerminal({ name: this.options?.title || 'Python', - env: { PYTHONSTARTUP: this.envVarScript }, + env: {}, hideFromUser: this.options?.hideFromUser, }); this.terminalAutoActivator.disableAutoActivation(this.terminal); From 377e70000ec0d4910cbb16385283d7c3d8e8d9dc Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 28 Oct 2024 15:36:57 -0700 Subject: [PATCH 02/46] create test to make sure PYTHONSTARTUP not auto injected --- src/test/common/terminals/helper.unit.test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/test/common/terminals/helper.unit.test.ts b/src/test/common/terminals/helper.unit.test.ts index 864188b7c7b4..b54ec7d787e3 100644 --- a/src/test/common/terminals/helper.unit.test.ts +++ b/src/test/common/terminals/helper.unit.test.ts @@ -96,7 +96,17 @@ suite('Terminal Service helpers', () => { teardown(() => shellDetectorIdentifyTerminalShell.restore()); suite('Misc', () => { setup(doSetup); - + test('Creating terminal should not automatically contain PYTHONSTARTUP', () => { + const theTitle = 'Hello'; + const terminal = 'Terminal Created'; + when(terminalManager.createTerminal(anything())).thenReturn(terminal as any); + const term = helper.createTerminal(theTitle); + const args = capture(terminalManager.createTerminal).first()[0]; + expect(term).to.be.deep.equal(terminal); + const temp = args.env; + // parse through temp or args.env and make sure there is no PYTHONSTARTUP + expect(temp).to.not.have.property('PYTHONSTARTUP'); + }); test('Create terminal without a title', () => { const terminal = 'Terminal Created'; when(terminalManager.createTerminal(anything())).thenReturn(terminal as any); From d60f310fe2535228cfcbe66a9552fc3b9c5ea17d Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 28 Oct 2024 15:38:10 -0700 Subject: [PATCH 03/46] make compiler happy --- src/client/common/terminal/service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index d3cd1cdef9b2..8e976a880e0c 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -33,7 +33,6 @@ export class TerminalService implements ITerminalService, Disposable { private terminalHelper: ITerminalHelper; private terminalActivator: ITerminalActivator; private terminalAutoActivator: ITerminalAutoActivation; - private readonly envVarScript = path.join(EXTENSION_ROOT_DIR, 'python_files', 'pythonrc.py'); private readonly executeCommandListeners: Set = new Set(); public get onDidCloseTerminal(): Event { return this.terminalClosed.event.bind(this.terminalClosed); From 6d8ba24a491dae87bd3711ae178f85ee5d682dc4 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 28 Oct 2024 15:40:35 -0700 Subject: [PATCH 04/46] compile --- src/client/common/terminal/service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 8e976a880e0c..712a7df8c380 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import * as path from 'path'; import { CancellationToken, Disposable, Event, EventEmitter, Terminal } from 'vscode'; import '../../common/extensions'; import { IInterpreterService } from '../../interpreter/contracts'; @@ -11,7 +10,6 @@ import { captureTelemetry } from '../../telemetry'; import { EventName } from '../../telemetry/constants'; import { ITerminalAutoActivation } from '../../terminals/types'; import { ITerminalManager } from '../application/types'; -import { EXTENSION_ROOT_DIR } from '../constants'; import { _SCRIPTS_DIR } from '../process/internal/scripts/constants'; import { IConfigurationService, IDisposableRegistry } from '../types'; import { From 37cd45b10f4471a494623243be1a761da3d9c64c Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 28 Oct 2024 16:04:09 -0700 Subject: [PATCH 05/46] make sure to be safe when checking for property potentitally empty --- src/test/common/terminals/helper.unit.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/common/terminals/helper.unit.test.ts b/src/test/common/terminals/helper.unit.test.ts index b54ec7d787e3..52252a6cfab8 100644 --- a/src/test/common/terminals/helper.unit.test.ts +++ b/src/test/common/terminals/helper.unit.test.ts @@ -103,9 +103,9 @@ suite('Terminal Service helpers', () => { const term = helper.createTerminal(theTitle); const args = capture(terminalManager.createTerminal).first()[0]; expect(term).to.be.deep.equal(terminal); - const temp = args.env; - // parse through temp or args.env and make sure there is no PYTHONSTARTUP - expect(temp).to.not.have.property('PYTHONSTARTUP'); + const terminalOptions = args.env; + const safeTerminalOptions = terminalOptions || {}; + expect(safeTerminalOptions).to.not.have.property('PYTHONSTARTUP'); }); test('Create terminal without a title', () => { const terminal = 'Terminal Created'; From fbcebd2c776c7599591e61078b46c605aef11b63 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 28 Oct 2024 19:34:38 -0700 Subject: [PATCH 06/46] what is going on with timeout --- src/test/smoke/smartSend.smoke.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index 7f894df923ee..e51fd1702cce 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -69,7 +69,7 @@ if (process.platform !== 'win32') { return new Promise((resolve) => { setTimeout(() => { resolve(); - }, 10000); + }, 5000); }); } From 1bbd0bcc66caff291844552e36d0ac9d583022f2 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 28 Oct 2024 20:07:20 -0700 Subject: [PATCH 07/46] try with done() ? --- src/test/smoke/smartSend.smoke.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index e51fd1702cce..854cebed0329 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -21,7 +21,7 @@ if (process.platform !== 'win32') { suiteTeardown(closeActiveWindows); teardown(closeActiveWindows); - test('Smart Send', async () => { + test('Smart Send', async (done) => { const file = path.join( EXTENSION_ROOT_DIR_FOR_TESTS, 'src', @@ -69,7 +69,7 @@ if (process.platform !== 'win32') { return new Promise((resolve) => { setTimeout(() => { resolve(); - }, 5000); + }, 10000); }); } @@ -81,6 +81,7 @@ if (process.platform !== 'win32') { } else { assert.fail(`"${outputFile}" file still exists`); } + done(); }); }); } From 3aa86bf2986bc63d1b0d66cc374a88826d387275 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 08:58:07 -0700 Subject: [PATCH 08/46] is it because of experiment value --- src/test/smoke/smartSend.smoke.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index 854cebed0329..37d303efb6aa 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -21,7 +21,10 @@ if (process.platform !== 'win32') { suiteTeardown(closeActiveWindows); teardown(closeActiveWindows); - test('Smart Send', async (done) => { + test('Smart Send', async () => { + const configuration = vscode.workspace.getConfiguration('python'); + await configuration.update('REPL.sendToNativeREPL', false, vscode.ConfigurationTarget.Global); + const file = path.join( EXTENSION_ROOT_DIR_FOR_TESTS, 'src', @@ -69,7 +72,7 @@ if (process.platform !== 'win32') { return new Promise((resolve) => { setTimeout(() => { resolve(); - }, 10000); + }, 30000); }); } @@ -81,7 +84,6 @@ if (process.platform !== 'win32') { } else { assert.fail(`"${outputFile}" file still exists`); } - done(); }); }); } From 5f537067bdc2e2ce39d0e8c84140c30378c1eb06 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 10:37:02 -0700 Subject: [PATCH 09/46] try adding async and see if that helps --- src/test/smoke/smartSend.smoke.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index 37d303efb6aa..b19c5d55d0fb 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -8,7 +8,7 @@ import { openFile, waitForCondition } from '../common'; // TODO: This test is being flaky for windows, need to investigate why only fails on windows if (process.platform !== 'win32') { - suite('Smoke Test: Run Smart Selection and Advance Cursor', () => { + suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { suiteSetup(async function () { if (!IS_SMOKE_TEST) { return this.skip(); From d3279035b445c453e3511b64b9b683cb80e82739 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 12:23:51 -0700 Subject: [PATCH 10/46] try to add more test --- src/test/common/terminals/helper.unit.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/common/terminals/helper.unit.test.ts b/src/test/common/terminals/helper.unit.test.ts index 52252a6cfab8..1f027fa5e140 100644 --- a/src/test/common/terminals/helper.unit.test.ts +++ b/src/test/common/terminals/helper.unit.test.ts @@ -107,6 +107,21 @@ suite('Terminal Service helpers', () => { const safeTerminalOptions = terminalOptions || {}; expect(safeTerminalOptions).to.not.have.property('PYTHONSTARTUP'); }); + test('Create terminal should respect env passed in', () => { + const terminal = 'Terminal Created'; + when(terminalManager.createTerminal(anything())).thenReturn(terminal as any); + terminalManager.createTerminal({ + name: 'Python', + env: {}, + hideFromUser: undefined, + }); + const args = capture(terminalManager.createTerminal).first()[0]; + const terminalOptions = args.env; + const safeTerminalOptions = terminalOptions || {}; + expect(safeTerminalOptions).to.have.property('myCustomEnv', '123'); + }); + }) + test('Create terminal without a title', () => { const terminal = 'Terminal Created'; when(terminalManager.createTerminal(anything())).thenReturn(terminal as any); From 2db93947b8b16d88cd56ef07b265f1e822990eed Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 12:40:54 -0700 Subject: [PATCH 11/46] adjust timeout to see if it helps with potential race condition --- src/test/smoke/smartSend.smoke.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index b19c5d55d0fb..d2e037b0a278 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -72,7 +72,7 @@ if (process.platform !== 'win32') { return new Promise((resolve) => { setTimeout(() => { resolve(); - }, 30000); + }, 5000); }); } From 8b5eeb094b5256e4388440b22a8240338149d9b2 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 12:42:13 -0700 Subject: [PATCH 12/46] parenthesis --- src/test/common/terminals/helper.unit.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/common/terminals/helper.unit.test.ts b/src/test/common/terminals/helper.unit.test.ts index 1f027fa5e140..b4fce8e850fd 100644 --- a/src/test/common/terminals/helper.unit.test.ts +++ b/src/test/common/terminals/helper.unit.test.ts @@ -107,11 +107,12 @@ suite('Terminal Service helpers', () => { const safeTerminalOptions = terminalOptions || {}; expect(safeTerminalOptions).to.not.have.property('PYTHONSTARTUP'); }); + test('Create terminal should respect env passed in', () => { const terminal = 'Terminal Created'; when(terminalManager.createTerminal(anything())).thenReturn(terminal as any); terminalManager.createTerminal({ - name: 'Python', + name: 'Python', env: {}, hideFromUser: undefined, }); @@ -119,8 +120,7 @@ suite('Terminal Service helpers', () => { const terminalOptions = args.env; const safeTerminalOptions = terminalOptions || {}; expect(safeTerminalOptions).to.have.property('myCustomEnv', '123'); - }); - }) + }); test('Create terminal without a title', () => { const terminal = 'Terminal Created'; From 7c0b405e192ef09cc13d5d17d775358fd66cc67c Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 13:43:57 -0700 Subject: [PATCH 13/46] add condition in executeCommand in case onDidEndTerminalShellExecution never returns --- src/client/common/terminal/service.ts | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 712a7df8c380..9ad60b8afb61 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -99,18 +99,28 @@ export class TerminalService implements ITerminalService, Disposable { if (terminal.shellIntegration) { const execution = terminal.shellIntegration.executeCommand(commandLine); - return await new Promise((resolve) => { - const listener = this.terminalManager.onDidEndTerminalShellExecution((e) => { - if (e.execution === execution) { - this.executeCommandListeners.delete(listener); - resolve({ execution, exitCode: e.exitCode }); + return await Promise.race([ + new Promise((resolve) => { + const listener = this.terminalManager.onDidEndTerminalShellExecution((e) => { + if (e.execution === execution) { + this.executeCommandListeners.delete(listener); + resolve({ execution, exitCode: e.exitCode }); + } + }); + if (listener) { + this.executeCommandListeners.add(listener); } - }); - if (listener) { - this.executeCommandListeners.add(listener); - } - traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); - }); + traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); + }), + new Promise((resolve) => { + setTimeout(() => { + traceVerbose(`Execution timed out, falling back to sendText: ${commandLine}`); + terminal.sendText(commandLine); + resolve(undefined); + return undefined; + }, 10000); + }), + ]); } else { terminal.sendText(commandLine); traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`); From 0ccb053c69a0066b03869b1e3e71c0f59091d1a7 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 15:12:11 -0700 Subject: [PATCH 14/46] remove wrong test --- src/test/common/terminals/helper.unit.test.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/test/common/terminals/helper.unit.test.ts b/src/test/common/terminals/helper.unit.test.ts index b4fce8e850fd..8dee35519b84 100644 --- a/src/test/common/terminals/helper.unit.test.ts +++ b/src/test/common/terminals/helper.unit.test.ts @@ -108,20 +108,6 @@ suite('Terminal Service helpers', () => { expect(safeTerminalOptions).to.not.have.property('PYTHONSTARTUP'); }); - test('Create terminal should respect env passed in', () => { - const terminal = 'Terminal Created'; - when(terminalManager.createTerminal(anything())).thenReturn(terminal as any); - terminalManager.createTerminal({ - name: 'Python', - env: {}, - hideFromUser: undefined, - }); - const args = capture(terminalManager.createTerminal).first()[0]; - const terminalOptions = args.env; - const safeTerminalOptions = terminalOptions || {}; - expect(safeTerminalOptions).to.have.property('myCustomEnv', '123'); - }); - test('Create terminal without a title', () => { const terminal = 'Terminal Created'; when(terminalManager.createTerminal(anything())).thenReturn(terminal as any); From 40ff86325868cd3a957f26f8c3d94465687aaf14 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 15:19:19 -0700 Subject: [PATCH 15/46] env should be undefined if not explicitly passed in --- src/test/common/terminals/helper.unit.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/common/terminals/helper.unit.test.ts b/src/test/common/terminals/helper.unit.test.ts index 8dee35519b84..0d130b573408 100644 --- a/src/test/common/terminals/helper.unit.test.ts +++ b/src/test/common/terminals/helper.unit.test.ts @@ -108,6 +108,19 @@ suite('Terminal Service helpers', () => { expect(safeTerminalOptions).to.not.have.property('PYTHONSTARTUP'); }); + test('Env should be undefined if not explicitly passed in ', () => { + const theTitle = 'Hello'; + const terminal = 'Terminal Created'; + when(terminalManager.createTerminal(anything())).thenReturn(terminal as any); + + const term = helper.createTerminal(theTitle); + + verify(terminalManager.createTerminal(anything())).once(); + const args = capture(terminalManager.createTerminal).first()[0]; + expect(term).to.be.deep.equal(terminal); + expect(args.env).to.be.deep.equal(undefined); + }); + test('Create terminal without a title', () => { const terminal = 'Terminal Created'; when(terminalManager.createTerminal(anything())).thenReturn(terminal as any); From 7dd3f833cd4c00b9308ca1833b1a2762b9cbc26e Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 15:38:47 -0700 Subject: [PATCH 16/46] add comment --- src/client/common/terminal/service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 9ad60b8afb61..c99457c04158 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -112,6 +112,7 @@ export class TerminalService implements ITerminalService, Disposable { } traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); }), + // Once shell integration is active, hearing back from onDidEndTerminalShellExecution should not take too long. new Promise((resolve) => { setTimeout(() => { traceVerbose(`Execution timed out, falling back to sendText: ${commandLine}`); From 3c3bfc9d91870c34db0782d126b3b820b3568fa1 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 15:41:04 -0700 Subject: [PATCH 17/46] allow smoke test on windows --- src/test/smoke/smartSend.smoke.test.ts | 135 ++++++++++++------------- 1 file changed, 66 insertions(+), 69 deletions(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index d2e037b0a278..b402308c9241 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -6,84 +6,81 @@ import { EXTENSION_ROOT_DIR_FOR_TESTS, IS_SMOKE_TEST } from '../constants'; import { closeActiveWindows, initialize, initializeTest } from '../initialize'; import { openFile, waitForCondition } from '../common'; -// TODO: This test is being flaky for windows, need to investigate why only fails on windows -if (process.platform !== 'win32') { - suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { - suiteSetup(async function () { - if (!IS_SMOKE_TEST) { - return this.skip(); - } - await initialize(); - return undefined; - }); +suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { + suiteSetup(async function () { + if (!IS_SMOKE_TEST) { + return this.skip(); + } + await initialize(); + return undefined; + }); - setup(initializeTest); - suiteTeardown(closeActiveWindows); - teardown(closeActiveWindows); + setup(initializeTest); + suiteTeardown(closeActiveWindows); + teardown(closeActiveWindows); - test('Smart Send', async () => { - const configuration = vscode.workspace.getConfiguration('python'); - await configuration.update('REPL.sendToNativeREPL', false, vscode.ConfigurationTarget.Global); + test('Smart Send', async () => { + const configuration = vscode.workspace.getConfiguration('python'); + await configuration.update('REPL.sendToNativeREPL', false, vscode.ConfigurationTarget.Global); - const file = path.join( - EXTENSION_ROOT_DIR_FOR_TESTS, - 'src', - 'testMultiRootWkspc', - 'smokeTests', - 'create_delete_file.py', - ); - const outputFile = path.join( - EXTENSION_ROOT_DIR_FOR_TESTS, - 'src', - 'testMultiRootWkspc', - 'smokeTests', - 'smart_send_smoke.txt', - ); + const file = path.join( + EXTENSION_ROOT_DIR_FOR_TESTS, + 'src', + 'testMultiRootWkspc', + 'smokeTests', + 'create_delete_file.py', + ); + const outputFile = path.join( + EXTENSION_ROOT_DIR_FOR_TESTS, + 'src', + 'testMultiRootWkspc', + 'smokeTests', + 'smart_send_smoke.txt', + ); - await fs.remove(outputFile); + await fs.remove(outputFile); - const textDocument = await openFile(file); + const textDocument = await openFile(file); - if (vscode.window.activeTextEditor) { - const myPos = new vscode.Position(0, 0); - vscode.window.activeTextEditor!.selections = [new vscode.Selection(myPos, myPos)]; - } - await vscode.commands - .executeCommand('python.execSelectionInTerminal', textDocument.uri) - .then(undefined, (err) => { - assert.fail(`Something went wrong running the Python file in the terminal: ${err}`); - }); + if (vscode.window.activeTextEditor) { + const myPos = new vscode.Position(0, 0); + vscode.window.activeTextEditor!.selections = [new vscode.Selection(myPos, myPos)]; + } + await vscode.commands + .executeCommand('python.execSelectionInTerminal', textDocument.uri) + .then(undefined, (err) => { + assert.fail(`Something went wrong running the Python file in the terminal: ${err}`); + }); - const checkIfFileHasBeenCreated = () => fs.pathExists(outputFile); - await waitForCondition(checkIfFileHasBeenCreated, 10_000, `"${outputFile}" file not created`); + const checkIfFileHasBeenCreated = () => fs.pathExists(outputFile); + await waitForCondition(checkIfFileHasBeenCreated, 10_000, `"${outputFile}" file not created`); - await vscode.commands - .executeCommand('python.execSelectionInTerminal', textDocument.uri) - .then(undefined, (err) => { - assert.fail(`Something went wrong running the Python file in the terminal: ${err}`); - }); - await vscode.commands - .executeCommand('python.execSelectionInTerminal', textDocument.uri) - .then(undefined, (err) => { - assert.fail(`Something went wrong running the Python file in the terminal: ${err}`); - }); + await vscode.commands + .executeCommand('python.execSelectionInTerminal', textDocument.uri) + .then(undefined, (err) => { + assert.fail(`Something went wrong running the Python file in the terminal: ${err}`); + }); + await vscode.commands + .executeCommand('python.execSelectionInTerminal', textDocument.uri) + .then(undefined, (err) => { + assert.fail(`Something went wrong running the Python file in the terminal: ${err}`); + }); - async function wait() { - return new Promise((resolve) => { - setTimeout(() => { - resolve(); - }, 5000); - }); - } + async function wait() { + return new Promise((resolve) => { + setTimeout(() => { + resolve(); + }, 5000); + }); + } - await wait(); + await wait(); - const deletedFile = !(await fs.pathExists(outputFile)); - if (deletedFile) { - assert.ok(true, `"${outputFile}" file has been deleted`); - } else { - assert.fail(`"${outputFile}" file still exists`); - } - }); + const deletedFile = !(await fs.pathExists(outputFile)); + if (deletedFile) { + assert.ok(true, `"${outputFile}" file has been deleted`); + } else { + assert.fail(`"${outputFile}" file still exists`); + } }); -} +}); From c1a51ad5ae6759453dc108d9153f45d1c6751663 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 16:06:27 -0700 Subject: [PATCH 18/46] reduce to 5 second --- src/client/common/terminal/service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index c99457c04158..596d56e36257 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -119,7 +119,7 @@ export class TerminalService implements ITerminalService, Disposable { terminal.sendText(commandLine); resolve(undefined); return undefined; - }, 10000); + }, 5000); }), ]); } else { From 4ea5c673cf3837c6e2d927d95376d1cbff9aa102 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 16:44:57 -0700 Subject: [PATCH 19/46] fix after feedback --- src/client/common/terminal/service.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 596d56e36257..9911f65baa9d 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -99,7 +99,7 @@ export class TerminalService implements ITerminalService, Disposable { if (terminal.shellIntegration) { const execution = terminal.shellIntegration.executeCommand(commandLine); - return await Promise.race([ + const result = await Promise.race([ new Promise((resolve) => { const listener = this.terminalManager.onDidEndTerminalShellExecution((e) => { if (e.execution === execution) { @@ -112,16 +112,20 @@ export class TerminalService implements ITerminalService, Disposable { } traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); }), - // Once shell integration is active, hearing back from onDidEndTerminalShellExecution should not take too long. new Promise((resolve) => { setTimeout(() => { - traceVerbose(`Execution timed out, falling back to sendText: ${commandLine}`); - terminal.sendText(commandLine); resolve(undefined); - return undefined; }, 5000); }), ]); + + if (result === undefined) { + traceVerbose(`Execution timed out, falling back to sendText: ${commandLine}`); + terminal.sendText(commandLine); + return undefined; + } else { + return result; + } } else { terminal.sendText(commandLine); traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`); From 8fb2e24d14388a61de09cbc6c0d40f1783861b22 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 17:44:48 -0700 Subject: [PATCH 20/46] fix test, {} to undefined --- src/client/common/terminal/service.ts | 32 +++++++++----------------- src/test/smoke/smartSend.smoke.test.ts | 2 ++ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 9911f65baa9d..8b83effb1ed2 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -99,32 +99,23 @@ export class TerminalService implements ITerminalService, Disposable { if (terminal.shellIntegration) { const execution = terminal.shellIntegration.executeCommand(commandLine); - const result = await Promise.race([ - new Promise((resolve) => { - const listener = this.terminalManager.onDidEndTerminalShellExecution((e) => { + + let result = undefined; + let disposable: Disposable | undefined; + try { + result = await new Promise((resolve) => { + disposable = this.terminalManager.onDidEndTerminalShellExecution((e) => { if (e.execution === execution) { - this.executeCommandListeners.delete(listener); resolve({ execution, exitCode: e.exitCode }); } }); - if (listener) { - this.executeCommandListeners.add(listener); - } - traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); - }), - new Promise((resolve) => { - setTimeout(() => { - resolve(undefined); - }, 5000); - }), - ]); - if (result === undefined) { - traceVerbose(`Execution timed out, falling back to sendText: ${commandLine}`); - terminal.sendText(commandLine); - return undefined; - } else { + traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); + }); return result; + } catch { + } finally { + disposable?.dispose(); } } else { terminal.sendText(commandLine); @@ -148,7 +139,6 @@ export class TerminalService implements ITerminalService, Disposable { this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal); this.terminal = this.terminalManager.createTerminal({ name: this.options?.title || 'Python', - env: {}, hideFromUser: this.options?.hideFromUser, }); this.terminalAutoActivator.disableAutoActivation(this.terminal); diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index b402308c9241..8ff7b7e9056d 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -23,6 +23,8 @@ suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { const configuration = vscode.workspace.getConfiguration('python'); await configuration.update('REPL.sendToNativeREPL', false, vscode.ConfigurationTarget.Global); + // TODO: change default setting to pwsh for this test + const file = path.join( EXTENSION_ROOT_DIR_FOR_TESTS, 'src', From 83dbb9078f802b57e61128916d0aa2ac607dd751 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 18:01:20 -0700 Subject: [PATCH 21/46] set default shell to pwsh --- src/test/smoke/smartSend.smoke.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index 8ff7b7e9056d..d89106f62e3c 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -23,7 +23,13 @@ suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { const configuration = vscode.workspace.getConfiguration('python'); await configuration.update('REPL.sendToNativeREPL', false, vscode.ConfigurationTarget.Global); - // TODO: change default setting to pwsh for this test + const configurationTerminal = vscode.workspace.getConfiguration('terminal'); + configurationTerminal.update( + 'integrated.defaultProfile.windows', + 'PowerShell', + vscode.ConfigurationTarget.Global, + ); + configurationTerminal.update('integrated.defaultProfile.osx', 'PowerShell', vscode.ConfigurationTarget.Global); const file = path.join( EXTENSION_ROOT_DIR_FOR_TESTS, From 2f3e787ca977de6eb06ea677c25bfbc5582eaee6 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 20:00:16 -0700 Subject: [PATCH 22/46] passing on local, fail on CI - try longer time --- src/test/smoke/smartSend.smoke.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index d89106f62e3c..4c1c2631f9ce 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -78,7 +78,7 @@ suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { return new Promise((resolve) => { setTimeout(() => { resolve(); - }, 5000); + }, 10000); }); } From eaa78f2e14558469e11ec2e5fd3e1be7bd9dc8cb Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 20:34:58 -0700 Subject: [PATCH 23/46] try increasing time --- src/test/smoke/smartSend.smoke.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index 4c1c2631f9ce..0c1753963bc0 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -61,7 +61,7 @@ suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { }); const checkIfFileHasBeenCreated = () => fs.pathExists(outputFile); - await waitForCondition(checkIfFileHasBeenCreated, 10_000, `"${outputFile}" file not created`); + await waitForCondition(checkIfFileHasBeenCreated, 20_000, `"${outputFile}" file not created`); await vscode.commands .executeCommand('python.execSelectionInTerminal', textDocument.uri) @@ -78,7 +78,7 @@ suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { return new Promise((resolve) => { setTimeout(() => { resolve(); - }, 10000); + }, 20000); }); } From d12ae35cfb82f7dd15f3f669ec29ed6243446b7b Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 29 Oct 2024 22:47:48 -0700 Subject: [PATCH 24/46] make sure shell integration is disabled on smart send smoke test --- src/test/smoke/smartSend.smoke.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index 0c1753963bc0..c6598e8fb556 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -24,6 +24,12 @@ suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { await configuration.update('REPL.sendToNativeREPL', false, vscode.ConfigurationTarget.Global); const configurationTerminal = vscode.workspace.getConfiguration('terminal'); + // set terminal.integrated.shellIntegration.enabled to false + await configurationTerminal.update( + 'integrated.shellIntegration.enabled', + false, + vscode.ConfigurationTarget.Global, + ); configurationTerminal.update( 'integrated.defaultProfile.windows', 'PowerShell', From f7f8ef67b3218c15405074d4dbcce888f9446e56 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 09:34:00 -0700 Subject: [PATCH 25/46] setting to make sure to enable REPLSmartSend --- src/test/smoke/smartSend.smoke.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index c6598e8fb556..5e68f193be01 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -22,7 +22,7 @@ suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { test('Smart Send', async () => { const configuration = vscode.workspace.getConfiguration('python'); await configuration.update('REPL.sendToNativeREPL', false, vscode.ConfigurationTarget.Global); - + await configuration.update('REPL.enableREPLSmartSend', true, vscode.ConfigurationTarget.Global); const configurationTerminal = vscode.workspace.getConfiguration('terminal'); // set terminal.integrated.shellIntegration.enabled to false await configurationTerminal.update( From 6b4b09788f5940b55cef2fba40706b210133d2e5 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 10:11:01 -0700 Subject: [PATCH 26/46] add log to debug in CI --- src/client/common/terminal/service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 8b83effb1ed2..61158909511d 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -107,6 +107,7 @@ export class TerminalService implements ITerminalService, Disposable { disposable = this.terminalManager.onDidEndTerminalShellExecution((e) => { if (e.execution === execution) { resolve({ execution, exitCode: e.exitCode }); + console.log('Resolving inside onDidEndTerminalShellExecution'); } }); @@ -120,6 +121,7 @@ export class TerminalService implements ITerminalService, Disposable { } else { terminal.sendText(commandLine); traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`); + console.log('sendText instead of try catch. This means terminal.shellIntegration is undefined'); } return undefined; From edb91bae7677023cdb149ec0029411cd5c6b7ae2 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 10:28:58 -0700 Subject: [PATCH 27/46] try different way in service,ts --- src/client/common/terminal/service.ts | 44 ++++++++++++++++++--------- src/client/common/terminal/types.ts | 2 +- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 61158909511d..2af9d09a6975 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -100,24 +100,38 @@ export class TerminalService implements ITerminalService, Disposable { if (terminal.shellIntegration) { const execution = terminal.shellIntegration.executeCommand(commandLine); - let result = undefined; - let disposable: Disposable | undefined; - try { - result = await new Promise((resolve) => { - disposable = this.terminalManager.onDidEndTerminalShellExecution((e) => { + // let result = undefined; + // let disposable: Disposable | undefined; + // try { + // result = await new Promise((resolve) => { + // disposable = this.terminalManager.onDidEndTerminalShellExecution((e) => { + // if (e.execution === execution) { + // resolve({ execution, exitCode: e.exitCode }); + // console.log('Resolving inside onDidEndTerminalShellExecution'); + // } + // }); + + // traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); + // }); + // return result; + // } catch { + // } finally { + // disposable?.dispose(); + // } + return { + execution, + exitCode: new Promise((resolve) => { + const listener = this.terminalManager.onDidEndTerminalShellExecution((e) => { if (e.execution === execution) { - resolve({ execution, exitCode: e.exitCode }); - console.log('Resolving inside onDidEndTerminalShellExecution'); + this.executeCommandListeners.delete(listener); + resolve(e.exitCode); } }); - - traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); - }); - return result; - } catch { - } finally { - disposable?.dispose(); - } + if (listener) { + this.executeCommandListeners.add(listener); + } + }), + }; } else { terminal.sendText(commandLine); traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`); diff --git a/src/client/common/terminal/types.ts b/src/client/common/terminal/types.ts index f8ae38f5d403..190470418440 100644 --- a/src/client/common/terminal/types.ts +++ b/src/client/common/terminal/types.ts @@ -60,7 +60,7 @@ export interface ITerminalService extends IDisposable { export interface ITerminalExecutedCommand { execution: TerminalShellExecution; - exitCode: number | undefined; + exitCode: Promise; } export const ITerminalServiceFactory = Symbol('ITerminalServiceFactory'); From eaaf338226def61d94b81bb0dadee907ae1468c6 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 11:52:48 -0700 Subject: [PATCH 28/46] more descriptive comment, ensure env is only passed in when setting enabled --- src/client/common/terminal/service.ts | 57 ++++++++++++++++----------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 2af9d09a6975..a11c31cf8386 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import { CancellationToken, Disposable, Event, EventEmitter, Terminal } from 'vscode'; +import { CancellationToken, Disposable, Event, EventEmitter, Terminal, TerminalOptions } from 'vscode'; import '../../common/extensions'; import { IInterpreterService } from '../../interpreter/contracts'; import { IServiceContainer } from '../../ioc/types'; @@ -11,6 +11,7 @@ import { EventName } from '../../telemetry/constants'; import { ITerminalAutoActivation } from '../../terminals/types'; import { ITerminalManager } from '../application/types'; import { _SCRIPTS_DIR } from '../process/internal/scripts/constants'; +import * as path from 'path'; import { IConfigurationService, IDisposableRegistry } from '../types'; import { ITerminalActivator, @@ -21,6 +22,10 @@ import { ITerminalExecutedCommand, } from './types'; import { traceVerbose } from '../../logging'; +import { EXTENSION_ROOT_DIR } from '../constants'; +import { getActiveResource } from '../vscodeApis/windowApis'; +import { getConfiguration } from '../vscodeApis/workspaceApis'; +import { create } from 'lodash'; @injectable() export class TerminalService implements ITerminalService, Disposable { @@ -31,6 +36,8 @@ export class TerminalService implements ITerminalService, Disposable { private terminalHelper: ITerminalHelper; private terminalActivator: ITerminalActivator; private terminalAutoActivator: ITerminalAutoActivation; + + private readonly envVarScript = path.join(EXTENSION_ROOT_DIR, 'python_files', 'pythonrc.py'); private readonly executeCommandListeners: Set = new Set(); public get onDidCloseTerminal(): Event { return this.terminalClosed.event.bind(this.terminalClosed); @@ -99,25 +106,11 @@ export class TerminalService implements ITerminalService, Disposable { if (terminal.shellIntegration) { const execution = terminal.shellIntegration.executeCommand(commandLine); + traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); + // exitCode as promise for the case: + // OnDidEndTerminalShellExecution never fires because python command does not finish until exit() + // In the case where SI is enabled in zsh/pwsh in Windows but not inside Python REPL so Python command won't finish until user exit() - // let result = undefined; - // let disposable: Disposable | undefined; - // try { - // result = await new Promise((resolve) => { - // disposable = this.terminalManager.onDidEndTerminalShellExecution((e) => { - // if (e.execution === execution) { - // resolve({ execution, exitCode: e.exitCode }); - // console.log('Resolving inside onDidEndTerminalShellExecution'); - // } - // }); - - // traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); - // }); - // return result; - // } catch { - // } finally { - // disposable?.dispose(); - // } return { execution, exitCode: new Promise((resolve) => { @@ -125,6 +118,9 @@ export class TerminalService implements ITerminalService, Disposable { if (e.execution === execution) { this.executeCommandListeners.delete(listener); resolve(e.exitCode); + traceVerbose( + `onDidEndTerminalShellExecution handler is called: Shell Integration exitCode: ${e.exitCode}`, + ); } }); if (listener) { @@ -135,7 +131,6 @@ export class TerminalService implements ITerminalService, Disposable { } else { terminal.sendText(commandLine); traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`); - console.log('sendText instead of try catch. This means terminal.shellIntegration is undefined'); } return undefined; @@ -149,14 +144,28 @@ export class TerminalService implements ITerminalService, Disposable { } // TODO: Debt switch to Promise ---> breaks 20 tests public async ensureTerminal(preserveFocus: boolean = true): Promise { + let createTerminalOptions: TerminalOptions; + const uri = getActiveResource(); + const configuration = getConfiguration('python', uri); + const pythonStartupSetting = configuration.get('terminal.shellIntegration.enabled', false); + + if (pythonStartupSetting) { + createTerminalOptions = { + name: this.options?.title || 'Python', + env: { PYTHONSTARTUP: this.envVarScript }, + hideFromUser: this.options?.hideFromUser, + }; + } else { + createTerminalOptions = { + name: this.options?.title || 'Python', + hideFromUser: this.options?.hideFromUser, + }; + } if (this.terminal) { return; } this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal); - this.terminal = this.terminalManager.createTerminal({ - name: this.options?.title || 'Python', - hideFromUser: this.options?.hideFromUser, - }); + this.terminal = this.terminalManager.createTerminal(createTerminalOptions); this.terminalAutoActivator.disableAutoActivation(this.terminal); // Sometimes the terminal takes some time to start up before it can start accepting input. From de99824e757281e6d4008d82632800e28cd33341 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 11:56:22 -0700 Subject: [PATCH 29/46] clean up --- src/client/common/terminal/service.ts | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index a11c31cf8386..a65043842aa0 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -144,28 +144,14 @@ export class TerminalService implements ITerminalService, Disposable { } // TODO: Debt switch to Promise ---> breaks 20 tests public async ensureTerminal(preserveFocus: boolean = true): Promise { - let createTerminalOptions: TerminalOptions; - const uri = getActiveResource(); - const configuration = getConfiguration('python', uri); - const pythonStartupSetting = configuration.get('terminal.shellIntegration.enabled', false); - - if (pythonStartupSetting) { - createTerminalOptions = { - name: this.options?.title || 'Python', - env: { PYTHONSTARTUP: this.envVarScript }, - hideFromUser: this.options?.hideFromUser, - }; - } else { - createTerminalOptions = { - name: this.options?.title || 'Python', - hideFromUser: this.options?.hideFromUser, - }; - } if (this.terminal) { return; } this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal); - this.terminal = this.terminalManager.createTerminal(createTerminalOptions); + this.terminal = this.terminalManager.createTerminal({ + name: this.options?.title || 'Python', + hideFromUser: this.options?.hideFromUser, + }); this.terminalAutoActivator.disableAutoActivation(this.terminal); // Sometimes the terminal takes some time to start up before it can start accepting input. From dbb2e2ab8d108631b6d058fbf791dff6b7da7739 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 11:56:53 -0700 Subject: [PATCH 30/46] clean up --- src/client/common/terminal/service.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index a65043842aa0..0b9c9138d77f 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import { CancellationToken, Disposable, Event, EventEmitter, Terminal, TerminalOptions } from 'vscode'; +import { CancellationToken, Disposable, Event, EventEmitter, Terminal } from 'vscode'; import '../../common/extensions'; import { IInterpreterService } from '../../interpreter/contracts'; import { IServiceContainer } from '../../ioc/types'; @@ -11,7 +11,6 @@ import { EventName } from '../../telemetry/constants'; import { ITerminalAutoActivation } from '../../terminals/types'; import { ITerminalManager } from '../application/types'; import { _SCRIPTS_DIR } from '../process/internal/scripts/constants'; -import * as path from 'path'; import { IConfigurationService, IDisposableRegistry } from '../types'; import { ITerminalActivator, @@ -22,10 +21,6 @@ import { ITerminalExecutedCommand, } from './types'; import { traceVerbose } from '../../logging'; -import { EXTENSION_ROOT_DIR } from '../constants'; -import { getActiveResource } from '../vscodeApis/windowApis'; -import { getConfiguration } from '../vscodeApis/workspaceApis'; -import { create } from 'lodash'; @injectable() export class TerminalService implements ITerminalService, Disposable { @@ -36,8 +31,6 @@ export class TerminalService implements ITerminalService, Disposable { private terminalHelper: ITerminalHelper; private terminalActivator: ITerminalActivator; private terminalAutoActivator: ITerminalAutoActivation; - - private readonly envVarScript = path.join(EXTENSION_ROOT_DIR, 'python_files', 'pythonrc.py'); private readonly executeCommandListeners: Set = new Set(); public get onDidCloseTerminal(): Event { return this.terminalClosed.event.bind(this.terminalClosed); From 038c98e1945a3cba7ad9017f12b5a61d042e763b Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 13:16:41 -0700 Subject: [PATCH 31/46] add TODO for future --- src/client/common/terminal/service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 0b9c9138d77f..a9f6931f662b 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -98,6 +98,7 @@ export class TerminalService implements ITerminalService, Disposable { } if (terminal.shellIntegration) { + // TODO: executeCommand would not execute command manually typed inside Python Terminal REPL. const execution = terminal.shellIntegration.executeCommand(commandLine); traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); // exitCode as promise for the case: From aa07144a601a763e767ae99c62fa454855eae747 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 13:29:03 -0700 Subject: [PATCH 32/46] improve comment --- src/client/common/terminal/service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index a9f6931f662b..95b356368f25 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -102,8 +102,8 @@ export class TerminalService implements ITerminalService, Disposable { const execution = terminal.shellIntegration.executeCommand(commandLine); traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); // exitCode as promise for the case: - // OnDidEndTerminalShellExecution never fires because python command does not finish until exit() // In the case where SI is enabled in zsh/pwsh in Windows but not inside Python REPL so Python command won't finish until user exit() + // This means OnDidEndTerminalShellExecution would not fire inside REPL launched once REPL is launched for above case. return { execution, From 490ef8b87cfc5840ca42e831946e3f67bd3cb110 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 13:29:49 -0700 Subject: [PATCH 33/46] update comment --- src/client/common/terminal/service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 95b356368f25..f30b38f1b352 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -99,6 +99,7 @@ export class TerminalService implements ITerminalService, Disposable { if (terminal.shellIntegration) { // TODO: executeCommand would not execute command manually typed inside Python Terminal REPL. + // We only run executeCommand when user shift+enter in .py file, and hence run command in terminal on user's behalf. const execution = terminal.shellIntegration.executeCommand(commandLine); traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); // exitCode as promise for the case: From c896ce70e62b01397ef78ea0af19030ba6b0aaeb Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 13:36:19 -0700 Subject: [PATCH 34/46] reset to original timeout number --- src/test/smoke/smartSend.smoke.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index 5e68f193be01..c36fd374f088 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -84,7 +84,7 @@ suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { return new Promise((resolve) => { setTimeout(() => { resolve(); - }, 20000); + }, 10000); }); } From 59a31166e23d479da9fb47100b8cbcf85a1c57c9 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 15:33:50 -0700 Subject: [PATCH 35/46] remove unncessary exitcode promise --- src/client/common/terminal/service.ts | 45 +++++-------------- .../common/terminal/syncTerminalService.ts | 6 +-- src/client/common/terminal/types.ts | 7 +-- 3 files changed, 16 insertions(+), 42 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index f30b38f1b352..afd8bb766777 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import { CancellationToken, Disposable, Event, EventEmitter, Terminal } from 'vscode'; +import { CancellationToken, Disposable, Event, EventEmitter, Terminal, TerminalShellExecution } from 'vscode'; import '../../common/extensions'; import { IInterpreterService } from '../../interpreter/contracts'; import { IServiceContainer } from '../../ioc/types'; @@ -18,7 +18,6 @@ import { ITerminalService, TerminalCreationOptions, TerminalShellType, - ITerminalExecutedCommand, } from './types'; import { traceVerbose } from '../../logging'; @@ -35,6 +34,8 @@ export class TerminalService implements ITerminalService, Disposable { public get onDidCloseTerminal(): Event { return this.terminalClosed.event.bind(this.terminalClosed); } + + // private _shellIntegrationEnabled constructor( @inject(IServiceContainer) private serviceContainer: IServiceContainer, private readonly options?: TerminalCreationOptions, @@ -73,7 +74,7 @@ export class TerminalService implements ITerminalService, Disposable { } this.terminal!.sendText(text); } - public async executeCommand(commandLine: string): Promise { + public async executeCommand(commandLine: string): Promise { const terminal = this.terminal!; if (!this.options?.hideFromUser) { terminal.show(true); @@ -82,15 +83,14 @@ export class TerminalService implements ITerminalService, Disposable { // If terminal was just launched, wait some time for shell integration to onDidChangeShellIntegration. if (!terminal.shellIntegration) { const promise = new Promise((resolve) => { - const shellIntegrationChangeEventListener = this.terminalManager.onDidChangeTerminalShellIntegration( - () => { - this.executeCommandListeners.delete(shellIntegrationChangeEventListener); - resolve(true); - }, - ); + const disposable = this.terminalManager.onDidChangeTerminalShellIntegration(() => { + clearTimeout(timer); //racetimeout + disposable.dispose(); + resolve(true); + }); const TIMEOUT_DURATION = 500; - setTimeout(() => { - this.executeCommandListeners.add(shellIntegrationChangeEventListener); + const timer = setTimeout(() => { + disposable.dispose(); resolve(true); }, TIMEOUT_DURATION); }); @@ -101,28 +101,7 @@ export class TerminalService implements ITerminalService, Disposable { // TODO: executeCommand would not execute command manually typed inside Python Terminal REPL. // We only run executeCommand when user shift+enter in .py file, and hence run command in terminal on user's behalf. const execution = terminal.shellIntegration.executeCommand(commandLine); - traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); - // exitCode as promise for the case: - // In the case where SI is enabled in zsh/pwsh in Windows but not inside Python REPL so Python command won't finish until user exit() - // This means OnDidEndTerminalShellExecution would not fire inside REPL launched once REPL is launched for above case. - - return { - execution, - exitCode: new Promise((resolve) => { - const listener = this.terminalManager.onDidEndTerminalShellExecution((e) => { - if (e.execution === execution) { - this.executeCommandListeners.delete(listener); - resolve(e.exitCode); - traceVerbose( - `onDidEndTerminalShellExecution handler is called: Shell Integration exitCode: ${e.exitCode}`, - ); - } - }); - if (listener) { - this.executeCommandListeners.add(listener); - } - }), - }; + return execution; } else { terminal.sendText(commandLine); traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`); diff --git a/src/client/common/terminal/syncTerminalService.ts b/src/client/common/terminal/syncTerminalService.ts index e5b120a11110..60f8ed7a6847 100644 --- a/src/client/common/terminal/syncTerminalService.ts +++ b/src/client/common/terminal/syncTerminalService.ts @@ -4,7 +4,7 @@ 'use strict'; import { inject } from 'inversify'; -import { CancellationToken, Disposable, Event } from 'vscode'; +import { CancellationToken, Disposable, Event, TerminalShellExecution } from 'vscode'; import { IInterpreterService } from '../../interpreter/contracts'; import { traceVerbose } from '../../logging'; import { PythonEnvironment } from '../../pythonEnvironments/info'; @@ -14,7 +14,7 @@ import * as internalScripts from '../process/internal/scripts'; import { createDeferred, Deferred } from '../utils/async'; import { noop } from '../utils/misc'; import { TerminalService } from './service'; -import { ITerminalService, ITerminalExecutedCommand } from './types'; +import { ITerminalService } from './types'; enum State { notStarted = 0, @@ -145,7 +145,7 @@ export class SynchronousTerminalService implements ITerminalService, Disposable public sendText(text: string): Promise { return this.terminalService.sendText(text); } - public executeCommand(commandLine: string): Promise { + public executeCommand(commandLine: string): Promise { return this.terminalService.executeCommand(commandLine); } public show(preserveFocus?: boolean | undefined): Promise { diff --git a/src/client/common/terminal/types.ts b/src/client/common/terminal/types.ts index 190470418440..db2b7f80e4b1 100644 --- a/src/client/common/terminal/types.ts +++ b/src/client/common/terminal/types.ts @@ -54,15 +54,10 @@ export interface ITerminalService extends IDisposable { ): Promise; /** @deprecated */ sendText(text: string): Promise; - executeCommand(commandLine: string): Promise; + executeCommand(commandLine: string): Promise; show(preserveFocus?: boolean): Promise; } -export interface ITerminalExecutedCommand { - execution: TerminalShellExecution; - exitCode: Promise; -} - export const ITerminalServiceFactory = Symbol('ITerminalServiceFactory'); export type TerminalCreationOptions = { From 4fd5369d94c008c84b09e95d911ff039eb02a09a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 15:42:10 -0700 Subject: [PATCH 36/46] add _shellIntegrationEnabled --- src/client/common/terminal/service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index afd8bb766777..fdc41d74f2ac 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -31,11 +31,11 @@ export class TerminalService implements ITerminalService, Disposable { private terminalActivator: ITerminalActivator; private terminalAutoActivator: ITerminalAutoActivation; private readonly executeCommandListeners: Set = new Set(); + private _shellIntegrationEnabled: boolean = false; public get onDidCloseTerminal(): Event { return this.terminalClosed.event.bind(this.terminalClosed); } - // private _shellIntegrationEnabled constructor( @inject(IServiceContainer) private serviceContainer: IServiceContainer, private readonly options?: TerminalCreationOptions, @@ -81,15 +81,17 @@ export class TerminalService implements ITerminalService, Disposable { } // If terminal was just launched, wait some time for shell integration to onDidChangeShellIntegration. - if (!terminal.shellIntegration) { + if (!terminal.shellIntegration && !this._shellIntegrationEnabled) { const promise = new Promise((resolve) => { const disposable = this.terminalManager.onDidChangeTerminalShellIntegration(() => { + this._shellIntegrationEnabled = true; clearTimeout(timer); //racetimeout disposable.dispose(); resolve(true); }); const TIMEOUT_DURATION = 500; const timer = setTimeout(() => { + this._shellIntegrationEnabled = false; disposable.dispose(); resolve(true); }, TIMEOUT_DURATION); @@ -101,8 +103,10 @@ export class TerminalService implements ITerminalService, Disposable { // TODO: executeCommand would not execute command manually typed inside Python Terminal REPL. // We only run executeCommand when user shift+enter in .py file, and hence run command in terminal on user's behalf. const execution = terminal.shellIntegration.executeCommand(commandLine); + this._shellIntegrationEnabled = true; return execution; } else { + this._shellIntegrationEnabled = false; terminal.sendText(commandLine); traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`); } From b40f53f9b285d5b168a990a4bb9655e1d4a6fc28 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 15:44:55 -0700 Subject: [PATCH 37/46] add _terminalFirstLaunched field to not call onDidChangeTerminalShellIntegration everytime --- src/client/common/terminal/service.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index fdc41d74f2ac..949c935874ac 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -31,7 +31,7 @@ export class TerminalService implements ITerminalService, Disposable { private terminalActivator: ITerminalActivator; private terminalAutoActivator: ITerminalAutoActivation; private readonly executeCommandListeners: Set = new Set(); - private _shellIntegrationEnabled: boolean = false; + private _terminalFirstLaunched: boolean = true; public get onDidCloseTerminal(): Event { return this.terminalClosed.event.bind(this.terminalClosed); } @@ -81,17 +81,16 @@ export class TerminalService implements ITerminalService, Disposable { } // If terminal was just launched, wait some time for shell integration to onDidChangeShellIntegration. - if (!terminal.shellIntegration && !this._shellIntegrationEnabled) { + if (!terminal.shellIntegration && this._terminalFirstLaunched) { + this._terminalFirstLaunched = false; const promise = new Promise((resolve) => { const disposable = this.terminalManager.onDidChangeTerminalShellIntegration(() => { - this._shellIntegrationEnabled = true; clearTimeout(timer); //racetimeout disposable.dispose(); resolve(true); }); const TIMEOUT_DURATION = 500; const timer = setTimeout(() => { - this._shellIntegrationEnabled = false; disposable.dispose(); resolve(true); }, TIMEOUT_DURATION); @@ -103,10 +102,8 @@ export class TerminalService implements ITerminalService, Disposable { // TODO: executeCommand would not execute command manually typed inside Python Terminal REPL. // We only run executeCommand when user shift+enter in .py file, and hence run command in terminal on user's behalf. const execution = terminal.shellIntegration.executeCommand(commandLine); - this._shellIntegrationEnabled = true; return execution; } else { - this._shellIntegrationEnabled = false; terminal.sendText(commandLine); traceVerbose(`Shell Integration is disabled, sendText: ${commandLine}`); } From e527be72366db4ec81f650c2cf55e626e5455da6 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 15:49:10 -0700 Subject: [PATCH 38/46] add log for executeCommand --- src/client/common/terminal/service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 949c935874ac..64b782c1d350 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -20,6 +20,7 @@ import { TerminalShellType, } from './types'; import { traceVerbose } from '../../logging'; +import { trace } from 'console'; @injectable() export class TerminalService implements ITerminalService, Disposable { @@ -102,6 +103,7 @@ export class TerminalService implements ITerminalService, Disposable { // TODO: executeCommand would not execute command manually typed inside Python Terminal REPL. // We only run executeCommand when user shift+enter in .py file, and hence run command in terminal on user's behalf. const execution = terminal.shellIntegration.executeCommand(commandLine); + traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); return execution; } else { terminal.sendText(commandLine); From 446e95c5fb366d04ea968efec32b749888980056 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 15:49:31 -0700 Subject: [PATCH 39/46] remove unused --- src/client/common/terminal/service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 64b782c1d350..c62c65a3aef6 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -20,7 +20,6 @@ import { TerminalShellType, } from './types'; import { traceVerbose } from '../../logging'; -import { trace } from 'console'; @injectable() export class TerminalService implements ITerminalService, Disposable { From 143532993547e322f4f8eee3b8c9099fca36715f Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 18:49:29 -0700 Subject: [PATCH 40/46] remove unnecessary comment --- src/client/common/terminal/service.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index c62c65a3aef6..45ce9afac47e 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -85,7 +85,7 @@ export class TerminalService implements ITerminalService, Disposable { this._terminalFirstLaunched = false; const promise = new Promise((resolve) => { const disposable = this.terminalManager.onDidChangeTerminalShellIntegration(() => { - clearTimeout(timer); //racetimeout + clearTimeout(timer); disposable.dispose(); resolve(true); }); @@ -99,8 +99,6 @@ export class TerminalService implements ITerminalService, Disposable { } if (terminal.shellIntegration) { - // TODO: executeCommand would not execute command manually typed inside Python Terminal REPL. - // We only run executeCommand when user shift+enter in .py file, and hence run command in terminal on user's behalf. const execution = terminal.shellIntegration.executeCommand(commandLine); traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`); return execution; From 12f7b3eed6d128e48b78d8f91da70d02f0f9f8a6 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 30 Oct 2024 18:54:05 -0700 Subject: [PATCH 41/46] make smoke test use pwsh --- src/test/smokeTest.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/test/smokeTest.ts b/src/test/smokeTest.ts index bcd70c0e3417..7a8e029e2788 100644 --- a/src/test/smokeTest.ts +++ b/src/test/smokeTest.ts @@ -5,7 +5,7 @@ // Must always be on top to setup expected env. process.env.VSC_PYTHON_SMOKE_TEST = '1'; - +import * as vscode from 'vscode'; import { spawn } from 'child_process'; import * as fs from '../client/common/platform/fs-paths'; import * as glob from 'glob'; @@ -47,6 +47,19 @@ class TestRunner { ); } private async launchTest(customEnvVars: Record) { + const configurationTerminal = vscode.workspace.getConfiguration('terminal'); + await configurationTerminal.update('integrated.defaultProfile.osx', 'pwsh', vscode.ConfigurationTarget.Global); + await configurationTerminal.update( + 'integrated.defaultProfile.linux', + 'pwsh', + vscode.ConfigurationTarget.Global, + ); + await configurationTerminal.update( + 'integrated.defaultProfile.windows', + 'pwsh', + vscode.ConfigurationTarget.Global, + ); + console.log('Launch tests in test runner'); await new Promise((resolve, reject) => { const env: Record = { From 4a2a5d099a50309f91ec6ab24a88b8f4e504b0c3 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 31 Oct 2024 09:18:54 -0700 Subject: [PATCH 42/46] stop complaining about unknown import --- src/test/smokeTest.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/test/smokeTest.ts b/src/test/smokeTest.ts index 7a8e029e2788..eb1f60792e1b 100644 --- a/src/test/smokeTest.ts +++ b/src/test/smokeTest.ts @@ -5,7 +5,7 @@ // Must always be on top to setup expected env. process.env.VSC_PYTHON_SMOKE_TEST = '1'; -import * as vscode from 'vscode'; +import { workspace, ConfigurationTarget } from 'vscode'; import { spawn } from 'child_process'; import * as fs from '../client/common/platform/fs-paths'; import * as glob from 'glob'; @@ -47,18 +47,10 @@ class TestRunner { ); } private async launchTest(customEnvVars: Record) { - const configurationTerminal = vscode.workspace.getConfiguration('terminal'); - await configurationTerminal.update('integrated.defaultProfile.osx', 'pwsh', vscode.ConfigurationTarget.Global); - await configurationTerminal.update( - 'integrated.defaultProfile.linux', - 'pwsh', - vscode.ConfigurationTarget.Global, - ); - await configurationTerminal.update( - 'integrated.defaultProfile.windows', - 'pwsh', - vscode.ConfigurationTarget.Global, - ); + const configurationTerminal = workspace.getConfiguration('terminal'); + await configurationTerminal.update('integrated.defaultProfile.osx', 'pwsh', ConfigurationTarget.Global); + await configurationTerminal.update('integrated.defaultProfile.linux', 'pwsh', ConfigurationTarget.Global); + await configurationTerminal.update('integrated.defaultProfile.windows', 'pwsh', ConfigurationTarget.Global); console.log('Launch tests in test runner'); await new Promise((resolve, reject) => { From c56fb61f00a8cd8e8901bb447c5e70199902e290 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 31 Oct 2024 10:12:25 -0700 Subject: [PATCH 43/46] append to standardTest to update setting --- src/test/smokeTest.ts | 5 ----- src/test/standardTest.ts | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/test/smokeTest.ts b/src/test/smokeTest.ts index eb1f60792e1b..6b71ff6fb8cf 100644 --- a/src/test/smokeTest.ts +++ b/src/test/smokeTest.ts @@ -47,11 +47,6 @@ class TestRunner { ); } private async launchTest(customEnvVars: Record) { - const configurationTerminal = workspace.getConfiguration('terminal'); - await configurationTerminal.update('integrated.defaultProfile.osx', 'pwsh', ConfigurationTarget.Global); - await configurationTerminal.update('integrated.defaultProfile.linux', 'pwsh', ConfigurationTarget.Global); - await configurationTerminal.update('integrated.defaultProfile.windows', 'pwsh', ConfigurationTarget.Global); - console.log('Launch tests in test runner'); await new Promise((resolve, reject) => { const env: Record = { diff --git a/src/test/standardTest.ts b/src/test/standardTest.ts index 00eb3d7cf8c4..8d6cf32edcc9 100644 --- a/src/test/standardTest.ts +++ b/src/test/standardTest.ts @@ -29,6 +29,29 @@ const extensionDevelopmentPath = process.env.CODE_EXTENSIONS_PATH ? process.env.CODE_EXTENSIONS_PATH : EXTENSION_ROOT_DIR_FOR_TESTS; +// Make sure shell used are pwsh for smoke tests +// create .vscode folder inside workspacePath and settings.json inside that .vscode path +async function setupWorkspace() { + await fs.ensureDir(path.join(workspacePath, '.vscode')); + const settingsPath = path.join(workspacePath, '.vscode', 'settings.json'); + if (!(await fs.pathExists(settingsPath))) { + await fs.writeFile( + settingsPath, + `{ + "terminal.integrated.defaultProfile.linux": "pwsh", + "terminal.integrated.defaultProfile.osx": "pwsh", + "terminal.integrated.defaultProfile.windows": "pwsh" + }`, + ); + } +} +if (process.env.TEST_FILES_SUFFIX !== 'smoke.test') { + setupWorkspace().catch((err) => { + console.error('Failed to setup workspace for smoke test', err); + process.exit(1); + }); +} + /** * Smoke tests & tests running in VSCode require Jupyter extension to be installed. */ From d4b022772c6f9ad9f2ff7e9c8f75aff5fec3f8ca Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 31 Oct 2024 10:15:34 -0700 Subject: [PATCH 44/46] no more importing vscode --- src/test/smokeTest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/smokeTest.ts b/src/test/smokeTest.ts index 6b71ff6fb8cf..a101e961e03d 100644 --- a/src/test/smokeTest.ts +++ b/src/test/smokeTest.ts @@ -5,7 +5,6 @@ // Must always be on top to setup expected env. process.env.VSC_PYTHON_SMOKE_TEST = '1'; -import { workspace, ConfigurationTarget } from 'vscode'; import { spawn } from 'child_process'; import * as fs from '../client/common/platform/fs-paths'; import * as glob from 'glob'; From 9e0d33dcde38cf68ab2bb6d3f8533ac33e63907b Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 31 Oct 2024 10:29:45 -0700 Subject: [PATCH 45/46] dont add setting programmatically for smoke test --- src/test/standardTest.ts | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/test/standardTest.ts b/src/test/standardTest.ts index 8d6cf32edcc9..00eb3d7cf8c4 100644 --- a/src/test/standardTest.ts +++ b/src/test/standardTest.ts @@ -29,29 +29,6 @@ const extensionDevelopmentPath = process.env.CODE_EXTENSIONS_PATH ? process.env.CODE_EXTENSIONS_PATH : EXTENSION_ROOT_DIR_FOR_TESTS; -// Make sure shell used are pwsh for smoke tests -// create .vscode folder inside workspacePath and settings.json inside that .vscode path -async function setupWorkspace() { - await fs.ensureDir(path.join(workspacePath, '.vscode')); - const settingsPath = path.join(workspacePath, '.vscode', 'settings.json'); - if (!(await fs.pathExists(settingsPath))) { - await fs.writeFile( - settingsPath, - `{ - "terminal.integrated.defaultProfile.linux": "pwsh", - "terminal.integrated.defaultProfile.osx": "pwsh", - "terminal.integrated.defaultProfile.windows": "pwsh" - }`, - ); - } -} -if (process.env.TEST_FILES_SUFFIX !== 'smoke.test') { - setupWorkspace().catch((err) => { - console.error('Failed to setup workspace for smoke test', err); - process.exit(1); - }); -} - /** * Smoke tests & tests running in VSCode require Jupyter extension to be installed. */ From 6fba2a857963fa2d25a1adb7a38f50585a3383d2 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 31 Oct 2024 10:50:54 -0700 Subject: [PATCH 46/46] clean up --- src/test/smoke/smartSend.smoke.test.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/test/smoke/smartSend.smoke.test.ts b/src/test/smoke/smartSend.smoke.test.ts index c36fd374f088..dc1f07f047e7 100644 --- a/src/test/smoke/smartSend.smoke.test.ts +++ b/src/test/smoke/smartSend.smoke.test.ts @@ -20,23 +20,6 @@ suite('Smoke Test: Run Smart Selection and Advance Cursor', async () => { teardown(closeActiveWindows); test('Smart Send', async () => { - const configuration = vscode.workspace.getConfiguration('python'); - await configuration.update('REPL.sendToNativeREPL', false, vscode.ConfigurationTarget.Global); - await configuration.update('REPL.enableREPLSmartSend', true, vscode.ConfigurationTarget.Global); - const configurationTerminal = vscode.workspace.getConfiguration('terminal'); - // set terminal.integrated.shellIntegration.enabled to false - await configurationTerminal.update( - 'integrated.shellIntegration.enabled', - false, - vscode.ConfigurationTarget.Global, - ); - configurationTerminal.update( - 'integrated.defaultProfile.windows', - 'PowerShell', - vscode.ConfigurationTarget.Global, - ); - configurationTerminal.update('integrated.defaultProfile.osx', 'PowerShell', vscode.ConfigurationTarget.Global); - const file = path.join( EXTENSION_ROOT_DIR_FOR_TESTS, 'src',