from app.api.routes import admin def test_extract_codex_login_controls_finds_url_and_device_code(): output = """ To sign in, open this URL in your browser: https://auth.openai.com/oauth/device?user_code=ABCD-EFGH&client_id=codex Then enter code ABCD-EFGH to continue. """ assert admin._extract_codex_login_controls(output) == { "url": "https://auth.openai.com/oauth/device?user_code=ABCD-EFGH&client_id=codex", "device_code": "ABCD-EFGH", } def test_extract_codex_login_controls_tolerates_wrapped_url_and_spaced_code(): output = ( "Visit https://auth.openai.com/oauth/device?client_id=codex&\r\n" "scope=device to authenticate.\n" "Your code is WXYZ 1234.\n" ) assert admin._extract_codex_login_controls(output) == { "url": "https://auth.openai.com/oauth/device?client_id=codex&scope=device", "device_code": "WXYZ-1234", } def test_extract_codex_login_controls_handles_current_codex_device_auth_output(): output = """ Follow these steps to sign in with ChatGPT using device code authorization: 1. Open this link in your browser and sign in to your account https://auth.openai.com/codex/device 2. Enter this one-time code (expires in 15 minutes) 8K9E-GF4JV Device codes are a common phishing target. Never share this code. """ assert admin._extract_codex_login_controls(output) == { "url": "https://auth.openai.com/codex/device", "device_code": "8K9E-GF4JV", } def test_extract_codex_login_controls_handles_codex_0142_screenshot_output(): output = """ Welcome to Codex [v0.142.0] OpenAI's command-line coding agent Follow these steps to sign in with ChatGPT using device code authorization: 1. Open this link in your browser and sign in to your account https://auth.openai.com/codex/device 2. Enter this one-time code (expires in 15 minutes) 8KXX-CDQAS """ assert admin._extract_codex_login_controls(output) == { "url": "https://auth.openai.com/codex/device", "device_code": "8KXX-CDQAS", }