Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions home-manager/programs/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
let
nvimInitLua = ./init.lua;
nvimPackLockJson = ./nvim-pack-lock.json;
packDir = "$HOME/.local/share/nvim/site/pack";
buildTools = if pkgs.stdenv.isDarwin then [ pkgs.gnumake pkgs.clang ] else [ pkgs.gnumake pkgs.gcc ];
libExt = "so";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The dynamic library extension is hardcoded to so. On macOS, the extension for shared libraries is .dylib. This will cause the activation script to fail to detect an already built library on macOS, leading to unnecessary rebuilds. The libExt variable should be set conditionally based on the operating system.

  libExt = if pkgs.stdenv.isDarwin then "dylib" else "so";

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On macOS/Darwin, shared libraries typically use the .dylib extension instead of .so. The libExt variable should be set conditionally based on the platform, similar to how buildTools is set. This will cause the build check to fail on macOS even when the library is successfully built, as the script will look for libfzf.so instead of libfzf.dylib.

Suggested change
libExt = "so";
libExt = if pkgs.stdenv.isDarwin then "dylib" else "so";

Copilot uses AI. Check for mistakes.
in
{
programs.neovim = {
Expand All @@ -33,4 +36,19 @@ in
$DRY_RUN_CMD cp -f ${nvimPackLockJson} "$HOME/.config/nvim/nvim-pack-lock.json"
$DRY_RUN_CMD chmod 644 "$HOME/.config/nvim/nvim-pack-lock.json"
'';

home.activation.buildNvimNativePlugins = config.lib.dag.entryAfter [ "writeBoundary" ] ''
export PATH="${lib.makeBinPath buildTools}:$PATH"
fzf_dir=""
for d in ${packDir}/*/opt/telescope-fzf-native.nvim ${packDir}/*/start/telescope-fzf-native.nvim; do
if [ -d "$d" ]; then
fzf_dir="$d"
break
fi
done
if [ -n "$fzf_dir" ] && [ ! -f "$fzf_dir/build/libfzf.${libExt}" ]; then
echo "Building telescope-fzf-native.nvim in $fzf_dir..."
$DRY_RUN_CMD make -C "$fzf_dir" clean all

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The activation script doesn't ensure the build directory exists before running make. While make typically creates its output directories, it's safer to explicitly create the build directory or verify it exists after the build completes. Additionally, there's no error handling if the make command fails - the script will silently continue even if compilation fails.

Suggested change
$DRY_RUN_CMD make -C "$fzf_dir" clean all
build_dir="$fzf_dir/build"
$DRY_RUN_CMD mkdir -p "$build_dir"
if ! $DRY_RUN_CMD make -C "$fzf_dir" clean all; then
echo "Error: Failed to build telescope-fzf-native.nvim in $fzf_dir" >&2
exit 1
fi

Copilot uses AI. Check for mistakes.
fi
'';
}
2 changes: 1 addition & 1 deletion home-manager/programs/neovim/lua/config/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ telescope.setup({
},
})
telescope.load_extension("gh")
telescope.load_extension("fzf")
pcall(telescope.load_extension, "fzf")
telescope.load_extension("ui-select")
Comment on lines 42 to 44

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the "fzf" extension is wrapped in pcall, while "gh" and "ui-select" extensions are called directly without error handling. For consistency, if the fzf extension requires defensive pcall handling due to potential build issues, consider whether the other extensions should also be wrapped in pcall, or alternatively, document why only fzf needs this special handling.

Copilot uses AI. Check for mistakes.

local function ivy(iopts)
Expand Down
34 changes: 34 additions & 0 deletions home-manager/programs/neovim/tests/plugins_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,38 @@ describe("plugins", function()
assert.equals("~", signs_config.change.text)
end)
end)

describe("e2e init.lua loading", function()
it("should load full config without Lua errors", function()
-- Capture any Lua errors that occur during init.lua sourcing
local errors = {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The errors table is initialized here to capture errors from vim.notify, but its contents are never checked later in the test. This means that non-fatal errors that are reported via vim.notify will be missed. Please add an assertion to check if this table is empty after sourcing init.lua. For example: assert.is_empty(errors, "init.lua produced errors via vim.notify: " .. table.concat(errors, "\\n"))

local orig_notify = vim.notify
vim.notify = function(msg, level)
if level == vim.log.levels.ERROR then
table.insert(errors, msg)
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

errors table is collected but never asserted; the "allow CI failures" comment is a no-op.

Two issues in the same block:

  1. Dead monitoring code: vim.notify is monkey-patched to collect ERROR-level messages into errors, but errors is never checked after the pcall. Any vim.notify(…, ERROR) call during init.lua sourcing is silently ignored. Either assert #errors == 0 or remove the monkey-patching.

  2. Misleading comment vs. actual behaviour: The comment on line 106 says "allow known CI-only failures (missing plugins in test env)", but the code on line 108 calls assert.is_true(ok, …) which unconditionally fails the test on any pcall error — there is no actual allowlist. If the intent is genuinely to tolerate known-missing-plugin errors in CI, the error message needs to be pattern-matched.

✨ Suggested improvement
 			local ok, err = pcall(function()
 				vim.cmd("source " .. vim.fn.fnameescape(init_lua))
 			end)

 			vim.notify = orig_notify

+			-- Assert no ERROR-level notifications were fired
+			assert.are.same({}, errors, "init.lua emitted ERROR notifications: " .. vim.inspect(errors))
+
 			-- If pcall caught an error, the config has a loading problem
 			if not ok then
-				-- Allow known CI-only failures (missing plugins in test env)
-				-- but flag unexpected errors
-				assert.is_true(
-					ok,
-					"init.lua raised an error: " .. tostring(err)
-				)
+				-- Tolerate "module not found" errors in CI (no plugins installed)
+				local is_missing_module = tostring(err):find("module .* not found") ~= nil
+				assert.is_true(is_missing_module,
+					"init.lua raised an unexpected error: " .. tostring(err))
 			end

Also applies to: 104-112

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@home-manager/programs/neovim/tests/plugins_spec.lua` around lines 85 - 91,
The test monkey-patches vim.notify to collect ERROR messages into the local
errors table but never asserts against it, and the pcall result (ok) is
unconditionally asserted via assert.is_true(ok,…), contradicting the "allow
CI-only failures" intent; update the test around the init.lua sourcing to either
remove the vim.notify override or add an assertion like assert(`#errors` == 0)
after the pcall, and change the assert.is_true(ok, ...) logic to pattern-match
known benign CI errors from the pcall error (ok, err = pcall(...)) and only fail
the test for unexpected errors—use the errors table and error pattern matching
together to allow known missing-plugin messages while failing on other errors
(referencing errors, vim.notify, ok, and the pcall that sources init.lua).


-- Locate init.lua relative to this test file
local tests_dir = debug.getinfo(1, "S").source:sub(2):match("(.*/)")
local nvim_dir = vim.fn.fnamemodify(tests_dir, ":h")
local init_lua = nvim_dir .. "/init.lua"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

local ok, err = pcall(function()
vim.cmd("source " .. init_lua)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing fnameescape in vim.cmd("source …").

If init_lua contains spaces (common in home directories on macOS/Linux), the unquoted path will be split by :source at the first space.

🛡️ Proposed fix
-				vim.cmd("source " .. init_lua)
+				vim.cmd("source " .. vim.fn.fnameescape(init_lua))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@home-manager/programs/neovim/tests/plugins_spec.lua` at line 99, The call
using vim.cmd("source " .. init_lua) can break when init_lua contains spaces;
update the code that constructs the source command (the vim.cmd call referencing
init_lua) to escape the filename first (use vim.fn.fnameescape on init_lua) or
otherwise quote/escape the path before concatenation so the sourced path is
treated as a single argument by :source.

end)

vim.notify = orig_notify

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test captures errors in the errors table by overriding vim.notify, but never checks this table. If errors are logged via vim.notify rather than thrown as exceptions, they would be silently ignored. Consider adding an assertion to check that the errors table is empty after restoring the original notify function.

Suggested change
-- Ensure no error-level notifications were emitted during init.lua loading
if #errors > 0 then
assert.is_true(
false,
"init.lua logged error notifications via vim.notify:\n"
.. table.concat(errors, "\n")
)
end

Copilot uses AI. Check for mistakes.
-- If pcall caught an error, the config has a loading problem
if not ok then
-- Allow known CI-only failures (missing plugins in test env)
-- but flag unexpected errors
assert.is_true(
ok,
"init.lua raised an error: " .. tostring(err)
)
end

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcing the full init.lua in a test can have significant side effects, including loading all plugins, setting up autocommands, and potentially interfering with other tests. The test runs within a test suite that uses minimal_init.lua to isolate tests, but then sources the full config which could override test isolation settings. Consider whether this test should run in complete isolation (separate test file run independently) or use a more targeted approach to test specific plugin loading without sourcing the entire configuration.

Suggested change
it("should load full config without Lua errors", function()
-- Capture any Lua errors that occur during init.lua sourcing
local errors = {}
local orig_notify = vim.notify
vim.notify = function(msg, level)
if level == vim.log.levels.ERROR then
table.insert(errors, msg)
end
end
-- Locate init.lua relative to this test file
local tests_dir = debug.getinfo(1, "S").source:sub(2):match("(.*/)")
local nvim_dir = vim.fn.fnamemodify(tests_dir, ":h")
local init_lua = nvim_dir .. "/init.lua"
local ok, err = pcall(function()
vim.cmd("source " .. init_lua)
end)
vim.notify = orig_notify
-- If pcall caught an error, the config has a loading problem
if not ok then
-- Allow known CI-only failures (missing plugins in test env)
-- but flag unexpected errors
assert.is_true(
ok,
"init.lua raised an error: " .. tostring(err)
)
end
it("should have an init.lua file present", function()
-- Locate init.lua relative to this test file without sourcing it,
-- to avoid side effects in the minimal test environment.
local tests_dir = debug.getinfo(1, "S").source:sub(2):match("(.*/)")
local nvim_dir = vim.fn.fnamemodify(tests_dir, ":h")
local init_lua = nvim_dir .. "/init.lua"
-- Assert that init.lua exists and is readable.
local readable = vim.fn.filereadable(init_lua)
assert.is_true(
readable == 1,
"init.lua is missing or not readable at path: " .. tostring(init_lua)
)

Copilot uses AI. Check for mistakes.

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional check if not ok then assert.is_true(ok, ...) is redundant because if ok is false, the assertion will always fail. The assertion could be moved outside the conditional block to be more straightforward. Additionally, the comment mentions "Allow known CI-only failures" but the code doesn't actually allow any failures - it always asserts that ok must be true.

Suggested change
if not ok then
-- Allow known CI-only failures (missing plugins in test env)
-- but flag unexpected errors
assert.is_true(
ok,
"init.lua raised an error: " .. tostring(err)
)
end
assert.is_true(
ok,
"init.lua raised an error: " .. tostring(err)
)

Copilot uses AI. Check for mistakes.
end)
end)
end)
Loading