Files
coredesktop/tests/neovim.bats
T
davidandClaude Opus 5.5 902967f111 Sync Neovim's plugins once more if Neovim crashes
Neovim 0.12.6 segfaulted on the way out after a finished Lazy! sync
(report CD-P8RUBS), and the update step failed though the plugins were
up to date. If nvim dies from a signal, run the sync once more; it
fails if Neovim crashes again, and an ordinary failure isn't retried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 06:10:38 -07:00

102 lines
2.7 KiB
Bash

#!/usr/bin/env bats
load test_helper
# updates.d/46-neovim.sh, with real git repositories standing in for the
# plugins lazy.nvim cloned
setup() {
common_setup
export XDG_DATA_HOME="$HOME/.local/share" XDG_STATE_HOME="$HOME/.local/state"
LAZY="$XDG_DATA_HOME/nvim/lazy"
BACKUPS="$XDG_STATE_HOME/coredesktop/nvim-plugins"
mkdir -p "$LAZY"
export GIT_AUTHOR_NAME=test GIT_AUTHOR_EMAIL=test@example.com
export GIT_COMMITTER_NAME=test GIT_COMMITTER_EMAIL=test@example.com
stub nvim
}
# plugin NAME: a plugin checkout with one committed file
plugin() {
git init -q "$LAZY/$1"
echo original > "$LAZY/$1/README.md"
git -C "$LAZY/$1" add README.md
git -C "$LAZY/$1" commit -q -m initial
}
update_neovim() {
source "$REPO/updates.d/46-neovim.sh"
run_update
}
@test "a plugin whose files don't match its checkout is set aside to be installed again" {
plugin LuaSnip
echo changed > "$LAZY/LuaSnip/README.md"
mkdir "$LAZY/LuaSnip/data"
echo leftover > "$LAZY/LuaSnip/data/new.md"
run update_neovim
[ "$status" -eq 0 ]
[[ "$output" == *"LuaSnip's files didn't match its version"* ]]
[ ! -e "$LAZY/LuaSnip" ]
# The old copy, edits and all, is kept
copies=("$BACKUPS"/LuaSnip-*)
[ "${#copies[@]}" -eq 1 ]
[ "$(cat "${copies[0]}/README.md")" = changed ]
[ -f "${copies[0]}/data/new.md" ]
called nvim --headless "+Lazy! sync" +qa
}
@test "a plugin an earlier update only stashed is set aside too" {
plugin LuaSnip
echo changed > "$LAZY/LuaSnip/README.md"
git -C "$LAZY/LuaSnip" stash push -q -m "Stashed by CoreDesktop's update"
run update_neovim
[ "$status" -eq 0 ]
[ ! -e "$LAZY/LuaSnip" ]
[ -d "$(echo "$BACKUPS"/LuaSnip-*)" ]
}
@test "plugins that match their checkout are left as they are" {
plugin lazy.nvim
echo build output > "$LAZY/lazy.nvim/untracked.so"
echo changed > "$LAZY/lazy.nvim/README.md"
git -C "$LAZY/lazy.nvim" stash push -q -m "the user's own stash"
run update_neovim
[ "$status" -eq 0 ]
[[ "$output" != *"didn't match"* ]]
[ -f "$LAZY/lazy.nvim/untracked.so" ]
[ ! -e "$BACKUPS" ]
}
@test "a sync that crashes Neovim is run once more" {
plugin lazy.nvim
# Crash the first time only
stub nvim '[ -e "$HOME/crashed" ] && exit 0; touch "$HOME/crashed"; exit 139'
run update_neovim
[ "$status" -eq 0 ]
[[ "$output" == *"Neovim crashed (signal 11)"* ]]
[ "$(grep -c '^nvim ' "$STUB_LOG")" -eq 2 ]
}
@test "a sync that crashes Neovim twice fails" {
plugin lazy.nvim
stub nvim 'exit 139'
run update_neovim
[ "$status" -eq 139 ]
[ "$(grep -c '^nvim ' "$STUB_LOG")" -eq 2 ]
}
@test "a sync that fails without crashing isn't run again" {
plugin lazy.nvim
stub nvim 'exit 1'
run update_neovim
[ "$status" -eq 1 ]
[ "$(grep -c '^nvim ' "$STUB_LOG")" -eq 1 ]
}