@@ -47,6 +47,21 @@ T["ToolRegistry"][":add"]["adds a group to the registry"] = function()
4747 h .expect_tbl_contains (" cmd" , registry )
4848end
4949
50+ T [" ToolRegistry" ][" :add" ][" renders collapsed tool group without member tools" ] = function ()
51+ child .lua ([[
52+ _G.chat.tool_registry:add("senior_dev")
53+ _G.chat.context:render()
54+ _G.buf_lines = h.get_buf_lines(_G.chat.bufnr)
55+ ]] )
56+
57+ local lines = child .lua_get ([[ _G.buf_lines]] )
58+ local content = table.concat (lines , " \n " )
59+
60+ h .expect_contains (" senior_dev" , content )
61+ h .eq (nil , content :find (" <tool>func</tool>" , 1 , true ))
62+ h .eq (nil , content :find (" <tool>cmd</tool>" , 1 , true ))
63+ end
64+
5065T [" ToolRegistry" ][" :add" ][" renders tool in the chat buffer" ] = function ()
5166 child .lua ([[
5267 _G.chat.tool_registry:add("func")
@@ -60,6 +75,82 @@ T["ToolRegistry"][":add"]["renders tool in the chat buffer"] = function()
6075 h .expect_contains (" func" , content )
6176end
6277
78+ T [" ToolRegistry" ][" :add" ][" hides tool context for ACP chats" ] = function ()
79+ child .lua ([[
80+ _G.chat = h.setup_chat_buffer({}, {
81+ name = "test_acp",
82+ config = {
83+ name = "test_acp",
84+ type = "acp",
85+ roles = { user = "user", assistant = "assistant" },
86+ handlers = {
87+ form_messages = function()
88+ return {}
89+ end,
90+ },
91+ },
92+ })
93+ _G.chat.tool_registry:add("func")
94+ _G.chat.context:render()
95+ _G.buf_lines = h.get_buf_lines(_G.chat.bufnr)
96+ ]] )
97+
98+ local lines = child .lua_get ([[ _G.buf_lines]] )
99+ local content = table.concat (lines , " \n " )
100+
101+ h .expect_tbl_contains (" func" , child .lua_get ([[ _G.chat.tool_registry.in_use]] ))
102+ h .eq (nil , content :find (" func" , 1 , true ))
103+ end
104+
105+ T [" ToolRegistry" ][" :add" ][" hides tool group context for ACP chats" ] = function ()
106+ child .lua ([[
107+ _G.chat = h.setup_chat_buffer({}, {
108+ name = "test_acp",
109+ config = {
110+ name = "test_acp",
111+ type = "acp",
112+ roles = { user = "user", assistant = "assistant" },
113+ handlers = {
114+ form_messages = function()
115+ return {}
116+ end,
117+ },
118+ },
119+ })
120+ _G.chat.tool_registry:add("senior_dev")
121+ _G.chat.context:render()
122+ _G.buf_lines = h.get_buf_lines(_G.chat.bufnr)
123+ ]] )
124+
125+ local lines = child .lua_get ([[ _G.buf_lines]] )
126+ local content = table.concat (lines , " \n " )
127+
128+ h .expect_tbl_contains (" func" , child .lua_get ([[ _G.chat.tool_registry.in_use]] ))
129+ h .expect_tbl_contains (" cmd" , child .lua_get ([[ _G.chat.tool_registry.in_use]] ))
130+ h .eq (nil , content :find (" senior_dev" , 1 , true ))
131+ h .eq (nil , content :find (" func" , 1 , true ))
132+ h .eq (nil , content :find (" cmd" , 1 , true ))
133+ end
134+
135+ T [" ToolRegistry" ][" :add" ][" updates tool context visibility when switching to ACP" ] = function ()
136+ child .lua ([[
137+ _G.chat.tool_registry:add("senior_dev")
138+ _G.http_visible = _G.chat.context_items[1].opts.visible
139+
140+ _G.chat.adapter = { name = "test_acp", type = "acp" }
141+ _G.chat.tool_registry:update_context_visibility()
142+ _G.acp_visible = _G.chat.context_items[1].opts.visible
143+
144+ _G.chat.adapter = { name = "test_adapter", type = "http" }
145+ _G.chat.tool_registry:update_context_visibility()
146+ _G.http_again_visible = _G.chat.context_items[1].opts.visible
147+ ]] )
148+
149+ h .eq (true , child .lua_get ([[ _G.http_visible]] ))
150+ h .eq (false , child .lua_get ([[ _G.acp_visible]] ))
151+ h .eq (true , child .lua_get ([[ _G.http_again_visible]] ))
152+ end
153+
63154T [" ToolRegistry" ][" :add" ][" returns nil for unknown name" ] = function ()
64155 local result = child .lua_get ([[ _G.chat.tool_registry:add("nonexistent_tool_xyz")]] )
65156
0 commit comments