@@ -66,6 +66,27 @@ describe('AuthStore', () => {
6666 } ) ;
6767
6868 describe ( 'checkAuthStatus' , ( ) => {
69+ it ( 'coalesces concurrent recovery checks' , async ( ) => {
70+ let resolveStatus ! : ( status : {
71+ needsSetup : boolean ;
72+ isAuthenticated : boolean ;
73+ authDisabled : boolean ;
74+ } ) => void ;
75+ vi . mocked ( getAuthStatus ) . mockImplementation (
76+ ( ) =>
77+ new Promise ( ( resolve ) => {
78+ resolveStatus = resolve ;
79+ } ) ,
80+ ) ;
81+ const auth = new AuthStore ( ) ;
82+ const first = auth . checkAuthStatus ( ) ;
83+ const second = auth . checkAuthStatus ( ) ;
84+ expect ( getAuthStatus ) . toHaveBeenCalledTimes ( 1 ) ;
85+ resolveStatus ( { needsSetup : false , isAuthenticated : false , authDisabled : false } ) ;
86+ await Promise . all ( [ first , second ] ) ;
87+ expect ( getAuthStatus ) . toHaveBeenCalledTimes ( 1 ) ;
88+ } ) ;
89+
6990 it ( 'sets needsSetup when server reports setup needed' , async ( ) => {
7091 vi . mocked ( getAuthStatus ) . mockResolvedValue ( {
7192 needsSetup : true ,
@@ -210,9 +231,11 @@ describe('AuthStore', () => {
210231 } ) ;
211232 const auth = new AuthStore ( ) ;
212233 auth . needsSetup = true ;
234+ auth . isUnavailable = true ;
213235 const result = await auth . register ( 'newuser' , 'pass' ) ;
214236 expect ( result . success ) . toBe ( true ) ;
215237 expect ( auth . needsSetup ) . toBe ( false ) ;
238+ expect ( auth . isUnavailable ) . toBe ( false ) ;
216239 expect ( auth . token ) . toBe ( 'reg-token' ) ;
217240 expect ( setAuthToken ) . toHaveBeenCalledWith ( 'reg-token' ) ;
218241 } ) ;
0 commit comments