diff --git a/.tests/fakebin/_fake b/.tests/fakebin/_fake index e3ee3f0..cc0abab 100755 --- a/.tests/fakebin/_fake +++ b/.tests/fakebin/_fake @@ -157,6 +157,22 @@ herdr) integration:install) [ "$mode" = install ] && exit 1 ;; esac exit 0 ;; +nvim) + # Behaves like lazy.nvim's first start: a plain boot creates the plugin + # directory and REWRITES lazy-lock.json with drifted commits, which is the + # bug the installer's first-boot step exists to undo. `+Lazy! restore` + # records the lockfile it was handed in ~/.nvim-restored-from. Injections: + # FAKE_FAIL=nvim:boot and FAKE_FAIL=nvim:restore. + _lock=${XDG_CONFIG_HOME:-$HOME/.config}/nvim/lazy-lock.json + case "$*" in + *'Lazy! restore'*) + [ "$mode" = restore ] && exit 1 + cp "$_lock" "$HOME/.nvim-restored-from"; exit 0 ;; + esac + mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lazy/lazy.nvim" + [ -f "$_lock" ] && printf '{ "drifted": "tip" }\n' > "$_lock" + [ "$mode" = boot ] && exit 1 + exit 0 ;; fzf) # The picker's own fzf, and the only fake here whose ARGV is the thing # under test. `--bind` strings are built across a dozen continued lines, so diff --git a/.tests/mutations/35-nvim-restore-against-rewritten-lock.mut b/.tests/mutations/35-nvim-restore-against-rewritten-lock.mut new file mode 100644 index 0000000..4a72449 --- /dev/null +++ b/.tests/mutations/35-nvim-restore-against-rewritten-lock.mut @@ -0,0 +1,8 @@ +# what: nvim's first boot no longer puts the seeded lazy-lock.json back +# why: restore then pins to the tips the boot just wrote, and the pins are lost +# kills: …against the SEEDED lockfile, not the one the boot rewrote +# run: unit +<< "$SB/.config/nvim/lazy-lock.json" +} +newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal +seedlock; pick core/ripgrep +out=$(box install 2>&1 | plain || true) +is "a fresh box boots nvim, then restores" "boot restore" \ + "$(awk '$1=="nvim" {print (/Lazy! restore/ ? "restore" : "boot")}' "$LOG" | tr '\n' ' ' | sed 's/ $//')" +is "…against the SEEDED lockfile, not the one the boot rewrote" '{ "plugin": "pinned" }' \ + "$(cat "$SB/.nvim-restored-from" 2>/dev/null)" +is "…and leaves the seed in place" '{ "plugin": "pinned" }' \ + "$(cat "$SB/.config/nvim/lazy-lock.json")" +: > "$LOG"; out=$(box install 2>&1 | plain || true) +is "a second run starts no nvim" "0" "$(grep -c '^nvim ' "$LOG" || true)" +hasnt "…and prints no nvim section" "pinned to lazy-lock.json" "$out" +newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal +printf '{ "plugin": "updated-by-user" }\n' > "$SB/lock.user" +seedlock; cp "$SB/lock.user" "$SB/.config/nvim/lazy-lock.json" +mkdir -p "$SB/.local/share/nvim/lazy/lazy.nvim"; pick core/ripgrep +box install >/dev/null 2>&1 || true +is "a lockfile lazy already manages is left alone" "$(cat "$SB/lock.user")" \ + "$(cat "$SB/.config/nvim/lazy-lock.json")" +is "…and nvim is not started" "0" "$(grep -c '^nvim ' "$LOG" || true)" +newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal; pick core/ripgrep +box install >/dev/null 2>&1 || true +is "with no nvim config there is nothing to pin" "0" "$(grep -c '^nvim ' "$LOG" || true)" +newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal +seedlock; pick core/ripgrep; BOXENV='FAKE_FAIL=nvim:restore' +rc=0; box install >"$SB/out" 2>&1 || rc=$?; out=$(plain < "$SB/out") +has "a failed restore says how to retry" "nvim --headless '+Lazy! restore' +qa" "$out" +is "…without failing the install" "0" "$rc" +newbox; sh ./seal.sh "$SB/seal" --with nvim >/dev/null; BOXPATH=$SB/seal +seedlock; pick core/ripgrep; BOXENV='FAKE_FAIL=nvim:boot' +box install >/dev/null 2>&1 || true +is "a failed first boot still restores the seed" '{ "plugin": "pinned" }' \ + "$(cat "$SB/.nvim-restored-from" 2>/dev/null)" +newbox +if holed nvim; then + seedlock; pick core/ripgrep + hasnt "with no nvim the step says nothing" "lazy-lock" "$(box install 2>&1 | plain || true)" +else + printf ' \033[33mskip\033[0m nvim sits at an absolute path find_tool probes\n' +fi + printf '\n\033[1mclaude desktop trusts only Anthropic'"'"'s key\033[0m\n' # A vendor apt repository is a key apt will trust for root-installed packages, # so the key is checked against the published fingerprint before it is placed. diff --git a/dot_local/bin/executable_dotup b/dot_local/bin/executable_dotup index ed4a006..936f780 100755 --- a/dot_local/bin/executable_dotup +++ b/dot_local/bin/executable_dotup @@ -1219,6 +1219,44 @@ herdr_integrations() { done } +# nvim's first boot, done here so the lazy-lock.json pins survive it. +# +# The config seeds lazy-lock.json (a create_ file). On a first start lazy.nvim +# installs most plugins at their pins, but the ones that join in a later +# bootstrap round (claudecode, mini.*, nvim-lint, friendly-snippets, ...) are +# cloned at branch tip, and lazy then rewrites the lockfile with the tips. The +# pins are gone after the one boot meant to honor them. So the installer does +# that boot headless, puts the seeded lockfile back, and `Lazy! restore`s every +# plugin to it. +# +# The gate is "lazy has never installed a plugin here": no plugin directory. +# That is also what proves the lockfile on disk is the seed (or one written by +# hand), never one lazy rewrote. A lockfile moved on by `:Lazy update` sits +# beside a plugin directory and is left alone. The directory this step creates +# is its own stamp, so a second run does nothing. +nvim_first_boot() { + have nvim || return 0 + nb_lock=${XDG_CONFIG_HOME:-$HOME/.config}/nvim/lazy-lock.json + nb_lazy=${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lazy + [ -f "$nb_lock" ] || return 0 + [ ! -e "$nb_lazy" ] || return 0 + NVIM=$(find_tool nvim) + workdir || return 0 + nb_seed=$WORKDIR/lazy-lock.seed.json nb_log=$WORKDIR/nvim-first-boot.log + head_ "nvim plugins, pinned to lazy-lock.json" + run_sh "cp '$nb_lock' '$nb_seed'" || { warn "could not save the seeded lazy-lock.json"; return 0; } + if ! run_sh "'$NVIM' --headless +qa '$nb_log' 2>&1"; then + warn "nvim's first boot failed -- restoring the pins anyway" + [ -r "$nb_log" ] && tail -n 20 "$nb_log" >&2 + fi + run_sh "cp '$nb_seed' '$nb_lock'" || { warn "could not put the seeded lazy-lock.json back"; return 0; } + run_sh "'$NVIM' --headless '+Lazy! restore' +qa '$nb_log' 2>&1" && return 0 + warn "Lazy! restore failed -- plugins may not match lazy-lock.json. Retry with:" + warn " nvim --headless '+Lazy! restore' +qa" + [ -r "$nb_log" ] && tail -n 20 "$nb_log" >&2 + return 0 +} + cmd_install() { # A cron job re-running `--unattended install` gets its SAVED selection -- # that contract stands. But on a box where nothing was ever chosen, @@ -1279,6 +1317,7 @@ cmd_install() { install_npm "$(col npm)" install_uv "$(col uv)" herdr_integrations + nvim_first_boot rm -f "$tbl" if [ -s "$FAILED" ]; then