Refactor utils tests to avoid testing implementation details
Problem
The utils test suite (tests/zk-extras/utils_spec.lua) contains multiple tests that verify implementation details rather than behavior. This makes tests fragile and doesn't validate actual requirements.
Specific Issues
1. Trash utility preference testing (lines 472-505)
Current: Tests explicitly verify gio is checked before trash-put
it("prefers gio over trash-put when both available", function()
-- Verifies check order
Issue: This is pure implementation detail. The requirement is "move file to trash", not "prefer gio".
Should test:
- File is successfully moved to trash
- Appropriate trash utility is used
- Falls back gracefully when utilities unavailable
- Returns meaningful error when all methods fail
2. Mock-heavy tests (lines 69-82)
Current: Mocks executable and checks for exact error string
assert.equals("No trash utility", output)
Issue:
- Tests exact implementation of error handling
- Breaks if error message changes
- Doesn't verify actual behavior (file not deleted)
Should test:
- Operation fails when no trash available
- File is NOT deleted
- User receives actionable error
- System state is unchanged
3. Path resolution tests
Current: Tests internal path manipulation logic
Should test:
- Correct file is operated on
- Symbolic links are handled
- Relative vs absolute paths work correctly
- Edge cases: spaces, unicode, special chars
Recommended Changes
- Rewrite trash tests:
-- BAD
it("prefers gio over trash-put when both available", function()
-- GOOD
describe("move_to_trash", function()
it("successfully moves file to system trash", function()
-- Verify file moved, don't care about utility
it("fails gracefully when no trash utility available", function()
-- Verify error, file untouched
it("handles permission errors appropriately", function()
-- Verify error handling
- Add filesystem integration tests:
it("handles files with special characters in names", function()
it("preserves file metadata when moving to trash", function()
it("handles concurrent deletion requests", function()
- Test picker abstraction properly:
-- Don't test telescope/fzf/etc implementation
-- Test: "user can select from items and selection is returned"
Missing Tests
-
find_notebook_zkwith nested .zk directories -
get_visual_selectionwith multibyte characters -
show_pickerwith very large item lists (performance) -
Error recovery when filesystem operations fail mid-stream -
Buffer operations when buffer is modified externally
Success Criteria
-
Tests verify user-facing behavior only -
Tests pass with alternative implementations -
Error conditions are thoroughly tested -
Performance edge cases covered -
No mocking of implementation details
References
-
tests/zk-extras/utils_spec.lualines 69-82, 472-505 lua/zk-extras/utils.lua