Replace Neovim providers atomically and preserve dotfile links

This commit is contained in:
Ryan Hughes committed 2026-09-13 19:48:41 -04:00
1 parent 90f0054658
commit 905ff1f792
2 files changed
+69 -1

No files matched your search

+51
View File
@@ -58,3 +58,54 @@ mv "$test_home/package.lua" "$test_home/package.saved"
if run_migration; then fail "missing package source leaves migration pending"; fi
cmp "$provider" "$SHELL_TEST_DIR/fixtures/neovim-clipboard/june.lua" || fail "missing source leaves provider unchanged"
pass "old or missing package cannot mark an unrepaired provider complete"
mv "$test_home/package.saved" "$test_home/package.lua"
# A write that fails after producing partial output must never damage the live
# provider. Exercise the real install destination with a failing replacement.
cat >"$test_home/bin/install" <<'STUB'
#!/bin/bash
printf '%s' '-- truncated replacement' >"${@: -1}"
exit 1
STUB
chmod +x "$test_home/bin/install"
if run_migration; then fail "failed staging write leaves migration pending"; fi
cmp "$provider" "$SHELL_TEST_DIR/fixtures/neovim-clipboard/june.lua" || fail "failed write preserves live provider"
if compgen -G "$provider.new.*" >/dev/null; then fail "failed staging file is cleaned up"; fi
rm "$test_home/bin/install"
run_migration
cmp "$provider" "$test_home/package.lua" || fail "retry repairs the recognized original"
pass "failed write preserves original and retry succeeds"
# Also fail the final rename, after successful staging.
cp "$SHELL_TEST_DIR/fixtures/neovim-clipboard/july.lua" "$provider"
printf '#!/bin/bash\nexit 1\n' >"$test_home/bin/mv"
chmod +x "$test_home/bin/mv"
if run_migration; then fail "failed rename leaves migration pending"; fi
cmp "$provider" "$SHELL_TEST_DIR/fixtures/neovim-clipboard/july.lua" || fail "failed rename preserves original"
if compgen -G "$provider.new.*" >/dev/null; then fail "failed rename staging file is cleaned up"; fi
rm "$test_home/bin/mv"
run_migration
cmp "$provider" "$test_home/package.lua" || fail "retry after rename failure succeeds"
pass "failed rename preserves original and retry succeeds"
cp "$SHELL_TEST_DIR/fixtures/neovim-clipboard/july.lua" "$test_home/dotfile.lua"
rm "$provider"
ln -s "$test_home/dotfile.lua" "$provider"
run_migration >"$test_home/output"
[[ -L $provider ]] || fail "provider symlink is preserved"
cmp "$test_home/dotfile.lua" "$SHELL_TEST_DIR/fixtures/neovim-clipboard/july.lua" || fail "symlink target is preserved"
grep -q 'symlink-managed' "$test_home/output" || fail "linked provider receives guidance"
rm "$provider"
ln -s "$test_home/absent.lua" "$provider"
run_migration
[[ -L $provider && ! -e $provider ]] || fail "dangling symlink is preserved"
rm "$provider"
mkdir "$test_home/dotfiles"
mv "$test_home/.config/nvim/lua/config" "$test_home/dotfiles/config"
ln -s "$test_home/dotfiles/config" "$test_home/.config/nvim/lua/config"
cp "$SHELL_TEST_DIR/fixtures/neovim-clipboard/july.lua" "$provider"
run_migration
[[ -L $test_home/.config/nvim/lua/config ]] || fail "linked config directory is preserved"
cmp "$provider" "$SHELL_TEST_DIR/fixtures/neovim-clipboard/july.lua" || fail "provider in linked directory is preserved"
pass "linked files, dangling links and linked directories are preserved"