@@ -389,13 +389,15 @@ describe("bridgeCodexAppServerStartOptions", () => {
389389 await applyCodexAppServerAuthProfile ( {
390390 client : { request } as never ,
391391 agentDir,
392- startOptions : createStartOptions ( ) ,
392+ startOptions : createStartOptions ( {
393+ env : { CODEX_API_KEY : "configured-codex-api-key" } ,
394+ } ) ,
393395 } ) ;
394396
395397 expect ( request ) . toHaveBeenNthCalledWith ( 1 , "account/read" , { refreshToken : false } ) ;
396398 expect ( request ) . toHaveBeenNthCalledWith ( 2 , "account/login/start" , {
397399 type : "apiKey" ,
398- apiKey : "codex-env -api-key" ,
400+ apiKey : "configured-codex -api-key" ,
399401 } ) ;
400402 } finally {
401403 await fs . rm ( agentDir , { recursive : true , force : true } ) ;
@@ -478,6 +480,31 @@ describe("bridgeCodexAppServerStartOptions", () => {
478480 }
479481 } ) ;
480482
483+ it ( "honors clearEnv before env API-key fallback" , async ( ) => {
484+ const agentDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-codex-app-server-" ) ) ;
485+ const request = vi . fn ( async ( method : string ) => {
486+ if ( method === "account/read" ) {
487+ return { account : null , requiresOpenaiAuth : true } ;
488+ }
489+ return { type : "apiKey" } ;
490+ } ) ;
491+ vi . stubEnv ( "CODEX_API_KEY" , "codex-env-api-key" ) ;
492+ vi . stubEnv ( "OPENAI_API_KEY" , "openai-env-api-key" ) ;
493+ try {
494+ await applyCodexAppServerAuthProfile ( {
495+ client : { request } as never ,
496+ agentDir,
497+ startOptions : createStartOptions ( {
498+ clearEnv : [ "CODEX_API_KEY" , "OPENAI_API_KEY" ] ,
499+ } ) ,
500+ } ) ;
501+
502+ expect ( request ) . not . toHaveBeenCalled ( ) ;
503+ } finally {
504+ await fs . rm ( agentDir , { recursive : true , force : true } ) ;
505+ }
506+ } ) ;
507+
481508 it ( "does not send env API-key fallback to websocket app-server connections" , async ( ) => {
482509 const agentDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-codex-app-server-" ) ) ;
483510 const request = vi . fn ( async ( method : string ) => {
0 commit comments