Path: blob/main/extensions/copilot/test/e2e/vscode-metaprompt.stest.ts
13388 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { ChatVariablesCollection } from '../../src/extension/prompt/common/chatVariablesCollection';7import { VscodePrompt } from '../../src/extension/prompts/node/panel/vscode';8import { IEndpointProvider } from '../../src/platform/endpoint/common/endpointProvider';9import { CancellationToken } from '../../src/util/vs/base/common/cancellation';10import { IInstantiationService } from '../../src/util/vs/platform/instantiation/common/instantiation';11import { ssuite, stest } from '../base/stest';1213ssuite.skip({ title: 'vscode', subtitle: 'metaprompt', location: 'panel' }, async (_) => {1415const scenarios = [16{17question: 'how to opne command pallete',18keywords: ['open', 'command palette'],19excludedKeywords: ['how',]20},21{22question: 'how do I change font size setting',23keywords: ['setting', 'font size'],24excludedKeywords: ['how',]25},26{27question: 'enable word wrap in editer',28keywords: ['enable', 'editor', 'word wrap'],29excludedKeywords: []30},31];3233for (const scenario of scenarios) {34stest({ description: scenario.question },35async (testingServiceCollection) => {36const accessor = testingServiceCollection.createTestingAccessor();37const instantiationService = accessor.get(IInstantiationService);3839const endpoint = await accessor.get(IEndpointProvider).getChatEndpoint('copilot-base');40const vscodePrompt = instantiationService.createInstance(VscodePrompt, {41promptContext: {42chatVariables: new ChatVariablesCollection([]),43history: [],44query: scenario.question,45},46endpoint47});4849const tokenizer = endpoint.acquireTokenizer();50const countTokens = (text: string) => tokenizer.tokenLength(text);5152const prompt = await vscodePrompt.prepare({ tokenBudget: 2048, endpoint, countTokens }, undefined, CancellationToken.None);53assert.notEqual(prompt.query, scenario.question);5455for (const keyword of scenario.keywords) {56assert.ok(prompt.query.toLowerCase().includes(keyword.toLowerCase()), `${keyword} not found in prompt query`);57}58for (const keyword of scenario.excludedKeywords) {59assert.ok(!prompt.query.toLowerCase().includes(keyword.toLowerCase()), `prompt query should not include "${keyword}"`);60}61});62}63});646566