1
1
import { describe , it , expect } from "vitest" ;
2
- import { setupUserConfig , UserConfig } from "../../../src/common/config.js" ;
2
+ import { setupUserConfig , UserConfig , defaultUserConfig } from "../../../src/common/config.js" ;
3
3
4
4
describe ( "config" , ( ) => {
5
5
describe ( "env var parsing" , ( ) => {
6
6
describe ( "string cases" , ( ) => {
7
- const testCases = {
8
- MDB_MCP_API_BASE_URL : "apiBaseUrl" ,
9
- MDB_MCP_API_CLIENT_ID : "apiClientId" ,
10
- MDB_MCP_API_CLIENT_SECRET : "apiClientSecret" ,
11
- MDB_MCP_TELEMETRY : "telemetry" ,
12
- MDB_MCP_LOG_PATH : "logPath" ,
13
- MDB_MCP_CONNECTION_STRING : "connectionString" ,
14
- MDB_MCP_READ_ONLY : "readOnly" ,
15
- MDB_MCP_INDEX_CHECK : "indexCheck" ,
16
- MDB_MCP_TRANSPORT : "transport" ,
17
- MDB_MCP_HTTP_PORT : "httpPort" ,
18
- MDB_MCP_HTTP_HOST : "httpHost" ,
19
- MDB_MCP_IDLE_TIMEOUT_MS : "idleTimeoutMs" ,
20
- MDB_MCP_NOTIFICATION_TIMEOUT_MS : "notificationTimeoutMs" ,
21
- } as const ;
22
-
23
- for ( const [ envVar , config ] of Object . entries ( testCases ) ) {
24
- it ( `should map ${ envVar } to ${ config } ` , ( ) => {
25
- const randomValue = "value=" + Math . random ( ) ;
7
+ const testCases = [
8
+ { envVar : "MDB_MCP_API_BASE_URL" , property : "apiBaseUrl" , value : "http://test.com" } ,
9
+ { envVar : "MDB_MCP_API_CLIENT_ID" , property : "apiClientId" , value : "ClientIdLol" } ,
10
+ { envVar : "MDB_MCP_API_CLIENT_SECRET" , property : "apiClientSecret" , value : "SuperClientSecret" } ,
11
+ { envVar : "MDB_MCP_TELEMETRY" , property : "telemetry" , value : "enabled" } ,
12
+ { envVar : "MDB_MCP_LOG_PATH" , property : "logPath" , value : "/var/log" } ,
13
+ { envVar : "MDB_MCP_CONNECTION_STRING" , property : "connectionString" , value : "mongodb://localhost" } ,
14
+ { envVar : "MDB_MCP_READ_ONLY" , property : "readOnly" , value : true } ,
15
+ { envVar : "MDB_MCP_INDEX_CHECK" , property : "indexCheck" , value : true } ,
16
+ { envVar : "MDB_MCP_TRANSPORT" , property : "transport" , value : "http" } ,
17
+ { envVar : "MDB_MCP_HTTP_PORT" , property : "httpPort" , value : 8080 } ,
18
+ { envVar : "MDB_MCP_HTTP_HOST" , property : "httpHost" , value : "localhost" } ,
19
+ { envVar : "MDB_MCP_IDLE_TIMEOUT_MS" , property : "idleTimeoutMs" , value : 5000 } ,
20
+ { envVar : "MDB_MCP_NOTIFICATION_TIMEOUT_MS" , property : "notificationTimeoutMs" , value : 5000 } ,
21
+ ] as const ;
26
22
23
+ for ( const { envVar, property, value } of testCases ) {
24
+ it ( `should map ${ envVar } to ${ property } with value "${ value } "` , ( ) => {
27
25
const actual = setupUserConfig ( {
28
26
cli : [ ] ,
29
27
env : {
30
- [ envVar ] : randomValue ,
28
+ [ envVar ] : String ( value ) ,
31
29
} ,
32
- defaults : { } ,
30
+ defaults : defaultUserConfig ,
33
31
} ) ;
34
32
35
- expect ( actual [ config ] ) . toBe ( randomValue ) ;
33
+ expect ( actual [ property ] ) . toBe ( value ) ;
36
34
} ) ;
37
35
}
38
36
} ) ;
@@ -45,17 +43,15 @@ describe("config", () => {
45
43
46
44
for ( const [ envVar , config ] of Object . entries ( testCases ) ) {
47
45
it ( `should map ${ envVar } to ${ config } ` , ( ) => {
48
- const randomValue = "value=" + Math . random ( ) ;
49
-
50
46
const actual = setupUserConfig ( {
51
47
cli : [ ] ,
52
48
env : {
53
- [ envVar ] : randomValue ,
49
+ [ envVar ] : "disk,mcp" ,
54
50
} ,
55
- defaults : { } ,
51
+ defaults : defaultUserConfig ,
56
52
} ) ;
57
53
58
- expect ( actual [ config ] ) . toEqual ( [ randomValue ] ) ;
54
+ expect ( actual [ config ] ) . toEqual ( [ "disk" , "mcp" ] ) ;
59
55
} ) ;
60
56
}
61
57
} ) ;
@@ -101,8 +97,8 @@ describe("config", () => {
101
97
expected : { notificationTimeoutMs : "42" } ,
102
98
} ,
103
99
{
104
- cli : [ "--telemetry" , "obviously " ] ,
105
- expected : { telemetry : "obviously " } ,
100
+ cli : [ "--telemetry" , "enabled " ] ,
101
+ expected : { telemetry : "enabled " } ,
106
102
} ,
107
103
{
108
104
cli : [ "--transport" , "stdio" ] ,
@@ -223,7 +219,7 @@ describe("config", () => {
223
219
const actual = setupUserConfig ( {
224
220
cli : [ "myself" , "--" , ...cli ] ,
225
221
env : { } ,
226
- defaults : { } ,
222
+ defaults : defaultUserConfig ,
227
223
} ) ;
228
224
229
225
for ( const [ key , value ] of Object . entries ( expected ) ) {
@@ -322,7 +318,7 @@ describe("config", () => {
322
318
const actual = setupUserConfig ( {
323
319
cli : [ "myself" , "--" , ...cli ] ,
324
320
env : { } ,
325
- defaults : { } ,
321
+ defaults : defaultUserConfig ,
326
322
} ) ;
327
323
328
324
for ( const [ key , value ] of Object . entries ( expected ) ) {
@@ -339,8 +335,8 @@ describe("config", () => {
339
335
expected : { disabledTools : [ "some" , "tool" ] } ,
340
336
} ,
341
337
{
342
- cli : [ "--loggers" , "canada,file " ] ,
343
- expected : { loggers : [ "canada " , "file " ] } ,
338
+ cli : [ "--loggers" , "disk,mcp " ] ,
339
+ expected : { loggers : [ "disk " , "mcp " ] } ,
344
340
} ,
345
341
] as { cli : string [ ] ; expected : Partial < UserConfig > } [ ] ;
346
342
@@ -349,7 +345,7 @@ describe("config", () => {
349
345
const actual = setupUserConfig ( {
350
346
cli : [ "myself" , "--" , ...cli ] ,
351
347
env : { } ,
352
- defaults : { } ,
348
+ defaults : defaultUserConfig ,
353
349
} ) ;
354
350
355
351
for ( const [ key , value ] of Object . entries ( expected ) ) {
@@ -365,7 +361,7 @@ describe("config", () => {
365
361
const actual = setupUserConfig ( {
366
362
cli : [ "myself" , "--" , "--connectionString" , "mongodb://localhost" ] ,
367
363
env : { MDB_MCP_CONNECTION_STRING : "mongodb://crazyhost" } ,
368
- defaults : { } ,
364
+ defaults : defaultUserConfig ,
369
365
} ) ;
370
366
371
367
expect ( actual . connectionString ) . toBe ( "mongodb://localhost" ) ;
@@ -376,6 +372,7 @@ describe("config", () => {
376
372
cli : [ "myself" , "--" , "--connectionString" , "mongodb://localhost" ] ,
377
373
env : { } ,
378
374
defaults : {
375
+ ...defaultUserConfig ,
379
376
connectionString : "mongodb://crazyhost" ,
380
377
} ,
381
378
} ) ;
@@ -388,6 +385,7 @@ describe("config", () => {
388
385
cli : [ ] ,
389
386
env : { MDB_MCP_CONNECTION_STRING : "mongodb://localhost" } ,
390
387
defaults : {
388
+ ...defaultUserConfig ,
391
389
connectionString : "mongodb://crazyhost" ,
392
390
} ,
393
391
} ) ;
@@ -401,7 +399,7 @@ describe("config", () => {
401
399
const actual = setupUserConfig ( {
402
400
cli : [ "myself" , "--" , "mongodb://localhost" , "--connectionString" , "toRemove" ] ,
403
401
env : { } ,
404
- defaults : { } ,
402
+ defaults : defaultUserConfig ,
405
403
} ) ;
406
404
407
405
// the shell specifies directConnection=true and serverSelectionTimeoutMS=2000 by default
0 commit comments