Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 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
77a0eea
use noop logger and clean up api response handling
mabaasit Dec 8, 2025
aafe769
remove mms from name
mabaasit Dec 8, 2025
089b30c
clean up error, names
mabaasit Dec 8, 2025
0d2ab07
Merge branch 'main' into COMPASS-10081-switch-to-edu-api
mabaasit Dec 8, 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
142 changes: 141 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
144 changes: 144 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,145 @@ 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('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 () {
// 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('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.'
);
});
});
});
Loading
Loading