Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1295d51
add feature flag
mabaasit Nov 25, 2025
7a44de4
migrate prompts to compass
mabaasit Nov 25, 2025
2e2defe
Merge branch 'main' into COMPASS-10082-add-mms-prompts-and-feature-flag
mabaasit Nov 25, 2025
d524682
co-pilot feedback
mabaasit Nov 25, 2025
f9212fb
Merge branch 'COMPASS-10082-add-mms-prompts-and-feature-flag' of http…
mabaasit Nov 25, 2025
c96161b
clean up
mabaasit Dec 1, 2025
f499026
Merge branch 'main' into COMPASS-10082-add-mms-prompts-and-feature-flag
mabaasit Dec 1, 2025
f4d05a7
use edu api for gen ai
mabaasit Dec 1, 2025
1763531
clean up a bit
mabaasit Dec 1, 2025
d5e2c84
fix url for test and ensure aggregations have content
mabaasit Dec 2, 2025
0781580
tests
mabaasit Dec 3, 2025
058e950
fix error handling
mabaasit Dec 3, 2025
7d54d4d
clean up transport
mabaasit Dec 3, 2025
0aa7ff5
Merge branch 'main' of https://github.com/mongodb-js/compass into COM…
mabaasit Dec 3, 2025
309335a
changes in field name
mabaasit Dec 3, 2025
feacddc
use query parser
mabaasit Dec 3, 2025
c321983
fix check
mabaasit Dec 3, 2025
f5a34df
fix test
mabaasit Dec 3, 2025
91b17d5
clean up
mabaasit Dec 3, 2025
ea4dfdf
copilot feedback
mabaasit Dec 3, 2025
f8a4c43
fix log id
mabaasit Dec 3, 2025
8190219
fix cors issue on e2e tests
mabaasit Dec 4, 2025
c444cb9
more tests
mabaasit Dec 4, 2025
6eec8db
add type
mabaasit Dec 4, 2025
25c8089
wip
mabaasit Dec 8, 2025
9b4c9b7
fix alltext
mabaasit Dec 8, 2025
5e6d537
make expected output xml string
mabaasit Dec 9, 2025
d1b0b51
add fixtures and run gen ai eval tests
mabaasit Dec 10, 2025
1b7343f
ts fixes
mabaasit Dec 10, 2025
a1b38c5
reformat
mabaasit Dec 10, 2025
79e9910
clean up scorer
mabaasit Dec 10, 2025
821917d
Merge branch 'main' of https://github.com/mongodb-js/compass into eva…
mabaasit Dec 11, 2025
3bc7295
bootstrap
mabaasit Dec 11, 2025
eb49493
remove extra files
mabaasit Dec 11, 2025
fa1cf6f
Merge branch 'main' of https://github.com/mongodb-js/compass into eva…
mabaasit Dec 15, 2025
edc5e73
bootstrap
mabaasit Dec 15, 2025
718e8b7
fix prompts and data
mabaasit Dec 15, 2025
5244598
Merge branch 'main' of https://github.com/mongodb-js/compass into eva…
mabaasit Dec 15, 2025
534b0d8
copilot review
mabaasit Dec 15, 2025
d0568ff
reduce num of docs
mabaasit Dec 16, 2025
40ad7c9
reduce fixtures
mabaasit Dec 16, 2025
48b38ce
Merge branch 'main' of https://github.com/mongodb-js/compass into eva…
mabaasit Dec 16, 2025
6153f52
check fix
mabaasit Dec 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests
  • Loading branch information
mabaasit committed Dec 3, 2025
commit 07815800e112776264c939af1c3e18d44c78e4e6
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/helpers/assistant-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ export async function startMockAssistantServer(
});

if (response.status !== 200) {
res.writeHead(response.status);
res.setHeader('Content-Type', 'application/json');
res.writeHead(response.status);
return res.end(JSON.stringify({ error: response.body }));
}

Expand Down
145 changes: 145 additions & 0 deletions packages/compass-e2e-tests/tests/collection-ai-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
cleanup,
screenshotIfFailed,
DEFAULT_CONNECTION_NAME_1,
screenshotPathName,
} from '../helpers/compass';
import type { Compass } from '../helpers/compass';
import * as Selectors from '../helpers/selectors';
import { createNumbersCollection } from '../helpers/insert-data';
import { startMockAtlasServiceServer } from '../helpers/mock-atlas-service';
import type { MockAtlasServerResponse } from '../helpers/mock-atlas-service';
import { startMockAssistantServer } from '../helpers/assistant-service';

describe('Collection ai query (with mocked backend)', function () {
let compass: Compass;
Expand Down Expand Up @@ -171,3 +173,146 @@ describe('Collection ai query (with mocked backend)', function () {
});
});
});

async function setup(
browser: CompassBrowser,
dbName: string,
collName: string
) {
await createNumbersCollection();
await browser.setupDefaultConnections();
await browser.connectToDefaults();
await browser.navigateToCollectionTab(
DEFAULT_CONNECTION_NAME_1,
dbName,
collName,
'Documents'
);

await browser.setFeature('enableChatbotEndpointForGenAI', true);
await browser.setFeature('enableGenAIFeatures', true);
await browser.setFeature('enableGenAISampleDocumentPassing', true);
await browser.setFeature('optInGenAIFeatures', true);
}

describe.only('Collection ai query with chatbot (with mocked backend)', function () {
const dbName = 'test';
const collName = 'numbers';
let compass: Compass;
let browser: CompassBrowser;

let mockAssistantServer: Awaited<ReturnType<typeof startMockAssistantServer>>;

before(async function () {
mockAssistantServer = await startMockAssistantServer();
compass = await init(this.test?.fullTitle());
browser = compass.browser;

await browser.setEnv(
'COMPASS_ASSISTANT_BASE_URL_OVERRIDE',
mockAssistantServer.endpoint
);
});

after(async function () {
await mockAssistantServer.stop();
await cleanup(compass);
});

afterEach(async function () {
await screenshotIfFailed(compass, this.currentTest);
try {
mockAssistantServer.clearRequests();
} catch (err) {
await browser.screenshot(screenshotPathName('afterEach-GenAi-Query'));
throw err;
}
});

describe('when the ai model response is valid', function () {
beforeEach(async function () {
await setup(browser, dbName, collName);
mockAssistantServer.setResponse({
status: 200,
body: '<filter>{i: {$gt: 50}}</filter>',
});
});

it('makes request to the server and updates the query bar with the response', async function () {
await new Promise((resolve) => setTimeout(resolve, 10000));
// Click the ai entry button.
await browser.clickVisible(Selectors.GenAIEntryButton);

// Enter the ai prompt.
await browser.clickVisible(Selectors.GenAITextInput);

const testUserInput = 'find all documents where i is greater than 50';
await browser.setValueVisible(Selectors.GenAITextInput, testUserInput);

// Click generate.
await browser.clickVisible(Selectors.GenAIGenerateQueryButton);

// Wait for the ipc events to succeed.
await browser.waitUntil(async function () {
// Make sure the query bar was updated.
const queryBarFilterContent = await browser.getCodemirrorEditorText(
Selectors.queryBarOptionInputFilter('Documents')
);
return queryBarFilterContent === '{"i":{"$gt":50}}';
});

// Check that the request was made with the correct parameters.
const requests = mockAssistantServer.getRequests();
expect(requests.length).to.equal(1);

const queryRequest = requests[0];
// TODO(COMPASS-10125): Switch the model to `mongodb-slim-latest` when
// enabling this feature.
expect(queryRequest.content.model).to.equal('mongodb-chat-latest');
expect(queryRequest.content.instructions).to.be.string;
expect(queryRequest.content.input).to.be.an('array').of.length(1);

const message = queryRequest.content.input[0];
expect(message.role).to.equal('user');
expect(message.content).to.be.an('array').of.length(1);
expect(message.content[0]).to.have.property('type');
expect(message.content[0]).to.have.property('text');

// Run it and check that the correct documents are shown.
await browser.runFind('Documents', true);
const modifiedResult = await browser.getFirstListDocument();
expect(modifiedResult.i).to.be.equal('51');
});
});

describe.only('when the chatbot api request errors', function () {
beforeEach(async function () {
await setup(browser, dbName, collName);
mockAssistantServer.setResponse({
status: 500,
body: '',
});
});

it('the error is shown to the user', async function () {
// Click the ai entry button.
await browser.clickVisible(Selectors.GenAIEntryButton);

// Enter the ai prompt.
await browser.clickVisible(Selectors.GenAITextInput);

const testUserInput = 'find all documents where i is greater than 50';
await browser.setValueVisible(Selectors.GenAITextInput, testUserInput);

// Click generate.
await browser.clickVisible(Selectors.GenAIGenerateQueryButton);

// Check that the error is shown.
const errorBanner = browser.$(Selectors.GenAIErrorMessageBanner);
await errorBanner.waitForDisplayed();
expect(await errorBanner.getText()).to.equal(
'Sorry, we were unable to generate the query, please try again. If the error persists, try changing your prompt.'
);
});
});
});