Skip to content

Commit c29581f

Browse files
fix integration tests
1 parent a8e10bd commit c29581f

File tree

5 files changed

+20
-91
lines changed

5 files changed

+20
-91
lines changed

tests/integration/helpers.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import { MCPConnectionManager } from "../../src/common/connectionManager.js";
1919
import { DeviceId } from "../../src/helpers/deviceId.js";
2020
import { connectionErrorHandler } from "../../src/common/connectionErrorHandler.js";
2121
import { Keychain } from "../../src/common/keychain.js";
22-
import type { Client as AtlasLocalClient } from "@mongodb-js/atlas-local";
2322
import { Elicitation } from "../../src/elicitation.js";
2423
import type { MockClientCapabilities, createMockElicitInput } from "../utils/elicitationMocks.js";
2524
import { VectorSearchEmbeddingsManager } from "../../src/common/search/vectorSearchEmbeddingsManager.js";
25+
import { defaultCreateAtlasLocalClient } from "../../src/common/atlasLocal.js";
2626

2727
export const driverOptions = setupDriverConfig({
2828
config,
@@ -115,6 +115,7 @@ export function setupIntegrationTest(
115115
connectionManager,
116116
keychain: new Keychain(),
117117
vectorSearchEmbeddingsManager: new VectorSearchEmbeddingsManager(userConfig, connectionManager),
118+
atlasLocalClient: await defaultCreateAtlasLocalClient(),
118119
});
119120

120121
// Mock hasValidAccessToken for tests
@@ -408,37 +409,6 @@ export function waitUntil<T extends ConnectionState>(
408409
});
409410
}
410411

411-
export function waitUntilAtlasLocalClientIsSet(
412-
mcpServer: Server,
413-
signal: AbortSignal,
414-
timeout: number = 5000
415-
): Promise<AtlasLocalClient> {
416-
let ts: NodeJS.Timeout | undefined;
417-
418-
const timeoutSignal = AbortSignal.timeout(timeout);
419-
const combinedSignal = AbortSignal.any([signal, timeoutSignal]);
420-
421-
return new Promise<AtlasLocalClient>((resolve, reject) => {
422-
ts = setInterval(() => {
423-
if (combinedSignal.aborted) {
424-
return reject(new Error(`Aborted: ${combinedSignal.reason}`));
425-
}
426-
427-
// wait until session.client != undefined
428-
// do not wait more than 1 second, should take a few milliseconds at most
429-
// try every 50ms to see if the client is set, if it's not set after 1 second, throw an error
430-
const client = mcpServer.session.atlasLocalClient;
431-
if (client) {
432-
return resolve(client);
433-
}
434-
}, 100);
435-
}).finally(() => {
436-
if (ts !== undefined) {
437-
clearInterval(ts);
438-
}
439-
});
440-
}
441-
442412
export function getDataFromUntrustedContent(content: string): string {
443413
const regex = /^[ \t]*<untrusted-user-data-[0-9a-f\\-]*>(?<data>.*)^[ \t]*<\/untrusted-user-data-[0-9a-f\\-]*>/gms;
444414
const match = regex.exec(content);

tests/integration/tools/atlas-local/connectDeployment.test.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
getResponseElements,
77
setupIntegrationTest,
88
validateToolMetadata,
9-
waitUntilAtlasLocalClientIsSet,
109
} from "../../helpers.js";
1110
import { afterEach, describe, expect, it } from "vitest";
1211

@@ -19,10 +18,6 @@ const integration = setupIntegrationTest(
1918
// Docker is not available on macOS in GitHub Actions
2019
// That's why we skip the tests on macOS in GitHub Actions
2120
describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment", () => {
22-
beforeEach(async ({ signal }) => {
23-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
24-
});
25-
2621
validateToolMetadata(integration, "atlas-local-connect-deployment", "Connect to a MongoDB Atlas Local deployment", [
2722
{
2823
name: "deploymentName",
@@ -56,9 +51,7 @@ describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment with dep
5651
let deploymentName: string = "";
5752
let deploymentNamesToCleanup: string[] = [];
5853

59-
beforeEach(async ({ signal }) => {
60-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
61-
54+
beforeEach(async () => {
6255
// Create deployments
6356
deploymentName = `test-deployment-1-${Date.now()}`;
6457
deploymentNamesToCleanup.push(deploymentName);
@@ -103,10 +96,8 @@ describe.skipIf(isMacOSInGitHubActions)("atlas-local-connect-deployment with dep
10396
});
10497

10598
describe.skipIf(!isMacOSInGitHubActions)("atlas-local-connect-deployment [MacOS in GitHub Actions]", () => {
106-
it("should not have the atlas-local-connect-deployment tool", async ({ signal }) => {
99+
it("should not have the atlas-local-connect-deployment tool", async () => {
107100
// This should throw an error because the client is not set within the timeout of 5 seconds (default)
108-
await expect(waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal)).rejects.toThrow();
109-
110101
const { tools } = await integration.mcpClient().listTools();
111102
const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment");
112103
expect(connectDeployment).toBeUndefined();

tests/integration/tools/atlas-local/createDeployment.test.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
expectDefined,
55
getResponseElements,
66
setupIntegrationTest,
7-
waitUntilAtlasLocalClientIsSet,
87
} from "../../helpers.js";
98
import { afterEach, describe, expect, it } from "vitest";
109

@@ -34,28 +33,22 @@ describe("atlas-local-create-deployment", () => {
3433
() => defaultDriverOptions
3534
);
3635

37-
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-create-deployment tool", async ({ signal }) => {
38-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
39-
36+
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-create-deployment tool", async () => {
4037
const { tools } = await integration.mcpClient().listTools();
4138
const createDeployment = tools.find((tool) => tool.name === "atlas-local-create-deployment");
4239
expectDefined(createDeployment);
4340
});
4441

4542
it.skipIf(!isMacOSInGitHubActions)(
4643
"[MacOS in GitHub Actions] should not have the atlas-local-create-deployment tool",
47-
async ({ signal }) => {
48-
// This should throw an error because the client is not set within the timeout of 5 seconds (default)
49-
await expect(waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal)).rejects.toThrow();
50-
44+
async () => {
5145
const { tools } = await integration.mcpClient().listTools();
5246
const createDeployment = tools.find((tool) => tool.name === "atlas-local-create-deployment");
5347
expect(createDeployment).toBeUndefined();
5448
}
5549
);
5650

57-
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async ({ signal }) => {
58-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
51+
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async () => {
5952
const { tools } = await integration.mcpClient().listTools();
6053
const createDeployment = tools.find((tool) => tool.name === "atlas-local-create-deployment");
6154
expectDefined(createDeployment);
@@ -64,8 +57,7 @@ describe("atlas-local-create-deployment", () => {
6457
expect(createDeployment.inputSchema.properties).toHaveProperty("deploymentName");
6558
});
6659

67-
it.skipIf(isMacOSInGitHubActions)("should create a deployment when calling the tool", async ({ signal }) => {
68-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
60+
it.skipIf(isMacOSInGitHubActions)("should create a deployment when calling the tool", async () => {
6961
const deploymentName = `test-deployment-${Date.now()}`;
7062

7163
// Check that deployment doesn't exist before creation
@@ -97,9 +89,7 @@ describe("atlas-local-create-deployment", () => {
9789

9890
it.skipIf(isMacOSInGitHubActions)(
9991
"should return an error when creating a deployment that already exists",
100-
async ({ signal }) => {
101-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
102-
92+
async () => {
10393
// Create a deployment
10494
const deploymentName = `test-deployment-${Date.now()}`;
10595
deploymentNamesToCleanup.push(deploymentName);
@@ -119,9 +109,7 @@ describe("atlas-local-create-deployment", () => {
119109
}
120110
);
121111

122-
it.skipIf(isMacOSInGitHubActions)("should create a deployment with the correct name", async ({ signal }) => {
123-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
124-
112+
it.skipIf(isMacOSInGitHubActions)("should create a deployment with the correct name", async () => {
125113
// Create a deployment
126114
const deploymentName = `test-deployment-${Date.now()}`;
127115
deploymentNamesToCleanup.push(deploymentName);
@@ -147,9 +135,7 @@ describe("atlas-local-create-deployment", () => {
147135
expect(elements[1]?.text ?? "").toContain("Running");
148136
});
149137

150-
it.skipIf(isMacOSInGitHubActions)("should create a deployment when name is not provided", async ({ signal }) => {
151-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
152-
138+
it.skipIf(isMacOSInGitHubActions)("should create a deployment when name is not provided", async () => {
153139
// Create a deployment
154140
const createResponse = await integration.mcpClient().callTool({
155141
name: "atlas-local-create-deployment",

tests/integration/tools/atlas-local/deleteDeployment.test.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
expectDefined,
55
getResponseElements,
66
setupIntegrationTest,
7-
waitUntilAtlasLocalClientIsSet,
87
} from "../../helpers.js";
98
import { describe, expect, it } from "vitest";
109

@@ -18,28 +17,22 @@ describe("atlas-local-delete-deployment", () => {
1817
() => defaultDriverOptions
1918
);
2019

21-
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-delete-deployment tool", async ({ signal }) => {
22-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
23-
20+
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-delete-deployment tool", async () => {
2421
const { tools } = await integration.mcpClient().listTools();
2522
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
2623
expectDefined(deleteDeployment);
2724
});
2825

2926
it.skipIf(!isMacOSInGitHubActions)(
3027
"[MacOS in GitHub Actions] should not have the atlas-local-delete-deployment tool",
31-
async ({ signal }) => {
32-
// This should throw an error because the client is not set within the timeout of 5 seconds (default)
33-
await expect(waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal)).rejects.toThrow();
34-
28+
async () => {
3529
const { tools } = await integration.mcpClient().listTools();
3630
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
3731
expect(deleteDeployment).toBeUndefined();
3832
}
3933
);
4034

41-
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async ({ signal }) => {
42-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
35+
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async () => {
4336
const { tools } = await integration.mcpClient().listTools();
4437
const deleteDeployment = tools.find((tool) => tool.name === "atlas-local-delete-deployment");
4538
expectDefined(deleteDeployment);
@@ -50,8 +43,7 @@ describe("atlas-local-delete-deployment", () => {
5043

5144
it.skipIf(isMacOSInGitHubActions)(
5245
"should return 'no such container' error when deployment to delete does not exist",
53-
async ({ signal }) => {
54-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
46+
async () => {
5547
const deploymentName = "non-existent";
5648

5749
const response = await integration.mcpClient().callTool({
@@ -66,8 +58,7 @@ describe("atlas-local-delete-deployment", () => {
6658
}
6759
);
6860

69-
it.skipIf(isMacOSInGitHubActions)("should delete a deployment when calling the tool", async ({ signal }) => {
70-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
61+
it.skipIf(isMacOSInGitHubActions)("should delete a deployment when calling the tool", async () => {
7162
// Create a deployment
7263
const deploymentName = `test-deployment-${Date.now()}`;
7364
await integration.mcpClient().callTool({

tests/integration/tools/atlas-local/listDeployments.test.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
expectDefined,
55
getResponseElements,
66
setupIntegrationTest,
7-
waitUntilAtlasLocalClientIsSet,
87
} from "../../helpers.js";
98
import { describe, expect, it } from "vitest";
109

@@ -18,28 +17,22 @@ describe("atlas-local-list-deployments", () => {
1817
() => defaultDriverOptions
1918
);
2019

21-
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-list-deployments tool", async ({ signal }) => {
22-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
23-
20+
it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-list-deployments tool", async () => {
2421
const { tools } = await integration.mcpClient().listTools();
2522
const listDeployments = tools.find((tool) => tool.name === "atlas-local-list-deployments");
2623
expectDefined(listDeployments);
2724
});
2825

2926
it.skipIf(!isMacOSInGitHubActions)(
3027
"[MacOS in GitHub Actions] should not have the atlas-local-list-deployments tool",
31-
async ({ signal }) => {
32-
// This should throw an error because the client is not set within the timeout of 5 seconds (default)
33-
await expect(waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal)).rejects.toThrow();
34-
28+
async () => {
3529
const { tools } = await integration.mcpClient().listTools();
3630
const listDeployments = tools.find((tool) => tool.name === "atlas-local-list-deployments");
3731
expect(listDeployments).toBeUndefined();
3832
}
3933
);
4034

41-
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async ({ signal }) => {
42-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
35+
it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async () => {
4336
const { tools } = await integration.mcpClient().listTools();
4437
const listDeployments = tools.find((tool) => tool.name === "atlas-local-list-deployments");
4538
expectDefined(listDeployments);
@@ -48,9 +41,7 @@ describe("atlas-local-list-deployments", () => {
4841
expect(listDeployments.inputSchema.properties).toEqual({});
4942
});
5043

51-
it.skipIf(isMacOSInGitHubActions)("should not crash when calling the tool", async ({ signal }) => {
52-
await waitUntilAtlasLocalClientIsSet(integration.mcpServer(), signal);
53-
44+
it.skipIf(isMacOSInGitHubActions)("should not crash when calling the tool", async () => {
5445
const response = await integration.mcpClient().callTool({
5546
name: "atlas-local-list-deployments",
5647
arguments: {},

0 commit comments

Comments
 (0)