@@ -88,11 +88,53 @@ describe('MCP server lifecycle orchestration', () => {
8888
8989 expect ( result . success ) . toBe ( true )
9090 expect ( dbChainMockFns . set ) . toHaveBeenCalledWith ( expect . objectContaining ( { authType : 'oauth' } ) )
91- // Flipping to OAuth must reset the server to disconnected — it hasn't
92- // completed an auth flow, so it can't remain 'connected'.
91+ // Flipping to OAuth must reset to disconnected — it hasn't completed an auth flow.
9392 expect ( dbChainMockFns . set ) . toHaveBeenCalledWith (
94- expect . objectContaining ( { connectionStatus : 'disconnected' , lastConnected : null } )
93+ expect . objectContaining ( {
94+ connectionStatus : 'disconnected' ,
95+ lastConnected : null ,
96+ lastError : null ,
97+ } )
9598 )
9699 expect ( mockClearCache ) . toHaveBeenCalledWith ( 'workspace-1' )
97100 } )
101+
102+ it ( 'resets an OAuth server to disconnected when its auth type flips to headers' , async ( ) => {
103+ dbChainMockFns . limit . mockResolvedValueOnce ( [
104+ {
105+ url : 'https://example.com/mcp' ,
106+ authType : 'oauth' ,
107+ oauthClientId : 'client-1' ,
108+ oauthClientSecret : 'secret-1' ,
109+ } ,
110+ ] )
111+ dbChainMockFns . returning . mockResolvedValueOnce ( [
112+ {
113+ id : 'server-1' ,
114+ workspaceId : 'workspace-1' ,
115+ name : 'Example' ,
116+ transport : 'streamable-http' ,
117+ url : 'https://example.com/mcp' ,
118+ authType : 'headers' ,
119+ } ,
120+ ] )
121+
122+ const result = await performUpdateMcpServer ( {
123+ workspaceId : 'workspace-1' ,
124+ userId : 'user-1' ,
125+ serverId : 'server-1' ,
126+ authType : 'headers' ,
127+ } )
128+
129+ expect ( result . success ) . toBe ( true )
130+ // Flipping away from OAuth must reset too — no stale 'connected'/lastError until re-discovery.
131+ expect ( dbChainMockFns . set ) . toHaveBeenCalledWith (
132+ expect . objectContaining ( {
133+ authType : 'headers' ,
134+ connectionStatus : 'disconnected' ,
135+ lastConnected : null ,
136+ lastError : null ,
137+ } )
138+ )
139+ } )
98140} )
0 commit comments