Repository navigation
test(diff): pin that a failed openDiff setup in a new tab closes its tab - #529
Conversation
Three real-Neovim guards for the failure branch of the openDiff setup with diff_opts.open_in_new_tab. The setup fails after :tabnew and a handler of the user raises: a WinClosed handler, or a WinLeave or BufLeave handler during the cleanup. openDiff still answers "Diff setup failed", closes the tab it opened and goes back to the tab it left. The tests come from the closed PR #498. They pin what main already does, so they pass with no change under lua/. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
…n AGENTS.md Add a Code Shape section with one rule: a cleanup closes, changes or deletes only a window, buffer or tab that the plugin can show it made, and it closes such a window without force. A later change adds the rest of the section. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
A close without force does not refuse for a buffer with buftype=nofile, so the rule no longer promises that it keeps unsaved work. The rule now says that "close such a window" means a window that the plugin made, and that deleting a buffer can close each window that shows it. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…der#522) ## What a developer sees The integration runner passes `{minimal_init = 'tests/minimal_init.lua'}` to plenary, but plenary's `test_harness.test_file(path)` takes no options and drops them. The Neovim that plenary starts for each spec has no `-u`, so: - it does not run `tests/minimal_init.lua`: no leader key, `timeoutlen` 1000 instead of 300, `updatetime` 4000 instead of 250, - it reads the developer's own init file, and runs the developer's `ftplugin` and `after` files, so a local run depends on `~/.config/nvim`, - every Neovim of a run writes ShaDa, a log and swap files under `~/.local/state/nvim`. The only part of `minimal_init.lua` that reached the spec's Neovim was the stub `claude` on `PATH`, which it inherited from the runner's own Neovim. ## What changes 1. **`VIMINIT`.** `scripts/run_integration_tests_individually.sh` sets `VIMINIT` for the Neovim it starts. A Neovim without `-u` runs `$VIMINIT` instead of the user's init file, so the Neovim that plenary starts now runs `tests/minimal_init.lua`. `VIMINIT` reads the file from `CLAUDECODE_MINIMAL_INIT`, an absolute path (`$PWD/tests/minimal_init.lua`), so a path with a space or `%` needs no escaping and a nested Neovim started from another folder finds the file. A comment says that `VIMINIT` and the variable reach every process a spec starts. The runner's own Neovim still has `-u`, and the unused `{minimal_init = ...}` argument is gone. 2. **State and config folders.** Each file gets one `XDG_STATE_HOME` and one `XDG_CONFIG_HOME`, in temp folders the runner removes afterwards. The Neovim the runner starts and the Neovim that plenary starts for the spec share them, so the runner's own Neovim takes `-i NONE`: two Neovims that write ShaDa into one new folder made the first fail with `E886` after a timeout. A run no longer writes `~/.local/state/nvim`, and the `ftplugin` and `after` files under `~/.config/nvim` do not run. Files in the data folder (`~/.local/share/nvim/site/...`) still run, as on `main`. `XDG_DATA_HOME` stays, because plenary lives there. 3. **Cleanup on SIGTERM.** An `EXIT` trap kills the process group of the file that runs, then removes its temp files and folders. Bash runs the trap when the runner gets SIGTERM too, just before the runner dies with 143 as it did before. On `main`, a runner that got SIGTERM left its temp files and left the file's Neovim running until its timeout. Killing the group first matters: a Neovim that ends later writes ShaDa and makes the removed state folder again. Two known limits: a SIGTERM that arrives before `timeout` has created the file's process group misses the kill (the file's Neovim then runs until its timeout, as on `main`), and on hosts whose `timeout` is uutils (this repo's CI image included) the SIGTERM test cannot tell a group kill from a kill of the `timeout` process alone. A follow-up PR fixes the test and the README wording. 4. **`tests/minimal_init.lua`** loses its `VimLeavePre` cleanup (`_G.claudecode_test_cleanup`). It ran only when `PLENARY_TEST_HARNESS` was set, and nothing sets it (not this repo and not plenary at CI's pin). I deleted it instead of arming it: it never ran, the plugin stops its own server in its `VimLeavePre` handler, and arming it would add an exit-time path to every spec Neovim, where a hung handler turns into a `TIMEOUT:`. 5. **Tests.** `tests/unit/integration_runner_spec.lua` gets six tests. The Neovim that plenary starts runs `tests/minimal_init.lua` of the working folder by an absolute path (the test runs the `VIMINIT` command with `dofile` stood in for). The `VIMINIT` command loads no file when `CLAUDECODE_MINIMAL_INIT` is missing (without its `if f then` guard, `dofile(nil)` would read standard input). Each file gets state and config folders that are removed afterwards. `XDG_DATA_HOME` is the one the runner got. The runner's own Neovim takes `-i NONE`. A runner that gets SIGTERM during a file stops that file's Neovim, leaves no temp file or folder, and exits 143. 6. `scripts/README.md` lists the two per-file temp folders (shared by the file's two Neovims), their removal including on SIGTERM, and the four variables the runner sets for each file's Neovim (`VIMINIT`, `CLAUDECODE_MINIMAL_INIT`, `XDG_STATE_HOME`, `XDG_CONFIG_HOME`). 7. A comment at `PLENARY_SHA` in `.github/workflows/test.yml` tells whoever bumps the pin to recheck plenary's own 50 s per-file timeout against the runner's `FILE_TIMEOUT`. 8. The cache-check comment in `.github/workflows/test.yml` now says which code writes under `stdpath("cache")`: only the legacy `diff.open_diff`, which `diff_legacy_swap_spec.lua` points at a temp folder. 9. `tests/integration/diff_hand_over_spec.lua` asserts that the `:split` step opened the expected file. ### Why `VIMINIT` and not `test_directory(<file>, opts)` `test_directory` or a direct `plenary.busted` call would carry the options, but they change the text `test_file('<file>'` in the runner's command line, which the stub `nvim` of the runner spec reads the file name from. `VIMINIT` keeps the command line as it is, and it also stops the developer's init file from running, which options alone would not. Its cost is that `VIMINIT` reaches nested Neovims too (the comment says so). ### One behavior change The spec Neovims of `command_args_spec.lua` and `mcp_tools_spec.lua` now run the `setup({ auto_start = false, log_level = "trace" })` of `tests/minimal_init.lua` before their tests, because their command line matches its `should_load` check. That adds debug log lines. The results are identical. ### The 50 s timeout plenary applies its own per-file timeout of 50 s (`timeout = 50000` in `test_harness.lua`), and `test_file` has no way to change it. The runner's `FILE_TIMEOUT` (40 s) plus its 5 s kill grace stays under it, as coder#515 set. ## Evidence The runner's real script on a tree whose only spec prints the state of its own Neovim, with a fake developer init file and a fake developer `ftplugin/lua.lua` in `XDG_CONFIG_HOME`: | Tree | `mapleader` | `timeoutlen` | `updatetime` | developer init ran | developer ftplugin ran | state folder under `$HOME` | |---|---|---|---|---|---|---| | `main` | none | 1000 | 4000 | yes | yes | yes | | this branch | `" "` | 300 | 250 | no | no | no | The whole integration runner, Neovim 0.12.3 and v0.8.0, `main` against this branch: 316 passed (237 rows on v0.8.0, 229 passed and 8 pending), 0 failed on both. The sorted `Success`, `Fail` and `Pending` rows are identical for both trees on both versions, and so are the success counts of all 24 files. The same runner with `HOME` set to an empty folder: | Tree | Left under that `HOME` | |---|---| | `main`, Neovim 0.12.3 | `.local/state/nvim/` with `lsp.log`, `nvim.log`, `shada`, `swap` | | `main`, Neovim v0.8.0 | `.local/state/nvim/` with `log`, `shada`, `swap` | | this branch, both versions | nothing | The two new runner spec tests, with each mutant of the script (a mutant is red when its row says "red"): | Mutant of the script | `VIMINIT` test | state and config test | |---|---|---| | none | green | green | | `VIMINIT` renamed so it is not set | red | green | | the variable names another file than `tests/minimal_init.lua` | red | green | | the variable holds a relative path | red | green | | the runner of `main` | red | red | | `XDG_STATE_HOME` and `XDG_CONFIG_HOME` not set | green | red | | the temp folders not removed | green | red | Two more mutants, for the two new assertions: | Mutant of the script | Assertion | Result | |---|---|---| | the `if f then` guard dropped | no file loaded without the variable | red (green on the head) | | `XDG_DATA_HOME` also set to a temp folder | `XDG_DATA_HOME` unchanged | red (green on the head) | Mutants for the two tests of this round (green on the head): | Mutant of the script | `-i NONE` test | SIGTERM test | |---|---|---| | `-i NONE` removed | red | green | | no `EXIT` trap (the trap on `HUP`) | green | red | | the trap without the process group kill | green | red | | the temp files not recorded for the trap | green | red | | the process group file not recorded | green | red | | the runner of `main` | red | red | Nested Neovim without `-u` from another folder (the verifier's finding): with the relative `luafile tests/minimal_init.lua` of the first version, both Neovim versions print `E5112 ... cannot open tests/minimal_init.lua` and run with defaults. With the absolute path in the variable, neither prints an error and `mapleader` is `" "`. A root folder named `odd dir 50%` works too. The swap file step assertion in `diff_hand_over_spec.lua`, under `TMPDIR` set to `odd tmp 50%`: | Plugin | Spec | Result | |---|---|---| | as is | with the assertion | 13 passed, 0 failed | | the step's `fnameescape` removed | with the assertion | 10 passed, 3 failed | | the step's `fnameescape` removed | as on `main` | 13 passed, 0 failed (the silent pass) | Without the odd `TMPDIR`, the mutant with the assertion is green too: the escape only matters for a `%` or a space. Hang probe from coder#515 (a spec that sleeps 120 s), three runs on this branch: each exits 1, prints `TIMEOUT: hang_spec.lua was stopped (exit 124): nvim did not exit within 40s`, and leaves no Neovim running. The `TIMEOUT:` line came after 40.4 s, 44.4 s and 40.5 s. The 44.4 s run was on a loaded host (the Opus verifier saw 41.8 s to 43.7 s at a load of 37 to 40, and 41.0 s to 42.2 s on `main`), so the limit plus the 5 s kill grace (45 s) is not far from a loaded run, and still under plenary's 50 s. The runner's state and config folders are gone from the run's `TMPDIR`. Only the temp folder of the killed Neovim itself is left, as before. `E886` after a timeout, the hang probe on the head of the previous round and on this branch, three runs each: | Head | Runs with an `E886` line | |---|---| | previous round (`6ed9c83`) | 1 of 3 (the Opus verifier saw 3 of 4) | | this branch | 0 of 3 | SIGTERM sent to the runner while the hang spec runs (the runner's `TMPDIR` is a fresh folder): | Tree | Runner exit | Left in `TMPDIR` right after | Hang spec's Neovim | |---|---|---|---| | `main` | 143 at once | 2 temp files | runs on until its timeout (39 s) | | this branch | 143 at once | nothing (only Neovim's own folder) | killed at once, nothing recreated at the end | The trap without the process group kill left a recreated state folder in `TMPDIR` after the hang Neovim ended. Gate: `mise run clean && mise run all` exit 0 (seed 1794435649, 1661 passed, 0 failed, 22 pending). `actionlint` and `shellcheck` pass. The whole runner on Neovim 0.12.3 gives 316 passed, 0 failed, with rows identical to `main` at the branch base. Merged with current `main` (which adds the 3 rows of coder#529's spec), it gives 319 passed on 0.12.3 and 232 passed plus 8 pending on v0.8.0, with rows identical to `main`. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
…oder#534) Comment-only change in `lua/claudecode/terminal/snacks.lua`. No behavior changes. The comment above `instance.opts.bo = {}` in `wrap_terminal` said that "the window options that the terminal started with (an older version's, built from the config)" can hold `bo`. That was true before coder#526. coder#526 removed the `window.bo = nil` store from `M.open`, so a start of this version now stores the `bo` of its instance too. I checked it with real snacks.nvim. After `:ClaudeCode` with the snacks provider, `vim.b[buf].claudecode_snacks_window` holds about a dozen window options. The two versions differ only by `bo`: - on `c9e57d1` (before coder#526): no `bo` key - on `3a0bb76` (coder#526 merged): `bo = { filetype = "claudecode" }` The comment now names both sources: a start of this version stores the `bo` of its instance, and an older version's options are built from the config. The reset itself stays, for the same reason as before: Snacks sets `bo` on the buffer again on every `VimResized`, which would fire `FileType` again. ## Validation - `busted tests`: 1509 successes, 0 failures, 0 errors (24 pending). - Integration runner: 331 passed on Neovim 0.12.3, and 244 passed on the 0.8-era build, 0 failures. - One earlier full run on the 0.8-era build printed `FAILED: diff_failed_setup_guards_spec.lua: no plenary summary (nvim exit 0)`. That spec is from coder#529 and this PR does not touch it. It passed 3 of 3 alone on this branch, 2 of 2 alone on a clean `origin/main`, and in a full rerun (244 passed). I did not find the cause of the one-time failure. - `stylua --check lua tests`, `luacheck lua/ tests/`, `treefmt --ci`: clean. - `verify-diff-lifecycle/check.sh`: the lock read STALE because `snacks.lua` is covered as a file. Only the `file` line changed, and no model block did. I re-recorded the lock, and the check passes. ## Notes for the reviewer - `verify-terminal-lifecycle` (coder#525) hashes `snacks.lua` too. coder#525 merges `main` and re-records its `covered.lock` after this PR merges. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
Why
The goal of this run is to land a code-shape refactor of the plugin's Lua code on main in small PRs, fixes first. The refactor of
lua/claudecode/diff.luais next. It must keep one behavior. The setup of anopenDiffcall can fail in a new tab (diff_opts.open_in_new_tab) while a handler of the user raises. Main then answersDiff setup failed, closes the new tab, and puts the cursor back in the tab it left. If the refactor loses this, the user keeps an empty extra tab and Claude gets the handler's error text instead ofDiff setup failed.A unit test on the mock vim already pins the tab close and the return to the user's tab for an early setup failure. It is the test "does not strand a tab when setup errors before the diff state is registered" in
tests/unit/diff_new_tab_strand_spec.lua. What is new here is the same behavior in real Neovim, with a handler of the user that raises during the cleanup.PR #498 added a cleanup for failed setups. It is closed without a merge. Review found that its cleanup could close a window that a handler of the user had opened. Three of its tests do not test that cleanup. They pin what main already does. This PR lands those three tests. It changes no plugin code.
What changed
tests/integration/diff_failed_setup_guards_spec.luahas three real-Neovim tests from fix(diff): remove what a failed openDiff setup leaves behind #498. Each one asserts three things: the answer is-32000withDiff setup failed, the tab list is the same as before the call, and the current tab is the tab it left. They differ in the handler that raises:WinClosedhandler raises. The setup fails because aBufWinEnterhandler wiped the proposed buffer.WinLeavehandler raises during the cleanup. The setup fails because aBufWinEnterhandler raised.BufLeavehandler raises during the cleanup. The setup fails the same way.AGENTS.mdgets a new## Code Shapesection with one rule for window cleanup. A later PR of this run adds the rest of the section. The verifier found three problems in the first text of the rule, and the last commit fixes them. A close withoutforcedoes not refuse for abuftype=nofilebuffer, so the rule no longer promises that it keeps unsaved work. "Close such a window" now says a window that the plugin made. The rule now says that deleting a buffer can close each window that shows it.I changed the copies from #498 in three ways:
(NEW FILE)buffer. Issue A failed openDiff setup leaves its split window, buffer and diff mode behind #528 records those as defects of main.:tabclosealone lands in the tab it left, and a mutant that drops the plugin's own step back survives.Invalid buffer idare gone. These tests do not need the hook, and the cause text is a message of Neovim that a refactor can change.How I proved it
Base: main at
c9e57d13.git diff --stat origin/main -- lua plugin scriptsprints nothing.Pass on main.
Success: 3,Failed : 0,Errors : 0on Neovim 0.12.3 and on v0.8.0.Handlers fire. An instrumented copy of the spec counts the raises in the cleanup on both versions:
WinClosed1,WinLeave3,BufLeave3.Red proofs. Each mutant below changes a scratch copy of
lua/claudecode/diff.luain the failed-setup branch of_setup_blocking_diff. No mutant is committed. Each cell is the same on Neovim 0.12.3 and on v0.8.0.redmeans the test fails.WinClosedhandlerWinLeavehandlerBufLeavehandlerM1_no_tabclose: drop:tabcloseof the new tabM2_no_refocus: drop the return to the tab it leftM3_unprotected_tabclose:vim.cmd("tabclose")withoutpcallDiff setup failedM5_unprotected_refocus: the return to the tab it left withoutpcallDiff setup failedM6_other_answer: the answer message isError setting up diffDiff setup failedM5_unprotected_refocusstays green for theWinClosedtest on purpose. The return to the tab it left closes no window, so theWinClosedhandler does not run there. I dropped a mutantM4that makes the switch into the new tab unprotected. That switch is a no-op because the new tab is already current, soM4can never turn a test red.Stability. 20 runs in a row, each in a fresh Neovim: 20 of 20 pass on Neovim 0.12.3, and 20 of 20 pass on v0.8.0. No run printed an assertion or a crash.
Leaked stubs. I read
tests/unit/diff_buffer_cleanup_spec.luaon main. It has nofinallycall. Itsbefore_eachrebuilds every stub and clears the four failure switches. A stub of one test cannot reach the next. The file passes with 30 shuffled seeds (1 to 30). I changed nothing there.Gates. The full gates below ran on
86f5c7a3. The last commit2ad1ea5fchanges one line ofAGENTS.mdand nothing else. After it,mise run format-check,mise run checkandcheck.sh --hash-onlypass again. CI runs the rest on the new head.mise run format-check: 350 files, 0 changed.mise run check: 0 warnings, 0 errors in 177 files.mise run test(seed 1794430444): 1655 successes, 0 failures, 0 errors, 23 pending. Main gives 1655, 0, 0 and 22 pending. The extra pending is the placeholder of the new spec under the mock vim.scripts/run_integration_tests_individually.sh: Neovim 0.12.3 gives 319 successes, 0 failed, 0 errors. v0.8.0 gives 232 successes, 0 failed, 0 errors. Each ran once, with no retry.check.sh --hash-only:covered.lock matches the code. This PR does not changecovered.lock.One result line per mutant and Neovim version
Limits
(NEW FILE)buffer and a window in diff mode behind. Issue A failed openDiff setup leaves its split window, buffer and diff mode behind #528 records that. This PR does not fix it.Error in command line..WinLeave Autocommands for "*":and thenLua callback: .... Neovim v0.8.0 printsError detected while processing command line..andError executing lua callback: .... They are not failures.NVIM v0.8.0-1210-gd367ed9b2for--version.Refs #528
Generated with
xum• Model:anthropic:claude-sonnet-5-5• Thinking:xhigh