Skip to content

Commit 50b5c90

Browse files
committed
fix tests
1 parent 4f223a6 commit 50b5c90

File tree

2 files changed

+91
-92
lines changed

2 files changed

+91
-92
lines changed

tests/test_select_commands.lua

Lines changed: 22 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ local T = MiniTest.new_set({
99
child.lua([[
1010
-- Setup commands
1111
require('eca.commands').setup()
12-
12+
1313
-- Instantiate state singleton
1414
_G.State = require('eca.state').new()
15-
15+
1616
-- Mock vim.ui.select for testing
1717
_G.selected_choice = nil
1818
_G.shown_items = nil
1919
_G.shown_prompt = nil
2020
_G.original_select = vim.ui.select
21-
21+
2222
_G.mock_select = function(choice)
2323
_G.selected_choice = choice
2424
vim.ui.select = function(items, opts, on_choice)
@@ -27,7 +27,7 @@ local T = MiniTest.new_set({
2727
on_choice(choice)
2828
end
2929
end
30-
30+
3131
_G.restore_select = function()
3232
vim.ui.select = _G.original_select
3333
end
@@ -54,14 +54,14 @@ T["EcaChatSelectModel"]["updates state when model selected"] = function()
5454
child.lua([[
5555
_G.State.config.models.list = { "model1", "model2", "model3" }
5656
_G.State.config.models.selected = "model1"
57-
57+
5858
-- Mock vim.ui.select to auto-select model2
5959
_G.mock_select("model2")
6060
]])
61-
61+
6262
-- Execute command
6363
child.cmd("EcaChatSelectModel")
64-
64+
6565
-- Check that state was updated
6666
eq(child.lua_get("_G.State.config.models.selected"), "model2")
6767
end
@@ -71,14 +71,14 @@ T["EcaChatSelectModel"]["handles nil selection"] = function()
7171
child.lua([[
7272
_G.State.config.models.list = { "model1", "model2" }
7373
_G.State.config.models.selected = "model1"
74-
74+
7575
-- Mock vim.ui.select to return nil (user cancelled)
7676
_G.mock_select(nil)
7777
]])
78-
78+
7979
-- Execute command
8080
child.cmd("EcaChatSelectModel")
81-
81+
8282
-- Check that state was NOT updated (still model1)
8383
eq(child.lua_get("_G.State.config.models.selected"), "model1")
8484
end
@@ -87,14 +87,14 @@ T["EcaChatSelectModel"]["displays all available models"] = function()
8787
-- Setup models list
8888
child.lua([[
8989
_G.State.config.models.list = { "gpt-4", "gpt-3.5-turbo", "claude-3" }
90-
90+
9191
-- Mock vim.ui.select to capture the items shown
9292
_G.mock_select(nil)
9393
]])
94-
94+
9595
-- Execute command
9696
child.cmd("EcaChatSelectModel")
97-
97+
9898
-- Verify all models were shown
9999
local shown_items = child.lua_get("_G.shown_items")
100100
eq(shown_items[1], "gpt-4")
@@ -116,14 +116,14 @@ T["EcaChatSelectBehavior"]["updates state when behavior selected"] = function()
116116
child.lua([[
117117
_G.State.config.behaviors.list = { "helpful", "creative", "concise" }
118118
_G.State.config.behaviors.selected = "helpful"
119-
119+
120120
-- Mock vim.ui.select to auto-select creative
121121
_G.mock_select("creative")
122122
]])
123-
123+
124124
-- Execute command
125125
child.cmd("EcaChatSelectBehavior")
126-
126+
127127
-- Check that state was updated
128128
eq(child.lua_get("_G.State.config.behaviors.selected"), "creative")
129129
end
@@ -133,14 +133,14 @@ T["EcaChatSelectBehavior"]["handles nil selection"] = function()
133133
child.lua([[
134134
_G.State.config.behaviors.list = { "helpful", "creative" }
135135
_G.State.config.behaviors.selected = "helpful"
136-
136+
137137
-- Mock vim.ui.select to return nil (user cancelled)
138138
_G.mock_select(nil)
139139
]])
140-
140+
141141
-- Execute command
142142
child.cmd("EcaChatSelectBehavior")
143-
143+
144144
-- Check that state was NOT updated (still helpful)
145145
eq(child.lua_get("_G.State.config.behaviors.selected"), "helpful")
146146
end
@@ -149,14 +149,14 @@ T["EcaChatSelectBehavior"]["displays all available behaviors"] = function()
149149
-- Setup behaviors list
150150
child.lua([[
151151
_G.State.config.behaviors.list = { "helpful", "creative", "concise", "technical" }
152-
152+
153153
-- Mock vim.ui.select to capture the items shown
154154
_G.mock_select(nil)
155155
]])
156-
156+
157157
-- Execute command
158158
child.cmd("EcaChatSelectBehavior")
159-
159+
160160
-- Verify all behaviors were shown
161161
local shown_items = child.lua_get("_G.shown_items")
162162
eq(shown_items[1], "helpful")
@@ -165,73 +165,4 @@ T["EcaChatSelectBehavior"]["displays all available behaviors"] = function()
165165
eq(shown_items[4], "technical")
166166
end
167167

168-
-- Test State update methods
169-
T["State"] = MiniTest.new_set()
170-
171-
T["State"]["update_selected_model updates config"] = function()
172-
child.lua([[
173-
_G.State.config.models.list = { "model1", "model2" }
174-
_G.State.config.models.selected = "model1"
175-
176-
_G.State:update_selected_model("model2")
177-
]])
178-
179-
eq(child.lua_get("_G.State.config.models.selected"), "model2")
180-
end
181-
182-
T["State"]["update_selected_model handles nil"] = function()
183-
child.lua([[
184-
_G.State.config.models.selected = "model1"
185-
186-
-- Should not update if nil is passed
187-
_G.State:update_selected_model(nil)
188-
]])
189-
190-
eq(child.lua_get("_G.State.config.models.selected"), "model1")
191-
end
192-
193-
T["State"]["update_selected_model handles non-string"] = function()
194-
child.lua([[
195-
_G.State.config.models.selected = "model1"
196-
197-
-- Should not update if non-string is passed
198-
_G.State:update_selected_model(123)
199-
]])
200-
201-
eq(child.lua_get("_G.State.config.models.selected"), "model1")
202-
end
203-
204-
T["State"]["update_selected_behavior updates config"] = function()
205-
child.lua([[
206-
_G.State.config.behaviors.list = { "helpful", "creative" }
207-
_G.State.config.behaviors.selected = "helpful"
208-
209-
_G.State:update_selected_behavior("creative")
210-
]])
211-
212-
eq(child.lua_get("_G.State.config.behaviors.selected"), "creative")
213-
end
214-
215-
T["State"]["update_selected_behavior handles nil"] = function()
216-
child.lua([[
217-
_G.State.config.behaviors.selected = "helpful"
218-
219-
-- Should not update if nil is passed
220-
_G.State:update_selected_behavior(nil)
221-
]])
222-
223-
eq(child.lua_get("_G.State.config.behaviors.selected"), "helpful")
224-
end
225-
226-
T["State"]["update_selected_behavior handles non-string"] = function()
227-
child.lua([[
228-
_G.State.config.behaviors.selected = "helpful"
229-
230-
-- Should not update if non-string is passed
231-
_G.State:update_selected_behavior(123)
232-
]])
233-
234-
eq(child.lua_get("_G.State.config.behaviors.selected"), "helpful")
235-
end
236-
237168
return T

tests/test_state.lua

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ T["updates via observer notifications"]["updates usage on usage content"] = func
9797
method = 'chat/contentReceived',
9898
params = { content = {
9999
type = 'usage',
100-
limit = { output = 1024 },
100+
limit = { context = 1024 },
101101
sessionTokens = 256,
102102
lastMessageCost = '0.42',
103103
sessionCost = '3.14',
@@ -184,4 +184,72 @@ T["updates via observer notifications"]["updates tools on tool/serverUpdated"] =
184184
eq(#updates >= 1, true)
185185
end
186186

187+
T["update selected model and behavior"] = MiniTest.new_set()
188+
189+
T["update selected model and behavior"]["update_selected_model updates config"] = function()
190+
child.lua([[
191+
_G.State.config.models.list = { "model1", "model2" }
192+
_G.State.config.models.selected = "model1"
193+
194+
_G.State:update_selected_model("model2")
195+
]])
196+
197+
eq(child.lua_get("_G.State.config.models.selected"), "model2")
198+
end
199+
200+
T["update selected model and behavior"]["update_selected_model handles nil"] = function()
201+
child.lua([[
202+
_G.State.config.models.selected = "model1"
203+
204+
-- Should not update if nil is passed
205+
_G.State:update_selected_model(nil)
206+
]])
207+
208+
eq(child.lua_get("_G.State.config.models.selected"), "model1")
209+
end
210+
211+
T["update selected model and behavior"]["update_selected_model handles non-string"] = function()
212+
child.lua([[
213+
_G.State.config.models.selected = "model1"
214+
215+
-- Should not update if non-string is passed
216+
_G.State:update_selected_model(123)
217+
]])
218+
219+
eq(child.lua_get("_G.State.config.models.selected"), "model1")
220+
end
221+
222+
T["update selected model and behavior"]["update_selected_behavior updates config"] = function()
223+
child.lua([[
224+
_G.State.config.behaviors.list = { "helpful", "creative" }
225+
_G.State.config.behaviors.selected = "helpful"
226+
227+
_G.State:update_selected_behavior("creative")
228+
]])
229+
230+
eq(child.lua_get("_G.State.config.behaviors.selected"), "creative")
231+
end
232+
233+
T["update selected model and behavior"]["update_selected_behavior handles nil"] = function()
234+
child.lua([[
235+
_G.State.config.behaviors.selected = "helpful"
236+
237+
-- Should not update if nil is passed
238+
_G.State:update_selected_behavior(nil)
239+
]])
240+
241+
eq(child.lua_get("_G.State.config.behaviors.selected"), "helpful")
242+
end
243+
244+
T["update selected model and behavior"]["update_selected_behavior handles non-string"] = function()
245+
child.lua([[
246+
_G.State.config.behaviors.selected = "helpful"
247+
248+
-- Should not update if non-string is passed
249+
_G.State:update_selected_behavior(123)
250+
]])
251+
252+
eq(child.lua_get("_G.State.config.behaviors.selected"), "helpful")
253+
end
254+
187255
return T

0 commit comments

Comments
 (0)