Skip to content

Commit e6e8d14

Browse files
committed
rename context area test and add one more use case
1 parent d06e18a commit e6e8d14

1 file changed

Lines changed: 62 additions & 9 deletions

File tree

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ local function flush(ms)
9595
child.api.nvim_eval("1")
9696
end
9797

98-
T["contexts area"] = MiniTest.new_set()
98+
T["context area"] = MiniTest.new_set()
9999

100-
T["contexts area"]["deletes all lines"] = function()
100+
T["context area"]["deletes all lines"] = function()
101101
flush()
102102

103103
local initial = child.lua_get("_G.get_state()")
@@ -118,7 +118,7 @@ T["contexts area"]["deletes all lines"] = function()
118118
eq(result.contexts, {})
119119
end
120120

121-
T["contexts area"]["deletes the contexts line"] = function()
121+
T["context area"]["deletes the contexts line"] = function()
122122
flush()
123123

124124
local initial = child.lua_get("_G.get_state()")
@@ -139,7 +139,7 @@ T["contexts area"]["deletes the contexts line"] = function()
139139
eq(result.contexts, {})
140140
end
141141

142-
T["contexts area"]["deletes the input line"] = function()
142+
T["context area"]["deletes the input line"] = function()
143143
flush()
144144

145145
local initial = child.lua_get("_G.get_state()")
@@ -160,7 +160,7 @@ T["contexts area"]["deletes the input line"] = function()
160160
eq(result.contexts, {})
161161
end
162162

163-
T["contexts area"]["keep input text when deleting contexts line"] = function()
163+
T["context area"]["keep input text when deleting contexts line"] = function()
164164
flush()
165165

166166
local input_text = "text*in<>the > input#preFIX 123456 lIne"
@@ -188,7 +188,7 @@ T["contexts area"]["keep input text when deleting contexts line"] = function()
188188
eq(result.contexts, {})
189189
end
190190

191-
T["contexts area"]["keep multiple lines text input when removing the first context"] = function()
191+
T["context area"]["keep multiple lines text input when removing the first context"] = function()
192192
flush()
193193

194194
local input_text_first_line = "text*in<>the > input#preFIX 123456 lIne"
@@ -227,7 +227,7 @@ T["contexts area"]["keep multiple lines text input when removing the first conte
227227
eq(result.contexts, {})
228228
end
229229

230-
T["contexts area"]["remove all contexts when deleting the contexts line"] = function()
230+
T["context area"]["remove all contexts when deleting the contexts line"] = function()
231231
flush()
232232

233233
local input_text_first_line = "text*in<>the > input#preFIX 123456 lIne"
@@ -263,7 +263,7 @@ T["contexts area"]["remove all contexts when deleting the contexts line"] = func
263263
eq(result.contexts, {})
264264
end
265265

266-
T["contexts area"]["remove one specific context when multiple contexts are present"] = function()
266+
T["context area"]["remove one specific context when multiple contexts are present"] = function()
267267
flush()
268268

269269
local input_text_first_line = "text*in<>the > input#preFIX 123456 lIne"
@@ -303,7 +303,7 @@ T["contexts area"]["remove one specific context when multiple contexts are prese
303303
eq(result.contexts, { "sidebar.lua ", "server.lua " })
304304
end
305305

306-
T["contexts area"]["remove contexts one by one in an arbitrary order while preserving input"] = function()
306+
T["context area"]["remove contexts one by one in an arbitrary order while preserving input"] = function()
307307
flush()
308308

309309
local input_text_first_line = "text*in<>the > input#preFIX 123456 lIne"
@@ -384,4 +384,57 @@ T["contexts area"]["remove contexts one by one in an arbitrary order while prese
384384
eq(result_4.contexts, {})
385385
end
386386

387+
T["context area"]["displays filename in context area and expands path in sent message"] = function()
388+
flush()
389+
390+
local rel_path = "lua/eca/sidebar.lua"
391+
local abs_path = child.lua_get("vim.fn.fnamemodify(..., ':p')", { rel_path })
392+
local tail = child.lua_get("vim.fn.fnamemodify(..., ':t')", { rel_path }) .. " "
393+
394+
-- Add a context with relative path; context area should show only the
395+
-- filename (tail), not the full path.
396+
child.lua([[_G.add_contexts({
397+
{ type = 'file', data = { path = 'lua/eca/sidebar.lua' } },
398+
})]])
399+
400+
flush()
401+
402+
local state = child.lua_get("_G.get_state()")
403+
404+
-- Contexts in the area should use the tail of the path
405+
eq(state.contexts, { tail })
406+
407+
-- Mock server on mediator so we don't start a real process. Capture
408+
-- the last request instead of sending anything.
409+
child.lua([[
410+
_G.last_request = nil
411+
_G.Mediator.server = {
412+
is_running = function()
413+
return true
414+
end,
415+
send_request = function(_, method, params, callback)
416+
_G.last_request = { method = method, params = params }
417+
if callback then
418+
callback(nil, {})
419+
end
420+
end,
421+
}
422+
]])
423+
424+
-- Send a message that references the same relative path using the
425+
-- @path shorthand. Sidebar should expand it to an absolute path
426+
-- before sending to the (mocked) server.
427+
child.lua("_G.Sidebar:_send_message('please check @' .. '" .. rel_path .. "')")
428+
429+
local req = child.lua_get("_G.last_request")
430+
eq(req.method, "chat/prompt")
431+
432+
local msg = req.params.message
433+
local expected = "please check @" .. abs_path
434+
435+
-- Message sent to the server must contain the absolute path and no
436+
-- longer contain the original relative path.
437+
eq(msg, expected)
438+
end
439+
387440
return T

0 commit comments

Comments
 (0)