@@ -60,9 +60,9 @@ function fixture(t, options = {}) {
6060 const client = {
6161 hostConfig : { id : "local" , kind : "local" } ,
6262 ensureReady : async ( ) => { ready = true ; calls . push ( "ensureReady" ) ; } ,
63- getPendingRequestCount : ( ) => options . pending ?? 0 ,
63+ getConnectionState : ( ) => ready ? "connected" : "disconnected" ,
64+ getPendingRequestCount : async ( ) => options . pending ?? 0 ,
6465 getAuthenticatedPrincipal : async ( ) => ( { accountId : `account-${ active } ` , userId : `user-${ active } ` } ) ,
65- clearAuthTokenCache : ( ) => calls . push ( "clearCache" ) ,
6666 restart : async ( ) => {
6767 calls . push ( "restart" ) ;
6868 const name = JSON . parse ( fs . readFileSync ( authPath ) ) . tokens . account_id . slice ( 8 ) ;
@@ -322,7 +322,9 @@ for (const action of ["add", "switch"]) {
322322 const f = fixture ( t ) ;
323323 const reads = [ ] ;
324324 f . clients . push ( {
325- hostConfig : { id : "durable" , kind : "local" } , getPendingRequestCount : ( ) => pending ,
325+ hostConfig : { id : "durable" , kind : "local" } ,
326+ getConnectionState : ( ) => "connected" ,
327+ getPendingRequestCount : async ( ) => pending ,
326328 sendAppServerRequest : async method => {
327329 reads . push ( method ) ;
328330 // A catalog would contain a permanently active task from another
@@ -348,6 +350,23 @@ for (const action of ["add", "switch"]) {
348350 }
349351}
350352
353+ test ( "disconnected durable host is not opened during idle checks" , async t => {
354+ for ( const action of [ "switch" , "add" ] ) {
355+ const f = fixture ( t , action === "add" ? { login : "second" } : { } ) ;
356+ let durableOpened = false ;
357+ f . clients . push ( {
358+ hostConfig : { id : "durable" , kind : "local" } ,
359+ getConnectionState : ( ) => "disconnected" ,
360+ getPendingRequestCount : async ( ) => { durableOpened = true ; return 0 ; } ,
361+ } ) ;
362+ if ( action === "switch" ) { await f . open ( 3 ) ; f . seedSecond ( ) ; }
363+ await f . open ( 1 ) ;
364+ assert . equal ( durableOpened , false , `disconnected durable host must not be opened during ${ action } ` ) ;
365+ assert . equal ( f . dialogs . filter ( dialog => dialog . type === "error" ) . length , 0 ) ;
366+ assert . equal ( fs . readFileSync ( f . authPath , "utf8" ) , credentials ( "second" ) ) ;
367+ }
368+ } ) ;
369+
351370test ( "login setup errors name the phase without exposing upstream error details" , async t => {
352371 const f = fixture ( t ) ;
353372 f . client . registerInternalNotificationHandler = ( ) => { throw new Error ( "private-error-token" ) ; } ;
@@ -648,40 +667,3 @@ test("official main and profile dropdown chunks patch uniquely and remain valid
648667 }
649668 }
650669} ) ;
651-
652- test ( "official Owl reaches OAuth and reopens an encrypted vault without querying independent cloud work" , {
653- skip : ! process . env . CODEX_ACCOUNT_SWITCHER_NATIVE_APP || ! process . env . CODEX_ACCOUNT_SWITCHER_ASAR_CLI ,
654- timeout : 30_000 ,
655- } , t => {
656- const dir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "account-native-" ) ) ;
657- const app = process . env . CODEX_ACCOUNT_SWITCHER_NATIVE_APP ;
658- const home = path . join ( dir , "home" ) , profile = path . join ( dir , "profile" ) ;
659- const probe = path . join ( dir , "app" ) , source = path . join ( dir , "source" ) ;
660- fs . mkdirSync ( path . join ( probe , "resources" ) , { recursive : true } ) ;
661- fs . mkdirSync ( source ) ;
662- t . after ( ( ) => {
663- if ( fs . existsSync ( home ) ) {
664- const id = crypto . createHash ( "sha256" ) . update ( fs . realpathSync ( home ) ) . digest ( "hex" ) ;
665- try { execFileSync ( "secret-tool" , [ "clear" , "application" , "codex-desktop" , "feature" , "account-switcher" , "profile" , id ] , { stdio : "ignore" , timeout : 5_000 } ) ; } catch { }
666- }
667- fs . rmSync ( dir , { recursive : true , force : true } ) ;
668- } ) ;
669- fs . copyFileSync ( path . join ( app , "ChatGPT" ) , path . join ( probe , "ChatGPT" ) ) ;
670- fs . chmodSync ( path . join ( probe , "ChatGPT" ) , 0o755 ) ;
671- for ( const name of fs . readdirSync ( app ) ) {
672- if ( [ "ChatGPT" , "resources" , "start.sh" , ".codex-linux" ] . includes ( name ) ) continue ;
673- fs . symlinkSync ( path . join ( app , name ) , path . join ( probe , name ) ) ;
674- }
675- for ( const name of [ "owl-app.ini" , "owl-electron-app.json" ] ) fs . copyFileSync ( path . join ( app , "resources" , name ) , path . join ( probe , "resources" , name ) ) ;
676- fs . copyFileSync ( path . join ( __dirname , "native-probe.js" ) , path . join ( source , "probe.js" ) ) ;
677- fs . writeFileSync ( path . join ( source , "package.json" ) , JSON . stringify ( { name : "account-native-probe" , version : "1.0.0" , main : "probe.js" } ) ) ;
678- execFileSync ( process . execPath , [ process . env . CODEX_ACCOUNT_SWITCHER_ASAR_CLI , "pack" , source , path . join ( probe , "resources/app.asar" ) ] , { stdio : "pipe" , timeout : 5_000 } ) ;
679- const result = path . join ( dir , "result.json" ) ;
680- execFileSync ( path . join ( probe , "ChatGPT" ) , [ `--user-data-dir=${ profile } ` ] , {
681- env : { ...process . env , TMPDIR : process . env . XDG_RUNTIME_DIR || "/tmp" , CODEX_HOME : home , CODEX_ELECTRON_USER_DATA_PATH : profile ,
682- ACCOUNT_SWITCHER_PROBE_RUNTIME : process . env . CODEX_ACCOUNT_SWITCHER_PROBE_RUNTIME || path . join ( __dirname , "runtime.js" ) , ACCOUNT_SWITCHER_PROBE_RESULT : result ,
683- ACCOUNT_SWITCHER_PROBE_NATIVE_APP : app } ,
684- stdio : "pipe" , timeout : 20_000 ,
685- } ) ;
686- assert . deepEqual ( JSON . parse ( fs . readFileSync ( result ) ) , { menus : 3 , encryptedVault : true , errors : [ ] , openedLogin : 1 , readyChecks : 4 , cloudUntouched : true } ) ;
687- } ) ;
0 commit comments