feat: async scraper

This commit is contained in:
Barrett Ruth 2025-09-22 22:59:57 -04:00
parent 53562eb6a8
commit a32fd396d3
12 changed files with 1527 additions and 474 deletions

View file

@ -103,6 +103,61 @@ function M.mock_scraper_success()
}
end
function M.mock_async_scraper_success()
package.loaded['cp.async.scraper'] = {
scrape_contest_metadata_async = function(platform, contest_id, callback)
vim.schedule(function()
callback({
success = true,
problems = {
{ id = 'a' },
{ id = 'b' },
{ id = 'c' },
},
})
end)
end,
scrape_problem_async = function(platform, contest_id, problem_id, callback)
vim.schedule(function()
callback({
success = true,
problem_id = problem_id,
test_cases = {
{ input = '1 2', expected = '3' },
{ input = '3 4', expected = '7' },
},
test_count = 2,
timeout_ms = 2000,
memory_mb = 256.0,
url = 'https://example.com',
})
end)
end,
}
end
function M.mock_async_scraper_failure()
package.loaded['cp.async.scraper'] = {
scrape_contest_metadata_async = function(platform, contest_id, callback)
vim.schedule(function()
callback({
success = false,
error = 'mock network error',
})
end)
end,
scrape_problem_async = function(platform, contest_id, problem_id, callback)
vim.schedule(function()
callback({
success = false,
problem_id = problem_id,
error = 'mock scraping failed',
})
end)
end,
}
end
function M.has_error_logged()
for _, log_entry in ipairs(M.logged_messages) do
if log_entry.level == vim.log.levels.ERROR then
@ -135,6 +190,10 @@ end
function M.teardown()
package.loaded['cp.log'] = nil
package.loaded['cp.scrape'] = nil
package.loaded['cp.async.scraper'] = nil
package.loaded['cp.async.jobs'] = nil
package.loaded['cp.async.setup'] = nil
package.loaded['cp.async'] = nil
M.logged_messages = {}
end