Path: blob/main/extensions/copilot/test/intent/inlineChatIntent.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 * as fs from 'fs';6import { join } from 'path';7import { Intent } from '../../src/extension/common/constants';8import { EditCodeIntent } from '../../src/extension/intents/node/editCodeIntent';9import { GenerateCodeIntent } from '../../src/extension/intents/node/generateCodeIntent';10import { ChatLocation } from '../../src/platform/chat/common/commonTypes';11import { ssuite, stest } from '../base/stest';12import { simulateInlineChat } from '../simulation/inlineChatSimulator';13import { fromFixture } from '../simulation/stestUtil';14import { generateIntentTest } from './intentTest';1516ssuite({ title: 'intent', location: 'inline' }, () => {17generateIntentTest({18location: ChatLocation.Editor,19name: 'convert',20query: 'convert private property to lowercase',21expectedIntent: EditCodeIntent.ID,22});2324generateIntentTest({25location: ChatLocation.Editor,26name: 'log to console',27query: 'log to console in case the action is missing',28// Actually gives Explain29expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],30});3132generateIntentTest({33location: ChatLocation.Editor,34name: 'add a cat',35query: 'Add a cat to this comment',36// Actually gives Unknown37expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],38});3940generateIntentTest({41location: ChatLocation.Editor,42name: 'make simpler',43query: 'make simpler',44expectedIntent: [EditCodeIntent.ID, Intent.Fix],45});4647generateIntentTest({48location: ChatLocation.Editor,49name: 'generate',50query: 'generate a nodejs server that responds with "Hello World"',51expectedIntent: GenerateCodeIntent.ID,52});5354generateIntentTest({55location: ChatLocation.Editor,56name: 'rewrite',57query: 'Rewrite the selection to use async/await',58expectedIntent: EditCodeIntent.ID,59});6061generateIntentTest({62location: ChatLocation.Editor,63name: 'print',64query: 'print seconds in a week',65expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],66});6768generateIntentTest({69location: ChatLocation.Editor,70name: 'add a column to dataframe',71query: 'add a new column called adjusted to the dataframe and set it to the value of the activity column minus 2',72expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],73});7475generateIntentTest({76location: ChatLocation.Editor,77name: 'plot dataframe',78query: 'plot the data frame',79expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],80});8182generateIntentTest({83location: ChatLocation.Editor,84name: 'add test',85query: 'add another test for containsUppercaseCharacter with other non latin chars',86expectedIntent: 'tests',87});8889generateIntentTest({90location: ChatLocation.Editor,91name: 'add types',92query: 'Add types to `reviewRequiredCheck`',93expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],94});9596generateIntentTest({97location: ChatLocation.Editor,98name: 'issue #1126: expand comments',99query: 'Expand comments to a full paragraph`',100expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],101});102103generateIntentTest({104location: ChatLocation.Editor,105name: 'issue #1126: change to GDPR',106query: 'change to GDPR documentation`',107expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],108});109110generateIntentTest({111location: ChatLocation.Editor,112name: `create a vscode launch task`,113query: `create a launch task that invokes MOCHA_GREP='Edit Generation' make test-extension`,114expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],115});116117generateIntentTest({118location: ChatLocation.Editor,119name: 'create basic jest config',120query: 'create basic jest config',121expectedIntent: [GenerateCodeIntent.ID],122});123124const additionalCases = JSON.parse(fs.readFileSync(join(__dirname, '../test/intent/inline-chat.json'), { encoding: 'utf8' }));125if (additionalCases && Array.isArray(additionalCases)) {126additionalCases.forEach((testCase: any) => {127if (typeof testCase === 'object' && !!testCase && testCase['Location'] === 'inline') {128const query: string = testCase['Request'];129generateIntentTest({ location: ChatLocation.Editor, name: query.split('\n')[0], query, expectedIntent: testCase['Intent'] });130}131});132}133134stest('/tests cannot be intent-detected', (testingServiceCollection) => {135return simulateInlineChat(testingServiceCollection, {136files: [fromFixture('notebook/fibonacci.ipynb')],137queries: [138{139file: 'fibonacci.ipynb',140activeCell: 0,141selection: [0, 9],142query: 'generate tests',143expectedIntent: 'generate',144validate: async (outcome, workspace, accessor) => {145// @ulugbekna: left empty on purpose146}147}148]149});150});151152});153154155