fix(submit): use file path over stdin; fix CF CodeMirror textarea (#305)

## Problem

After the initial submit hardening, two issues remained: source code was
read in Lua and piped as stdin to the scraper (unnecessary roundtrip
since
the file exists on disk), and CF's `page.fill()` timed out on the hidden
`textarea[name="source"]` because CodeMirror owns the editor state.

## Solution

Pass the source file path as a CLI arg instead — AtCoder calls
`page.set_input_files(file_path)` directly, CF reads it with
`Path(file_path).read_text()`. Fix CF source injection via
`page.evaluate()`
into the CodeMirror instance. Extract `BROWSER_SUBMIT_NAV_TIMEOUT` as a
per-platform `defaultdict` (CF defaults to 2× nav timeout). Save the
buffer
with `vim.cmd.update()` before submitting.
This commit is contained in:
Barrett Ruth 2026-03-05 14:34:14 -05:00 committed by GitHub
parent 127089c57f
commit a202725cc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 269 additions and 168 deletions

View file

@ -47,26 +47,30 @@ function M.handle_cache_command(cmd)
constants.PLATFORM_DISPLAY_NAMES[cmd.platform],
cmd.contest
),
vim.log.levels.INFO,
true
{ level = vim.log.levels.INFO, override = true }
)
else
logger.log(("Unknown platform '%s'."):format(cmd.platform), vim.log.levels.ERROR)
logger.log(
("Unknown platform '%s'."):format(cmd.platform),
{ level = vim.log.levels.ERROR }
)
end
elseif cmd.platform then
if vim.tbl_contains(platforms, cmd.platform) then
cache.clear_platform(cmd.platform)
logger.log(
("Cache cleared for platform '%s'"):format(constants.PLATFORM_DISPLAY_NAMES[cmd.platform]),
vim.log.levels.INFO,
true
{ level = vim.log.levels.INFO, override = true }
)
else
logger.log(("Unknown platform '%s'."):format(cmd.platform), vim.log.levels.ERROR)
logger.log(
("Unknown platform '%s'."):format(cmd.platform),
{ level = vim.log.levels.ERROR }
)
end
else
cache.clear_all()
logger.log('Cache cleared', vim.log.levels.INFO, true)
logger.log('Cache cleared', { level = vim.log.levels.INFO, override = true })
end
end
end

View file

@ -83,8 +83,6 @@ local function parse_command(args)
else
return { type = 'action', action = 'interact' }
end
elseif first == 'login' or first == 'logout' then
return { type = 'action', action = first, platform = args[2] }
elseif first == 'stress' then
return {
type = 'action',
@ -245,6 +243,9 @@ local function parse_command(args)
message = 'Too few arguments - specify a contest.',
}
elseif #args == 2 then
if args[2] == 'login' or args[2] == 'logout' then
return { type = 'action', action = args[2], platform = first }
end
return {
type = 'contest_setup',
platform = first,
@ -287,7 +288,7 @@ function M.handle_command(opts)
local cmd = parse_command(opts.fargs)
if cmd.type == 'error' then
logger.log(cmd.message, vim.log.levels.ERROR)
logger.log(cmd.message, { level = vim.log.levels.ERROR })
return
end
@ -336,7 +337,7 @@ function M.handle_command(opts)
local problem_id = cmd.problem_id
if not (platform and contest_id) then
logger.log('No contest is currently active.', vim.log.levels.ERROR)
logger.log('No contest is currently active.', { level = vim.log.levels.ERROR })
return
end
@ -351,7 +352,7 @@ function M.handle_command(opts)
contest_id,
problem_id
),
vim.log.levels.ERROR
{ level = vim.log.levels.ERROR }
)
return
end

View file

@ -12,7 +12,7 @@ function M.handle_pick_action(language)
if not (config.ui and config.ui.picker) then
logger.log(
'No picker configured. Set ui.picker = "{telescope,fzf-lua}" in your config.',
vim.log.levels.ERROR
{ level = vim.log.levels.ERROR }
)
return
end
@ -25,13 +25,13 @@ function M.handle_pick_action(language)
if not ok then
logger.log(
'telescope.nvim is not available. Install telescope.nvim xor change your picker config.',
vim.log.levels.ERROR
{ level = vim.log.levels.ERROR }
)
return
end
local ok_cp, telescope_picker = pcall(require, 'cp.pickers.telescope')
if not ok_cp then
logger.log('Failed to load telescope integration.', vim.log.levels.ERROR)
logger.log('Failed to load telescope integration.', { level = vim.log.levels.ERROR })
return
end
@ -41,13 +41,13 @@ function M.handle_pick_action(language)
if not ok then
logger.log(
'fzf-lua is not available. Install fzf-lua or change your picker config',
vim.log.levels.ERROR
{ level = vim.log.levels.ERROR }
)
return
end
local ok_cp, fzf_picker = pcall(require, 'cp.pickers.fzf_lua')
if not ok_cp then
logger.log('Failed to load fzf-lua integration.', vim.log.levels.ERROR)
logger.log('Failed to load fzf-lua integration.', { level = vim.log.levels.ERROR })
return
end