11import { expect } from 'chai' ;
22
33import type { CompassBrowser } from '../helpers/compass-browser' ;
4- import { startTelemetryServer } from '../helpers/telemetry' ;
5- import type { Telemetry } from '../helpers/telemetry' ;
64import {
75 init ,
86 cleanup ,
@@ -13,167 +11,8 @@ import {
1311import type { Compass } from '../helpers/compass' ;
1412import * as Selectors from '../helpers/selectors' ;
1513import { createNumbersCollection } from '../helpers/insert-data' ;
16- import { startMockAtlasServiceServer } from '../helpers/mock-atlas-service' ;
17- import type { MockAtlasServerResponse } from '../helpers/mock-atlas-service' ;
1814import { startMockAssistantServer } from '../helpers/assistant-service' ;
1915
20- describe ( 'Collection ai query (with mocked backend)' , function ( ) {
21- let compass : Compass ;
22- let browser : CompassBrowser ;
23- let telemetry : Telemetry ;
24- let setMockAtlasServerResponse : ( response : MockAtlasServerResponse ) => void ;
25- let stopMockAtlasServer : ( ) => Promise < void > ;
26- let getRequests : ( ) => any [ ] ;
27- let clearRequests : ( ) => void ;
28-
29- before ( async function ( ) {
30- // Start a mock server to pass an ai response.
31- const {
32- endpoint,
33- getRequests : _getRequests ,
34- clearRequests : _clearRequests ,
35- setMockAtlasServerResponse : _setMockAtlasServerResponse ,
36- stop,
37- } = await startMockAtlasServiceServer ( ) ;
38-
39- stopMockAtlasServer = stop ;
40- getRequests = _getRequests ;
41- clearRequests = _clearRequests ;
42- setMockAtlasServerResponse = _setMockAtlasServerResponse ;
43-
44- telemetry = await startTelemetryServer ( ) ;
45- compass = await init ( this . test ?. fullTitle ( ) ) ;
46- browser = compass . browser ;
47-
48- await browser . setEnv (
49- 'COMPASS_ATLAS_SERVICE_UNAUTH_BASE_URL_OVERRIDE' ,
50- endpoint
51- ) ;
52-
53- await browser . setFeature ( 'enableGenAIFeatures' , true ) ;
54- await browser . setFeature ( 'enableGenAISampleDocumentPassing' , true ) ;
55- await browser . setFeature ( 'optInGenAIFeatures' , true ) ;
56-
57- await browser . setupDefaultConnections ( ) ;
58- } ) ;
59-
60- beforeEach ( async function ( ) {
61- await createNumbersCollection ( ) ;
62- await browser . disconnectAll ( ) ;
63- await browser . connectToDefaults ( ) ;
64- await browser . navigateToCollectionTab (
65- DEFAULT_CONNECTION_NAME_1 ,
66- 'test' ,
67- 'numbers' ,
68- 'Documents'
69- ) ;
70- } ) ;
71-
72- after ( async function ( ) {
73- await stopMockAtlasServer ( ) ;
74-
75- await cleanup ( compass ) ;
76- await telemetry . stop ( ) ;
77- } ) ;
78-
79- afterEach ( async function ( ) {
80- clearRequests ( ) ;
81- await screenshotIfFailed ( compass , this . currentTest ) ;
82- } ) ;
83-
84- describe ( 'when the ai model response is valid' , function ( ) {
85- beforeEach ( function ( ) {
86- setMockAtlasServerResponse ( {
87- status : 200 ,
88- body : {
89- content : {
90- query : {
91- filter : '{i: {$gt: 50}}' ,
92- } ,
93- } ,
94- } ,
95- } ) ;
96- } ) ;
97-
98- it ( 'makes request to the server and updates the query bar with the response' , async function ( ) {
99- // Click the ai entry button.
100- await browser . clickVisible ( Selectors . GenAIEntryButton ) ;
101-
102- // Enter the ai prompt.
103- await browser . clickVisible ( Selectors . GenAITextInput ) ;
104-
105- const testUserInput = 'find all documents where i is greater than 50' ;
106- await browser . setValueVisible ( Selectors . GenAITextInput , testUserInput ) ;
107-
108- // Click generate.
109- await browser . clickVisible ( Selectors . GenAIGenerateQueryButton ) ;
110-
111- // Wait for the ipc events to succeed.
112- await browser . waitUntil ( async function ( ) {
113- // Make sure the query bar was updated.
114- const queryBarFilterContent = await browser . getCodemirrorEditorText (
115- Selectors . queryBarOptionInputFilter ( 'Documents' )
116- ) ;
117- return queryBarFilterContent === '{i: {$gt: 50}}' ;
118- } ) ;
119-
120- // Check that the request was made with the correct parameters.
121- const requests = getRequests ( ) ;
122- expect ( requests . length ) . to . equal ( 1 ) ;
123-
124- const queryRequest = requests [ 0 ] ;
125- const queryURL = new URL (
126- queryRequest . req . url ,
127- `http://${ queryRequest . req . headers . host } `
128- ) ;
129- expect ( [ ...new Set ( queryURL . searchParams . keys ( ) ) ] . length ) . to . equal ( 1 ) ;
130- const requestId = queryURL . searchParams . get ( 'request_id' ) ;
131- expect ( ( requestId ?. match ( / - / g) || [ ] ) . length ) . to . equal ( 4 ) ; // Is uuid like.
132- expect ( queryRequest . content . userInput ) . to . equal ( testUserInput ) ;
133- expect ( queryRequest . content . collectionName ) . to . equal ( 'numbers' ) ;
134- expect ( queryRequest . content . databaseName ) . to . equal ( 'test' ) ;
135- expect ( queryRequest . content . schema ) . to . exist ;
136-
137- // Run it and check that the correct documents are shown.
138- await browser . runFind ( 'Documents' , true ) ;
139- const modifiedResult = await browser . getFirstListDocument ( ) ;
140- expect ( modifiedResult . i ) . to . be . equal ( '51' ) ;
141- } ) ;
142- } ) ;
143-
144- describe ( 'when the Atlas service request errors' , function ( ) {
145- beforeEach ( function ( ) {
146- setMockAtlasServerResponse ( {
147- status : 500 ,
148- body : {
149- content : 'error' ,
150- } ,
151- } ) ;
152- } ) ;
153-
154- it ( 'the error is shown to the user' , async function ( ) {
155- // Click the ai entry button.
156- await browser . clickVisible ( Selectors . GenAIEntryButton ) ;
157-
158- // Enter the ai prompt.
159- await browser . clickVisible ( Selectors . GenAITextInput ) ;
160-
161- const testUserInput = 'find all documents where i is greater than 50' ;
162- await browser . setValueVisible ( Selectors . GenAITextInput , testUserInput ) ;
163-
164- // Click generate.
165- await browser . clickVisible ( Selectors . GenAIGenerateQueryButton ) ;
166-
167- // Check that the error is shown.
168- const errorBanner = browser . $ ( Selectors . GenAIErrorMessageBanner ) ;
169- await errorBanner . waitForDisplayed ( ) ;
170- expect ( await errorBanner . getText ( ) ) . to . equal (
171- 'Sorry, we were unable to generate the query, please try again. If the error persists, try changing your prompt.'
172- ) ;
173- } ) ;
174- } ) ;
175- } ) ;
176-
17716async function setup (
17817 browser : CompassBrowser ,
17918 dbName : string ,
@@ -189,13 +28,12 @@ async function setup(
18928 'Documents'
19029 ) ;
19130
192- await browser . setFeature ( 'enableChatbotEndpointForGenAI' , true ) ;
19331 await browser . setFeature ( 'enableGenAIFeatures' , true ) ;
19432 await browser . setFeature ( 'enableGenAISampleDocumentPassing' , true ) ;
19533 await browser . setFeature ( 'optInGenAIFeatures' , true ) ;
19634}
19735
198- describe ( 'Collection ai query with chatbot (with mocked backend)' , function ( ) {
36+ describe ( 'Collection ai query (with mocked backend)' , function ( ) {
19937 const dbName = 'test' ;
20038 const collName = 'numbers' ;
20139 let compass : Compass ;
@@ -266,9 +104,8 @@ describe('Collection ai query with chatbot (with mocked backend)', function () {
266104
267105 const queryRequest = requests [ 0 ] ;
268106 expect ( queryRequest . req . headers ) . to . have . property ( 'x-client-request-id' ) ;
269- // TODO(COMPASS-10125): Switch the model to `mongodb-slim-latest` when
270- // enabling this feature.
271- expect ( queryRequest . content . model ) . to . equal ( 'mongodb-chat-latest' ) ;
107+ expect ( queryRequest . req . headers ) . to . have . property ( 'entrypoint' ) ;
108+ expect ( queryRequest . content . model ) . to . equal ( 'mongodb-slim-latest' ) ;
272109 expect ( queryRequest . content . instructions ) . to . be . string ;
273110 expect ( queryRequest . content . metadata ) . to . have . property ( 'userId' ) ;
274111 expect ( queryRequest . content . metadata . store ) . to . have . equal ( 'true' ) ;
0 commit comments