Skip to content

Commit 8258b3e

Browse files
chore: changeState does not have to be public
1 parent e26376d commit 8258b3e

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/common/connectionManager.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ export interface ConnectionManagerEvents {
6868
"connection-errored": [ConnectionStateErrored];
6969
}
7070

71+
/**
72+
* For a few tests, we need the changeState method to force a connection state
73+
* which is we have this type to typecast the actual ConnectionManager with
74+
* public changeState (only to make TS happy).
75+
*/
76+
export type TestConnectionManager = ConnectionManager & {
77+
changeState<Event extends keyof ConnectionManagerEvents, State extends ConnectionManagerEvents[Event][0]>(
78+
event: Event,
79+
newState: State
80+
): State;
81+
};
82+
7183
export abstract class ConnectionManager {
7284
protected clientName: string = "unknown";
7385

@@ -80,7 +92,7 @@ export abstract class ConnectionManager {
8092
return this.state;
8193
}
8294

83-
changeState<Event extends keyof ConnectionManagerEvents, State extends ConnectionManagerEvents[Event][0]>(
95+
protected changeState<Event extends keyof ConnectionManagerEvents, State extends ConnectionManagerEvents[Event][0]>(
8496
event: Event,
8597
newState: State
8698
): State {

tests/integration/common/connectionManager.oidc.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import process from "process";
55
import type { MongoDBIntegrationTestCase } from "../tools/mongodb/mongodbHelpers.js";
66
import { describeWithMongoDB, isCommunityServer, getServerVersion } from "../tools/mongodb/mongodbHelpers.js";
77
import { defaultTestConfig, responseAsText, timeout, waitUntil } from "../helpers.js";
8-
import type { ConnectionStateConnected, ConnectionStateConnecting } from "../../../src/common/connectionManager.js";
8+
import type {
9+
ConnectionStateConnected,
10+
ConnectionStateConnecting,
11+
TestConnectionManager,
12+
} from "../../../src/common/connectionManager.js";
913
import type { UserConfig } from "../../../src/common/config.js";
1014
import { setupDriverConfig } from "../../../src/common/config.js";
1115
import path from "path";
@@ -122,7 +126,8 @@ describe.skipIf(process.platform !== "linux")("ConnectionManager OIDC Tests", as
122126
}
123127

124128
beforeEach(async () => {
125-
const connectionManager = integration.mcpServer().session.connectionManager;
129+
const connectionManager = integration.mcpServer().session
130+
.connectionManager as TestConnectionManager;
126131
// disconnect on purpose doesn't change the state if it was failed to avoid losing
127132
// information in production.
128133
await connectionManager.disconnect();

tests/integration/common/connectionManager.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import type {
2-
ConnectionManager,
32
ConnectionManagerEvents,
43
ConnectionStateConnected,
54
ConnectionStringAuthType,
5+
TestConnectionManager,
66
} from "../../../src/common/connectionManager.js";
77
import { MCPConnectionManager } from "../../../src/common/connectionManager.js";
88
import type { UserConfig } from "../../../src/common/config.js";
99
import { describeWithMongoDB } from "../tools/mongodb/mongodbHelpers.js";
1010
import { describe, beforeEach, expect, it, vi, afterEach } from "vitest";
1111

1212
describeWithMongoDB("Connection Manager", (integration) => {
13-
function connectionManager(): ConnectionManager {
14-
return integration.mcpServer().session.connectionManager;
13+
function connectionManager(): TestConnectionManager {
14+
return integration.mcpServer().session.connectionManager as TestConnectionManager;
1515
}
1616

1717
afterEach(async () => {

0 commit comments

Comments
 (0)