1
1
import { describeWithMongoDB , getSingleDocFromUntrustedContent } from "../mongodbHelpers.js" ;
2
- import { describe , it , expect , beforeEach , afterEach } from "vitest" ;
2
+ import { describe , it , expect , beforeEach , beforeAll , afterAll } from "vitest" ;
3
3
import {
4
4
getResponseContent ,
5
5
databaseCollectionParameters ,
@@ -11,6 +11,9 @@ import {
11
11
import type { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver" ;
12
12
import type { SearchIndexStatus } from "../../../../../src/tools/mongodb/search/listSearchIndexes.js" ;
13
13
14
+ const SEARCH_RETRIES = 10_000 ;
15
+ const SEARCH_TIMEOUT = 20_000 ;
16
+
14
17
describeWithMongoDB ( "list search indexes tool in local MongoDB" , ( integration ) => {
15
18
validateToolMetadata (
16
19
integration ,
@@ -62,11 +65,7 @@ describeWithMongoDB(
62
65
await provider . createSearchIndexes ( "any" , "foo" , [ { definition : { mappings : { dynamic : true } } } ] ) ;
63
66
} ) ;
64
67
65
- afterEach ( async ( ) => {
66
- await provider . dropCollection ( "any" , "foo" ) ;
67
- } ) ;
68
-
69
- it ( "returns the list of existing indexes" , async ( ) => {
68
+ it ( "returns the list of existing indexes" , { timeout : SEARCH_TIMEOUT } , async ( ) => {
70
69
const response = await integration . mcpClient ( ) . callTool ( {
71
70
name : "list-search-indexes" ,
72
71
arguments : { database : "any" , collection : "foo" } ,
@@ -79,31 +78,34 @@ describeWithMongoDB(
79
78
expect ( indexDefinition ?. latestDefinition ) . toEqual ( { mappings : { dynamic : true , fields : { } } } ) ;
80
79
} ) ;
81
80
82
- it ( "returns the list of existing indexes and detects if they are queryable" , async ( { signal } ) => {
83
- await waitUntilIndexIsQueryable ( provider , "any" , "foo" , "default" , signal ) ;
84
-
85
- const response = await integration . mcpClient ( ) . callTool ( {
86
- name : "list-search-indexes" ,
87
- arguments : { database : "any" , collection : "foo" } ,
88
- } ) ;
89
-
90
- const content = getResponseContent ( response . content ) ;
91
- const indexDefinition = getSingleDocFromUntrustedContent < SearchIndexStatus > ( content ) ;
92
-
93
- expect ( indexDefinition ?. name ) . toEqual ( "default" ) ;
94
- expect ( indexDefinition ?. type ) . toEqual ( "search" ) ;
95
- expect ( indexDefinition ?. latestDefinition ) . toEqual ( { mappings : { dynamic : true , fields : { } } } ) ;
96
- expect ( indexDefinition ?. queryable ) . toEqual ( true ) ;
97
- expect ( indexDefinition ?. status ) . toEqual ( "READY" ) ;
98
- } ) ;
81
+ it (
82
+ "returns the list of existing indexes and detects if they are queryable" ,
83
+ { timeout : SEARCH_TIMEOUT } ,
84
+ async ( { signal } ) => {
85
+ await waitUntilIndexIsQueryable ( provider , "any" , "foo" , "default" , signal ) ;
86
+
87
+ const response = await integration . mcpClient ( ) . callTool ( {
88
+ name : "list-search-indexes" ,
89
+ arguments : { database : "any" , collection : "foo" } ,
90
+ } ) ;
91
+
92
+ const content = getResponseContent ( response . content ) ;
93
+ const indexDefinition = getSingleDocFromUntrustedContent < SearchIndexStatus > ( content ) ;
94
+
95
+ expect ( indexDefinition ?. name ) . toEqual ( "default" ) ;
96
+ expect ( indexDefinition ?. type ) . toEqual ( "search" ) ;
97
+ expect ( indexDefinition ?. latestDefinition ) . toEqual ( { mappings : { dynamic : true , fields : { } } } ) ;
98
+ expect ( indexDefinition ?. queryable ) . toEqual ( true ) ;
99
+ expect ( indexDefinition ?. status ) . toEqual ( "READY" ) ;
100
+ }
101
+ ) ;
99
102
} ) ;
100
103
} ,
101
104
undefined , // default user config
102
105
undefined , // default driver config
103
106
{ search : true } // use a search cluster
104
107
) ;
105
108
106
- const SEARCH_RETRIES = 10_000 ;
107
109
async function waitUntilSearchIsReady ( provider : NodeDriverServiceProvider , abortSignal : AbortSignal ) : Promise < void > {
108
110
let success = true ;
109
111
let lastError : unknown = false ;
@@ -153,7 +155,7 @@ async function waitUntilIndexIsQueryable(
153
155
154
156
if ( ! success ) {
155
157
throw new Error (
156
- `Index ${ indexName } in ${ database } .${ collection } is not ready: \nlastIndexStatus: ${ lastIndexStatus } \nlastError: ${ lastError } `
158
+ `Index ${ indexName } in ${ database } .${ collection } is not ready: \nlastIndexStatus: ${ JSON . stringify ( lastIndexStatus ) } \nlastError: ${ lastError } `
157
159
) ;
158
160
}
159
161
}
0 commit comments