Skip to content

Replace plenary.nvim with in-tree test framework at tests/framework/ - #494

Merged
esmuellert merged 29 commits into
mainfrom
copilot/lookup-plenary-replacement
Jul 30, 2026
Merged

esmuellert merged 29 commits into
mainfrom
copilot/lookup-plenary-replacement

Conversation

Copilot AI commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

plenary.nvim is deprecated (#367). Audit of the 68 spec files shows the test surface actually used is small (5 busted keywords, ~17 pure-equality/type assertions, 0 spies/stubs/mocks/coroutines) — small enough to own in-tree, mirroring what lua/codediff/ui/lib/ already did for nui.nvim.

Framework — new tests/framework/

  • assert.lua — callable table replacing luassert. equal/equals/are.equal use strict ==; same/are.same delegate to vim.deep_equal. Chain tables: is, is_not, are, are_not, has, has_no. _G.assert is augmented (not replaced) so stdlib assert(cond, msg) passthrough keeps working.
  • busted.lua — describe/it/before_each/after_each/pending collector with a suite stack. Supports both pending() forms — mid-test skip (via a PENDING_SENTINEL unwind) and describe-scope placeholder with or without a body.
  • runner.lua — per-file executor: reset → dofile → for each test { before_each outer→inner, xpcall(fn), after_each inner→outer always }. run_and_exit() uses cq 1 for exit-code propagation.
  • reporter.lua — stdout with ANSI colors (respects NO_COLOR), traceback on failure, summary line.
  • init.lua — setup() installs globals + registers package.preload["luassert"] so the 3 specs that do local assert = require("luassert") keep resolving.

Bootstrap & runners

  • tests/init.lua — dropped the plenary git clone block; calls require("tests.framework").setup().
  • tests/run_plenary_tests.{sh,cmd} → tests/run_tests.{sh,cmd} (invocation switched to require('tests.framework').run_and_exit('$spec_file')).
  • CMakeLists.txt + generated Makefile/Makefile.win, build-and-test.yml, standalone-build-test.yml, copilot-setup-steps.yml — updated to the renamed script; plenary install/cache steps removed.
  • .gitignore — removed tests/plenary.nvim.

Docs

tests/README.md, README.md, lua/codediff/core/argparse/README.md, ATTRIBUTION.md, .github/skills/nvim-e2e-workflow/SKILL.md, docs/development/05-architecture/timeout-mechanism.md updated to reference the in-tree framework; plenary.nvim entry dropped from ATTRIBUTION.md.

Not modified

All 68 tests/**/*_spec.lua files — the API is byte-for-byte compatible.

Example — the assertion semantics that matter

local a, b = {x = 1}, {x = 1}

assert.equal(a, a)     -- pass: strict ==
assert.equal(a, b)     -- FAIL: same content, different refs
assert.are_not.equal(a, b)  -- pass

assert.same(a, b)      -- pass: deep_equal
assert.are.same(a, b)  -- pass

Original impl incorrectly deep-equaled both; the LRU cache spec (assert.are_not.equal(first_result, second_result)) surfaced it.

Trade-offs

  • No mocks/stubs/spies. Zero call sites today; add ~20 LOC spy.on closure if a future test needs one.
  • Reporter is not as polished as plenary's; uses debug.traceback() + vim.inspect.
  • Deep equality delegates to vim.deep_equal (handles cycles, mixed keys, NaN).

Rebased onto origin/main (aaef5cc) — Neovim install steps, VERSION bump to 2.57.0, explorer/formatter additions all preserved.

Copilot AI and others added 16 commits July 29, 2026 00:08
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
#484)

The `build-and-test` job in `release.yml` called a reusable workflow
without an explicit `permissions` block, leaving it subject to
over-privileged repository/org defaults — flagged by CodeQL as
`actions/missing-workflow-permissions` (alert #7).

## Changes

- **`.github/workflows/release.yml`**: Added `permissions: contents:
read` to the `build-and-test` job (minimum required for
`actions/checkout@v4`)

```yaml
jobs:
  build-and-test:
    uses: ./.github/workflows/build-and-test.yml
    permissions:
      contents: read   # ← added
```
…ect race (#486)

Two related changes in the explorer refresh path.

## 1. Skip refresh when status is unchanged (`refresh.lua`, +11 LOC)

The 500ms polling introduced by #483 always ran the full downstream
refresh — tree rebuild + re-selection + `sync_mutable_buffers` — on
every tick, even when `git status`'s output hadn't changed since the
last tick. That produces steady UI churn (tree re-render, extmark
rewrites) and interrupts users (manual pane sizes reset, tree-flatten
flicker, cursor jumps) with no observable benefit.

Fix: `vim.deep_equal(status_result, explorer.status_result)`
early-return.

- `git status` still runs every tick — **coverage is unchanged**.
- We only skip UI work that produces the same output as before.
- ~2ms per idle tick saved on typical repos; much more on large repos
where tree rebuild dominates.

## 2. Guard on_file_select against stale scheduled callbacks
(`render.lua`, +37 LOC across 8 sites)

The optimization above exposed a pre-existing async race that polling
was masking.

**The race.** `on_file_select` schedules its diff-view swap via
`vim.schedule`. When two selections queue in quick succession (e.g.
focus_file auto-select racing with a user click), both scheduled
callbacks fire in order — the stale one runs `view.update` on the old
file, swapping buffers in the pane, wiping the newer virtual buffer via
`bufhidden=wipe` (which drops any in-flight async content load),
resetting `layout.arrange`, and clearing `session.single_pane`.

Polling had been running `on_file_select` for the current file ~2×/s,
silently re-establishing the correct state within 500ms — so users saw
at most a brief flicker. Once we skip the polling, the race becomes
durable — the wrong file's content stays on screen until the user clicks
again.

**Fix.** At every `vim.schedule` block in `on_file_select`, check
whether the current selection has moved on before doing any work:

```lua
vim.schedule(function()
  if explorer.current_file_path ~= file_path then
    return
  end
  -- ...actual work...
end)
```

`explorer.current_file_path` is set synchronously by the outer wrapper
on every selection, so by the time a stale callback runs, the mismatch
is authoritative. Applied to all 8 schedule sites: dir mode,
`??`/`A`/`D` single-pane paths, two-revision, `base_revision`
single-rev, conflicts, staged.

The guard is a targeted fix at each choke point, not an architectural
cancellation model — it's correct on its own, plays cleanly with any
future cancellation architecture (redundant under it, never wrong), and
matches the idiom used elsewhere in the async ecosystem (React
`isMounted`, LSP request IDs).

## Verified

- `explorer_spec.lua`: **21/21** (5× runs, zero flake). Includes the
`#480` regression guards for the manual resize + external `touch`
detection.
- `issue_390_spec.lua`: **1/1** (3× runs, zero flake). Deleted-file
content in revision mode.
- Full `make test-lua`: **751 pass / 0 fail**.
- `stylua --check` clean on both changed files.

## Why the two changes ship together

The refresh skip alone would leave the stale-selection race producing
user-visible bugs (broke `issue_390_spec` when tested in isolation). The
guard fixes the race regardless of the optimization. Shipping them
together closes both.
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Code scanning flagged workflow-level implicit token permissions in
`.github/workflows/standalone-build-test.yml`
(`actions/missing-workflow-permissions`, alert #6). This change makes
token scope explicit and least-privilege to satisfy the alert and
prevent permission drift.

- **What changed**
  - Added an explicit workflow-level `permissions` block:
    - `contents: read`

- **Why this matters**
  - Stops relying on repository/org defaults for `GITHUB_TOKEN`.
- Documents intended access and keeps the workflow compliant with
least-privilege expectations.

- **Patch excerpt**
  ```yaml
  on:
    workflow_call:
    workflow_dispatch:

  permissions:
    contents: read
  ```
… use it

Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
…y-replacement

# Conflicts:
#	.github/workflows/copilot-setup-steps.yml
#	VERSION

Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Copilot AI and others added 2 commits July 29, 2026 18:49
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Copilot AI and others added 4 commits July 29, 2026 20:06
…y-replacement

Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Copilot AI and others added 3 commits July 29, 2026 21:27
- Route real-file buffer displays through a new
  `helpers.show_real_file_buffer`, which runs `silent! checktime {buf}`
  *before* `nvim_win_set_buf`. Neovim timestamp-checks a buffer when it
  becomes visible; for a file deleted behind our back that check emitted
  `E211: File ... no longer available` to stderr and could even surface as
  an error out of `nvim_win_set_buf`, aborting view construction halfway.
- Add an opt-in `no_optional_locks` flag to `run_git_async` and use it for
  the read-only queries the explorer polls every 500ms (`status --porcelain`,
  `diff --name-status`, `ls-files --others`). Without it a plain `git status`
  rewrites `.git/index` and takes `.git/index.lock`, racing concurrent
  `git add` / `git apply --cached` from stage/unstage actions
  (`fatal: Unable to create '.../index.lock': File exists`).
- Regression coverage for both in existing spec files.

Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
…tured output

Co-authored-by: yanuoma <220247883+yanuoma@users.noreply.github.com>
esmuellert and others added 2 commits July 30, 2026 01:07
Covers the previously-uncovered fix from c43b1f9: on a watch_err callback
the .git fs_event handle must be stopped and closed so a dead watch
(typically the repository being deleted or replaced) does not keep
re-delivering the same error forever on Windows.

The watcher lives inside a local closure in `setup_auto_refresh`, so the
spec stubs `vim.uv.new_fs_event()` with a spy handle, drives the
callback with a synthetic 'EPERM' error, and asserts that :stop() and
:close() were both invoked exactly once. A second callback firing is
also driven to prove that git_watcher was nilled and the teardown does
not re-run.

Verified fail-before / pass-after: with the c43b1f9 fix reverted the
spec fails at the :stop() assertion; with the fix restored it passes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b8fc9c4e-ddd0-4b67-b38b-70ba06220865
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b8fc9c4e-ddd0-4b67-b38b-70ba06220865
@esmuellert
esmuellert marked this pull request as ready for review July 30, 2026 05:09
@esmuellert
esmuellert self-requested a review as a code owner July 30, 2026 05:09
@esmuellert
esmuellert enabled auto-merge July 30, 2026 05:16
@esmuellert
esmuellert merged commit dc38f0b into main Jul 30, 2026
18 of 19 checks passed
@esmuellert
esmuellert deleted the copilot/lookup-plenary-replacement branch July 30, 2026 05:16
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.

3 participants