Skip to content

Commit 895b674

Browse files
committed
make server test integration more reasonable
1 parent 46e331a commit 895b674

File tree

3 files changed

+25
-75
lines changed

3 files changed

+25
-75
lines changed

lua/eca/server.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function M:start(opts)
110110
nvim_exe = "nvim"
111111
end
112112

113-
local lua_cmd = string.format("lua ServerPath.run(%s)", Config.server_path or "")
113+
local lua_cmd = string.format("lua ServerPath.run(%s)", Utils.lua_quote(Config.options.server_path) or "")
114114

115115
local cmd = { nvim_exe, "--headless", "--noplugin", "-u", script_path, "-c", lua_cmd }
116116

lua/eca/utils.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,11 @@ function M.constants()
118118
return CONSTANTS
119119
end
120120

121+
---@param str string
122+
---@return string
123+
function M.lua_quote(str)
124+
-- Escape backslashes and double quotes for Lua string literal
125+
return '"' .. tostring(str):gsub('\\', '\\\\'):gsub('"', '\\"') .. '"'
126+
end
127+
121128
return M

tests/test_server_integration.lua

Lines changed: 17 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,13 @@ local function setup_test_environment()
1313
table.insert(_G.notifications, { message = message, level = level, opts = opts })
1414
end
1515
_G.server = require("eca.server").new()
16-
1716
end
1817

1918
local T = MiniTest.new_set({
2019
hooks = {
2120
pre_case = function()
2221
child.restart({ "-u", "scripts/minimal_init.lua" })
2322
child.lua_func(setup_test_environment)
24-
child.lua([[
25-
package.preload["eca.path_finder"] = function()
26-
local M = {}
27-
28-
function M.new()
29-
return setmetatable({}, { __index = M })
30-
end
31-
32-
function M.find(arg)
33-
return ":" -- do nothing
34-
end
35-
36-
return M
37-
end
38-
]])
3923
end,
4024
post_case = function()
4125
child.lua("if _G.server and _G.server.process then _G.server.process:kill() end")
@@ -54,70 +38,29 @@ local function sleep(ms)
5438
end
5539

5640
T["server"] = MiniTest.new_set()
41+
5742
T["server"]["start"] = function()
58-
child.lua("_G.server.start()")
59-
eq(child.lua_get("_G.server.process"), vim.NIL)
60-
child.lua([[
61-
_G.server:start()
62-
_G.server_started = vim.wait(5000, function()
43+
child.lua("_G.server:start()")
44+
child.lua([[
45+
_G.server_started = vim.wait(10000, function()
6346
return _G.server and _G.server:is_running()
64-
end, 50)
47+
end, 100)
6548
]])
6649
eq(child.lua_get("_G.server_started"), true)
50+
sleep(1000)
51+
eq(child.lua_get("_G.server.initialized"), true)
6752
end
6853

69-
T["server"]["initialize"] = function()
70-
local test_cases = {
71-
{
72-
method = "initialize",
73-
want = {
74-
chatBehaviors = { "agent", "plan" },
75-
chatDefaultBehavior = "agent",
76-
chatDefaultModel = "anthropic/claude-sonnet-4-20250514",
77-
chatWelcomeMessage = "Welcome to ECA!\n\nType '/' for commands\n\n",
78-
models = {
79-
"anthropic/claude-3-5-haiku-20241022",
80-
"anthropic/claude-opus-4-1-20250805",
81-
"anthropic/claude-opus-4-20250514",
82-
"anthropic/claude-sonnet-4-20250514",
83-
"github-copilot/claude-sonnet-4",
84-
"github-copilot/gpt-4.1",
85-
"github-copilot/gpt-5",
86-
"github-copilot/gpt-5-mini",
87-
"openai/gpt-4.1",
88-
"openai/gpt-5",
89-
"openai/gpt-5-mini",
90-
"openai/gpt-5-nano",
91-
"openai/o3",
92-
"openai/o4-mini",
93-
},
94-
},
95-
},
96-
{ method = "not a command", want = vim.NIL },
97-
}
98-
for i, test_case in ipairs(test_cases) do
99-
if i == 1 then
100-
test_case = test_cases[i + 1]
101-
end
102-
child.lua("_G.method = " .. vim.inspect(test_case.method))
103-
child.lua("_G.server:start({initialize = false})")
104-
-- Wait for async server start
105-
child.lua([[
106-
_G.server_started = vim.wait(5000, function()
107-
return _G.server and _G.server:is_running()
108-
end, 50)
109-
]])
110-
eq(child.lua_get("_G.server_started"), true)
111-
112-
child.lua_func(function()
113-
_G.server:send_request(_G.method, {}, function(err, result)
114-
_G.err = err
115-
_G.result = result
116-
end)
117-
end)
118-
sleep(1500)
119-
eq(child.lua_get("_G.result"), test_case.want)
120-
end
54+
T["server"]["start without initialize"] = function()
55+
child.lua("_G.server:start({ initialize = false })")
56+
child.lua([[
57+
_G.server_started = vim.wait(10000, function()
58+
return _G.server and _G.server:is_running()
59+
end, 100)
60+
]])
61+
eq(child.lua_get("_G.server_started"), true)
62+
sleep(1000)
63+
eq(child.lua_get("_G.server.initialized"), false)
12164
end
12265

12366
return T

0 commit comments

Comments
 (0)