Files
avante.nvim/tests/llm_tools/helpers_spec.lua
Joseph b2064a8f40 Fix has_permissions_to_access when file is not ignored but patter is a substring (#2011)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
2025-05-08 01:43:43 +08:00

50 lines
1.7 KiB
Lua

local LlmToolHelpers = require("avante.llm_tools.helpers")
local Utils = require("avante.utils")
local stub = require("luassert.stub")
describe("has_permission_to_access", function()
local test_dir = "/tmp/test_llm_tools_helpers"
before_each(function()
os.execute("mkdir -p " .. test_dir)
-- create .gitignore file with test.idx file
os.execute("rm " .. test_dir .. "/.gitignore 2>/dev/null")
local gitignore_file = io.open(test_dir .. "/.gitignore", "w")
if gitignore_file then
gitignore_file:write("test.txt\n")
gitignore_file:write("data\n")
gitignore_file:close()
end
stub(Utils, "get_project_root", function() return test_dir end)
end)
after_each(function() os.execute("rm -rf " .. test_dir) end)
it("Basic ignored and not ignored", function()
local abs_path
abs_path = test_dir .. "/test.txt"
assert.is_false(LlmToolHelpers.has_permission_to_access(abs_path))
abs_path = test_dir .. "/test1.txt"
assert.is_true(LlmToolHelpers.has_permission_to_access(abs_path))
end)
it("Ignore files inside directories", function()
local abs_path
abs_path = test_dir .. "/data/test.txt"
assert.is_false(LlmToolHelpers.has_permission_to_access(abs_path))
abs_path = test_dir .. "/data/test1.txt"
assert.is_false(LlmToolHelpers.has_permission_to_access(abs_path))
end)
it("Do not ignore files with just similar paths", function()
local abs_path
abs_path = test_dir .. "/data_test/test.txt"
assert.is_false(LlmToolHelpers.has_permission_to_access(abs_path))
abs_path = test_dir .. "/data_test/test1.txt"
assert.is_true(LlmToolHelpers.has_permission_to_access(abs_path))
end)
end)