Skip to content

Commit 5a2a28e

Browse files
guillaumeboehmsudo-tee
authored andcommitted
test(api): Add current_model api tests
1 parent 9626f89 commit 5a2a28e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/unit/api_spec.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,35 @@ describe('opencode.api', function()
487487
config_file.get_user_commands = original_get_user_commands
488488
end)
489489
end)
490+
491+
describe('current_model', function()
492+
it('returns the current model from state', function()
493+
local original_model = state.current_model
494+
state.current_model = 'testmodel'
495+
496+
local model = api.current_model()
497+
assert.equal('testmodel', model)
498+
499+
state.current_model = original_model
500+
end)
501+
502+
it('falls back to config file model when state.current_model is nil', function()
503+
local original_model = state.current_model
504+
state.current_model = nil
505+
506+
local config_file = require('opencode.config_file')
507+
local original_get_opencode_config = config_file.get_opencode_config
508+
509+
config_file.get_opencode_config = function()
510+
return { model = 'testmodel' }
511+
end
512+
513+
local model = api.current_model()
514+
515+
assert.equal('testmodel', model)
516+
517+
config_file.get_opencode_config = original_get_opencode_config
518+
state.current_model = original_model
519+
end)
520+
end)
490521
end)

0 commit comments

Comments
 (0)