@@ -17,9 +17,7 @@ vi.mock("electron", () => ({
1717 } ,
1818 ipcRenderer : {
1919 sendSync,
20- invoke : vi . fn ( async ( channel : string ) =>
21- channel === IpcChannels . GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL ? true : [ ] ,
22- ) ,
20+ invoke : vi . fn ( async ( ) => undefined ) ,
2321 on : vi . fn ( ) ,
2422 removeListener : vi . fn ( ) ,
2523 } ,
@@ -28,38 +26,30 @@ vi.mock("electron", () => ({
2826} ) ) ;
2927vi . mock ( "@clerk/electron/preload" , ( ) => ( { exposeClerkBridge : vi . fn ( ) } ) ) ;
3028
31- it ( "polling topology reads do not block the renderer on synchronous IPC each time " , async ( ) => {
29+ it ( "topology polling reads the cache and refreshes it without synchronous IPC" , async ( ) => {
3230 vi . stubGlobal ( "window" , {
3331 addEventListener : ( ) => { } ,
3432 localStorage : { getItem : ( ) => null , setItem : ( ) => { } } ,
3533 } ) ;
34+ vi . stubGlobal ( "document" , {
35+ addEventListener : ( ) => { } ,
36+ fullscreenElement : null ,
37+ documentElement : { style : { setProperty : ( ) => { } } } ,
38+ } ) ;
3639 await import ( "./preload.ts" ) ;
3740 const bridge = exposed . get ( "desktopBridge" ) as DesktopBridge ;
3841 sendSync . mockClear ( ) ;
3942
40- // The renderer's platform poll reads these every few seconds; ipcRenderer.sendSync
41- // freezes the renderer for as long as the main process takes to answer.
43+ // sendSync freezes the renderer until main answers; only the first read may use it.
4244 for ( let poll = 0 ; poll < 5 ; poll += 1 ) {
4345 bridge . getLocalEnvironmentBootstraps ( ) ;
44- bridge . getLocalEnvironmentEnabled ?. ( ) ;
46+ bridge . getLocalEnvironmentEnabled ( ) ;
4547 }
46-
4748 const syncCalls = ( channel : string ) =>
4849 sendSync . mock . calls . filter ( ( [ called ] ) => called === channel ) . length ;
49- // Each read may block once at startup; later polls must not.
50- expect
51- . soft ( syncCalls ( IpcChannels . GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL ) )
52- . toBeLessThanOrEqual ( 1 ) ;
53- expect . soft ( syncCalls ( IpcChannels . GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL ) ) . toBeLessThanOrEqual ( 1 ) ;
54- } ) ;
50+ expect ( syncCalls ( IpcChannels . GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL ) ) . toBeLessThanOrEqual ( 1 ) ;
51+ expect ( syncCalls ( IpcChannels . GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL ) ) . toBeLessThanOrEqual ( 1 ) ;
5552
56- it ( "an async topology refresh replaces the bootstraps later reads return" , async ( ) => {
57- vi . stubGlobal ( "window" , {
58- addEventListener : ( ) => { } ,
59- localStorage : { getItem : ( ) => null , setItem : ( ) => { } } ,
60- } ) ;
61- await import ( "./preload.ts" ) ;
62- const bridge = exposed . get ( "desktopBridge" ) as DesktopBridge ;
6353 const wsl = {
6454 id : "wsl:Ubuntu" ,
6555 label : "WSL (Ubuntu)" ,
@@ -69,7 +59,6 @@ it("an async topology refresh replaces the bootstraps later reads return", async
6959 } ;
7060 vi . mocked ( ipcRenderer . invoke ) . mockResolvedValueOnce ( [ wsl ] ) . mockResolvedValueOnce ( [ ] ) ;
7161 sendSync . mockClear ( ) ;
72-
7362 await bridge . refreshLocalEnvironmentBootstraps ?.( ) ;
7463 expect ( bridge . getLocalEnvironmentBootstraps ( ) ) . toEqual ( [ wsl ] ) ;
7564 await bridge . refreshLocalEnvironmentBootstraps ?.( ) ;
0 commit comments