From 6a0d6355a887992e62db77fda10ede877ea94e52 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Sat, 17 Oct 2026 09:53:26 +0200 Subject: [PATCH] chat: run implicit context selection debounce tests in virtual time Both tests slept a real 510ms per step to get past the 500ms selection debounce. Run them in virtual time; the ordering they check is unchanged. Each test drops from ~1.5s to a few ms. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../browser/attachments/chatImplicitContext.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/chat/test/browser/attachments/chatImplicitContext.test.ts b/src/vs/workbench/contrib/chat/test/browser/attachments/chatImplicitContext.test.ts index 8855c86e52c057..4008f5bf1973cc 100644 --- a/src/vs/workbench/contrib/chat/test/browser/attachments/chatImplicitContext.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/attachments/chatImplicitContext.test.ts @@ -11,6 +11,7 @@ import { constObservable } from '../../../../../../base/common/observable.js'; import { URI } from '../../../../../../base/common/uri.js'; import { upcastPartial } from '../../../../../../base/test/common/mock.js'; import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../base/test/common/utils.js'; +import { runWithFakedTimers } from '../../../../../../base/test/common/virtualScheduling/index.js'; import { ICodeEditor } from '../../../../../../editor/browser/editorBrowser.js'; import { ICodeEditorService } from '../../../../../../editor/browser/services/codeEditorService.js'; import { ISelection, Selection } from '../../../../../../editor/common/core/selection.js'; @@ -133,7 +134,8 @@ suite('Chat implicit custom editor context', () => { assert.strictEqual(fixture.implicitContext.enabledBaseEntries(false)[0].id, 'vscode.implicit.selection'); }); - test('selection changes, collapsed carets and cleared selections update context without webview messages', async () => { + test('selection changes, collapsed carets and cleared selections update context without webview messages', () => runWithFakedTimers({}, async () => { + // Advance past the selection debounce in virtual time. const fixture = setupContext(); fixture.input.navigation = fixture.navigation; fixture.navigation.updateSelection(new Selection(3, 5, 2, 1)); @@ -147,7 +149,7 @@ suite('Chat implicit custom editor context', () => { fixture.navigation.updateSelection(undefined); await timeout(510); assert.deepStrictEqual(fixture.values(), [{ value: fixture.model.uri, isSelection: false }]); - }); + })); test('switching panels uses only the active panel and detaches the previous navigation', async () => { const fixture = setupContext(); @@ -199,7 +201,8 @@ suite('Chat implicit custom editor context', () => { }); } - test('an older async selection update cannot replace a newer selection or editor', async () => { + test('an older async selection update cannot replace a newer selection or editor', () => runWithFakedTimers({}, async () => { + // Advance past the selection debounce in virtual time. let pending: DeferredPromise | undefined; const fixture = setupContext({ contextForResource: () => pending?.p ?? Promise.resolve(undefined) }); fixture.input.navigation = fixture.navigation; @@ -229,7 +232,7 @@ suite('Chat implicit custom editor context', () => { assert.deepStrictEqual(fixture.values(), [{ value: { uri: fixture.codeModel.uri, range: fixture.codeSelection }, isSelection: true, }]); - }); + })); test('disposing the contribution cancels pending updates and removes selection listeners', async () => { let pending: DeferredPromise | undefined;