Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions test/automation/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await this.code.waitForElement(CHAT_VIEW_BOUND_SESSION, element => {
Expand Down
7 changes: 7 additions & 0 deletions test/smoke/extensions/vscode-smoketest-ext-host/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
})
);

Expand Down
6 changes: 2 additions & 4 deletions test/smoke/src/areas/browserView/browserView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions test/smoke/src/areas/chat/chatModelConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions test/smoke/src/areas/chat/chatSandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
});

Expand Down
12 changes: 2 additions & 10 deletions test/smoke/src/areas/chat/chatSessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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);
}
}

Expand Down
35 changes: 35 additions & 0 deletions test/smoke/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -392,6 +393,40 @@ export async function retryWithRestart(app: Application, testFn: () => Promise<u
throw lastError ?? new Error('retryWithRestart failed with an unknown error');
}

/**
* Written by `smoketest.openLocalChat` (`test/smoke/extensions/vscode-smoketest-ext-host`)
* once the chat view shows the new local chat it opened.
*/
const OPEN_LOCAL_CHAT_DONE_FILE = join(tmpdir(), 'vscode-smoketest-open-local-chat-done.txt');

/**
* Opens a new local chat in the chat view with `smoketest.openLocalChat`, and
* returns once the view shows it.
*
* The command palette closes before the command has run. In a fresh window
* the command can run seconds later, once the extension host has activated
* the smoke test extension. Meanwhile the chat view can bind a session of its
* own, also a local one, and a message sent to it is left running in the
* background when the command opens its new chat. So wait for the command to
* finish rather than for the view to show some other local chat.
*/
export async function openLocalChatInChatView(app: Application): Promise<void> {
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> {
(): T;
}
Expand Down