@@ -5417,6 +5417,54 @@ describe("codex manager cli commands", () => {
54175417 expect ( storageState . accounts ) . toHaveLength ( 0 ) ;
54185418 } ) ;
54195419
5420+ it ( "skips manual callback prompting when stdin is already closed in non-tty mode" , async ( ) => {
5421+ setInteractiveTTY ( false ) ;
5422+ setOpenStdinState ( ) ;
5423+ Object . defineProperty ( process . stdin , "readableEnded" , {
5424+ value : true ,
5425+ configurable : true ,
5426+ } ) ;
5427+ let storageState = {
5428+ version : 3 as const ,
5429+ activeIndex : 0 ,
5430+ activeIndexByFamily : { codex : 0 } ,
5431+ accounts : [ ] as Array < Record < string , unknown > > ,
5432+ } ;
5433+ loadAccountsMock . mockImplementation ( async ( ) =>
5434+ structuredClone ( storageState ) ,
5435+ ) ;
5436+ saveAccountsMock . mockImplementation ( async ( nextStorage ) => {
5437+ storageState = structuredClone ( nextStorage ) ;
5438+ } ) ;
5439+ promptLoginModeMock . mockResolvedValueOnce ( { mode : "cancel" } ) ;
5440+
5441+ const authModule = await import ( "../lib/auth/auth.js" ) ;
5442+ vi . mocked ( authModule . createAuthorizationFlow ) . mockResolvedValueOnce ( {
5443+ pkce : { challenge : "pkce-challenge" , verifier : "pkce-verifier" } ,
5444+ state : "oauth-state" ,
5445+ url : "https://auth.openai.com/mock" ,
5446+ } ) ;
5447+ const exchangeAuthorizationCodeMock = vi . mocked (
5448+ authModule . exchangeAuthorizationCode ,
5449+ ) ;
5450+
5451+ const browserModule = await import ( "../lib/auth/browser.js" ) ;
5452+ const openBrowserUrlMock = vi . mocked ( browserModule . openBrowserUrl ) ;
5453+ const serverModule = await import ( "../lib/auth/server.js" ) ;
5454+
5455+ const { runCodexMultiAuthCli } = await import ( "../lib/codex-manager.js" ) ;
5456+ const exitCode = await runCodexMultiAuthCli ( [ "auth" , "login" , "--manual" ] ) ;
5457+
5458+ expect ( exitCode ) . toBe ( 0 ) ;
5459+ expect ( promptQuestionMock ) . not . toHaveBeenCalled ( ) ;
5460+ expect ( openBrowserUrlMock ) . not . toHaveBeenCalled ( ) ;
5461+ expect (
5462+ vi . mocked ( serverModule . startLocalOAuthServer ) ,
5463+ ) . not . toHaveBeenCalled ( ) ;
5464+ expect ( exchangeAuthorizationCodeMock ) . not . toHaveBeenCalled ( ) ;
5465+ expect ( storageState . accounts ) . toHaveLength ( 0 ) ;
5466+ } ) ;
5467+
54205468 it ( "falls back to pasted manual input when Windows-style callback bind fails" , async ( ) => {
54215469 setInteractiveTTY ( false ) ;
54225470 const now = Date . now ( ) ;
0 commit comments