From 24ce438201f6ff5f3ac66178bcd04d92b54c47b8 Mon Sep 17 00:00:00 2001 From: nirinchev Date: Tue, 16 Sep 2025 09:22:29 +0200 Subject: [PATCH] fix: incorrect number of clusters found --- src/tools/atlas/read/listClusters.ts | 14 +++++++------- tests/integration/tools/atlas/clusters.test.ts | 9 ++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/tools/atlas/read/listClusters.ts b/src/tools/atlas/read/listClusters.ts index 5c8e72a30..60344f7d3 100644 --- a/src/tools/atlas/read/listClusters.ts +++ b/src/tools/atlas/read/listClusters.ts @@ -97,17 +97,17 @@ ${rows}`, } const formattedClusters = clusters?.results?.map((cluster) => formatCluster(cluster)) || []; const formattedFlexClusters = flexClusters?.results?.map((cluster) => formatFlexCluster(cluster)) || []; - const rows = [...formattedClusters, ...formattedFlexClusters] - .map((formattedCluster) => { - return `${formattedCluster.name || "Unknown"} | ${formattedCluster.instanceType} | ${formattedCluster.instanceSize || "N/A"} | ${formattedCluster.state || "UNKNOWN"} | ${formattedCluster.mongoDBVersion || "N/A"} | ${formattedCluster.connectionString || "N/A"}`; - }) - .join("\n"); + const allClusters = [...formattedClusters, ...formattedFlexClusters]; return { content: formatUntrustedData( - `Found ${rows.length} clusters in project "${project.name}" (${project.id}):`, + `Found ${allClusters.length} clusters in project "${project.name}" (${project.id}):`, `Cluster Name | Cluster Type | Tier | State | MongoDB Version | Connection String ----------------|----------------|----------------|----------------|----------------|---------------- -${rows}` +${allClusters + .map((formattedCluster) => { + return `${formattedCluster.name || "Unknown"} | ${formattedCluster.instanceType} | ${formattedCluster.instanceSize || "N/A"} | ${formattedCluster.state || "UNKNOWN"} | ${formattedCluster.mongoDBVersion || "N/A"} | ${formattedCluster.connectionString || "N/A"}`; + }) + .join("\n")}` ), }; } diff --git a/tests/integration/tools/atlas/clusters.test.ts b/tests/integration/tools/atlas/clusters.test.ts index ccb6e774d..5c50c570c 100644 --- a/tests/integration/tools/atlas/clusters.test.ts +++ b/tests/integration/tools/atlas/clusters.test.ts @@ -1,6 +1,6 @@ import type { Session } from "../../../../src/common/session.js"; -import { expectDefined, getResponseElements } from "../../helpers.js"; -import { describeWithAtlas, withProject, randomId } from "./atlasHelpers.js"; +import { expectDefined, getDataFromUntrustedContent, getResponseElements } from "../../helpers.js"; +import { describeWithAtlas, withProject, randomId, parseTable } from "./atlasHelpers.js"; import type { ClusterDescription20240805 } from "../../../../src/common/atlas/openapi.js"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; @@ -152,9 +152,12 @@ describeWithAtlas("clusters", (integration) => { const elements = getResponseElements(response); expect(elements).toHaveLength(2); - expect(elements[0]?.text).toMatch(/Found \d+ clusters in project/); + expect(elements[1]?.text).toContain("