Skip to content

Commit dd386b4

Browse files
chore: use ListDatabasesTool response creator for tests
1 parent c658a60 commit dd386b4

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

src/tools/mongodb/metadata/listDatabases.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ import { MongoDBToolBase } from "../mongodbTool.js";
33
import * as bson from "bson";
44
import { OperationType } from "../../tool.js";
55

6+
export function listDatabasesResponse(databases: { name: string; sizeOnDisk: string }[]): CallToolResult {
7+
return {
8+
content: databases.map((db) => {
9+
return {
10+
text: `Name: ${db.name}, Size: ${db.sizeOnDisk} bytes`,
11+
type: "text",
12+
};
13+
}),
14+
};
15+
}
16+
617
export class ListDatabasesTool extends MongoDBToolBase {
718
protected name = "list-databases";
819
protected description = "List all databases for a MongoDB connection";
@@ -13,13 +24,13 @@ export class ListDatabasesTool extends MongoDBToolBase {
1324
const provider = await this.ensureConnected();
1425
const dbs = (await provider.listDatabases("")).databases as { name: string; sizeOnDisk: bson.Long }[];
1526

16-
return {
17-
content: dbs.map((db) => {
27+
return listDatabasesResponse(
28+
dbs.map((db) => {
1829
return {
19-
text: `Name: ${db.name}, Size: ${db.sizeOnDisk.toString()} bytes`,
20-
type: "text",
30+
name: db.name,
31+
sizeOnDisk: db.sizeOnDisk.toString(),
2132
};
22-
}),
23-
};
33+
})
34+
);
2435
}
2536
}

tests/accuracy/list-databases.test.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import { describeAccuracyTests } from "./sdk/describe-accuracy-tests.js";
22
import { getAvailableModels } from "./sdk/models.js";
33
import { AccuracyTestConfig } from "./sdk/describe-accuracy-tests.js";
4+
import { listDatabasesResponse } from "../../src/tools/mongodb/metadata/listDatabases.js";
45

5-
function describeListDatabasesAccuracyTests(prompt: string): AccuracyTestConfig {
6+
function callsListDatabases(prompt: string): AccuracyTestConfig {
67
return {
78
injectConnectedAssumption: true,
89
prompt: prompt,
910
mockedTools: {
1011
"list-databases": function listDatabases() {
11-
return {
12-
content: [
13-
{
14-
type: "text",
15-
text: "Name: db1",
16-
},
17-
{
18-
type: "text",
19-
text: "Name: db2",
20-
},
21-
],
22-
};
12+
return listDatabasesResponse([
13+
{
14+
name: "db1",
15+
sizeOnDisk: "1024",
16+
},
17+
{
18+
name: "db2",
19+
sizeOnDisk: "2048",
20+
},
21+
]);
2322
},
2423
},
2524
expectedToolCalls: [
@@ -32,7 +31,7 @@ function describeListDatabasesAccuracyTests(prompt: string): AccuracyTestConfig
3231
}
3332

3433
describeAccuracyTests("list-databases", getAvailableModels(), [
35-
describeListDatabasesAccuracyTests("How many databases do I have?"),
36-
describeListDatabasesAccuracyTests("List all the databases in my cluster."),
37-
describeListDatabasesAccuracyTests("Is there a sample_mflix database in my cluster?"),
34+
callsListDatabases("How many databases do I have?"),
35+
callsListDatabases("List all the databases in my cluster."),
36+
callsListDatabases("Is there a sample_mflix database in my cluster?"),
3837
]);

0 commit comments

Comments
 (0)