Files
nuwiki/development/tests/test-keymaps.sh
T
gffranco cb11889e72
CI / cargo clippy (pull_request) Failing after 42s
CI / cargo fmt --check (pull_request) Failing after 45s
CI / cargo test (pull_request) Failing after 49s
CI / editor keymaps (pull_request) Has been skipped
Remove Rust code, delegate server to nuwiki-rs repo
Delete all Rust crates (crates/) and Cargo files. The nuwiki-ls binary
is now built in the separate nuwiki-rs repository and downloaded at
install time from the Gitea release assets, with a cargo build fallback
that clones nuwiki-rs.

Update all documentation to reflect the split repo layout.
2026-06-24 12:57:15 +00:00

97 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# development/tests/test-keymaps.sh — drive development/tests/test-keymaps.lua under
# headless Neovim and report pass/fail per buffer-local keymap.
#
# The Lua harness needs a real LSP attachment (most keymaps dispatch
# `workspace/executeCommand`), so we:
# 1. download `bin/nuwiki-ls` from the nuwiki-rs releases,
# 2. spin up a scratch wiki under a temp dir,
# 3. invoke `nvim --headless` with a minimal init that loads the
# plugin + calls `setup()`, then sources the harness Lua.
#
# Exit code mirrors the harness: 0 on green, 1 on any failure.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
TMP="$(mktemp -d -t nuwiki-keymap-test-XXXXXX)"
trap 'rm -rf "$TMP"' EXIT
log() { printf '\033[1;34m[keymap-test]\033[0m %s\n' "$*"; }
# Download the LSP binary from nuwiki-rs releases (falls back to cargo build).
BIN="$REPO_ROOT/bin/nuwiki-ls"
log 'downloading nuwiki-ls…'
if [[ ! -x "$BIN" ]]; then
vim -e -s -c "source $REPO_ROOT/scripts/download_bin.vim" -c "q" >/dev/null 2>&1 || true
fi
# If download failed, fall back to cargo build from nuwiki-rs.
if [[ ! -x "$BIN" ]]; then
log "download failed, falling back to cargo build from nuwiki-rs…"
rs_repo="$REPO_ROOT/nuwiki-rs"
if [[ ! -f "$rs_repo/Cargo.toml" ]]; then
log "cloning nuwiki-rs …"
git clone --depth 1 https://code.gfran.co/gffranco/nuwiki-rs.git "$rs_repo"
fi
cargo build --release -p nuwiki-ls --manifest-path "$rs_repo/Cargo.toml" >/dev/null
if [[ ! -f "$rs_repo/target/release/nuwiki-ls" ]]; then
echo 'FAIL: could not build nuwiki-ls binary' >&2
exit 1
fi
mkdir -p "$REPO_ROOT/bin"
ln -sf "$rs_repo/target/release/nuwiki-ls" "$BIN"
fi
if [[ ! -x "$BIN" ]]; then
echo 'FAIL: could not obtain nuwiki-ls binary' >&2
exit 1
fi
mkdir -p "$TMP/wiki"
echo "= seed =" > "$TMP/wiki/index.wiki"
INIT="$TMP/init.lua"
cat > "$INIT" <<EOF
-- Keep the harness self-contained; no plugin manager required.
vim.opt.runtimepath:prepend('$REPO_ROOT')
vim.g.nuwiki_binary_path = '$BIN'
-- Enable the opt-in mouse mappings so the harness can assert the full
-- documented mapping surface (doc §6 mouse group). table_auto_fmt is off here
-- so its async on-InsertLeave re-align doesn't perturb the deterministic
-- table-nav keystroke cases (its wiring is verified on a scratch buffer).
require('nuwiki').setup({
wiki_root = '$TMP/wiki',
mappings = { mouse = true },
table_auto_fmt = false,
})
EOF
RESULTS="$TMP/results.txt"
log "running harness…"
# `nvim --headless -u init.lua FILE +luafile …` — the harness's
# `vim.defer_fn` lets the LSP attach before tests fire, then writes
# the results file and exits. Output path is plumbed through env.
# Wrapped in `timeout` so a hung LSP / harness fails fast instead of
# stalling CI runners indefinitely.
NUWIKI_KEYMAP_RESULTS="$RESULTS" \
timeout 60 nvim --clean -u "$INIT" --headless "$TMP/wiki/index.wiki" \
-c "luafile $REPO_ROOT/development/tests/test-keymaps.lua" \
>"$TMP/nvim.log" 2>&1 || true
if [[ ! -f "$RESULTS" ]]; then
echo 'keymap test harness produced no output' >&2
echo '--- nvim log ---' >&2
cat "$TMP/nvim.log" >&2 || true
exit 1
fi
cat "$RESULTS"
if grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS"; then
exit 0
fi
exit 1