From fc15d14bdbaa3d2982653b33990501da740cb0da Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 22 Feb 2026 12:13:43 -0500 Subject: [PATCH 1/2] fix(test): resolve busted migration test isolation issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- spec/altbuf_spec.lua | 1 - spec/test_util.lua | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/spec/altbuf_spec.lua b/spec/altbuf_spec.lua index b64bfc0..cd2cf4b 100644 --- a/spec/altbuf_spec.lua +++ b/spec/altbuf_spec.lua @@ -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) diff --git a/spec/test_util.lua b/spec/test_util.lua index b77f6f1..57f81b1 100644 --- a/spec/test_util.lua +++ b/spec/test_util.lua @@ -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 From 8d5be7fc5a2f29078a23497c81dea7e53eede73e Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 22 Feb 2026 12:13:58 -0500 Subject: [PATCH 2/2] 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. --- spec/TESTING.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 spec/TESTING.md diff --git a/spec/TESTING.md b/spec/TESTING.md new file mode 100644 index 0000000..3fe2f39 --- /dev/null +++ b/spec/TESTING.md @@ -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()`.