## Problem `:CP <platform> login` blindly caches username/password without server-side validation. Bad credentials are only discovered at submit time, which is confusing and wastes a browser session. ## Solution Wire `:CP <platform> login` through the scraper pipeline so each platform actually authenticates before persisting credentials. On failure, the user sees an error and nothing is cached. - CSES: reuses `_check_token` (fast path) and `_web_login`; returns API token in `LoginResult.credentials` so subsequent submits skip re-auth. - AtCoder/Codeforces: new `_login_headless` functions open a StealthySession, solve Turnstile/Cloudflare, fill the login form, and validate success by checking for the logout link. Cookies only persist on confirmed login. - CodeChef/Kattis/USACO: return "not yet implemented" errors. - `scraper.lua`: generalizes submit-only guards (`needs_browser` flag) to cover both `submit` and `login` subcommands. - `credentials.lua`: prompts for username/password, passes cached token for CSES fast path, shows ndjson status notifications, only caches on success.
86 lines
1.7 KiB
Python
86 lines
1.7 KiB
Python
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
|
|
class TestCase(BaseModel):
|
|
input: str
|
|
expected: str
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class CombinedTest(BaseModel):
|
|
input: str
|
|
expected: str
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class ProblemSummary(BaseModel):
|
|
id: str
|
|
name: str
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class ContestSummary(BaseModel):
|
|
id: str
|
|
name: str
|
|
display_name: str | None = None
|
|
start_time: int | None = None
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class ScrapingResult(BaseModel):
|
|
success: bool
|
|
error: str
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class MetadataResult(ScrapingResult):
|
|
contest_id: str = ""
|
|
problems: list[ProblemSummary] = Field(default_factory=list)
|
|
url: str
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class ContestListResult(ScrapingResult):
|
|
contests: list[ContestSummary] = Field(default_factory=list)
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class TestsResult(ScrapingResult):
|
|
problem_id: str
|
|
combined: CombinedTest
|
|
tests: list[TestCase] = Field(default_factory=list)
|
|
timeout_ms: int
|
|
memory_mb: float
|
|
interactive: bool = False
|
|
multi_test: bool = False
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class LoginResult(ScrapingResult):
|
|
credentials: dict[str, str] = Field(default_factory=dict)
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class SubmitResult(ScrapingResult):
|
|
submission_id: str = ""
|
|
verdict: str = ""
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
class ScraperConfig(BaseModel):
|
|
timeout_seconds: int = 30
|
|
max_retries: int = 3
|
|
backoff_base: float = 2.0
|
|
rate_limit_delay: float = 1.0
|
|
|
|
model_config = ConfigDict(extra="forbid")
|