dev: start-* launchers always start from a clean setup
CI / cargo fmt --check (push) Successful in 18s
CI / cargo clippy (push) Successful in 31s
CI / cargo test (push) Successful in 27s
CI / editor keymaps (push) Successful in 1m24s

The launchers reused whatever was left under $XDG_CACHE_HOME/nuwiki-dev
between runs — seed_wiki() skipped reseeding when index.wiki already
existed, so stale edits from a previous session leaked into the next, and
old swap/viminfo/coc state carried over.

Each launch now starts clean:
- seed_wiki() reseeds the managed scratch wiki from a pristine copy every
  run (rm -rf + write_sample_wiki). A user-pointed NUWIKI_DEV_WIKI is never
  wiped — it's seeded only when empty, so a real wiki is never clobbered.
  NUWIKI_DEV_NO_SEED still bypasses seeding entirely.
- new reset_dirs() helper wipes + recreates each launcher's owned state dirs
  (vim viminfo/swap/undo, coc data, nvim XDG state/data/config) before launch.

Cached plugin clones (vim-lsp, async.vim, coc.nvim) are kept — only the
wiki and editor state are reset. Header docs updated to describe the
fresh-each-launch behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 15:07:15 +00:00
parent 6983daa637
commit 39692ba99f
4 changed files with 47 additions and 6 deletions
+29 -5
View File
@@ -12,7 +12,10 @@
# log — prefixed status line
# ensure_binary — build + symlink nuwiki-ls
# write_sample_wiki DIR — lay down the feature-showcase wiki
# seed_wiki — seed WIKI_DIR (respects NUWIKI_DEV_NO_SEED)
# reset_dirs DIR... — wipe + recreate owned state dirs
# seed_wiki — (re)seed WIKI_DIR fresh each run; never
# touches a user-supplied NUWIKI_DEV_WIKI;
# respects NUWIKI_DEV_NO_SEED
# Resolve paths relative to this file so it works regardless of which
# launcher sources it.
@@ -261,16 +264,37 @@ A diary entry. Back to [[diary]].
EOF
}
# reset_dirs DIR... — wipe and recreate each dir so a launch always starts
# from clean editor state (swap/undo/viminfo, coc data, nvim XDG dirs). Only
# ever called on dirs the launchers own under $DEV_DIR.
reset_dirs() {
local d
for d in "$@"; do
rm -rf "$d"
mkdir -p "$d"
done
}
seed_wiki() {
if [[ "${NUWIKI_DEV_NO_SEED:-0}" == "1" ]]; then
log "NUWIKI_DEV_NO_SEED=1 — skipping wiki seed (using $WIKI_DIR as-is)"
return
fi
mkdir -p "$WIKI_DIR" "$WIKI_DIR/diary"
# Seed the whole showcase as a unit; skip when an index already exists
# so a re-run never clobbers edits made while testing.
if [[ -f "$WIKI_DIR/index.wiki" ]]; then
# A user-pointed wiki (NUWIKI_DEV_WIKI) is never wiped — it might be a real
# wiki. Seed the sample only when it has no index yet, so we don't clobber it.
if [[ -n "${NUWIKI_DEV_WIKI:-}" ]]; then
mkdir -p "$WIKI_DIR" "$WIKI_DIR/diary"
if [[ -f "$WIKI_DIR/index.wiki" ]]; then
log "using existing wiki at $WIKI_DIR (left untouched)"
return
fi
write_sample_wiki "$WIKI_DIR"
return
fi
# Managed scratch wiki under the dev cache: always start from a pristine
# copy so stale edits from a previous run never leak into the next.
log "reseeding scratch wiki (fresh copy): $WIKI_DIR"
rm -rf "$WIKI_DIR"
mkdir -p "$WIKI_DIR" "$WIKI_DIR/diary"
write_sample_wiki "$WIKI_DIR"
}