Skip to content

Commit 7fa4a2f

Browse files
authored
fix: incorrect number of clusters found (#561)
1 parent 62a57d8 commit 7fa4a2f

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/tools/atlas/read/listClusters.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ ${rows}`,
9797
}
9898
const formattedClusters = clusters?.results?.map((cluster) => formatCluster(cluster)) || [];
9999
const formattedFlexClusters = flexClusters?.results?.map((cluster) => formatFlexCluster(cluster)) || [];
100-
const rows = [...formattedClusters, ...formattedFlexClusters]
101-
.map((formattedCluster) => {
102-
return `${formattedCluster.name || "Unknown"} | ${formattedCluster.instanceType} | ${formattedCluster.instanceSize || "N/A"} | ${formattedCluster.state || "UNKNOWN"} | ${formattedCluster.mongoDBVersion || "N/A"} | ${formattedCluster.connectionString || "N/A"}`;
103-
})
104-
.join("\n");
100+
const allClusters = [...formattedClusters, ...formattedFlexClusters];
105101
return {
106102
content: formatUntrustedData(
107-
`Found ${rows.length} clusters in project "${project.name}" (${project.id}):`,
103+
`Found ${allClusters.length} clusters in project "${project.name}" (${project.id}):`,
108104
`Cluster Name | Cluster Type | Tier | State | MongoDB Version | Connection String
109105
----------------|----------------|----------------|----------------|----------------|----------------
110-
${rows}`
106+
${allClusters
107+
.map((formattedCluster) => {
108+
return `${formattedCluster.name || "Unknown"} | ${formattedCluster.instanceType} | ${formattedCluster.instanceSize || "N/A"} | ${formattedCluster.state || "UNKNOWN"} | ${formattedCluster.mongoDBVersion || "N/A"} | ${formattedCluster.connectionString || "N/A"}`;
109+
})
110+
.join("\n")}`
111111
),
112112
};
113113
}

tests/integration/tools/atlas/clusters.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Session } from "../../../../src/common/session.js";
2-
import { expectDefined, getResponseElements } from "../../helpers.js";
3-
import { describeWithAtlas, withProject, randomId } from "./atlasHelpers.js";
2+
import { expectDefined, getDataFromUntrustedContent, getResponseElements } from "../../helpers.js";
3+
import { describeWithAtlas, withProject, randomId, parseTable } from "./atlasHelpers.js";
44
import type { ClusterDescription20240805 } from "../../../../src/common/atlas/openapi.js";
55
import { afterAll, beforeAll, describe, expect, it } from "vitest";
66

@@ -152,9 +152,12 @@ describeWithAtlas("clusters", (integration) => {
152152

153153
const elements = getResponseElements(response);
154154
expect(elements).toHaveLength(2);
155-
expect(elements[0]?.text).toMatch(/Found \d+ clusters in project/);
155+
156156
expect(elements[1]?.text).toContain("<untrusted-user-data-");
157157
expect(elements[1]?.text).toContain(`${clusterName} | `);
158+
const data = parseTable(getDataFromUntrustedContent(elements[1]?.text ?? ""));
159+
expect(data.length).toBeGreaterThanOrEqual(1);
160+
expect(elements[0]?.text).toMatch(`Found ${data.length} clusters in project`);
158161
});
159162
});
160163

0 commit comments

Comments
 (0)