@@ -10,6 +10,10 @@ import { ServerConfigSchema, McpHub } from "../McpHub"
1010import { OAUTH_FLOW_TIMEOUT_MS } from "../constants"
1111import { t } from "../../../i18n"
1212
13+ type McpHubPrivate = {
14+ watchMcpSettingsFile : ( ) => Promise < void >
15+ }
16+
1317// Mock fs/promises before importing anything that uses it.
1418// Named exports and the default export must share the same vi.fn() instances so that
1519// `import * as fs` (used by McpHub.ts) and `import fs` (default) both see the same mocks.
@@ -192,6 +196,22 @@ describe("McpHub", () => {
192196 }
193197 } )
194198
199+ it ( "should log settings watcher startup failures" , async ( ) => {
200+ const watcherError = new Error ( "watcher startup failed" )
201+ const watchSpy = vi
202+ . spyOn ( McpHub . prototype as unknown as McpHubPrivate , "watchMcpSettingsFile" )
203+ . mockRejectedValueOnce ( watcherError )
204+ vi . mocked ( console . error ) . mockClear ( )
205+
206+ const failingHub = new McpHub ( mockProvider as ClineProvider )
207+ await failingHub . waitUntilReady ( )
208+ await Promise . resolve ( )
209+
210+ expect ( console . error ) . toHaveBeenCalledWith ( "[McpHub] Failed to watch MCP settings file:" , watcherError )
211+ await failingHub . dispose ( )
212+ watchSpy . mockRestore ( )
213+ } )
214+
195215 describe ( "Discriminated union type handling" , ( ) => {
196216 it ( "should create connected connections with proper type" , async ( ) => {
197217 // Mock StdioClientTransport
@@ -2526,7 +2546,7 @@ describe("McpHub", () => {
25262546 } )
25272547
25282548 mockSecretStorage . onDidChange . mockImplementation ( ( _key : string , cb : ( ) => void ) => {
2529- Promise . resolve ( ) . then ( ( ) => {
2549+ queueMicrotask ( ( ) => {
25302550 mockSecretStorage . getOAuthData . mockResolvedValue ( {
25312551 expires_at : Date . now ( ) + 10 * 60 * 1000 ,
25322552 } )
@@ -2811,7 +2831,7 @@ describe("McpHub", () => {
28112831 } )
28122832
28132833 mockSecretStorage . onDidChange . mockImplementation ( ( _key : string , cb : ( ) => void ) => {
2814- Promise . resolve ( ) . then ( ( ) => {
2834+ queueMicrotask ( ( ) => {
28152835 // Dispose the hub before the token callback runs
28162836 ; ( mcpHub as any ) . isDisposed = true
28172837 mockSecretStorage . getOAuthData . mockResolvedValue ( {
0 commit comments