fix(test): use new st8 mgmt

This commit is contained in:
Barrett Ruth 2025-09-23 15:05:51 -04:00
parent 75994c07a5
commit a08ad8e2ee
3 changed files with 21 additions and 18 deletions

View file

@ -476,13 +476,13 @@ describe('cp command parsing', function()
if num_args == 2 then if num_args == 2 then
local candidates = {} local candidates = {}
local cp_mod = require('cp') local state = require('cp.state')
local context = cp_mod.get_current_context() if state.get_platform() and state.get_contest_id() then
if context.platform and context.contest_id then
vim.list_extend(candidates, actions) vim.list_extend(candidates, actions)
local cache = require('cp.cache') local cache = require('cp.cache')
cache.load() cache.load()
local contest_data = cache.get_contest_data(context.platform, context.contest_id) local contest_data =
cache.get_contest_data(state.get_platform(), state.get_contest_id())
if contest_data and contest_data.problems then if contest_data and contest_data.problems then
for _, problem in ipairs(contest_data.problems) do for _, problem in ipairs(contest_data.problems) do
table.insert(candidates, problem.id) table.insert(candidates, problem.id)
@ -525,9 +525,12 @@ describe('cp command parsing', function()
return {} return {}
end end
package.loaded['cp'] = { package.loaded['cp.state'] = {
get_current_context = function() get_platform = function()
return { platform = nil, contest_id = nil } return nil
end,
get_contest_id = function()
return nil
end, end,
} }
@ -596,9 +599,12 @@ describe('cp command parsing', function()
end) end)
it('completes all actions and problems when contest context exists', function() it('completes all actions and problems when contest context exists', function()
package.loaded['cp'] = { package.loaded['cp.state'] = {
get_current_context = function() get_platform = function()
return { platform = 'atcoder', contest_id = 'abc350' } return 'atcoder'
end,
get_contest_id = function()
return 'abc350'
end, end,
} }
package.loaded['cp.cache'] = { package.loaded['cp.cache'] = {

View file

@ -118,7 +118,7 @@ describe('Error boundary handling', function()
after_each(function() after_each(function()
package.loaded['cp.log'] = nil package.loaded['cp.log'] = nil
package.loaded['cp.scrape'] = nil package.loaded['cp.scraper'] = nil
if state then if state then
state.reset() state.reset()
end end
@ -127,7 +127,6 @@ describe('Error boundary handling', function()
it('should handle scraping failures without state corruption', function() it('should handle scraping failures without state corruption', function()
cp.handle_command({ fargs = { 'codeforces', 'fail_scrape', 'a' } }) cp.handle_command({ fargs = { 'codeforces', 'fail_scrape', 'a' } })
-- Wait for async callback to complete
vim.wait(100) vim.wait(100)
local has_metadata_error = false local has_metadata_error = false
@ -139,8 +138,7 @@ describe('Error boundary handling', function()
end end
assert.is_true(has_metadata_error, 'Should log contest metadata failure') assert.is_true(has_metadata_error, 'Should log contest metadata failure')
local context = cp.get_current_context() assert.equals('codeforces', state.get_platform())
assert.equals('codeforces', context.platform)
assert.has_no_errors(function() assert.has_no_errors(function()
cp.handle_command({ fargs = { 'run' } }) cp.handle_command({ fargs = { 'run' } })

View file

@ -51,10 +51,9 @@ describe('Panel integration', function()
it('should handle run command with properly set contest context', function() it('should handle run command with properly set contest context', function()
cp.handle_command({ fargs = { 'codeforces', '2146', 'b' } }) cp.handle_command({ fargs = { 'codeforces', '2146', 'b' } })
local context = cp.get_current_context() assert.equals('codeforces', state.get_platform())
assert.equals('codeforces', context.platform) assert.equals('2146', state.get_contest_id())
assert.equals('2146', context.contest_id) assert.equals('b', state.get_problem_id())
assert.equals('b', context.problem_id)
assert.has_no_errors(function() assert.has_no_errors(function()
cp.handle_command({ fargs = { 'run' } }) cp.handle_command({ fargs = { 'run' } })