-
-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathtest_queue_async.lua
More file actions
109 lines (94 loc) · 2.47 KB
/
test_queue_async.lua
File metadata and controls
109 lines (94 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
local h = require("tests.helpers")
local new_set = MiniTest.new_set
local child = MiniTest.new_child_neovim()
T = new_set({
hooks = {
pre_case = function()
h.child_start(child)
-- Load helpers and set up the environment in the child process
child.lua([[
--require("tests.log")
h = require('tests.helpers')
chat, tools = h.setup_chat_buffer()
-- Reset test globals
_G._test_func = nil
_G._test_exit = nil
_G._test_order = nil
_G._test_output = nil
_G._test_setup = nil
]])
end,
post_case = function()
child.lua([[h.teardown_chat_buffer()]])
end,
post_once = child.stop,
},
})
T["Tools"] = new_set()
T["Tools"]["queue"] = new_set()
T["Tools"]["queue"]["can queue multiple async functions"] = function()
h.eq(vim.NIL, child.lua_get([[_G._test_order]]))
child.lua([[
local tool_call = {
{
["function"] = {
arguments = { data = "Data 1" },
name = "func_async_1",
},
},
{
["function"] = {
name = "cmd_queue",
},
},
{
["function"] = {
arguments = { data = "Data 2" },
name = "func_async_2",
},
},
}
tools:execute(chat, tool_call)
while (chat.tool_orchestrator) do
vim.wait(100)
end
]])
-- Test order
h.eq(
"AsyncFunc[Setup]->AsyncFunc[Success]->AsyncFunc[Exit]->Cmd[Setup]->Cmd[Success]->Cmd[Exit]->AsyncFunc2[Setup]->AsyncFunc2[Success]->AsyncFunc2[Exit]",
child.lua_get([[_G._test_order]])
)
-- Test that the function was called
h.eq("Data 1 Data 2", child.lua_get([[_G._test_func]]))
end
T["Tools"]["queue"]["can queue async function with sync function"] = function()
h.eq(vim.NIL, child.lua_get([[_G._test_order]]))
child.lua([[
local tool_call = {
{
["function"] = {
arguments = { data = "Data 1" },
name = "func_queue",
},
},
{
["function"] = {
arguments = { data = "Data 2" },
name = "func_async_2",
},
},
}
tools:execute(chat, tool_call)
while (chat.tool_orchestrator) do
vim.wait(100)
end
]])
-- Test order
h.eq(
"Func[Setup]->Func[Success]->Func[Exit]->AsyncFunc2[Setup]->AsyncFunc2[Success]->AsyncFunc2[Exit]",
child.lua_get([[_G._test_order]])
)
-- Test that the function was called
h.eq("Data 1 Data 2", child.lua_get([[_G._test_func]]))
end
return T