|
| 1 | +import { |
| 2 | + defaultDriverOptions, |
| 3 | + defaultTestConfig, |
| 4 | + expectDefined, |
| 5 | + getResponseElements, |
| 6 | + setupIntegrationTest, |
| 7 | + waitUntilMcpClientIsSet, |
| 8 | +} from "../../helpers.js"; |
| 9 | +import { describe, expect, it } from "vitest"; |
| 10 | + |
| 11 | +const isMacOSInGitHubActions = process.platform === "darwin" && process.env.GITHUB_ACTIONS === "true"; |
| 12 | + |
| 13 | +// Docker is not available on macOS in GitHub Actions |
| 14 | +// That's why we skip the tests on macOS in GitHub Actions |
| 15 | +describe("atlas-local-connect-deployment", () => { |
| 16 | + const integration = setupIntegrationTest( |
| 17 | + () => defaultTestConfig, |
| 18 | + () => defaultDriverOptions |
| 19 | + ); |
| 20 | + |
| 21 | + it.skipIf(isMacOSInGitHubActions)("should have the atlas-local-connect-deployment tool", async ({ signal }) => { |
| 22 | + await waitUntilMcpClientIsSet(integration.mcpServer(), signal); |
| 23 | + |
| 24 | + const { tools } = await integration.mcpClient().listTools(); |
| 25 | + const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment"); |
| 26 | + expectDefined(connectDeployment); |
| 27 | + }); |
| 28 | + |
| 29 | + it.skipIf(!isMacOSInGitHubActions)( |
| 30 | + "[MacOS in GitHub Actions] should not have the atlas-local-connect-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(waitUntilMcpClientIsSet(integration.mcpServer(), signal)).rejects.toThrow(); |
| 34 | + |
| 35 | + const { tools } = await integration.mcpClient().listTools(); |
| 36 | + const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment"); |
| 37 | + expect(connectDeployment).toBeUndefined(); |
| 38 | + } |
| 39 | + ); |
| 40 | + |
| 41 | + it.skipIf(isMacOSInGitHubActions)("should have correct metadata", async ({ signal }) => { |
| 42 | + await waitUntilMcpClientIsSet(integration.mcpServer(), signal); |
| 43 | + const { tools } = await integration.mcpClient().listTools(); |
| 44 | + const connectDeployment = tools.find((tool) => tool.name === "atlas-local-connect-deployment"); |
| 45 | + expectDefined(connectDeployment); |
| 46 | + expect(connectDeployment.inputSchema.type).toBe("object"); |
| 47 | + expectDefined(connectDeployment.inputSchema.properties); |
| 48 | + expect(connectDeployment.inputSchema.properties).toHaveProperty("deploymentIdOrName"); |
| 49 | + }); |
| 50 | + |
| 51 | + it.skipIf(isMacOSInGitHubActions)( |
| 52 | + "should return 'no such container' error when connecting to non-existent deployment", |
| 53 | + async ({ signal }) => { |
| 54 | + await waitUntilMcpClientIsSet(integration.mcpServer(), signal); |
| 55 | + |
| 56 | + const response = await integration.mcpClient().callTool({ |
| 57 | + name: "atlas-local-connect-deployment", |
| 58 | + arguments: { deploymentIdOrName: "non-existent" }, |
| 59 | + }); |
| 60 | + const elements = getResponseElements(response.content); |
| 61 | + expect(elements.length).toBeGreaterThanOrEqual(1); |
| 62 | + expect(elements[0]?.text).toContain( |
| 63 | + "Docker responded with status code 404: No such container: non-existent" |
| 64 | + ); |
| 65 | + } |
| 66 | + ); |
| 67 | + |
| 68 | + it.skipIf(isMacOSInGitHubActions)("should connect to a deployment when calling the tool", async ({ signal }) => { |
| 69 | + await waitUntilMcpClientIsSet(integration.mcpServer(), signal); |
| 70 | + // Create a deployment |
| 71 | + const deploymentName = `test-deployment-${Date.now()}`; |
| 72 | + await integration.mcpClient().callTool({ |
| 73 | + name: "atlas-local-create-deployment", |
| 74 | + arguments: { deploymentName }, |
| 75 | + }); |
| 76 | + |
| 77 | + // Connect to the deployment |
| 78 | + const response = await integration.mcpClient().callTool({ |
| 79 | + name: "atlas-local-connect-deployment", |
| 80 | + arguments: { deploymentIdOrName: deploymentName }, |
| 81 | + }); |
| 82 | + const elements = getResponseElements(response.content); |
| 83 | + expect(elements.length).toBeGreaterThanOrEqual(1); |
| 84 | + expect(elements[0]?.text).toContain( |
| 85 | + 'Successfully connected to Atlas Local deployment "' + deploymentName + '".' |
| 86 | + ); |
| 87 | + |
| 88 | + // cleanup |
| 89 | + try { |
| 90 | + await integration.mcpClient().callTool({ |
| 91 | + name: "atlas-local-delete-deployment", |
| 92 | + arguments: { deploymentName }, |
| 93 | + }); |
| 94 | + } catch (error) { |
| 95 | + console.warn(`Failed to delete deployment ${deploymentName}:`, error); |
| 96 | + } |
| 97 | + }); |
| 98 | +}); |
0 commit comments