local current = "ses_old" local created = 0 local prompted = 0 local inherited 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 = "ses_new" }) 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, } require("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")