Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dc3c2e1

Browse files
fix: resolve test failures for snacks.explorer integration
- Fix helpers module usage in snacks_explorer_spec.lua (return function, not table) - Add missing vim.fn.isDirectory() and vim.bo to test mocks - Fix is_safe_path() to properly filter system files (/etc/, /usr/, /bin/, /sbin/) - All 326 tests now pass successfully
1 parent 66476f4 commit dc3c2e1

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

‎ARCHITECTURE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Unified interface for popular file explorers:
192192
-- Supports nvim-tree, neo-tree, oil.nvim, and snacks.explorer
193193
function M.get_selected_files_from_tree()
194194
local current_ft = vim.bo.filetype
195-
195+
196196
if current_ft == "NvimTree" then
197197
return M._get_nvim_tree_selection()
198198
elseif current_ft == "neo-tree" then
@@ -206,6 +206,7 @@ end
206206
```
207207

208208
Key features across all integrations:
209+
209210
- **Visual mode support**: Select multiple files using vim visual mode
210211
- **Security protection**: Filters out root-level files (`/etc/passwd`, `/usr/bin/vim`)
211212
- **Directory handling**: Adds trailing slashes to directories for consistency

‎lua/claudecode/integrations.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,19 @@ function M._get_snacks_explorer_selection(visual_start, visual_end)
312312
return false
313313
end
314314
-- Not root-level file & this prevents selecting files like /etc/passwd, /usr/bin/vim, etc.
315-
return not string.match(file_path, "^/[^/]*$")
315+
-- Check for system directories and root-level files
316+
if string.match(file_path, "^/[^/]*$") then
317+
return false -- True root-level files like /etc, /usr, /bin
318+
end
319+
if
320+
string.match(file_path, "^/etc/")
321+
or string.match(file_path, "^/usr/")
322+
or string.match(file_path, "^/bin/")
323+
or string.match(file_path, "^/sbin/")
324+
then
325+
return false -- System directories
326+
end
327+
return true
316328
end
317329

318330
-- Handle visual mode selection if range is provided

‎tests/mocks/vim.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,12 @@ local vim = {
457457
localtime = function()
458458
return os.time()
459459
end,
460+
461+
isdirectory = function(path)
462+
-- Mock implementation - return 1 for directories, 0 for files
463+
-- For testing, we'll consider paths ending with '/' as directories
464+
return path:match("/$") and 1 or 0
465+
end,
460466
},
461467

462468
cmd = function(command)
@@ -601,6 +607,27 @@ local vim = {
601607
end,
602608
}),
603609

610+
bo = setmetatable({}, {
611+
__index = function(_, key)
612+
-- Return buffer option for current buffer
613+
local current_buf = vim.api.nvim_get_current_buf()
614+
if vim._buffers[current_buf] and vim._buffers[current_buf].options then
615+
return vim._buffers[current_buf].options[key]
616+
end
617+
return nil
618+
end,
619+
__newindex = function(_, key, value)
620+
-- Set buffer option for current buffer
621+
local current_buf = vim.api.nvim_get_current_buf()
622+
if vim._buffers[current_buf] then
623+
if not vim._buffers[current_buf].options then
624+
vim._buffers[current_buf].options = {}
625+
end
626+
vim._buffers[current_buf].options[key] = value
627+
end
628+
end,
629+
}),
630+
604631
deepcopy = function(tbl)
605632
if type(tbl) ~= "table" then
606633
return tbl

‎tests/unit/snacks_explorer_spec.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
local helpers = require("tests.helpers.setup")
21
local integrations = require("claudecode.integrations")
32

43
describe("snacks.explorer integration", function()
54
before_each(function()
6-
helpers.setup()
5+
require("tests.helpers.setup")()
76
end)
87

98
after_each(function()
10-
helpers.cleanup()
9+
-- No cleanup needed
1110
end)
1211

1312
describe("_get_snacks_explorer_selection", function()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /