Skip to content

Commit da348f7

Browse files
committed
test(core): add test for persisting options when sending a message
1 parent 57a6277 commit da348f7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/unit/core_spec.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local ui = require('opencode.ui.ui')
55
local session = require('opencode.session')
66
local Promise = require('opencode.promise')
77
local stub = require('luassert.stub')
8+
local assert = require('luassert')
89

910
-- Provide a mock api_client for tests that need it
1011
local function mock_api_client()
@@ -236,6 +237,28 @@ describe('opencode.core', function()
236237
assert.equal('sess-new', new.id)
237238
state.api_client.create_session = orig_session
238239
end)
240+
241+
it('persist options in state when sending message', function()
242+
local orig = state.api_client.create_message
243+
state.windows = { mock = 'windows' }
244+
state.active_session = { id = 'sess1' }
245+
246+
state.api_client.create_message = function(_, sid, params)
247+
create_called = true
248+
assert.equal('sess1', sid)
249+
assert.truthy(params.parts)
250+
return Promise.new():resolve({ id = 'm1' })
251+
end
252+
253+
core.send_message(
254+
'hello world',
255+
{ context = { current_file = { enabled = false } }, agent = 'plan', model = 'test/model' }
256+
)
257+
assert.same(state.current_context_config, { current_file = { enabled = false } })
258+
assert.equal(state.current_mode, 'plan')
259+
assert.equal(state.current_model, 'test/model')
260+
state.api_client.create_message = orig
261+
end)
239262
end)
240263

241264
describe('opencode_ok (version checks)', function()

0 commit comments

Comments
 (0)