fix(codechef): fast bad-credentials detection and prompt prefix

Replace `wait_for_url` with `wait_for_function` in both login and
submit `login_action` callbacks, racing URL change against `div.error`
appearing — same pattern as AtCoder and Codeforces. Also prefix
credential prompts with `[cp.nvim]:` for consistency.
This commit is contained in:
Barrett Ruth 2026-03-07 17:55:13 -05:00
parent 0ad7a9614f
commit f63b72788c
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
2 changed files with 12 additions and 8 deletions

View file

@ -15,13 +15,13 @@ local STATUS_MESSAGES = {
---@param platform string
---@param display string
local function prompt_and_login(platform, display)
vim.ui.input({ prompt = display .. ' username: ' }, function(username)
vim.ui.input({ prompt = '[cp.nvim]: ' .. display .. ' username: ' }, function(username)
if not username or username == '' then
logger.log('Cancelled', { level = vim.log.levels.WARN })
return
end
vim.fn.inputsave()
local password = vim.fn.inputsecret(display .. ' password: ')
local password = vim.fn.inputsecret('[cp.nvim]: ' .. display .. ' password: ')
vim.fn.inputrestore()
if not password or password == '' then
logger.log('Cancelled', { level = vim.log.levels.WARN })

View file

@ -84,9 +84,11 @@ def _login_headless_codechef(credentials: dict[str, str]) -> LoginResult:
page.locator('input[name="name"]').fill(credentials.get("username", ""))
page.locator('input[name="pass"]').fill(credentials.get("password", ""))
page.locator("input.cc-login-btn").click()
try:
page.wait_for_url(lambda url: "/login" not in url, timeout=3000)
except Exception:
page.wait_for_function(
"() => !window.location.href.includes('/login') || !!document.querySelector('div.error')",
timeout=BROWSER_NAV_TIMEOUT,
)
if "/login" in page.url:
login_error = "bad_credentials"
return
except Exception as e:
@ -163,9 +165,11 @@ def _submit_headless_codechef(
page.locator('input[name="name"]').fill(credentials.get("username", ""))
page.locator('input[name="pass"]').fill(credentials.get("password", ""))
page.locator("input.cc-login-btn").click()
try:
page.wait_for_url(lambda url: "/login" not in url, timeout=3000)
except Exception:
page.wait_for_function(
"() => !window.location.href.includes('/login') || !!document.querySelector('div.error')",
timeout=BROWSER_NAV_TIMEOUT,
)
if "/login" in page.url:
login_error = "bad_credentials"
return
except Exception as e: