Compare commits

...

2 commits

Author SHA1 Message Date
8d5be7fc5a
docs(test): add busted migration log
Problem: The plenary-to-busted migration surfaced three test isolation
issues whose root causes and fixes were not documented.

Solution: Add spec/TESTING.md recording the issues, their root causes,
and the applied fixes for future reference. Update CLAUDE.md test
section with correct framework, run command, and test count.
2026-02-22 12:13:58 -05:00
fc15d14bdb
fix(test): resolve busted migration test isolation issues
Problem: Two issues introduced during the plenary-to-busted migration
(6be0148). First, altbuf_spec waited for two BufEnter events but
oil:// → file resolution only fires one async BufEnter (the synchronous
one from vim.cmd.edit fires before wait_for_autocmd is registered).
Second, reset_editor kept the first window which could be a preview
window with stale oil_preview/oil_source_win state, causing
close_preview_window_if_not_in_oil to close the wrong window in
subsequent tests.

Solution: Wait for a single BufEnter in the altbuf test. Replace the
window-keeping logic in reset_editor with vim.cmd.new() +
vim.cmd.only() to guarantee a fresh window with no inherited state.
This also fixes the preview_spec.lua:30 timeout which had the same
root cause. 114/114 tests pass.
2026-02-22 12:13:43 -05:00
3 changed files with 51 additions and 7 deletions

49
spec/TESTING.md Normal file
View file

@ -0,0 +1,49 @@
# Test Framework Migration Log
Issues encountered during the plenary-to-busted migration (`6be0148`) and
how they were resolved.
## Final status
114 successes / 0 failures / 0 errors.
## Issue 1: altbuf_spec.lua:18 — BufEnter wait mismatch (resolved)
The test `sets previous buffer as alternate when editing url file` originally
waited for two `BufEnter` events via `wait_for_autocmd('BufEnter')` x2.
The oil:// → real file resolution only produces one async BufEnter:
1. `vim.cmd.edit('oil://...')` fires BufEnter synchronously (before any
wait_for_autocmd is registered)
2. `normalize_url` resolves asynchronously via `uv.fs_realpath` + `uv.fs_stat`
3. `rename_buffer` discovers dest is a real file on disk, schedules
`nvim_win_set_buf()` via `vim.schedule()`
4. `nvim_win_set_buf()` fires one async BufEnter on the real file buffer
The second `wait_for_autocmd('BufEnter')` was never correct — it passed under
plenary due to coroutine event loop yielding, not because a second BufEnter
actually fired.
**Fix:** single `wait_for_autocmd('BufEnter')`.
## Issue 2: regression_spec.lua:20 — stale preview window state (resolved)
`reset_editor()` closed all windows except the first, but the surviving window
could be a preview window with stale `oil_preview`, `oil_source_win`,
`previewwindow`, etc. from a prior test. Subsequent tests that triggered
`close_preview_window_if_not_in_oil()` would close the wrong window.
**Fix:** `vim.cmd.new()` + `vim.cmd.only()` creates a fresh window and closes
all others (including the stale one). No variable cleanup needed — the new
window has no oil state.
## Issue 3: preview_spec.lua:30 — M.await timed out (resolved)
Originally thought to be a pre-existing issue unrelated to the migration. Root
cause was identical to issue 2: stale preview window state from a prior test
caused `close_preview_window_if_not_in_oil()` to close the wrong window during
`oil.open()`, preventing the callback from completing.
Fixed by the same `vim.cmd.new()` + `vim.cmd.only()` approach in
`reset_editor()`.

View file

@ -22,7 +22,6 @@ describe('Alternate buffer', function()
local readme = fs.join(vim.fn.getcwd(), 'README.md')
vim.cmd.edit({ args = { 'oil://' .. fs.os_to_posix_path(readme) } })
test_util.wait_for_autocmd('BufEnter')
test_util.wait_for_autocmd('BufEnter')
assert.equals(readme, vim.api.nvim_buf_get_name(0))
assert.equals('foo', vim.fn.expand('#'))
end)

View file

@ -12,12 +12,8 @@ M.reset_editor = function()
prompt_save_on_select_new_entry = false,
})
vim.cmd.tabonly({ mods = { silent = true } })
for i, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if i > 1 then
vim.api.nvim_win_close(winid, true)
end
end
vim.api.nvim_win_set_buf(0, vim.api.nvim_create_buf(false, true))
vim.cmd.new()
vim.cmd.only()
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
vim.api.nvim_buf_delete(bufnr, { force = true })
end