Something went wrong. Try again.
A neovim plugin for OpenCode
Something went wrong. Try again.
2.0 kB · 56 lines
Lua
at commit 73c91f2a
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657local current = "ses_old"local created = 0local prompted = 0local inheritedlocal rendered
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, switch_model = function(_, _, callback) 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 }
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")