Upgrade known clipboard providers with backups and package version guard
This commit is contained in:
1 parent
7270ee5021
commit
90f0054658
6 files changed
+734
-46
No files matched your search
@@ -1,52 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||
|
||||
test_home=$(mktemp -d)
|
||||
trap 'rm -rf "$test_home"' EXIT
|
||||
provider="$test_home/.config/nvim/lua/config/remote_clipboard.lua"
|
||||
migration="$ROOT/migrations/1788996284.sh"
|
||||
mkdir -p "$(dirname "$provider")" "$test_home/bin"
|
||||
# Redirect only the packaged source path; run the actual migration logic.
|
||||
sed "s@/usr/share/omarchy-nvim/config/lua/config/remote_clipboard.lua@$test_home/package.lua@" \
|
||||
"$ROOT/migrations/1788996284.sh" >"$test_home/migration.sh"
|
||||
printf '%s\n' '-- corrected packaged provider' >"$test_home/package.lua"
|
||||
cat >"$test_home/bin/pacman" <<'STUB'
|
||||
#!/bin/bash
|
||||
[[ $* == '-Q omarchy-nvim' ]] || exit 1
|
||||
printf 'omarchy-nvim %s\n' "${TEST_NVIM_VERSION:-2026.8.13-2}"
|
||||
STUB
|
||||
chmod +x "$test_home/bin/pacman"
|
||||
run_migration() {
|
||||
env HOME="$test_home" PATH="$test_home/bin:$PATH" bash -euo pipefail "$test_home/migration.sh"
|
||||
}
|
||||
|
||||
env HOME="$test_home" bash -euo pipefail "$migration"
|
||||
[[ ! -e $provider ]] || fail "missing Neovim config is left alone"
|
||||
pass "missing Neovim config is left alone"
|
||||
run_migration
|
||||
[[ ! -e $provider ]] || fail "missing provider is left alone"
|
||||
pass "missing provider is left alone"
|
||||
|
||||
mkdir -p "$(dirname "$provider")"
|
||||
printf '%s\n' '-- Custom provider' >"$provider"
|
||||
cp "$provider" "$test_home/before.lua"
|
||||
env HOME="$test_home" bash -euo pipefail "$migration"
|
||||
cmp "$provider" "$test_home/before.lua" || fail "custom provider is preserved"
|
||||
pass "custom provider is preserved"
|
||||
for fixture in "$SHELL_TEST_DIR/fixtures/neovim-clipboard/"*.lua; do
|
||||
cp "$fixture" "$provider"
|
||||
run_migration
|
||||
cmp "$provider" "$test_home/package.lua" || fail "known provider is upgraded: $fixture"
|
||||
backup=$(ls -t "$provider".bak.* | head -n1)
|
||||
cmp "$backup" "$fixture" || fail "known provider is backed up: $fixture"
|
||||
[[ $(stat -c %a "$provider") == "644" ]] || fail "provider is mode 0644"
|
||||
before=$(ls "$provider".bak.*)
|
||||
run_migration
|
||||
[[ $(ls "$provider".bak.*) == "$before" ]] || fail "repeat migration does not create backups"
|
||||
pass "known provider is backed up and upgraded idempotently: ${fixture##*/}"
|
||||
done
|
||||
|
||||
cat >"$provider" <<'LUA'
|
||||
local M = {}
|
||||
function M.setup()
|
||||
if not vim.env.SSH_CONNECTION then
|
||||
return
|
||||
end
|
||||
vim.g.clipboard = {
|
||||
name = "OmarchyRemoteClipboard",
|
||||
}
|
||||
end
|
||||
return M
|
||||
LUA
|
||||
env HOME="$test_home" bash -euo pipefail "$migration"
|
||||
require_command nvim
|
||||
cat >"$test_home/check.lua" <<'LUA'
|
||||
vim.env.SSH_CONNECTION = nil
|
||||
vim.opt.clipboard = ""
|
||||
dofile(vim.env.TEST_PROVIDER).setup()
|
||||
assert(vim.o.clipboard == "")
|
||||
vim.env.SSH_CONNECTION = "test"
|
||||
dofile(vim.env.TEST_PROVIDER).setup()
|
||||
assert(vim.o.clipboard == "unnamedplus")
|
||||
LUA
|
||||
env NVIM_LOG_FILE="$test_home/nvim.log" TEST_PROVIDER="$provider" nvim --clean -n --headless -i NONE -l "$test_home/check.lua"
|
||||
pass "clipboard syncing is enabled inside remote provider setup"
|
||||
cp "$SHELL_TEST_DIR/fixtures/neovim-clipboard/july.lua" "$provider"
|
||||
printf '%s\n' '-- user customization' >>"$provider"
|
||||
cp "$provider" "$test_home/custom.lua"
|
||||
run_migration >"$test_home/output"
|
||||
cmp "$provider" "$test_home/custom.lua" || fail "customized provider is preserved"
|
||||
grep -q 'Preserving customized' "$test_home/output" || fail "customized provider receives guidance"
|
||||
printf '%s\n' '-- unrelated provider' >"$provider"
|
||||
cp "$provider" "$test_home/custom.lua"
|
||||
run_migration
|
||||
cmp "$provider" "$test_home/custom.lua" || fail "unrelated provider is preserved"
|
||||
pass "customized and unrelated providers are preserved"
|
||||
|
||||
cp "$provider" "$test_home/once.lua"
|
||||
env HOME="$test_home" bash -euo pipefail "$migration"
|
||||
cmp "$provider" "$test_home/once.lua" || fail "migration is idempotent"
|
||||
pass "migration is idempotent"
|
||||
cp "$SHELL_TEST_DIR/fixtures/neovim-clipboard/june.lua" "$provider"
|
||||
export TEST_NVIM_VERSION=2026.8.13-1
|
||||
if run_migration; then fail "old package leaves migration pending"; fi
|
||||
cmp "$provider" "$SHELL_TEST_DIR/fixtures/neovim-clipboard/june.lua" || fail "old package leaves provider unchanged"
|
||||
unset TEST_NVIM_VERSION
|
||||
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"
|
||||
Reference in new issue
Block a user