From 2d86c4b42dbf7a8236069aa9c6610459549dccf5 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Tue, 24 Nov 2026 13:16:50 +0100 Subject: [PATCH] smoke: wait for smoketest.openLocalChat to finish before using the Chat view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In a fresh window, `smoketest.openLocalChat` can run seconds after the command palette closes: the extension host activates the smoke test extension on that command only once it has activated the eager extensions. Meanwhile the Chat view binds its own startup session, which is a local chat when the Agent Host is not available yet. When the test read the view before that binding, `waitForNewLocalChatViewSession` accepted the startup session, the prompt went to it, and the late New Local Chat then moved it to the sessions list, so its reply never showed in the view. The command now writes a marker file once New Local Chat has finished, and the new `openLocalChatInChatView` helper waits for it before checking the view's session. All four callers of the command use the helper. 🤖 Authored with GitHub Copilot on behalf of @lszomoru. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- test/automation/src/chat.ts | 11 +++--- .../vscode-smoketest-ext-host/extension.js | 7 ++++ .../src/areas/browserView/browserView.test.ts | 6 ++-- .../src/areas/chat/chatModelConfig.test.ts | 6 ++-- test/smoke/src/areas/chat/chatSandbox.test.ts | 6 ++-- .../smoke/src/areas/chat/chatSessions.test.ts | 12 ++----- test/smoke/src/utils.ts | 35 +++++++++++++++++++ 7 files changed, 55 insertions(+), 28 deletions(-) diff --git a/test/automation/src/chat.ts b/test/automation/src/chat.ts index ec2b99ac6b62dc..89d198ebf981d4 100644 --- a/test/automation/src/chat.ts +++ b/test/automation/src/chat.ts @@ -74,12 +74,11 @@ export class Chat { /** * Waits until the chat view is bound to a local chat session other than - * `previousSessionResource`, such as the one `smoketest.openLocalChat` - * opens. That command keeps running after the command palette closes, and - * first waits for the command that opens a local chat to be registered: a - * message sent before then goes to the session the view had, such as the - * Agent Host Copilot session that is its default, and never gets the - * response the test expects. + * `previousSessionResource`. A session the view binds on its own, such as + * a local one while the agent host is not available, also satisfies this + * wait. So to wait for a session a command opens, first wait for the + * command to finish, as the smoke tests' `openLocalChatInChatView` does + * for `smoketest.openLocalChat`. */ async waitForNewLocalChatViewSession(previousSessionResource: string | undefined, retryCount?: number): Promise { await this.code.waitForElement(CHAT_VIEW_BOUND_SESSION, element => { diff --git a/test/smoke/extensions/vscode-smoketest-ext-host/extension.js b/test/smoke/extensions/vscode-smoketest-ext-host/extension.js index 94d299218ece1b..7ca4a5496b2ad5 100644 --- a/test/smoke/extensions/vscode-smoketest-ext-host/extension.js +++ b/test/smoke/extensions/vscode-smoketest-ext-host/extension.js @@ -108,6 +108,13 @@ function activate(context) { const command = 'workbench.action.chat.newLocalChat'; await waitForCommand(command, 60_000); await vscode.commands.executeCommand(command); + + // The command palette does not wait for this command, which can run + // seconds after the palette closed while the extension host is still + // activating this extension. Tell the smoke test that the chat view + // now shows the new local chat. + // Note: filename must match name in test/smoke/src/utils.ts + fs.writeFileSync(path.join(os.tmpdir(), 'vscode-smoketest-open-local-chat-done.txt'), String(Date.now()), 'utf-8'); }) ); diff --git a/test/smoke/src/areas/browserView/browserView.test.ts b/test/smoke/src/areas/browserView/browserView.test.ts index 5d5382af71598f..11248a78ff955f 100644 --- a/test/smoke/src/areas/browserView/browserView.test.ts +++ b/test/smoke/src/areas/browserView/browserView.test.ts @@ -10,7 +10,7 @@ import * as path from 'path'; import { fileURLToPath, pathToFileURL } from 'url'; import type { Page } from '@playwright/test'; import { Application, ApplicationOptions, Logger } from '../../../../automation'; -import { getCopilotSmokeTestEnv, getMockLlmServerPath, getMockLlmServerUrl, installAllHandlers, MockLlmServer, preseedChatExtensionEnablement } from '../../utils'; +import { getCopilotSmokeTestEnv, getMockLlmServerPath, getMockLlmServerUrl, installAllHandlers, MockLlmServer, openLocalChatInChatView, preseedChatExtensionEnablement } from '../../utils'; const browserCommandPrefix = 'workbench.action.browser'; @@ -379,9 +379,7 @@ export function setup(logger: Logger): void { await workbenchPage.locator('.tab', { hasText: 'Browser Smoke Sharing' }).click(); await unshareButton.waitFor(); - const previousSessionResource = await app.workbench.chat.getChatViewSessionResource(); - await app.workbench.quickaccess.runCommand('smoketest.openLocalChat'); - await app.workbench.chat.waitForNewLocalChatViewSession(previousSessionResource, 600); + await openLocalChatInChatView(app); await app.workbench.chat.sendMessage('[scenario:browser-sharing-click-success]'); const successToolResult = await waitForScenarioToolResult(mockServer, 'browser-sharing-click-success'); assert.doesNotMatch(successToolResult, /not found/i); diff --git a/test/smoke/src/areas/chat/chatModelConfig.test.ts b/test/smoke/src/areas/chat/chatModelConfig.test.ts index 2c5524624644fc..4c9103b3370465 100644 --- a/test/smoke/src/areas/chat/chatModelConfig.test.ts +++ b/test/smoke/src/areas/chat/chatModelConfig.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; import { Application, Chat, Logger } from '../../../../automation'; -import { dumpFailureDiagnostics, getCopilotSmokeTestEnv, getMockLlmServerPath, installAllHandlers, latestUserInputCarriesTag, MOCK_CONFIG_MODEL_DEFAULT_LABEL, MOCK_CONFIG_MODEL_DEFAULT_SECTIONS, MockLlmServer, preseedChatExtensionEnablement } from '../../utils'; +import { dumpFailureDiagnostics, getCopilotSmokeTestEnv, getMockLlmServerPath, installAllHandlers, latestUserInputCarriesTag, MOCK_CONFIG_MODEL_DEFAULT_LABEL, MOCK_CONFIG_MODEL_DEFAULT_SECTIONS, MockLlmServer, openLocalChatInChatView, preseedChatExtensionEnablement } from '../../utils'; /** * A chat request captured by the mock LLM server, exposed via @@ -226,9 +226,7 @@ export function setup(logger: Logger) { // override is applied on the agent request path). Select the local // harness explicitly since the panel default is Agent Host Copilot // when the agent host is enabled. - const previousSessionResource = await chat.getChatViewSessionResource(); - await app.workbench.quickaccess.runCommand('smoketest.openLocalChat'); - await chat.waitForNewLocalChatViewSession(previousSessionResource, 600); + await openLocalChatInChatView(app); // Retry the warm-up send until the model actually replies, which // confirms copilot-chat is active and the panel is usable. diff --git a/test/smoke/src/areas/chat/chatSandbox.test.ts b/test/smoke/src/areas/chat/chatSandbox.test.ts index c58b957b2c503d..6fd88bccb66626 100644 --- a/test/smoke/src/areas/chat/chatSandbox.test.ts +++ b/test/smoke/src/areas/chat/chatSandbox.test.ts @@ -8,7 +8,7 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; import { Application, Chat, Logger } from '../../../../automation'; -import { dumpFailureDiagnostics, getCopilotSmokeTestEnv, getMockLlmServerPath, installAllHandlers, latestUserInputCarriesTag, MockLlmServer, preseedChatExtensionEnablement } from '../../utils'; +import { dumpFailureDiagnostics, getCopilotSmokeTestEnv, getMockLlmServerPath, installAllHandlers, latestUserInputCarriesTag, MockLlmServer, openLocalChatInChatView, preseedChatExtensionEnablement } from '../../utils'; const WARMUP_SCENARIO_ID = 'smoke-chat-sandbox-warmup'; const WARMUP_REPLY = 'MOCKED_CHAT_SANDBOX_WARMUP'; @@ -212,9 +212,7 @@ export function setup(logger: Logger): void { before(async function () { const app = this.app as Application; - const previousSessionResource = await app.workbench.chat.getChatViewSessionResource(); - await app.workbench.quickaccess.runCommand('smoketest.openLocalChat'); - await app.workbench.chat.waitForNewLocalChatViewSession(previousSessionResource, 600); + await openLocalChatInChatView(app); await warmUpChat(app.workbench.chat, mockServer, logger); }); diff --git a/test/smoke/src/areas/chat/chatSessions.test.ts b/test/smoke/src/areas/chat/chatSessions.test.ts index d892b51e855676..8d66bf2b30e15a 100644 --- a/test/smoke/src/areas/chat/chatSessions.test.ts +++ b/test/smoke/src/areas/chat/chatSessions.test.ts @@ -7,7 +7,7 @@ import * as assert from 'assert'; import * as fs from 'fs'; import * as path from 'path'; import { Application, Chat, Logger } from '../../../../automation'; -import { dumpFailureDiagnostics, getCopilotSmokeTestEnv, getMockLlmServerPath, getMockLlmServerUrl, installAllHandlers, MockLlmServer, preseedChatExtensionEnablement } from '../../utils'; +import { dumpFailureDiagnostics, getCopilotSmokeTestEnv, getMockLlmServerPath, getMockLlmServerUrl, installAllHandlers, MockLlmServer, openLocalChatInChatView, preseedChatExtensionEnablement } from '../../utils'; import { runInTerminalScenario, shellEchoResponseMatcher } from './shellScenarios'; /** @@ -192,15 +192,7 @@ async function openSession(app: Application, session: { readonly command: string await app.workbench.quickaccess.runCommand(session.command); await app.workbench.chat.waitForChatEditor(600); } else { - // Wait for the command to bind a new local session to the view, not - // just any session. The view can open first with its default Agent Host - // Copilot session while the command still waits for the local chat - // command to register, as when this test is the first of the suite in - // a cold window. A prompt sent then goes to that session and never gets - // the local reply. - const previousSessionResource = await app.workbench.chat.getChatViewSessionResource(); - await app.workbench.quickaccess.runCommand(session.command); - await app.workbench.chat.waitForNewLocalChatViewSession(previousSessionResource, 600); + await openLocalChatInChatView(app); } } diff --git a/test/smoke/src/utils.ts b/test/smoke/src/utils.ts index cf88243916bea2..b5627a34a4c339 100644 --- a/test/smoke/src/utils.ts +++ b/test/smoke/src/utils.ts @@ -6,6 +6,7 @@ import * as sqlite3 from '@vscode/sqlite3'; import * as fs from 'fs'; import { Suite, Context } from 'mocha'; +import { tmpdir } from 'os'; import { dirname, join } from 'path'; import { Application, ApplicationOptions, IModelConfigSection, Logger } from '../../automation'; @@ -392,6 +393,40 @@ export async function retryWithRestart(app: Application, testFn: () => Promise { + fs.rmSync(OPEN_LOCAL_CHAT_DONE_FILE, { force: true }); + const previousSessionResource = await app.workbench.chat.getChatViewSessionResource(); + await app.workbench.quickaccess.runCommand('smoketest.openLocalChat'); + + // The command itself waits up to 60 seconds for New Local Chat to be registered. + const deadline = Date.now() + 90_000; + while (!fs.existsSync(OPEN_LOCAL_CHAT_DONE_FILE)) { + if (Date.now() > deadline) { + throw new Error('Timed out waiting for smoketest.openLocalChat to open a new local chat'); + } + await timeout(100); + } + + await app.workbench.chat.waitForNewLocalChatViewSession(previousSessionResource); +} + export interface ITask { (): T; }