Skip to content

test(import): cover single-file import, document precedence#33

Merged
zuqini merged 1 commit into
mainfrom
fix/single-file-import-hardening
Jun 15, 2026
Merged

test(import): cover single-file import, document precedence#33
zuqini merged 1 commit into
mainfrom
fix/single-file-import-hardening

Conversation

@zuqini

@zuqini zuqini commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Follow-up to #30, which added single-file import (import = 'plugins.foo' resolving lua/plugins/foo.lua, lazy.nvim parity) but landed without tests or docs.

Reopened from #32 (GitHub could not reopen it after the branch was updated).

Changes

  • Tests (tests/import_test.lua): single-file resolution (and that it does not walk a same-named directory), file-over-directory precedence, and enabled = false gating on a single-file import.
  • Test harness (tests/helpers.lua): captures vim.fn.stdpath / vim.uv.fs_stat at setup and restores them in after_each, so an assertion failure mid-test no longer leaks the mock into later tests (vim.uv == vim.loop).
  • Code comment (lua/zpack/import.lua): makes the file-shadows-directory precedence intentional, mirroring Lua's own require (foo.lua shadows foo/init.lua).
  • Vimdoc (doc/zpack.txt): documents the single-file form and the precedence rule in both the importing-specs section and the Spec.import reference.
  • README.md / docs/spec.md: corrected the inline import comments to reflect single-file resolution.

Tradeoffs (recorded, not changed)

  • Double-load: configuring both import = 'plugins' and import = 'plugins.foo' requires foo.lua twice under different keys — harmless (require cache + merge dedup).
  • Path resolution: the existence check is config-dir-only, matching the existing directory walk's pre-existing ceiling.

Verification

  • nvim -u NONE -l tests/busted.lua — 483 passed / 0 failed
  • luacheck lua/ tests/ — 0 warnings / 0 errors

PR #30 added single-file import (import = 'plugins.foo' resolving
lua/plugins/foo.lua) but landed without tests or docs. This adds:

- tests for the single-file path, file-over-directory precedence, and
  enabled=false gating on a single-file import
- a code comment making the file-shadows-directory precedence intentional
- vimdoc (doc/zpack.txt) coverage of the single-file form and precedence
- README + docs/spec.md coverage of the file-over-directory precedence
- guaranteed restoration of mocked vim.fn.stdpath / vim.uv.fs_stat in the
  test harness teardown, so an assertion failure mid-test no longer leaks
  the mock into later tests

Closes zpack_nvim-thi
@zuqini zuqini merged commit c8b4e8d into main Jun 15, 2026
4 checks passed
@zuqini zuqini deleted the fix/single-file-import-hardening branch June 15, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant