refactor(submit): pass file path instead of source via stdin

Problem: Submit read the source file in Lua, piped the full content as
stdin through to Python, then re-encoded it into an in-memory buffer
just to hand it back to the browser's file input. Unnecessary roundtrip
for AtCoder; CF also gains nothing from Lua owning the read.

Solution: Pass `source_file` path as a CLI arg to the scraper instead
of reading it in Lua and streaming via stdin. AtCoder calls
`page.set_input_files(file_path)` directly. Codeforces reads the file
with `Path(file_path).read_text()` before the browser session. Also
saves the buffer with `vim.cmd.update()` before submitting.
This commit is contained in:
Barrett Ruth 2026-03-05 11:26:29 -05:00
parent b5a8fce13c
commit c963728fe9
5 changed files with 22 additions and 38 deletions

View file

@ -289,7 +289,7 @@ class CodeforcesScraper(BaseScraper):
self,
contest_id: str,
problem_id: str,
source_code: str,
file_path: str,
language_id: str,
credentials: dict[str, str],
) -> SubmitResult:
@ -297,7 +297,7 @@ class CodeforcesScraper(BaseScraper):
_submit_headless,
contest_id,
problem_id,
source_code,
file_path,
language_id,
credentials,
)
@ -306,13 +306,15 @@ class CodeforcesScraper(BaseScraper):
def _submit_headless(
contest_id: str,
problem_id: str,
source_code: str,
file_path: str,
language_id: str,
credentials: dict[str, str],
_retried: bool = False,
) -> SubmitResult:
from pathlib import Path
source_code = Path(file_path).read_text()
try:
from scrapling.fetchers import StealthySession # type: ignore[import-untyped,unresolved-import]
except ImportError:
@ -451,7 +453,7 @@ def _submit_headless(
return _submit_headless(
contest_id,
problem_id,
source_code,
file_path,
language_id,
credentials,
_retried=True,