feat(race): add supports_countdown to ContestListResult

Problem: `:CP race` on platforms without future contests (CSES, USACO)
wastes time fetching the full contest list only to discover there is
no `start_time`. The error message is also uninformative.

Solution: Add `supports_countdown` bool to `ContestListResult` (default
`True`). CSES and USACO set it to `False`. Cache the flag per-platform
so subsequent calls skip the fetch entirely. `race.lua` checks the
cached value first, then the scraper result, and shows
`"<Platform> does not support :CP race"` instead of a generic error.
This commit is contained in:
Barrett Ruth 2026-03-06 18:01:08 -05:00
parent 592f977296
commit 4e709c8470
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
7 changed files with 62 additions and 16 deletions

View file

@ -228,9 +228,13 @@ class CSESScraper(BaseScraper):
cats = parse_categories(html)
if not cats:
return ContestListResult(
success=False, error=f"{self.platform_name}: No contests found"
success=False,
error=f"{self.platform_name}: No contests found",
supports_countdown=False,
)
return ContestListResult(success=True, error="", contests=cats)
return ContestListResult(
success=True, error="", contests=cats, supports_countdown=False
)
async def login(self, credentials: dict[str, str]) -> LoginResult:
username = credentials.get("username", "")

View file

@ -50,6 +50,7 @@ class MetadataResult(ScrapingResult):
class ContestListResult(ScrapingResult):
contests: list[ContestSummary] = Field(default_factory=list)
supports_countdown: bool = True
model_config = ConfigDict(extra="forbid")

View file

@ -337,10 +337,16 @@ class USACOScraper(BaseScraper):
contests.extend(await coro)
if not contests:
return self._contests_error("No contests found")
return ContestListResult(success=True, error="", contests=contests)
return ContestListResult(
success=False, error="No contests found", supports_countdown=False
)
return ContestListResult(
success=True, error="", contests=contests, supports_countdown=False
)
except Exception as e:
return self._contests_error(str(e))
return ContestListResult(
success=False, error=str(e), supports_countdown=False
)
async def stream_tests_for_category_async(self, category_id: str) -> None:
month_year, division = _parse_contest_id(category_id)