diff --git a/lua/cp/config.lua b/lua/cp/config.lua index 8b1a482..6d00698 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -126,11 +126,14 @@ function M.setup(user_config) end if user_config.scrapers then - for _, contest_name in ipairs(user_config.scrapers) do - if not vim.tbl_contains(constants.PLATFORMS, contest_name) then + for _, platform_name in ipairs(user_config.scrapers) do + if type(platform_name) ~= 'string' then + error(('Invalid scraper value type. Expected string, got %s'):format(type(platform_name))) + end + if not vim.tbl_contains(constants.PLATFORMS, platform_name) then error( - ("Invalid contest '%s' in scrapers config. Valid contests: %s"):format( - contest_name, + ("Invalid platform '%s' in scrapers config. Valid platforms: %s"):format( + platform_name, table.concat(constants.PLATFORMS, ', ') ) ) diff --git a/lua/cp/snippets.lua b/lua/cp/snippets.lua index 43feaf5..b7b03ed 100644 --- a/lua/cp/snippets.lua +++ b/lua/cp/snippets.lua @@ -101,7 +101,7 @@ if __name__ == "__main__": } local user_overrides = {} - for _, snippet in ipairs(config.snippets) do + for _, snippet in ipairs(config.snippets or {}) do user_overrides[snippet.trigger] = snippet end diff --git a/spec/config_spec.lua b/spec/config_spec.lua index 97b504c..3b94ddf 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -46,7 +46,7 @@ describe('cp.config', function() it('validates scraper platforms', function() local invalid_config = { - scrapers = { invalid_platform = true }, + scrapers = { 'invalid_platform' }, } assert.has_error(function() @@ -54,9 +54,9 @@ describe('cp.config', function() end) end) - it('validates scraper values are booleans', function() + it('validates scraper values are strings', function() local invalid_config = { - scrapers = { atcoder = 'not_boolean' }, + scrapers = { 123 }, } assert.has_error(function() diff --git a/spec/health_spec.lua b/spec/health_spec.lua index 3bf774e..80c55f0 100644 --- a/spec/health_spec.lua +++ b/spec/health_spec.lua @@ -2,6 +2,9 @@ describe('cp.health', function() local health before_each(function() + local original_gsub = string.gsub + string.gsub = original_gsub + vim.fn = vim.tbl_extend('force', vim.fn, { executable = function() return 1 diff --git a/spec/integration_spec.lua b/spec/integration_spec.lua index 9ab1781..bb3ac31 100644 --- a/spec/integration_spec.lua +++ b/spec/integration_spec.lua @@ -80,6 +80,7 @@ describe('cp integration', function() default_language = 'cpp', timeout_ms = 2000, cpp = { + extension = 'cpp', compile = { 'g++', '{source}', '-o', '{binary}' }, run = { '{binary}' }, }, @@ -201,7 +202,19 @@ describe('cp integration', function() it('handles scraper communication properly', function() vim.system = function(cmd) - if cmd[1] == 'uv' and vim.tbl_contains(cmd, 'metadata') then + if cmd[1] == 'ping' then + return { + wait = function() + return { code = 0 } + end, + } + elseif cmd[1] == 'uv' and cmd[2] == 'sync' then + return { + wait = function() + return { code = 0 } + end, + } + elseif cmd[1] == 'uv' and vim.tbl_contains(cmd, 'metadata') then return { wait = function() return { code = 1, stderr = 'network error' } @@ -232,7 +245,19 @@ describe('cp integration', function() it('processes scraper output correctly', function() vim.system = function(cmd) - if vim.tbl_contains(cmd, 'metadata') then + if cmd[1] == 'ping' then + return { + wait = function() + return { code = 0 } + end, + } + elseif cmd[1] == 'uv' and cmd[2] == 'sync' then + return { + wait = function() + return { code = 0 } + end, + } + elseif vim.tbl_contains(cmd, 'metadata') then return { wait = function() return { @@ -339,7 +364,19 @@ describe('cp integration', function() it('recovers from interrupted operations', function() vim.system = function(cmd) - if vim.tbl_contains(cmd, 'metadata') then + if cmd[1] == 'ping' then + return { + wait = function() + return { code = 0 } + end, + } + elseif cmd[1] == 'uv' and cmd[2] == 'sync' then + return { + wait = function() + return { code = 0 } + end, + } + elseif vim.tbl_contains(cmd, 'metadata') then return { wait = function() return { code = 1, stderr = 'interrupted' } @@ -394,7 +431,19 @@ describe('cp integration', function() it('maintains system stability on errors', function() vim.system = function(cmd) - if vim.tbl_contains(cmd, 'metadata') then + if cmd[1] == 'ping' then + return { + wait = function() + return { code = 0 } + end, + } + elseif cmd[1] == 'uv' and cmd[2] == 'sync' then + return { + wait = function() + return { code = 0 } + end, + } + elseif vim.tbl_contains(cmd, 'metadata') then return { wait = function() return { code = 1, stderr = 'scraper failed' } diff --git a/spec/test_panel_spec.lua b/spec/test_panel_spec.lua index d0deb17..802e44d 100644 --- a/spec/test_panel_spec.lua +++ b/spec/test_panel_spec.lua @@ -154,7 +154,11 @@ describe('cp test panel', function() }, }) - vim.cmd('silent! %bwipeout!') + vim.cmd = function(cmd_str) + if cmd_str:match('silent! %%bwipeout!') then + return + end + end end) after_each(function() @@ -163,7 +167,11 @@ describe('cp test panel', function() package.loaded['cp.test'] = nil package.loaded['cp.problem'] = nil package.loaded['cp.execute'] = nil - vim.cmd('silent! %bwipeout!') + vim.cmd = function(cmd_str) + if cmd_str:match('silent! %%bwipeout!') then + return + end + end end) describe('panel creation', function()