@@ -711,6 +711,7 @@ describe("GatewayClient connect auth payload", () => {
711711 beforeEach ( ( ) => {
712712 vi . useRealTimers ( ) ;
713713 wsInstances . length = 0 ;
714+ clearDeviceAuthTokenMock . mockReset ( ) ;
714715 loadDeviceAuthTokenMock . mockReset ( ) ;
715716 storeDeviceAuthTokenMock . mockReset ( ) ;
716717 logDebugMock . mockClear ( ) ;
@@ -1207,6 +1208,33 @@ describe("GatewayClient connect auth payload", () => {
12071208 } ) ;
12081209 } ) ;
12091210
1211+ it ( "does not clear stored device tokens or reconnect on AUTH_SCOPE_MISMATCH" , async ( ) => {
1212+ loadDeviceAuthTokenMock . mockReturnValue ( {
1213+ token : "stored-device-token" ,
1214+ scopes : [ "operator.read" ] ,
1215+ } ) ;
1216+ const onReconnectPaused = vi . fn ( ) ;
1217+ const client = new GatewayClient ( {
1218+ url : "ws://127.0.0.1:18789" ,
1219+ onReconnectPaused,
1220+ } ) ;
1221+
1222+ const { ws : ws1 , connect : firstConnect } = startClientAndConnect ( { client } ) ;
1223+ expect ( firstConnect . params ?. auth ?. token ) . toBe ( "stored-device-token" ) ;
1224+ await expectNoReconnectAfterConnectFailure ( {
1225+ client,
1226+ firstWs : ws1 ,
1227+ connectId : firstConnect . id ,
1228+ failureDetails : { code : "AUTH_SCOPE_MISMATCH" } ,
1229+ } ) ;
1230+ expect ( clearDeviceAuthTokenMock ) . not . toHaveBeenCalled ( ) ;
1231+ expect ( onReconnectPaused ) . toHaveBeenCalledWith ( {
1232+ code : 1008 ,
1233+ reason : "connect failed" ,
1234+ detailCode : "AUTH_SCOPE_MISMATCH" ,
1235+ } ) ;
1236+ } ) ;
1237+
12101238 it ( "does not auto-reconnect on token mismatch when retry is not trusted" , async ( ) => {
12111239 loadDeviceAuthTokenMock . mockReturnValue ( { token : "stored-device-token" } ) ;
12121240 const client = new GatewayClient ( {
0 commit comments