From e7ebe738a4bb1a2b9cc9de1eb6079a20ba0b9734 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 6 Mar 2026 17:28:04 -0500 Subject: [PATCH 1/2] feat(config): add `submit_id` platform override for language selection Problem: The submission language ID is hardcoded per platform in `language_ids.py` (e.g. CF `"89"` = GNU G++17 7.3.0). Users have no way to select a different version like G++20 or C++23. Solution: Add `submit_id?: string` to `CpPlatformOverrides` and `CpLanguage`. When set, `submit.lua` passes the resolved `submit_id` directly to the scraper instead of the generic language key. The existing `get_language_id() or args[4]` fallback in `base.py` handles pre-resolved IDs without any Python changes. --- lua/cp/config.lua | 5 +++++ lua/cp/submit.lua | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/cp/config.lua b/lua/cp/config.lua index 728b85f..f9b678a 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -8,6 +8,7 @@ ---@field extension string ---@field commands CpLangCommands ---@field template? string +---@field submit_id? string ---@class CpTemplatesConfig ---@field cursor_marker? string @@ -16,6 +17,7 @@ ---@field extension? string ---@field commands? CpLangCommands ---@field template? string +---@field submit_id? string ---@class CpPlatform ---@field enabled_languages string[] @@ -293,6 +295,9 @@ local function merge_lang(base, ov) if ov.template then out.template = ov.template end + if ov.submit_id then + out.submit_id = ov.submit_id + end return out end diff --git a/lua/cp/submit.lua b/lua/cp/submit.lua index 50d884f..01329d8 100644 --- a/lua/cp/submit.lua +++ b/lua/cp/submit.lua @@ -1,6 +1,7 @@ local M = {} local cache = require('cp.cache') +local config = require('cp.config') local logger = require('cp.log') local state = require('cp.state') @@ -56,6 +57,12 @@ function M.submit(opts) end source_file = vim.fn.fnamemodify(source_file, ':p') + local lang_result = config.get_language_for_platform(platform, language) + local submit_language = language + if lang_result.valid and lang_result.effective and lang_result.effective.submit_id then + submit_language = lang_result.effective.submit_id + end + prompt_credentials(platform, function(creds) vim.cmd.update() vim.notify('[cp.nvim] Submitting...', vim.log.levels.INFO) @@ -64,7 +71,7 @@ function M.submit(opts) platform, contest_id, problem_id, - language, + submit_language, source_file, creds, function(ev) From 3fecffe676515e3af7c9297c300bc5b6677d4d82 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 6 Mar 2026 17:28:09 -0500 Subject: [PATCH 2/2] test: verify `language_ids.py` coverage and unknown-key fallback Problem: No tests verified that `language_ids.py` had entries for all six platforms and both core languages, or that unknown lookups returned `None` instead of raising. Solution: Add `test_language_ids_coverage` (asserts every platform has `cpp` and `python` entries with non-empty string values) and `test_language_ids_unknown_returns_none` (verifies fallback for unknown platform or language keys). --- tests/test_scrapers.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_scrapers.py b/tests/test_scrapers.py index c4fa6d5..25d2d80 100644 --- a/tests/test_scrapers.py +++ b/tests/test_scrapers.py @@ -1,5 +1,6 @@ import pytest +from scrapers.language_ids import LANGUAGE_IDS, get_language_id from scrapers.models import ( ContestListResult, MetadataResult, @@ -137,3 +138,21 @@ def test_scraper_metadata_error(run_scraper_offline, scraper, contest_id): assert objs assert objs[-1].get("success") is False assert objs[-1].get("error") + + +EXPECTED_PLATFORMS = {"atcoder", "codeforces", "cses", "usaco", "kattis", "codechef"} +EXPECTED_LANGUAGES = {"cpp", "python"} + + +def test_language_ids_coverage(): + assert set(LANGUAGE_IDS.keys()) == EXPECTED_PLATFORMS + for platform in EXPECTED_PLATFORMS: + for lang in EXPECTED_LANGUAGES: + lid = get_language_id(platform, lang) + assert lid is not None, f"Missing language ID: {platform}/{lang}" + assert isinstance(lid, str) and lid, f"Empty language ID: {platform}/{lang}" + + +def test_language_ids_unknown_returns_none(): + assert get_language_id("codeforces", "rust") is None + assert get_language_id("nonexistent", "cpp") is None