Path: blob/main/extensions/copilot/test/prompts/customInstructions.stest.ts
13389 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*--------------------------------------------------------------------------------------------*/4import assert from 'assert';5import { EditCodeIntent } from '../../src/extension/intents/node/editCodeIntent';6import { ConfigKey } from '../../src/platform/configuration/common/configurationService';7import { ssuite, stest } from '../base/stest';8import { simulateInlineChat } from '../simulation/inlineChatSimulator';9import { toFile } from '../simulation/stestUtil';1011ssuite({ title: 'custom instructions', location: 'inline' }, () => {12let configurations = [13{14key: ConfigKey.CodeGenerationInstructions,15value: [16{ 'text': `Field names should start with the prefix 'f'`, 'language': 'typescript' },17{ 'text': `Add a comment: 'Generated by Copilot'` }18]19}20];21stest({ description: 'Custom instructions for language', configurations }, (testingServiceCollection) => {22return simulateInlineChat(testingServiceCollection, {23files: [toFile({ fileName: 'hello.ts', fileContents: '\n\n' })],24queries: [25{26file: 'hello.ts',27selection: [0, 0, 0, 0],28query: [29`/edit add a class named 'Foo' with a field 'address' along with getters and setters`,30].join('\n'),31expectedIntent: EditCodeIntent.ID,32validate: async (outcome, workspace, accessor) => {33assert.strictEqual(outcome.type, 'inlineEdit');34assert.ok(outcome.fileContents.includes(' fAddress'));35assert.ok(outcome.fileContents.includes('Generated by Copilot'));36}37}38]39});40});41configurations = [42{43key: ConfigKey.CodeGenerationInstructions,44value: [45{ 'text': `Field names should start with the prefix 'f'`, 'language': 'javascript' },46{ 'text': `Add a comment: 'Generated by Copilot'`, 'language': 'java' },47]48}49];50stest({ description: 'Custom instructions not applicable to language', configurations }, (testingServiceCollection) => {51return simulateInlineChat(testingServiceCollection, {52files: [53toFile({ fileName: 'hello.ts', fileContents: '\n\n' }),54],55queries: [56{57file: 'hello.ts',58selection: [0, 0, 0, 0],59query: [60`/edit add a class named 'Foo' with a field 'address' along with getters and setters`,61].join('\n'),62expectedIntent: EditCodeIntent.ID,63validate: async (outcome, workspace, accessor) => {64assert.strictEqual(outcome.type, 'inlineEdit');65assert.ok(!outcome.fileContents.includes(' fAddress'));66assert.ok(!outcome.fileContents.includes('Generated by Copilot'));67}68}69]70});71});72const configurations2 = [73{74key: ConfigKey.CodeGenerationInstructions,75value: [76{ 'file': 'code-guidelines.md' }77]78}79];80stest({ description: 'Custom instructions from file', configurations: configurations2 }, (testingServiceCollection) => {81return simulateInlineChat(testingServiceCollection, {82files: [83toFile({ fileName: 'hello.ts', fileContents: '\n\n' }),84toFile({ fileName: 'code-guidelines.md', fileContents: `\n\nField names should start with the prefix '__'\n` })85],86queries: [87{88file: 'hello.ts',89selection: [0, 0, 0, 0],90query: [91`/edit add a class named 'Foo' with a field 'address' along with getters and setters`,92].join('\n'),93expectedIntent: EditCodeIntent.ID,94validate: async (outcome, workspace, accessor) => {95assert.strictEqual(outcome.type, 'inlineEdit');96assert.ok(outcome.fileContents.includes(' __address'));97}98}99]100});101});102const configurations3 = [103{104key: ConfigKey.CodeGenerationInstructions,105value: [106{ 'file': 'code-guidelines1.md' },107{ 'text': `Add a comment: 'Generated by Copilot'`, 'language': 'typescript' },108]109}110];111stest({ description: 'Custom instructions with missing file', configurations: configurations3 }, (testingServiceCollection) => {112return simulateInlineChat(testingServiceCollection, {113files: [114toFile({ fileName: 'hello.ts', fileContents: '\n\n' }),115toFile({ fileName: 'code-guidelines.md', fileContents: `\n\nField names should start with the prefix '__'\n` })116],117queries: [118{119file: 'hello.ts',120selection: [0, 0, 0, 0],121query: [122`/edit add a class named 'Foo' with a field 'address' along with getters and setters`,123].join('\n'),124expectedIntent: EditCodeIntent.ID,125validate: async (outcome, workspace, accessor) => {126assert.strictEqual(outcome.type, 'inlineEdit');127assert.ok(!outcome.fileContents.includes(' __address'));128assert.ok(outcome.fileContents.includes('Generated by Copilot'));129}130}131]132});133});134});135136137