@@ -36,6 +36,11 @@ const password = 'regularuser';
3636
3737const config = getAPIConfig ( ) ;
3838const skipMessage = getSkipMessage ( ) ;
39+ const citationInstruction = 'Use the web_search tool and include at least one citation in your response. Do not answer without citations.' ;
40+
41+ function withCitationInstruction ( prompt : string ) : string {
42+ return `${ citationInstruction } ${ prompt } ` ;
43+ }
3944
4045async function setupTestPage ( page , mattermost , provider : ProviderBundle ) {
4146 const mmPage = new MattermostPage ( page ) ;
@@ -89,13 +94,13 @@ function createProviderTestSuite(provider: ProviderBundle) {
8994 ? 'Search the web for TypeScript documentation and briefly summarize 2-3 key features'
9095 : 'Use web search to find TypeScript best practices and briefly list 2-3 points with citations' ;
9196
92- await aiPlugin . sendMessage ( prompt ) ;
97+ await aiPlugin . sendMessage ( withCitationInstruction ( prompt ) ) ;
9398
9499 // Wait for streaming to complete (smart wait, up to 5 min)
95100 await llmBotHelper . waitForStreamingComplete ( ) ;
96101
97102 // Wait for at least one citation to appear (smart wait, up to 5 min)
98- await llmBotHelper . waitForCitation ( 1 ) ;
103+ await llmBotHelper . waitForCitationWithRetry ( 1 , undefined , 60000 ) ;
99104
100105 const citations = llmBotHelper . getAllCitationIcons ( ) ;
101106 const count = await citations . count ( ) ;
@@ -120,13 +125,13 @@ function createProviderTestSuite(provider: ProviderBundle) {
120125
121126 const prompt = 'Search the web for TypeScript documentation and briefly summarize with citations (2-3 sentences)' ;
122127
123- await aiPlugin . sendMessage ( prompt ) ;
128+ await aiPlugin . sendMessage ( withCitationInstruction ( prompt ) ) ;
124129
125130 // Wait for streaming to complete (smart wait, up to 5 min)
126131 await llmBotHelper . waitForStreamingComplete ( ) ;
127132
128133 // Wait for citation to appear (smart wait, up to 5 min)
129- await llmBotHelper . waitForCitation ( 1 ) ;
134+ await llmBotHelper . waitForCitationWithRetry ( 1 , undefined , 60000 ) ;
130135
131136 const citations = llmBotHelper . getAllCitationIcons ( ) ;
132137 const count = await citations . count ( ) ;
@@ -160,13 +165,13 @@ function createProviderTestSuite(provider: ProviderBundle) {
160165
161166 const prompt = 'Search the web for TypeScript official website and cite it' ;
162167
163- await aiPlugin . sendMessage ( prompt ) ;
168+ await aiPlugin . sendMessage ( withCitationInstruction ( prompt ) ) ;
164169
165170 // Wait for streaming to complete (smart wait, up to 5 min)
166171 await llmBotHelper . waitForStreamingComplete ( ) ;
167172
168173 // Wait for citation to appear (smart wait, up to 5 min)
169- await llmBotHelper . waitForCitation ( 1 ) ;
174+ await llmBotHelper . waitForCitationWithRetry ( 1 , undefined , 60000 ) ;
170175
171176 const citations = llmBotHelper . getAllCitationIcons ( ) ;
172177 const count = await citations . count ( ) ;
@@ -205,14 +210,14 @@ function createProviderTestSuite(provider: ProviderBundle) {
205210 ? 'Search the web for TypeScript, JavaScript, and React and briefly compare them with citations (1 paragraph)'
206211 : 'Use web search to find TypeScript, JavaScript, React info and briefly compare with citations (1 paragraph)' ;
207212
208- await aiPlugin . sendMessage ( prompt ) ;
213+ await aiPlugin . sendMessage ( withCitationInstruction ( prompt ) ) ;
209214
210215 // Wait for streaming to complete (smart wait, up to 5 min)
211216 await llmBotHelper . waitForStreamingComplete ( ) ;
212217
213218 // Wait for multiple citations to appear (smart wait, up to 5 min)
214- await llmBotHelper . waitForCitation ( 1 ) ;
215- await llmBotHelper . waitForCitation ( 2 ) ;
219+ await llmBotHelper . waitForCitationWithRetry ( 1 , undefined , 60000 ) ;
220+ await llmBotHelper . waitForCitationWithRetry ( 2 , undefined , 60000 ) ;
216221
217222 const citations = llmBotHelper . getAllCitationIcons ( ) ;
218223 const count = await citations . count ( ) ;
@@ -261,13 +266,13 @@ function createProviderTestSuite(provider: ProviderBundle) {
261266
262267 const prompt = 'Search the web for TypeScript documentation and briefly describe it with citations (1 paragraph)' ;
263268
264- await aiPlugin . sendMessage ( prompt ) ;
269+ await aiPlugin . sendMessage ( withCitationInstruction ( prompt ) ) ;
265270
266271 // Wait for streaming to complete (smart wait, up to 5 min)
267272 await llmBotHelper . waitForStreamingComplete ( ) ;
268273
269274 // Wait for citation to appear (smart wait, up to 5 min)
270- await llmBotHelper . waitForCitation ( 1 ) ;
275+ await llmBotHelper . waitForCitationWithRetry ( 1 , undefined , 60000 ) ;
271276
272277 const citationsBefore = llmBotHelper . getAllCitationIcons ( ) ;
273278 const countBefore = await citationsBefore . count ( ) ;
@@ -307,13 +312,13 @@ function createProviderTestSuite(provider: ProviderBundle) {
307312
308313 const prompt = 'Search the web for 1-2 TypeScript code examples with markdown formatting and citations (brief)' ;
309314
310- await aiPlugin . sendMessage ( prompt ) ;
315+ await aiPlugin . sendMessage ( withCitationInstruction ( prompt ) ) ;
311316
312317 // Wait for streaming to complete (smart wait, up to 5 min)
313318 await llmBotHelper . waitForStreamingComplete ( ) ;
314319
315320 // Wait for citation to appear (smart wait, up to 5 min)
316- await llmBotHelper . waitForCitation ( 1 ) ;
321+ await llmBotHelper . waitForCitationWithRetry ( 1 , undefined , 60000 ) ;
317322
318323 const postText = llmBotHelper . getPostText ( ) ;
319324 await expect ( postText ) . toBeVisible ( ) ;
@@ -340,13 +345,13 @@ function createProviderTestSuite(provider: ProviderBundle) {
340345
341346 const prompt = 'Search the web for TypeScript official documentation and cite it' ;
342347
343- await aiPlugin . sendMessage ( prompt ) ;
348+ await aiPlugin . sendMessage ( withCitationInstruction ( prompt ) ) ;
344349
345350 // Wait for streaming to complete (smart wait, up to 5 min)
346351 await llmBotHelper . waitForStreamingComplete ( ) ;
347352
348353 // Wait for citation to appear (smart wait, up to 5 min)
349- await llmBotHelper . waitForCitation ( 1 ) ;
354+ await llmBotHelper . waitForCitationWithRetry ( 1 , undefined , 60000 ) ;
350355
351356 const citations = llmBotHelper . getAllCitationIcons ( ) ;
352357 const count = await citations . count ( ) ;
0 commit comments