-
Notifications
You must be signed in to change notification settings - Fork 245
chore(e2e-tests): add gen ai test with logged in atlas user COMPASS-8395 #6547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8b47080
chore(e2e): add gen ai test with atlas cloud
Anemy 54599a8
chore: on web startup, ping for group settings
Anemy 4250b3a
fixup: better override handling
Anemy 0edfec0
chore(e2e-tests): add opt in skip for e2e
Anemy a12b926
fixup: remove unrelated changes
Anemy 1a7e975
Merge branch 'main' into COMPASS-8395-e2e-compass-web-gen-ai
Anemy dea38f6
merge main
Anemy 42afc5a
chore: add org setting off e2e test, temp add evergreen in
Anemy 18a6cad
chore: add org setting test with preferences override server via e2e …
Anemy 8cba711
fixup: remove commented evergreen and code
Anemy 2a67c88
Merge branch 'main' into COMPASS-8395-e2e-compass-web-gen-ai
Anemy abed7c7
fixup: remove skip in after all
Anemy 7a9d223
fixup: remove unused dep and log
Anemy eed7a36
Merge branch 'main' into COMPASS-8395-e2e-compass-web-gen-ai
Anemy 72c84b9
fixup: check
Anemy 5139504
Merge branch 'main' into COMPASS-8395-e2e-compass-web-gen-ai
Anemy 60b7ef4
fixup: use shared params endpoint, add preferences listener for compa…
Anemy f68573f
fixup: remove .only
Anemy d0ba6c7
fixup: add aggregation test, use sandbox preference update provider
Anemy 7af999a
fixup: aggregation test
Anemy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
packages/compass-e2e-tests/helpers/atlas-ai-preferences-override.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import http from 'http'; | ||
| import { once } from 'events'; | ||
| import type { AddressInfo } from 'net'; | ||
|
|
||
| export const E2E_TEST_ATLAS_PREFERENCES_OVERRIDE_PORT = | ||
| (process.env.E2E_TEST_ATLAS_PREFERENCES_OVERRIDE_PORT ??= '8081'); | ||
|
|
||
| export type PreferencesServerResponse = { | ||
| enableGenAIFeaturesAtlasProject: boolean; | ||
| enableGenAISampleDocumentPassingOnAtlasProject: boolean; | ||
| enableGenAIFeaturesAtlasOrg: boolean; | ||
| optInDataExplorerGenAIFeatures: boolean; | ||
| }; | ||
|
|
||
| function preferencesResponse( | ||
| res: http.ServerResponse, | ||
| response: PreferencesServerResponse | ||
| ) { | ||
| // Get request to hello service. | ||
| res.setHeader('Content-Type', 'application/json'); | ||
| return res.end(JSON.stringify(response)); | ||
| } | ||
|
|
||
| export const enabledPreferencesResponse = { | ||
| enableGenAIFeaturesAtlasProject: true, | ||
| enableGenAISampleDocumentPassingOnAtlasProject: true, | ||
| enableGenAIFeaturesAtlasOrg: true, | ||
| optInDataExplorerGenAIFeatures: true, | ||
| }; | ||
|
|
||
| export async function startPreferencesOverrideServer( | ||
| response: PreferencesServerResponse = enabledPreferencesResponse | ||
| ): Promise<{ | ||
| setPreferencesResponse: (response: PreferencesServerResponse) => void; | ||
| endpoint: string; | ||
| server: http.Server; | ||
| stop: () => Promise<void>; | ||
| }> { | ||
| const server = http | ||
| .createServer((req, res) => { | ||
| return preferencesResponse(res, response); | ||
| }) | ||
| .listen(Number(E2E_TEST_ATLAS_PREFERENCES_OVERRIDE_PORT)); | ||
| await once(server, 'listening'); | ||
|
|
||
| // address() returns either a string or AddressInfo. | ||
| const address = server.address() as AddressInfo; | ||
|
|
||
| const endpoint = `http://localhost:${address.port}`; | ||
|
|
||
| async function stop() { | ||
| server.close(); | ||
| await once(server, 'close'); | ||
| } | ||
|
|
||
| function setPreferencesResponse(newResponse: PreferencesServerResponse) { | ||
| response = newResponse; | ||
| } | ||
|
|
||
| return { | ||
| endpoint, | ||
| server, | ||
| setPreferencesResponse, | ||
| stop, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
packages/compass-e2e-tests/tests/atlas-cloud/collection-ai-query.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import { expect } from 'chai'; | ||
|
|
||
| import type { CompassBrowser } from '../../helpers/compass-browser'; | ||
| import { | ||
| init, | ||
| cleanup, | ||
| screenshotIfFailed, | ||
| DEFAULT_CONNECTION_NAME_1, | ||
| } from '../../helpers/compass'; | ||
| import type { Compass } from '../../helpers/compass'; | ||
| import * as Selectors from '../../helpers/selectors'; | ||
| import { createNumbersCollection } from '../../helpers/insert-data'; | ||
| import { isTestingAtlasCloudSandbox } from '../../helpers/test-runner-context'; | ||
| import { | ||
| enabledPreferencesResponse, | ||
| startPreferencesOverrideServer, | ||
| } from '../../helpers/atlas-ai-preferences-override'; | ||
| import type { PreferencesServerResponse } from '../../helpers/atlas-ai-preferences-override'; | ||
|
|
||
| describe('Collection ai query', function () { | ||
| let compass: Compass; | ||
| let browser: CompassBrowser; | ||
| let setPreferencesResponse: (response: PreferencesServerResponse) => void; | ||
| let stopPreferencesServer: () => Promise<void>; | ||
|
|
||
| before(async function () { | ||
| if (!isTestingAtlasCloudSandbox()) { | ||
| this.skip(); | ||
| } | ||
|
|
||
| // Start a mock server to pass an ai response. | ||
| const { setPreferencesResponse: _setPreferencesResponse, stop } = | ||
| await startPreferencesOverrideServer(); | ||
|
|
||
| stopPreferencesServer = stop; | ||
| setPreferencesResponse = _setPreferencesResponse; | ||
| }); | ||
|
|
||
| afterEach(async function () { | ||
| await screenshotIfFailed(compass, this.currentTest); | ||
| await cleanup(compass); | ||
| }); | ||
|
|
||
| after(async function () { | ||
| if (!isTestingAtlasCloudSandbox()) { | ||
| return; | ||
| } | ||
|
|
||
| await stopPreferencesServer(); | ||
| }); | ||
|
|
||
| describe('when the feature is enabled', function () { | ||
| beforeEach(async function () { | ||
| setPreferencesResponse(enabledPreferencesResponse); | ||
|
|
||
| compass = await init(this.test?.fullTitle()); | ||
| browser = compass.browser; | ||
| await browser.setupDefaultConnections(); | ||
|
|
||
| await createNumbersCollection(); | ||
| await browser.connectToDefaults(); | ||
| await browser.navigateToCollectionTab( | ||
| DEFAULT_CONNECTION_NAME_1, | ||
| 'test', | ||
| 'numbers', | ||
| 'Documents' | ||
| ); | ||
| }); | ||
|
|
||
| it('should update the query bar with a generated query', async function () { | ||
| // Click the ai entry button. | ||
| await browser.clickVisible(Selectors.QueryBarAIEntryButton); | ||
|
|
||
| // Enter the ai prompt. | ||
| await browser.clickVisible(Selectors.QueryBarAITextInput); | ||
|
|
||
| const testUserInput = 'find all documents where i is greater than 50'; | ||
| await browser.setValueVisible( | ||
| Selectors.QueryBarAITextInput, | ||
| testUserInput | ||
| ); | ||
|
|
||
| // Click generate. | ||
| await browser.clickVisible(Selectors.QueryBarAIGenerateQueryButton); | ||
|
|
||
| // 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.includes('$gt') && | ||
| queryBarFilterContent.includes('50') | ||
| ); | ||
| }); | ||
|
|
||
| // 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 org feature is disabled', function () { | ||
| beforeEach(async function () { | ||
| setPreferencesResponse({ | ||
| enableGenAIFeaturesAtlasProject: true, | ||
| enableGenAISampleDocumentPassingOnAtlasProject: true, | ||
| enableGenAIFeaturesAtlasOrg: false, | ||
| optInDataExplorerGenAIFeatures: true, | ||
| }); | ||
|
|
||
| compass = await init(this.test?.fullTitle()); | ||
| browser = compass.browser; | ||
| await browser.setupDefaultConnections(); | ||
|
|
||
| await createNumbersCollection(); | ||
| await browser.connectToDefaults(); | ||
| await browser.navigateToCollectionTab( | ||
| DEFAULT_CONNECTION_NAME_1, | ||
| 'test', | ||
| 'numbers', | ||
| 'Documents' | ||
| ); | ||
| }); | ||
|
|
||
| it('should not show the gen ai intro button', async function () { | ||
| // Ensure the query bar is shown. | ||
| await browser | ||
| .$(Selectors.queryBarOptionInputFilter('Documents')) | ||
| .waitForDisplayed(); | ||
|
|
||
| const aiIntroButton = browser.$(Selectors.QueryBarAIEntryButton); | ||
| const isSidebarCreateCollectionButtonExisting = | ||
| await aiIntroButton.isExisting(); | ||
| expect(isSidebarCreateCollectionButtonExisting).to.be.equal(false); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.