@@ -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.
@@ -2125,6 +2126,61 @@ Schema:
21252126 getContentLength ( messages [ 1 ] )
21262127 ) ;
21272128 } ) ;
2129+
2130+ suite ( 'with invalid messages' , function ( ) {
2131+ test ( 'filters disallowed messages' , async function ( ) {
2132+ const chatRequestMock = {
2133+ prompt : 'find all docs by a name example' ,
2134+ } ;
2135+
2136+ chatContextStub = {
2137+ history : [
2138+ Object . assign ( Object . create ( vscode . ChatRequestTurn . prototype ) , {
2139+ prompt : 'give me the count of all people in the prod database' ,
2140+ command : 'query' ,
2141+ references : [ ] ,
2142+ participant : CHAT_PARTICIPANT_ID ,
2143+ } ) ,
2144+ Object . assign ( Object . create ( vscode . ChatRequestTurn . prototype ) , {
2145+ prompt : 'some disallowed message' ,
2146+ command : 'query' ,
2147+ references : [ ] ,
2148+ participant : CHAT_PARTICIPANT_ID ,
2149+ } ) ,
2150+ Object . assign ( Object . create ( vscode . ChatResponseTurn . prototype ) , {
2151+ result : {
2152+ errorDetails : {
2153+ message : ParticipantErrorTypes . FILTERED ,
2154+ } ,
2155+ } ,
2156+ response : [ ] ,
2157+ participant : CHAT_PARTICIPANT_ID ,
2158+ } ) ,
2159+ Object . assign ( Object . create ( vscode . ChatRequestTurn . prototype ) , {
2160+ prompt : 'ok message' ,
2161+ references : [ ] ,
2162+ participant : CHAT_PARTICIPANT_ID ,
2163+ } ) ,
2164+ ] ,
2165+ } ;
2166+ const { messages } = await Prompts . generic . buildMessages ( {
2167+ context : chatContextStub ,
2168+ request : chatRequestMock ,
2169+ connectionNames : [ ] ,
2170+ } ) ;
2171+
2172+ expect ( messages ) . to . have . lengthOf ( 4 ) ;
2173+ expect (
2174+ messages . find ( ( message ) =>
2175+ message . content . includes ( 'some disallowed message' )
2176+ )
2177+ ) . to . be . undefined ;
2178+
2179+ expect (
2180+ messages . find ( ( message ) => message . content . includes ( 'ok message' ) )
2181+ ) . to . not . be . undefined ;
2182+ } ) ;
2183+ } ) ;
21282184 } ) ;
21292185
21302186 suite ( 'telemetry' , function ( ) {
0 commit comments