From 7971332ff54915bbf2b9ef1df08013951ee3f9ad Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Wed, 27 Aug 2025 14:01:22 +0200 Subject: [PATCH 1/4] fix: don't execute cleanup code if setup failed --- .../tools/atlas/accessLists.test.ts | 20 +++++++++-------- tests/integration/tools/atlas/atlasHelpers.ts | 22 ++++++++++--------- .../integration/tools/atlas/clusters.test.ts | 8 +++---- tests/integration/tools/atlas/dbUsers.test.ts | 8 ++++++- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/tests/integration/tools/atlas/accessLists.test.ts b/tests/integration/tools/atlas/accessLists.test.ts index 961898ae4..a711f38ff 100644 --- a/tests/integration/tools/atlas/accessLists.test.ts +++ b/tests/integration/tools/atlas/accessLists.test.ts @@ -27,16 +27,18 @@ describeWithAtlas("ip access lists", (integration) => { const apiClient = integration.mcpServer().session.apiClient; const projectId = getProjectId(); - - for (const value of values) { - await apiClient.deleteProjectIpAccessList({ - params: { - path: { - groupId: projectId, - entryValue: value, + if (projectId) { + // projectId may be empty if beforeAll failed. + for (const value of values) { + await apiClient.deleteProjectIpAccessList({ + params: { + path: { + groupId: projectId, + entryValue: value, + }, }, - }, - }); + }); + } } }); diff --git a/tests/integration/tools/atlas/atlasHelpers.ts b/tests/integration/tools/atlas/atlasHelpers.ts index df3a52f95..38a69291d 100644 --- a/tests/integration/tools/atlas/atlasHelpers.ts +++ b/tests/integration/tools/atlas/atlasHelpers.ts @@ -41,7 +41,7 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio try { const group = await createProject(apiClient); - projectId = group.id || ""; + projectId = group.id; } catch (error) { console.error("Failed to create project:", error); throw error; @@ -50,14 +50,16 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio afterAll(async () => { const apiClient = integration.mcpServer().session.apiClient; - - await apiClient.deleteProject({ - params: { - path: { - groupId: projectId, + if (projectId) { + // projectId may be empty if beforeAll failed. + await apiClient.deleteProject({ + params: { + path: { + groupId: projectId, + }, }, - }, - }); + }); + } }); const args = { @@ -90,7 +92,7 @@ export function parseTable(text: string): Record[] { export const randomId = new ObjectId().toString(); -async function createProject(apiClient: ApiClient): Promise { +async function createProject(apiClient: ApiClient): Promise>> { const projectName: string = `testProj-` + randomId; const orgs = await apiClient.listOrganizations(); @@ -109,5 +111,5 @@ async function createProject(apiClient: ApiClient): Promise { throw new Error("Failed to create project"); } - return group; + return group as Group & Required>; } diff --git a/tests/integration/tools/atlas/clusters.test.ts b/tests/integration/tools/atlas/clusters.test.ts index 0621ec7f2..9ae7aabcb 100644 --- a/tests/integration/tools/atlas/clusters.test.ts +++ b/tests/integration/tools/atlas/clusters.test.ts @@ -62,10 +62,10 @@ describeWithAtlas("clusters", (integration) => { afterAll(async () => { const projectId = getProjectId(); - - const session: Session = integration.mcpServer().session; - - await deleteAndWaitCluster(session, projectId, clusterName); + if (projectId) { + const session: Session = integration.mcpServer().session; + await deleteAndWaitCluster(session, projectId, clusterName); + } }); describe("atlas-create-free-cluster", () => { diff --git a/tests/integration/tools/atlas/dbUsers.test.ts b/tests/integration/tools/atlas/dbUsers.test.ts index bbf76200f..b6b055321 100644 --- a/tests/integration/tools/atlas/dbUsers.test.ts +++ b/tests/integration/tools/atlas/dbUsers.test.ts @@ -28,11 +28,17 @@ describeWithAtlas("db users", (integration) => { }; afterEach(async () => { + const projectId = getProjectId(); + if (!projectId) { + // projectId may be empty if beforeAll failed + return; + } + try { await integration.mcpServer().session.apiClient.deleteDatabaseUser({ params: { path: { - groupId: getProjectId(), + groupId: projectId, username: userName, databaseName: "admin", }, From 4b67d439d85c2037637755abafa93be9348b2aa7 Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Wed, 27 Aug 2025 14:54:51 +0200 Subject: [PATCH 2/4] add more oidc test retry conditions --- .../common/connectionManager.oidc.test.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/integration/common/connectionManager.oidc.test.ts b/tests/integration/common/connectionManager.oidc.test.ts index a14a5ab4b..adc874827 100644 --- a/tests/integration/common/connectionManager.oidc.test.ts +++ b/tests/integration/common/connectionManager.oidc.test.ts @@ -169,14 +169,22 @@ describe.skipIf(process.platform !== "linux")("ConnectionManager OIDC Tests", as }; const status: ConnectionStatus = await vi.waitFor(async () => { - const result: ConnectionStatus = (await state.serviceProvider.runCommand("admin", { + const result = (await state.serviceProvider.runCommand("admin", { connectionStatus: 1, - })) as unknown as ConnectionStatus; + })) as unknown as ConnectionStatus | undefined; if (!result) { throw new Error("Status can not be undefined. Retrying."); } + if (!result.authInfo.authenticatedUsers.length) { + throw new Error("No authenticated users found. Retrying."); + } + + if (!result.authInfo.authenticatedUserRoles.length) { + throw new Error("No authenticated user roles found. Retrying."); + } + return result; }); From 2c3060686fa6748123561d7268e8346a87ea1a61 Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Wed, 27 Aug 2025 15:06:52 +0200 Subject: [PATCH 3/4] give it more time --- .../common/connectionManager.oidc.test.ts | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/tests/integration/common/connectionManager.oidc.test.ts b/tests/integration/common/connectionManager.oidc.test.ts index adc874827..e3a406eb6 100644 --- a/tests/integration/common/connectionManager.oidc.test.ts +++ b/tests/integration/common/connectionManager.oidc.test.ts @@ -168,25 +168,28 @@ describe.skipIf(process.platform !== "linux")("ConnectionManager OIDC Tests", as }; }; - const status: ConnectionStatus = await vi.waitFor(async () => { - const result = (await state.serviceProvider.runCommand("admin", { - connectionStatus: 1, - })) as unknown as ConnectionStatus | undefined; - - if (!result) { - throw new Error("Status can not be undefined. Retrying."); - } - - if (!result.authInfo.authenticatedUsers.length) { - throw new Error("No authenticated users found. Retrying."); - } - - if (!result.authInfo.authenticatedUserRoles.length) { - throw new Error("No authenticated user roles found. Retrying."); - } - - return result; - }); + const status: ConnectionStatus = await vi.waitFor( + async () => { + const result = (await state.serviceProvider.runCommand("admin", { + connectionStatus: 1, + })) as unknown as ConnectionStatus | undefined; + + if (!result) { + throw new Error("Status can not be undefined. Retrying."); + } + + if (!result.authInfo.authenticatedUsers.length) { + throw new Error("No authenticated users found. Retrying."); + } + + if (!result.authInfo.authenticatedUserRoles.length) { + throw new Error("No authenticated user roles found. Retrying."); + } + + return result; + }, + { timeout: 5000 } + ); expect(status.authInfo.authenticatedUsers[0]).toEqual({ user: "dev/testuser", From ef45fdb18882b139306ccbabba77a9f646957686 Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Wed, 27 Aug 2025 15:13:00 +0200 Subject: [PATCH 4/4] add exportTitle matchers to accuracy tests --- tests/accuracy/export.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/accuracy/export.test.ts b/tests/accuracy/export.test.ts index 46accd30f..5b2624171 100644 --- a/tests/accuracy/export.test.ts +++ b/tests/accuracy/export.test.ts @@ -10,6 +10,7 @@ describeAccuracyTests([ parameters: { database: "mflix", collection: "movies", + exportTitle: Matcher.string(), exportTarget: [ { name: "find", @@ -28,6 +29,7 @@ describeAccuracyTests([ parameters: { database: "mflix", collection: "movies", + exportTitle: Matcher.string(), exportTarget: [ { name: "find", @@ -50,6 +52,7 @@ describeAccuracyTests([ parameters: { database: "mflix", collection: "movies", + exportTitle: Matcher.string(), exportTarget: [ { name: "find", @@ -77,6 +80,7 @@ describeAccuracyTests([ parameters: { database: "mflix", collection: "movies", + exportTitle: Matcher.string(), exportTarget: [ { name: "find",