@@ -16,6 +16,8 @@ vi.mock("@roo-code/cloud", () => ({
1616 hasInstance : vi . fn ( ) ,
1717 instance : {
1818 hasActiveSession : vi . fn ( ) ,
19+ isRefreshingSession : vi . fn ( ) ,
20+ isAuthenticated : vi . fn ( ) ,
1921 getOrganizationId : vi . fn ( ) ,
2022 } ,
2123 } ,
@@ -244,6 +246,8 @@ describe("MdmService", () => {
244246
245247 mockCloudService . hasInstance . mockReturnValue ( true )
246248 mockCloudService . instance . hasActiveSession . mockReturnValue ( true )
249+ mockCloudService . instance . isRefreshingSession . mockReturnValue ( false )
250+ mockCloudService . instance . isAuthenticated . mockReturnValue ( true )
247251
248252 const service = await MdmService . createInstance ( )
249253 const compliance = service . isCompliant ( )
@@ -279,6 +283,8 @@ describe("MdmService", () => {
279283 // Mock CloudService to have instance and active session but wrong org
280284 mockCloudService . hasInstance . mockReturnValue ( true )
281285 mockCloudService . instance . hasActiveSession . mockReturnValue ( true )
286+ mockCloudService . instance . isRefreshingSession . mockReturnValue ( false )
287+ mockCloudService . instance . isAuthenticated . mockReturnValue ( true )
282288 mockCloudService . instance . getOrganizationId . mockReturnValue ( "different-org-456" )
283289
284290 const service = await MdmService . createInstance ( )
@@ -300,13 +306,69 @@ describe("MdmService", () => {
300306
301307 mockCloudService . hasInstance . mockReturnValue ( true )
302308 mockCloudService . instance . hasActiveSession . mockReturnValue ( true )
309+ mockCloudService . instance . isRefreshingSession . mockReturnValue ( false )
310+ mockCloudService . instance . isAuthenticated . mockReturnValue ( true )
303311 mockCloudService . instance . getOrganizationId . mockReturnValue ( "correct-org-123" )
304312
305313 const service = await MdmService . createInstance ( )
306314 const compliance = service . isCompliant ( )
307315
308316 expect ( compliance . compliant ) . toBe ( true )
309317 } )
318+
319+ it ( "should be compliant when refreshing session" , async ( ) => {
320+ const mockConfig = { requireCloudAuth : true }
321+ mockFs . existsSync . mockReturnValue ( true )
322+ mockFs . readFileSync . mockReturnValue ( JSON . stringify ( mockConfig ) )
323+
324+ mockCloudService . hasInstance . mockReturnValue ( true )
325+ mockCloudService . instance . hasActiveSession . mockReturnValue ( false )
326+ mockCloudService . instance . isRefreshingSession . mockReturnValue ( true )
327+ mockCloudService . instance . isAuthenticated . mockReturnValue ( true )
328+
329+ const service = await MdmService . createInstance ( )
330+ const compliance = service . isCompliant ( )
331+
332+ expect ( compliance . compliant ) . toBe ( true )
333+ } )
334+
335+ it ( "should be non-compliant when authenticated but not active or refreshing" , async ( ) => {
336+ const mockConfig = { requireCloudAuth : true }
337+ mockFs . existsSync . mockReturnValue ( true )
338+ mockFs . readFileSync . mockReturnValue ( JSON . stringify ( mockConfig ) )
339+
340+ mockCloudService . hasInstance . mockReturnValue ( true )
341+ mockCloudService . instance . hasActiveSession . mockReturnValue ( false )
342+ mockCloudService . instance . isRefreshingSession . mockReturnValue ( false )
343+ mockCloudService . instance . isAuthenticated . mockReturnValue ( true )
344+
345+ const service = await MdmService . createInstance ( )
346+ const compliance = service . isCompliant ( )
347+
348+ expect ( compliance . compliant ) . toBe ( false )
349+ if ( ! compliance . compliant ) {
350+ expect ( compliance . reason ) . toContain ( "requires Roo Code Cloud authentication" )
351+ }
352+ } )
353+
354+ it ( "should be non-compliant when not authenticated, not active, and not refreshing" , async ( ) => {
355+ const mockConfig = { requireCloudAuth : true }
356+ mockFs . existsSync . mockReturnValue ( true )
357+ mockFs . readFileSync . mockReturnValue ( JSON . stringify ( mockConfig ) )
358+
359+ mockCloudService . hasInstance . mockReturnValue ( true )
360+ mockCloudService . instance . hasActiveSession . mockReturnValue ( false )
361+ mockCloudService . instance . isRefreshingSession . mockReturnValue ( false )
362+ mockCloudService . instance . isAuthenticated . mockReturnValue ( false )
363+
364+ const service = await MdmService . createInstance ( )
365+ const compliance = service . isCompliant ( )
366+
367+ expect ( compliance . compliant ) . toBe ( false )
368+ if ( ! compliance . compliant ) {
369+ expect ( compliance . reason ) . toContain ( "requires Roo Code Cloud authentication" )
370+ }
371+ } )
310372 } )
311373
312374 describe ( "cloud enablement" , ( ) => {
0 commit comments