Skip to content

Commit 5aaff0b

Browse files
committed
fix tests
1 parent 9593675 commit 5aaff0b

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

lua/codecompanion/interactions/chat/tools/approvals.lua

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,23 @@ function Approvals:is_approved(bufnr, args)
8080
return false
8181
end
8282

83-
local tool_cfg = args.tool_name and config.interactions.chat.tools and config.interactions.chat.tools[args.tool_name]
83+
local tool_cfg = args
84+
and args.tool_name
85+
and config.interactions.chat.tools
86+
and config.interactions.chat.tools[args.tool_name]
8487

85-
if approvals.yolo_mode then
86-
if not args or not args.tool_name then
87-
return true
88-
end
89-
90-
if tool_cfg and tool_cfg.opts then
91-
-- Allow users to designate certain tools as not allowed in yolo mode
88+
-- Check if tool requires command-level approval first
89+
if tool_cfg and tool_cfg.opts and tool_cfg.opts.require_cmd_approval then
90+
-- Yolo mode overrides cmd approval requirement
91+
if approvals.yolo_mode then
92+
-- But still respect allowed_in_yolo_mode = false
9293
if tool_cfg.opts.allowed_in_yolo_mode == false then
9394
return false
9495
end
96+
return true
9597
end
9698

97-
return true
98-
end
99-
100-
if tool_cfg and tool_cfg.opts and tool_cfg.opts.require_cmd_approval then
99+
-- Not in yolo mode, check if this specific command was approved
101100
if not approvals[args.tool_name] then
102101
return false
103102
end
@@ -108,6 +107,22 @@ function Approvals:is_approved(bufnr, args)
108107
return false
109108
end
110109

110+
-- Handle yolo mode for regular tools (non-cmd-approval tools)
111+
if approvals.yolo_mode then
112+
if not args or not args.tool_name then
113+
return true
114+
end
115+
116+
if tool_cfg and tool_cfg.opts then
117+
-- Allow users to designate certain tools as not allowed in yolo mode
118+
if tool_cfg.opts.allowed_in_yolo_mode == false then
119+
return false
120+
end
121+
end
122+
123+
return true
124+
end
125+
111126
if args and args.tool_name then
112127
return approvals[args.tool_name] == true
113128
end

tests/interactions/chat/tools/test_approvals.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ local T = new_set({
88
pre_case = function()
99
h.child_start(child)
1010
child.lua([[
11-
Approvals = require('codecompanion.interactions.chat.tools.approvals')
12-
13-
-- Mock the config module
11+
-- Mock the config module BEFORE requiring approvals
1412
package.loaded['codecompanion.config'] = {
1513
interactions = {
1614
chat = {
@@ -25,6 +23,8 @@ local T = new_set({
2523
},
2624
},
2725
}
26+
27+
Approvals = require('codecompanion.interactions.chat.tools.approvals')
2828
]])
2929
end,
3030
post_case = function()
@@ -195,7 +195,6 @@ T["yolo mode"]["respects allowed_in_yolo_mode = false"] = function()
195195
allowed_value = tool_cfg and tool_cfg.opts and tool_cfg.opts.allowed_in_yolo_mode
196196
}
197197
]])
198-
print("Config check:", vim.inspect(config_check))
199198

200199
local restricted = child.lua([[
201200
return Approvals:is_approved(1, { tool_name = 'restricted_tool' })

0 commit comments

Comments
 (0)