Skip to content

Commit a419790

Browse files
ssjolearyclaude
andcommitted
fix(tests): filter nvim_get_commands output server-side
On nvim 0.12+, nvim_get_commands returns function-valued callbacks that can't cross MiniTest's msgpack boundary. Extract only the name via a small helper in each affected file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d629ff5 commit a419790

3 files changed

Lines changed: 44 additions & 42 deletions

File tree

tests/test_chat_clear.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ local function flush(ms)
77
child.api.nvim_eval("1")
88
end
99

10+
-- Returns the registered command's name, or nil if not registered. Filters
11+
-- server-side so the function-valued `callback` field (present on 0.12+)
12+
-- does not cross the MiniTest msgpack boundary.
13+
local function cmd_registered_name(name)
14+
return child.lua_get(string.format(
15+
"(vim.api.nvim_get_commands({})[%q] or {}).name",
16+
name
17+
))
18+
end
19+
1020
local function setup_helpers()
1121
_G.fill_chat = function()
1222
local sidebar = require("eca").get()
@@ -82,9 +92,7 @@ T["EcaChatClear"] = MiniTest.new_set()
8292

8393
T["EcaChatClear"]["command is registered"] = function()
8494
setup_env(false)
85-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
86-
eq(type(commands.EcaChatClear), "table")
87-
eq(commands.EcaChatClear.name, "EcaChatClear")
95+
eq(cmd_registered_name("EcaChatClear"), "EcaChatClear")
8896
end
8997

9098
T["EcaChatClear"]["clears chat buffer when sidebar is open"] = function()

tests/test_context_commands.lua

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ local function flush(ms)
77
child.api.nvim_eval("1")
88
end
99

10+
-- Returns the registered command's name, or nil if not registered. Filters
11+
-- server-side so the function-valued `callback` field (present on 0.12+)
12+
-- does not cross the MiniTest msgpack boundary.
13+
local function cmd_registered_name(name)
14+
return child.lua_get(string.format(
15+
"(vim.api.nvim_get_commands({})[%q] or {}).name",
16+
name
17+
))
18+
end
19+
1020
local function setup_test_environment()
1121
child.lua([[
1222
local Eca = require('eca')
@@ -100,9 +110,7 @@ end
100110
T["EcaChatAddFile"] = MiniTest.new_set()
101111

102112
T["EcaChatAddFile"]["command is registered"] = function()
103-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
104-
eq(type(commands.EcaChatAddFile), "table")
105-
eq(commands.EcaChatAddFile.name, "EcaChatAddFile")
113+
eq(cmd_registered_name("EcaChatAddFile"), "EcaChatAddFile")
106114
end
107115

108116
T["EcaChatAddFile"]["adds current file as context when no args"] = function()
@@ -140,9 +148,7 @@ end
140148
T["EcaAddFile"] = MiniTest.new_set()
141149

142150
T["EcaAddFile"]["command is registered"] = function()
143-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
144-
eq(type(commands.EcaAddFile), "table")
145-
eq(commands.EcaAddFile.name, "EcaAddFile")
151+
eq(cmd_registered_name("EcaAddFile"), "EcaAddFile")
146152
end
147153

148154
T["EcaAddFile"]["shows deprecation notice when called"] = function()
@@ -160,9 +166,7 @@ end
160166
T["EcaChatRemoveFile"] = MiniTest.new_set()
161167

162168
T["EcaChatRemoveFile"]["command is registered"] = function()
163-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
164-
eq(type(commands.EcaChatRemoveFile), "table")
165-
eq(commands.EcaChatRemoveFile.name, "EcaChatRemoveFile")
169+
eq(cmd_registered_name("EcaChatRemoveFile"), "EcaChatRemoveFile")
166170
end
167171

168172
T["EcaChatRemoveFile"]["removes current file context when no args"] = function()
@@ -197,9 +201,7 @@ end
197201
T["EcaRemoveContext"] = MiniTest.new_set()
198202

199203
T["EcaRemoveContext"]["command is registered"] = function()
200-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
201-
eq(type(commands.EcaRemoveContext), "table")
202-
eq(commands.EcaRemoveContext.name, "EcaRemoveContext")
204+
eq(cmd_registered_name("EcaRemoveContext"), "EcaRemoveContext")
203205
end
204206

205207
T["EcaRemoveContext"]["shows deprecation notice when called"] = function()
@@ -215,9 +217,7 @@ end
215217
T["EcaChatAddSelection"] = MiniTest.new_set()
216218

217219
T["EcaChatAddSelection"]["command is registered"] = function()
218-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
219-
eq(type(commands.EcaChatAddSelection), "table")
220-
eq(commands.EcaChatAddSelection.name, "EcaChatAddSelection")
220+
eq(cmd_registered_name("EcaChatAddSelection"), "EcaChatAddSelection")
221221
end
222222

223223
T["EcaChatAddSelection"]["adds a ranged file context based on visual selection"] = function()
@@ -250,9 +250,7 @@ end
250250
T["EcaAddSelection"] = MiniTest.new_set()
251251

252252
T["EcaAddSelection"]["command is registered"] = function()
253-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
254-
eq(type(commands.EcaAddSelection), "table")
255-
eq(commands.EcaAddSelection.name, "EcaAddSelection")
253+
eq(cmd_registered_name("EcaAddSelection"), "EcaAddSelection")
256254
end
257255

258256
T["EcaAddSelection"]["shows deprecation notice when called"] = function()
@@ -268,9 +266,7 @@ end
268266
T["EcaChatAddUrl"] = MiniTest.new_set()
269267

270268
T["EcaChatAddUrl"]["command is registered"] = function()
271-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
272-
eq(type(commands.EcaChatAddUrl), "table")
273-
eq(commands.EcaChatAddUrl.name, "EcaChatAddUrl")
269+
eq(cmd_registered_name("EcaChatAddUrl"), "EcaChatAddUrl")
274270
end
275271

276272
T["EcaChatAddUrl"]["adds web context and truncates name based on config"] = function()
@@ -329,9 +325,7 @@ end
329325
T["EcaChatListContexts"] = MiniTest.new_set()
330326

331327
T["EcaChatListContexts"]["command is registered"] = function()
332-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
333-
eq(type(commands.EcaChatListContexts), "table")
334-
eq(commands.EcaChatListContexts.name, "EcaChatListContexts")
328+
eq(cmd_registered_name("EcaChatListContexts"), "EcaChatListContexts")
335329
end
336330

337331
T["EcaChatListContexts"]["runs without modifying contexts"] = function()
@@ -352,9 +346,7 @@ end
352346
T["EcaListContexts"] = MiniTest.new_set()
353347

354348
T["EcaListContexts"]["command is registered"] = function()
355-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
356-
eq(type(commands.EcaListContexts), "table")
357-
eq(commands.EcaListContexts.name, "EcaListContexts")
349+
eq(cmd_registered_name("EcaListContexts"), "EcaListContexts")
358350
end
359351

360352
T["EcaListContexts"]["shows deprecation notice when called"] = function()
@@ -372,9 +364,7 @@ end
372364
T["EcaChatClearContexts"] = MiniTest.new_set()
373365

374366
T["EcaChatClearContexts"]["command is registered"] = function()
375-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
376-
eq(type(commands.EcaChatClearContexts), "table")
377-
eq(commands.EcaChatClearContexts.name, "EcaChatClearContexts")
367+
eq(cmd_registered_name("EcaChatClearContexts"), "EcaChatClearContexts")
378368
end
379369

380370
T["EcaChatClearContexts"]["clears all contexts"] = function()
@@ -395,9 +385,7 @@ end
395385
T["EcaClearContexts"] = MiniTest.new_set()
396386

397387
T["EcaClearContexts"]["command is registered"] = function()
398-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
399-
eq(type(commands.EcaClearContexts), "table")
400-
eq(commands.EcaClearContexts.name, "EcaClearContexts")
388+
eq(cmd_registered_name("EcaClearContexts"), "EcaClearContexts")
401389
end
402390

403391
T["EcaClearContexts"]["shows deprecation notice when called"] = function()

tests/test_select_commands.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ local MiniTest = require("mini.test")
22
local eq = MiniTest.expect.equality
33
local child = MiniTest.new_child_neovim()
44

5+
-- Returns the registered command's name, or nil if not registered. Filters
6+
-- server-side so the function-valued `callback` field (present on 0.12+)
7+
-- does not cross the MiniTest msgpack boundary.
8+
local function cmd_registered_name(name)
9+
return child.lua_get(string.format(
10+
"(vim.api.nvim_get_commands({})[%q] or {}).name",
11+
name
12+
))
13+
end
14+
515
local function setup_test_environment()
616
-- Setup commands
717
require('eca.commands').setup()
@@ -52,9 +62,7 @@ local T = MiniTest.new_set({
5262
T["EcaChatSelectModel"] = MiniTest.new_set()
5363

5464
T["EcaChatSelectModel"]["command is registered"] = function()
55-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
56-
eq(type(commands.EcaChatSelectModel), "table")
57-
eq(commands.EcaChatSelectModel.name, "EcaChatSelectModel")
65+
eq(cmd_registered_name("EcaChatSelectModel"), "EcaChatSelectModel")
5866
end
5967

6068
T["EcaChatSelectModel"]["updates state when model selected"] = function()
@@ -114,9 +122,7 @@ end
114122
T["EcaChatSelectBehavior"] = MiniTest.new_set()
115123

116124
T["EcaChatSelectBehavior"]["command is registered"] = function()
117-
local commands = child.lua_get("vim.api.nvim_get_commands({})")
118-
eq(type(commands.EcaChatSelectBehavior), "table")
119-
eq(commands.EcaChatSelectBehavior.name, "EcaChatSelectBehavior")
125+
eq(cmd_registered_name("EcaChatSelectBehavior"), "EcaChatSelectBehavior")
120126
end
121127

122128
T["EcaChatSelectBehavior"]["updates state when behavior selected"] = function()

0 commit comments

Comments
 (0)