Something went wrong. Try again.
A neovim plugin for OpenCode
Something went wrong. Try again.
2.7 kB · 78 lines
Lua
at master
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879local current = "ses_old"local created = 0local prompted = 0local inheritedlocal renderedlocal switched
package.loaded["brokencode.client"] = { sessions = function(_, callback) callback(nil, { { id = "ses_tui", model = { providerID = "test", id = "working" } }, }) end, create = function(_, model, callback) created = created + 1 inherited = model callback(nil, { id = created == 1 and "ses_new" or "ses_clear" }) end, prompt = function(session_id, _, callback) prompted = prompted + 1 if session_id == "ses_old" then callback("Session not found: ses_old") return end callback(nil) end, active = function(callback) callback(nil, {}) end, models = function(_, callback) callback(nil, { { providerID = "test", id = "new", name = "New", variants = { { id = "fast" } } }, }) end, switch_model = function(_, model, callback) switched = model callback(nil) end,}package.loaded["brokencode.state"] = { get = function() return current end, set = function(_, value) current = value end, clear = function() current = nil end,}package.loaded["brokencode.ui"] = { refresh = function() end, input = function() end, set_running = function() end, render = function(messages, session_id) rendered = { messages = messages, session_id = session_id } end,}package.loaded["brokencode.bridge"] = { start = function() end }package.loaded["brokencode.picker"] = { select = function(available, callback) callback(available[1]) end,}
local brokencode = require("brokencode")brokencode.send("hello")
assert(created == 1, "a replacement session was not created")assert(prompted == 2, "the prompt was not retried once")assert(current == "ses_new", "the replacement session was not saved")assert(inherited and inherited.id == "working", "the recent model was not inherited")
brokencode.setup()vim.cmd("BrokencodeClear")
assert(created == 2, "BrokencodeClear did not create a session")assert(current == "ses_clear", "BrokencodeClear did not save the new session")assert(rendered and rendered.session_id == "ses_clear", "BrokencodeClear did not select the new session")assert(vim.tbl_isempty(rendered.messages), "BrokencodeClear did not clear the conversation")
vim.cmd("BrokencodeSwitch test/new@fast")assert(switched.id == "new", "BrokencodeSwitch did not select the model")assert(switched.providerID == "test", "BrokencodeSwitch lost the provider")assert(switched.variant == "fast", "BrokencodeSwitch lost the variant")
switched = nilvim.cmd("BrokencodeSwitch")assert(switched and switched.id == "new", "BrokencodeSwitch did not use the picker")assert(switched.variant == nil, "the picker retained an old variant")