@@ -518,10 +518,7 @@ def get(self, url, *, headers, raise_for_status):
518518 base_url = "https://proxy.example/backend-api/codex/" ,
519519 )
520520
521- assert (
522- captured ["url" ]
523- == "https://proxy.example/backend-api/codex/models?client_version=1.0.0"
524- )
521+ assert captured ["url" ] == "https://proxy.example/backend-api/codex/models?client_version=1.0.0"
525522 assert [model .id for model in models ] == ["gpt-5.3-codex" ]
526523
527524
@@ -632,18 +629,20 @@ async def fake_exchange_code_for_tokens(code, verifier, redirect_uri):
632629 assert redirect_uri == "https://auth.openai.com/deviceauth/callback"
633630 return {
634631 "access_token" : "access-token" ,
632+ "id_token" : _jwt_with_chatgpt_account ("acc_headless" ),
635633 "refresh_token" : "refresh-token" ,
636634 "expires_in" : 3600 ,
637635 "token_type" : "Bearer" ,
638636 "scope" : "openid profile email offline_access" ,
639637 }
640638
641639 async def fake_exchange_id_token_for_api_key (id_token ):
640+ assert id_token == _jwt_with_chatgpt_account ("acc_headless" )
642641 return ""
643642
644643 async def fake_discover_chatgpt_models (api_key , * , account_id = None ):
645644 assert api_key == "access-token"
646- assert account_id is None
645+ assert account_id == "acc_headless"
647646 return [_model ("gpt-5.1-codex" , reasoning = True )]
648647
649648 monkeypatch .setattr ("pythinker_code.auth.openai._request_device_code" , fake_request_device_code )
@@ -668,6 +667,7 @@ async def fake_discover_chatgpt_models(api_key, *, account_id=None):
668667 token = load_tokens (OAuthRef (storage = "file" , key = OPENAI_CHATGPT_OAUTH_KEY ))
669668 assert token is not None
670669 assert token .access_token == "access-token"
670+ assert token .account_id == "acc_headless"
671671 provider = config .providers [managed_provider_key (OPENAI_CHATGPT_PLATFORM_ID )]
672672 assert provider .type == "openai_codex"
673673 assert provider .oauth == OAuthRef (storage = "file" , key = OPENAI_CHATGPT_OAUTH_KEY )
@@ -689,14 +689,19 @@ async def fake_exchange_code_for_tokens(code, verifier, redirect_uri):
689689 assert redirect_uri .startswith ("http://localhost:" )
690690 return {
691691 "access_token" : "access-token" ,
692+ "id_token" : _jwt_with_chatgpt_account ("acc_browser" ),
692693 "refresh_token" : "refresh-token" ,
693694 "expires_in" : 3600 ,
694695 "token_type" : "Bearer" ,
695696 "scope" : "openid profile email offline_access" ,
696697 }
697698
699+ async def fake_exchange_id_token_for_api_key (id_token ):
700+ assert id_token == _jwt_with_chatgpt_account ("acc_browser" )
701+ return ""
702+
698703 async def fake_discover_chatgpt_models (api_key , * , account_id = None ):
699- assert account_id is None
704+ assert account_id == "acc_browser"
700705 return [_model ("gpt-5.1-codex" , reasoning = True )]
701706
702707 monkeypatch .setattr (
@@ -705,6 +710,10 @@ async def fake_discover_chatgpt_models(api_key, *, account_id=None):
705710 monkeypatch .setattr (
706711 "pythinker_code.auth.openai._exchange_code_for_tokens" , fake_exchange_code_for_tokens
707712 )
713+ monkeypatch .setattr (
714+ "pythinker_code.auth.openai._exchange_id_token_for_api_key" ,
715+ fake_exchange_id_token_for_api_key ,
716+ )
708717 monkeypatch .setattr (
709718 "pythinker_code.auth.openai.discover_chatgpt_models" , fake_discover_chatgpt_models
710719 )
0 commit comments