@@ -34,6 +34,7 @@ import { Prompts } from '../../../participant/prompts';
3434import { createMarkdownLink } from '../../../participant/markdown' ;
3535import EXTENSION_COMMANDS from '../../../commands' ;
3636import { getContentLength } from '../../../participant/prompts/promptBase' ;
37+ import { ParticipantErrorTypes } from '../../../types/participantErrorTypes' ;
3738
3839// The Copilot's model in not available in tests,
3940// therefore we need to mock its methods and returning values.
@@ -2502,6 +2503,68 @@ Schema:
25022503 getContentLength ( messages [ 1 ] )
25032504 ) ;
25042505 } ) ;
2506+
2507+ suite ( 'with invalid messages' , function ( ) {
2508+ test ( 'filters disallowed messages' , async function ( ) {
2509+ const chatRequestMock = {
2510+ prompt : 'find all docs by a name example' ,
2511+ } ;
2512+
2513+ chatContextStub = {
2514+ history : [
2515+ Object . assign ( Object . create ( vscode . ChatRequestTurn . prototype ) , {
2516+ prompt : 'give me the count of all people in the prod database' ,
2517+ command : 'query' ,
2518+ references : [ ] ,
2519+ participant : CHAT_PARTICIPANT_ID ,
2520+ } ) ,
2521+ Object . assign ( Object . create ( vscode . ChatRequestTurn . prototype ) , {
2522+ prompt : 'some disallowed message' ,
2523+ command : 'query' ,
2524+ references : [ ] ,
2525+ participant : CHAT_PARTICIPANT_ID ,
2526+ } ) ,
2527+ Object . assign ( Object . create ( vscode . ChatResponseTurn . prototype ) , {
2528+ result : {
2529+ errorDetails : {
2530+ message : ParticipantErrorTypes . FILTERED ,
2531+ } ,
2532+ } ,
2533+ response : [ ] ,
2534+ participant : CHAT_PARTICIPANT_ID ,
2535+ } ) ,
2536+ Object . assign ( Object . create ( vscode . ChatRequestTurn . prototype ) , {
2537+ prompt : 'ok message' ,
2538+ references : [ ] ,
2539+ participant : CHAT_PARTICIPANT_ID ,
2540+ } ) ,
2541+ ] ,
2542+ } ;
2543+ const { messages } = await Prompts . generic . buildMessages ( {
2544+ context : chatContextStub ,
2545+ request : chatRequestMock ,
2546+ connectionNames : [ ] ,
2547+ } ) ;
2548+
2549+ expect ( messages ) . to . have . lengthOf ( 4 ) ;
2550+
2551+ const messageContents = messages . map ( ( message ) => {
2552+ // There may be different types for the messages' content
2553+ const content = Array . isArray ( message . content )
2554+ ? message . content . map ( ( sub ) => sub . value ) . join ( '' )
2555+ : message . content ;
2556+
2557+ return content ;
2558+ } ) ;
2559+
2560+ // Skip the preset prompt and check that the rest are correct.
2561+ expect ( messageContents . slice ( 1 ) ) . deep . equal ( [
2562+ 'give me the count of all people in the prod database' ,
2563+ 'ok message' ,
2564+ 'find all docs by a name example' ,
2565+ ] ) ;
2566+ } ) ;
2567+ } ) ;
25052568 } ) ;
25062569
25072570 suite ( 'telemetry' , function ( ) {
0 commit comments