Files
LLeMbas-IDE/scripts/test-ide.sh
T
HomerandClaude Opus 5.5 97d3f8bbba LLeMbas IDE: one rule for where the CLI is, its installer checked, honest doctor and start screen
- The CLI is found where the plugin finds it (require("llembas").cli(): PATH, then
  ~/.local/bin); the installer and the launcher keep the same find_cli in shell, and
  scripts/test-ide.sh fails when the two shell copies differ or disagree with the plugin. A CLI
  in ~/.local/bin that is not on PATH (right after a first install) is no longer "not installed".
- The CLI's get.sh is taken from a CLI release (the newest of the channel, or
  LLEMBAS_IDE_CLI_VERSION) and run only after that release's SHA256SUMS is verified with the
  release key and get.sh matches it; LEMBAS_REF names that release.
- curl … | bash -s -- --help prints the help (it is a here-document now); it names ssh-keygen.
- The start screen says a sign-in is needed only when there is none.
- doctor and an update see files added to a plugin, not only changed ones; doctor accepts the
  start as the installer does, says when plugins.lock is missing, checks ssh-keygen, and counts
  "1 check failed" / "N checks failed".
- A release archive that holds a link is refused; newest_tag keeps redirects on https.
- The README key table says where a chord also works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 07:52:31 +00:00

555 lines
37 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# The tests of the LLeMbas IDE distribution (ide/): the scripts, a dry run, real installs into
# temporary homes, a headless start checked from the inside, updating in place, failing without
# leaving anything half-done, and uninstalling.
#
# scripts/test-ide.sh everything: also downloads the pinned Neovim (about 12 MB, its
# SHA-256 checked) and compiles the Treesitter grammars, twice
# scripts/test-ide.sh --quick no download and no compiling: the Neovim on this machine and
# its bundled grammars only
# scripts/test-ide.sh --update-readme rewrite the key table in ide/README.md from the key map
#
# Needs bash, git, curl, tar, shellcheck, python3 and a Neovim 0.10 or newer on PATH (or in
# IDE_TEST_NVIM): the oldest supported one is what the installed IDE is also run on.
# The plugins are fetched from GitHub at their pinned commits; LLEMBAS_IDE_GIT_MIRROR (a
# directory of clones) spares the network. Nothing is written outside a temporary directory,
# which is removed on every way out.
# shellcheck disable=SC2016 # the small scripts given to bash -c are single-quoted on purpose
set -euo pipefail
cd "$(dirname "$0")/.."
REPO="$PWD"
QUICK=0
case "${1:-}" in
--quick) QUICK=1 ;;
--update-readme)
# LLeMbas's own rows are read from the plugin's key table, so the plugin is on the path too.
nvim --headless -u NONE --cmd "set rtp+=ide/config" --cmd "set rtp+=nvim" \
-c 'lua io.stdout:write(table.concat(require("llembas_ide.keys").markdown(), "\n"))' -c q >ide/README.keys.tmp
python3 - <<'PY'
import re
from pathlib import Path
keys = Path("ide/README.keys.tmp").read_text(encoding="utf-8").strip()
readme = Path("ide/README.md")
text = readme.read_text(encoding="utf-8")
text = re.sub(r"<!-- keys:begin -->\n.*?<!-- keys:end -->", lambda _: "<!-- keys:begin -->\n" + keys + "\n<!-- keys:end -->", text, flags=re.S)
readme.write_text(text, encoding="utf-8")
PY
rm -f ide/README.keys.tmp
echo "test-ide: ide/README.md has the key map's table"
exit 0
;;
"") ;;
*) echo "test-ide: unknown option $1" >&2 && exit 2 ;;
esac
SYSTEM_NVIM="${IDE_TEST_NVIM:-$(command -v nvim || true)}"
[ -n "$SYSTEM_NVIM" ] || { echo "test-ide: needs a Neovim on PATH (or IDE_TEST_NVIM)" >&2 && exit 2; }
VERSION="$(tr -d '[:space:]' <VERSION)"
WORK="$(mktemp -d "${TMPDIR:-/tmp}/llembas-ide-test.XXXXXX")"
trap 'rm -rf "$WORK"' EXIT
PASSED=0
FAILED=0
ok() {
PASSED=$((PASSED + 1))
printf ' ok %s\n' "$1"
}
fail() {
FAILED=$((FAILED + 1))
printf ' FAIL %s\n' "$1"
[ -z "${2:-}" ] || printf '%s\n' "$2" | sed 's/^/ /' | tail -n 15
}
# check "name" command… passes when the command does
check() {
local name="$1" out
shift
if out="$("$@" 2>&1)"; then ok "$name"; else fail "$name" "$out"; fi
}
# attempt command… runs it; its output is in OUT and its exit status in RC
OUT=""
RC=0
attempt() {
if OUT="$("$@" 2>&1)"; then RC=0; else RC=$?; fi
}
passes() { if [ "$RC" = 0 ]; then ok "$1"; else fail "$1" "$OUT"; fi; }
refuses() { if [ "$RC" != 0 ]; then ok "$1"; else fail "$1" "$OUT"; fi; }
has() { grep -q -F -- "$2" <<<"$1"; }
expect() { # expect "name" "text" "needle"
if has "$2" "$3"; then ok "$1"; else fail "$1" "wanted: $3
$2"; fi
}
# PATH without any LLeMbas CLI of this machine: the tests decide whether there is one.
CLEAN_PATH=""
IFS=: read -r -a parts <<<"$PATH"
for d in "${parts[@]}"; do
if [ -n "$d" ] && [ ! -x "$d/lembas" ]; then CLEAN_PATH="${CLEAN_PATH:+$CLEAN_PATH:}$d"; fi
done
BG_DARK="$(sed -n '/data-theme="moria"/,/}/s/^ *--bg: *\(#[0-9A-Fa-f]*\);.*/\1/p' ide/tokens.css)"
BG_LIGHT="$(sed -n '/data-theme="shire"/,/}/s/^ *--bg: *\(#[0-9A-Fa-f]*\);.*/\1/p' ide/tokens.css)"
# Run something as a person whose home is $1, with nothing of this machine's environment.
as() {
local home="$1"
shift
env -i PATH="$home/.local/bin:${EXTRA_PATH:+$EXTRA_PATH:}$CLEAN_PATH" HOME="$home" TERM=dumb LANG=C.UTF-8 LLEMBAS_IDE_PUBKEY= \
${LLEMBAS_IDE_GIT_MIRROR:+LLEMBAS_IDE_GIT_MIRROR="$LLEMBAS_IDE_GIT_MIRROR"} "$@"
}
installer() { # installer <home> <options…>
local home="$1"
shift
as "$home" bash "$REPO/ide/install.sh" --no-cli "$@" 2>&1
}
# The headless checks, through the launcher. headless <home> <parsers 0|1> [VAR=value…]
headless() {
local home="$1" parsers="$2"
shift 2
(cd "$WORK" && as "$home" env IDE_TEST_REPO="$REPO" IDE_TEST_PARSERS="$parsers" IDE_TEST_BG_DARK="$BG_DARK" \
IDE_TEST_BG_LIGHT="$BG_LIGHT" "$@" timeout 120 "$home/.local/bin/llembas-ide" --headless \
-c "luafile $REPO/ide/tests/headless.lua" 2>&1)
}
typing() { # the completion menu, through the launcher
local home="$1" out
out="$( (cd "$WORK" && as "$home" timeout 60 "$home/.local/bin/llembas-ide" --headless -c "luafile $REPO/ide/tests/typing.lua" 2>&1) || true)"
if grep -q -F 'ide-typing: the menu opens' <<<"$out"; then ok "$2"; else fail "$2" "$out"; fi
}
# The four bars, on the installed IDE's own screen. layout <home> "name"
layout() {
local home="$1" out line
out="$( (cd "$WORK" && as "$home" env IDE_TEST_REPO="$REPO" timeout 420 "$home/.local/bin/llembas-ide" --headless \
-c "luafile $REPO/ide/tests/layout.lua" 2>&1) || true)"
line="$(grep -o -E 'ide-layout: [0-9]+ passed, 0 failed.*' <<<"$out" || true)"
if [ -n "$line" ]; then ok "$2: ${line#ide-layout: }"; else fail "$2" "$(grep -E '^(FAIL|ide-layout:)' <<<"$out" | cut -c1-600 || true)
$(tail -n 5 <<<"$out" | cut -c1-300)"; fi
}
report_headless() { # report_headless "name" "output"
local line
line="$(grep -o -E 'ide-headless: [0-9]+ passed, 0 failed.*' <<<"$2" || true)"
if [ -n "$line" ]; then ok "$1: ${line#ide-headless: }"; else fail "$1" "$(cut -c1-600 <<<"$2")"; fi
}
startup_ms() { # the best of three starts, in milliseconds
local home="$1" best="" ms i
for i in 1 2 3; do
rm -f "$WORK/startup.$i"
as "$home" "$home/.local/bin/llembas-ide" --headless --startuptime "$WORK/startup.$i" -c 'qa!' >/dev/null 2>&1 || true
ms="$(grep -F 'NVIM STARTED' "$WORK/startup.$i" 2>/dev/null | tail -n1 | awk '{ print $1 + 0 }')"
if [ -n "$ms" ] && { [ -z "$best" ] || awk -v a="$ms" -v b="$best" 'BEGIN { exit !(a < b) }'; }; then best="$ms"; fi
done
echo "${best:-?}"
}
files_in() { (cd "$1" && find . -type f -o -type l | sort); }
# A copy of what a release carries, to break on purpose.
payload_copy() {
local to="$1"
mkdir -p "$to"
git ls-files -z -- VERSION LICENSE ide nvim | while IFS= read -r -d '' f; do
mkdir -p "$to/$(dirname "$f")"
cp -p "$f" "$to/$f"
done
}
# --- 1. the files themselves -------------------------------------------------------------------
echo "The scripts and the pins"
check "shellcheck: install.sh, the launcher, the packaging and test scripts" \
shellcheck ide/install.sh ide/bin/llembas-ide scripts/package-ide.sh scripts/test-ide.sh
check "the colourscheme is what the tokens give" python3 scripts/gen-ide-theme.py --check
check "install.sh runs nothing until its last line" bash -c '[ "$(tail -n1 ide/install.sh)" = "main \"\$@\"" ]'
check "no sudo anywhere in the scripts" bash -c '! grep -n -w sudo ide/install.sh ide/bin/llembas-ide'
check "no colour is written outside the generated theme" \
bash -c '! grep -rn -E "#[0-9A-Fa-f]{6}\b" ide/config/init.lua ide/config/lua'
check "every plugin is pinned to a full commit over https, under MIT, Apache-2.0, BSD or ISC" \
bash -c 'grep -v -E "^\s*(#|$)" ide/plugins.lock | awk "{ if (\$3 !~ /^https:\/\/github\.com\// || \$4 !~ /^[0-9a-f]{40}\$/ || \$5 !~ /^(MIT|Apache-2\.0|BSD-[23]-Clause|ISC)\$/) { print; bad = 1 } } END { exit bad }"'
check "every grammar is pinned to a full commit over https, under MIT, Apache-2.0, BSD or ISC" \
bash -c 'grep -v -E "^\s*(#|$)" ide/parsers.lock | awk "{ if (\$2 !~ /^https:\/\/github\.com\// || \$3 !~ /^[0-9a-f]{40}\$/ || \$5 !~ /^(MIT|Apache-2\.0|BSD-[23]-Clause|ISC)\$/) { print; bad = 1 } } END { exit bad }"'
check "THIRD_PARTY.md names every pinned commit" \
bash -c 'for c in $(grep -v -E "^\s*(#|$)" ide/plugins.lock | awk "{ print \$4 }") $(grep -v -E "^\s*(#|$)" ide/parsers.lock | awk "{ print \$3 }"); do grep -q "$c" ide/THIRD_PARTY.md || { echo "missing $c"; exit 1; }; done'
check "Neovim is pinned with a SHA-256 for each of the four platforms" \
bash -c '[ "$(grep -c -E "^[0-9a-f]{64} nvim-(linux|macos)-(x86_64|arm64)\.tar\.gz$" ide/neovim.sha256)" = 4 ] && grep -q -E "^[0-9]+\.[0-9]+\.[0-9]+$" ide/neovim.version'
check "nothing private in the tracked files" scripts/hygiene.sh
check "the Lua of the configuration parses" \
bash -c 'for f in ide/config/init.lua ide/config/colors/llembas.lua ide/config/lua/llembas_ide/*.lua ide/user-init.lua ide/tests/headless.lua ide/tests/layout.lua ide/tests/typing.lua; do "$0" --headless -u NONE -c "lua local f, e = loadfile([[$f]]); if not f then io.stdout:write(e) vim.cmd([[cquit 1]]) end" -c q || exit 1; done' "$SYSTEM_NVIM"
# --- 2. a dry run ------------------------------------------------------------------------------
echo "A dry run"
A="$WORK/a"
mkdir -p "$A"
out="$(installer "$A" --from-checkout --dry-run || true)"
expect "says it is a dry run" "$out" "dry run: nothing is downloaded or written"
case "$(uname -s)-$(uname -m)" in
Linux-x86_64) ASSET=nvim-linux-x86_64 ;;
Linux-aarch64 | Linux-arm64) ASSET=nvim-linux-arm64 ;;
Darwin-arm64) ASSET=nvim-macos-arm64 ;;
*) ASSET=nvim-macos-x86_64 ;;
esac
expect "names the pinned Neovim's address" "$out" "download https://github.com/neovim/neovim/releases/download/v$(cat ide/neovim.version)/$ASSET.tar.gz"
expect "and its checksum" "$out" "check its SHA-256 is $(awk -v f="$ASSET.tar.gz" '$2 == f { print $1 }' ide/neovim.sha256)"
while read -r name _ url commit _; do
expect "names $name, its source and its commit" "$out" "fetch $name from $url at commit $commit"
done < <(grep -v -E '^\s*(#|$)' ide/plugins.lock)
expect "names the staging and the swap" "$out" "would swap the staged nvim/, site/pack/llembas/ and lib/ into $A/.local/share/llembas-ide"
expect "names the launcher" "$out" "would write the launcher $A/.local/bin/llembas-ide"
expect "names the person's own file" "$out" "would create $A/.config/llembas-ide/lua/user/init.lua"
expect "names the menu entry" "$out" "would write the menu entry $A/.local/share/applications/llembas-ide.desktop"
if [ -z "$(find "$A" -mindepth 1 | head -n1)" ]; then ok "writes nothing"; else fail "writes nothing" "$(find "$A" -mindepth 1 | head)"; fi
out="$(as "$A" bash "$REPO/ide/install.sh" --from-checkout --dry-run 2>&1 || true)"
expect "with the CLI missing, offers the CLI's own installer" "$out" "offer to install the LLeMbas CLI (beta): its own installer (get.sh)"
out="$(as "$A" bash "$REPO/ide/install.sh" --dry-run --version 9.9.9 2>&1 || true)"
expect "from a release: names the archive and the checksum check" "$out" "releases/download/v9.9.9/llembas-ide-9.9.9.tar.gz"
out="$(installer "$A" --from-checkout --prefix relative/dir 2>&1 || true)"
expect "a relative --prefix is refused in words" "$out" "--prefix must be an absolute path"
out="$(installer "$A" --from-checkout --nvim-bin /bin/true 2>&1 || true)"
expect "a --nvim-bin that is not Neovim 0.10 or newer is refused in words" "$out" "older than Neovim 0.10"
out="$(as "$A" bash -c 'cat "$1" | bash -s -- --from-checkout' _ "$REPO/ide/install.sh" 2>&1 || true)"
expect "piped into bash, --from-checkout is refused in words" "$out" "--from-checkout needs this script run as a file"
if [ -z "$(find "$A" -mindepth 1 | head -n1)" ]; then ok "refusals write nothing"; else fail "refusals write nothing" "$(find "$A" -mindepth 1 | head)"; fi
# The help, also when the script comes down a pipe and there is no file to read it from.
attempt as "$A" bash -c 'cat "$1" | bash -s -- --help' _ "$REPO/ide/install.sh"
passes "piped into bash, --help ends well"
expect "…and prints the options" "$OUT" "--channel NAME stable (default) or beta"
expect "…and what the script needs, ssh-keygen with it" "$OUT" "ssh-keygen (openssh-client"
if [ "$(as "$A" bash "$REPO/ide/install.sh" --help 2>&1)" = "$OUT" ]; then ok "the same help as from the file"; else fail "the same help as from the file"; fi
if [ -z "$(find "$A" -mindepth 1 | head -n1)" ]; then ok "the help writes nothing"; else fail "the help writes nothing" "$(find "$A" -mindepth 1 | head)"; fi
# --- 3. a real install, with the Neovim of this machine and its bundled grammars ---------------
echo "A real install (the Neovim on this machine: $("$SYSTEM_NVIM" --version | head -n1), bundled grammars)"
attempt installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers
out="$OUT"
passes "installs"
expect "says so" "$out" "LLeMbas IDE $VERSION is installed"
P="$A/.local/share/llembas-ide"
check "the launcher, the configuration, the person's file, the menu entry and the icon are there" \
test -x "$A/.local/bin/llembas-ide" -a -f "$A/.config/llembas-ide/init.lua" -a -f "$A/.config/llembas-ide/lua/user/init.lua" \
-a -f "$A/.local/share/applications/llembas-ide.desktop" -a -f "$A/.local/share/icons/hicolor/256x256/apps/llembas-ide.png"
check "the menu entry is a terminal application with the IDE's name" \
bash -c 'grep -q "^Terminal=true$" "$1" && grep -q "^Name=LLeMbas IDE$" "$1" && grep -q "^Icon=llembas-ide$" "$1"' _ "$A/.local/share/applications/llembas-ide.desktop"
stray="$(files_in "$A" | grep -v -E '^\./(\.local/share/llembas-ide/|\.config/llembas-ide/|\.local/bin/llembas-ide$|\.local/share/applications/llembas-ide\.desktop$|\.local/share/icons/hicolor/256x256/apps/llembas-ide\.png$|\.local/state/llembas-ide/|\.cache/llembas-ide/)' || true)"
if [ -z "$stray" ]; then ok "nothing is written outside the IDE's own places"; else fail "nothing is written outside the IDE's own places" "$stray"; fi
check "no ~/.config/nvim is made" test ! -e "$A/.config/nvim"
if [ -z "$(find "$P" -maxdepth 1 \( -name '.staging.*' -o -name '.old.*' \) | head -n1)" ]; then ok "no staging directory is left"; else fail "no staging directory is left"; fi
out="$(as "$A" "$A/.local/bin/llembas-ide" --version 2>&1 || true)"
expect "--version: the IDE" "$out" "LLeMbas IDE $VERSION"
expect "--version: Neovim" "$out" "Neovim $("$SYSTEM_NVIM" --version | sed -n '1s/^NVIM v//p')"
expect "--version: the plugin" "$out" "LLeMbas plugin $VERSION"
report_headless "headless start, from the inside" "$(headless "$A" 0 IDE_TEST_FIRST=1 || true)"
typing "$A" "typing: the completion menu opens with the buffer's words, and <Tab> stays LLeMbas's"
layout "$A" "the four bars at 160×45, 100×30 and 80×24, the keys, what is remembered, the terminal's user var"
check "the plugin alone, in a Neovim without the distribution, loads and has no bars unless asked" \
bash -c 'cd "$1" && env -i PATH="$PATH" HOME="$2" XDG_STATE_HOME="$2/plain-state" TERM=dumb "$3" --headless -u NONE -i NONE --cmd "set rtp+=nvim" \
-c "runtime plugin/llembas.lua" \
-c "lua require([[llembas]]).setup({}); assert(vim.o.tabline == [[]] and vim.fn.maparg([[<C-S-A>]], [[n]]) == [[]] and #vim.api.nvim_list_wins() == 1); require([[llembas]]).setup({ bars = true }); assert(vim.o.tabline:find([[llembas.layout]], 1, true) and vim.fn.maparg([[<C-S-A>]], [[n]], false, true).desc)" \
-c "qa!" 2>&1 | { ! grep -q .; }' _ "$REPO" "$WORK" "$SYSTEM_NVIM"
attempt as "$A" "$A/.local/bin/llembas-ide" doctor
out="$OUT"
passes "doctor finds the installation sound"
expect "doctor: plugins at their pins" "$out" "ok mini.nvim $(awk '$1 == "mini.nvim" { print substr($4, 1, 12) }' ide/plugins.lock)"
expect "doctor: says what is off without compiled grammars" "$out" "Treesitter grammars are not compiled"
expect "doctor: says the CLI is missing and the editor works" "$out" "the LLeMbas CLI (lembas) is not installed"
expect "doctor: a clean headless start" "$out" "every part of the IDE loads"
START_A="$(startup_ms "$A")"
ok "startup, best of three: ${START_A} ms"
out="$(as "$A" "$A/.local/bin/llembas-ide" --headless -c 'lua io.stdout:write(vim.env.NVIM_APPNAME .. " " .. vim.fn.argv(0))' -c 'qa!' some-file.txt 2>&1 || true)"
expect "arguments go through to Neovim" "$out" "llembas-ide some-file.txt"
# --- 4. again: an update in place --------------------------------------------------------------
echo "Installing again"
echo 'vim.g.llembas_ide_test_user = 42' >>"$A/.config/llembas-ide/lua/user/init.lua"
# A plugin of the person's own, in the directory the README names.
mkdir -p "$A/.config/llembas-ide/pack/user/start/mine/plugin"
echo 'vim.g.llembas_ide_test_plugin = "loaded"' >"$A/.config/llembas-ide/pack/user/start/mine/plugin/mine.lua"
user_before="$(sha256sum "$A/.config/llembas-ide/lua/user/init.lua")"
attempt installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers
out="$OUT"
passes "installs over itself"
if [ "$(grep -c 'already installed, unchanged' <<<"$out")" = "$(grep -c -v -E '^\s*(#|$)' ide/plugins.lock)" ]; then ok "keeps every plugin that is at its pin"; else fail "keeps every plugin that is at its pin" "$out"; fi
expect "keeps the person's own file" "$out" "keep your $A/.config/llembas-ide/lua/user/init.lua as it is"
if [ "$(sha256sum "$A/.config/llembas-ide/lua/user/init.lua")" = "$user_before" ]; then ok "the person's own file is byte for byte the same"; else fail "the person's own file is byte for byte the same"; fi
report_headless "headless start again, with the person's file saying something" "$(headless "$A" 0 IDE_TEST_USER=1 || true)"
echo '-- mine' >>"$A/.config/llembas-ide/init.lua"
out="$(installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers || true)"
expect "an init.lua the person edited is kept" "$out" "keep your edited $A/.config/llembas-ide/init.lua"
check "and the IDE's own lies beside it" bash -c 'grep -q "^-- mine$" "$1/init.lua" && cmp -s "$1/init.lua.new" ide/config/init.lua' _ "$A/.config/llembas-ide"
cp ide/config/init.lua "$A/.config/llembas-ide/init.lua"
rm -f "$A/.config/llembas-ide/init.lua.new"
# A plugin somebody changed is fetched again, not trusted.
echo '-- changed' >>"$P/site/pack/llembas/start/conform.nvim/lua/conform/init.lua"
out="$(as "$A" "$A/.local/bin/llembas-ide" doctor 2>&1 || true)"
expect "doctor: a plugin whose files were changed is a failure" "$out" "FAIL conform.nvim is at its pin but its files were changed"
out="$(installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers || true)"
expect "the installer fetches that plugin again" "$out" "fetch conform.nvim from"
check "and doctor is content" as "$A" "$A/.local/bin/llembas-ide" doctor
# A file somebody added is loaded by Neovim like any other: it is a change too.
echo 'vim.g.llembas_ide_test_added = true' >"$P/site/pack/llembas/start/conform.nvim/plugin/added.lua"
out="$(as "$A" "$A/.local/bin/llembas-ide" doctor 2>&1 || true)"
expect "doctor: a plugin with a file added to it is a failure" "$out" "FAIL conform.nvim is at its pin but its files were changed or added to"
expect "doctor: and says how many checks failed, in words" "$out" "1 check failed. llembas-ide update installs it again."
out="$(installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers || true)"
expect "the installer fetches that plugin again too" "$out" "fetch conform.nvim from"
check "and the added file is gone" test ! -e "$P/site/pack/llembas/start/conform.nvim/plugin/added.lua"
check "and doctor is content again" as "$A" "$A/.local/bin/llembas-ide" doctor
# --- 5. failing without leaving anything half-done ----------------------------------------------
echo "Failures"
before="$(files_in "$A" | grep -v -E '/(\.local/state|\.cache)/' | sha256sum)"
payload_copy "$WORK/broken"
echo 'error("broken on purpose")' >>"$WORK/broken/ide/config/lua/llembas_ide/options.lua"
attempt as "$A" bash "$WORK/broken/ide/install.sh" --no-cli --from-dir "$WORK/broken" --nvim-bin "$SYSTEM_NVIM" --no-parsers
out="$OUT"
refuses "a configuration that does not start is refused"
expect "in words" "$out" "the staged IDE did not start"
expect "and says nothing was installed" "$out" "nothing installed"
payload_copy "$WORK/wrongpin"
sed -i -E 's/^(conform\.nvim .*)[0-9a-f]{6}( +MIT)/\1000000\2/' "$WORK/wrongpin/ide/plugins.lock"
attempt as "$A" bash "$WORK/wrongpin/ide/install.sh" --no-cli --from-dir "$WORK/wrongpin" --nvim-bin "$SYSTEM_NVIM" --no-parsers
out="$OUT"
refuses "a commit that cannot be fetched stops the install"
expect "in words" "$out" "could not fetch https://github.com/stevearc/conform.nvim at"
if [ "$(files_in "$A" | grep -v -E '/(\.local/state|\.cache)/' | sha256sum)" = "$before" ]; then ok "after both, the installation has exactly the files it had"; else fail "after both, the installation has exactly the files it had"; fi
if [ -z "$(find "$P" -maxdepth 1 \( -name '.staging.*' -o -name '.old.*' \) | head -n1)" ]; then ok "and no staging directory is left"; else fail "and no staging directory is left"; fi
check "and it still starts" as "$A" "$A/.local/bin/llembas-ide" doctor
E="$WORK/empty"
mkdir -p "$E"
out="$(as "$E" bash "$WORK/broken/ide/install.sh" --no-cli --from-dir "$WORK/broken" --nvim-bin "$SYSTEM_NVIM" --no-parsers 2>&1 || true)"
left="$(files_in "$E")$(cd "$E" && find . -mindepth 1 -type d -name '*llembas*')"
if [ -z "$left" ]; then ok "a failed first install leaves no file and no directory of the IDE's"; else fail "a failed first install leaves no file and no directory of the IDE's" "$left"; fi
# --- 6. with a LLeMbas CLI on PATH (a stand-in) -------------------------------------------------
echo "With a LLeMbas CLI"
mkdir -p "$WORK/cli/bin" "$WORK/cli/config"
cat >"$WORK/cli/bin/lembas" <<EOF
#!/bin/sh
case "\$1" in
--version) echo 2.0.0-beta.99 ;;
__paths) printf 'config=%s\ndata=%s\nstate=%s\n' "$WORK/cli/config" "$WORK/cli/data" "$WORK/cli/state" ;;
*) exit 1 ;;
esac
EOF
chmod +x "$WORK/cli/bin/lembas"
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" "$A/.local/bin/llembas-ide" doctor 2>&1 || true)"
expect "doctor: finds it and its version" "$out" "LLeMbas CLI 2.0.0-beta.99"
expect "doctor: not signed in" "$out" "not signed in: lembas login"
printf '{ "instances": { "home": { "base_url": "https://llembas.example.org" } } }\n' >"$WORK/cli/config/lembas.json"
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" "$A/.local/bin/llembas-ide" doctor 2>&1 || true)"
expect "doctor: signed in" "$out" "signed in to a LLeMbas server"
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" bash "$REPO/ide/install.sh" --from-checkout --dry-run 2>&1 || true)"
expect "the installer leaves an installed CLI alone" "$out" "leave the LLeMbas CLI alone: it is installed"
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" "$A/.local/bin/llembas-ide" --headless \
-c 'lua local t, live = require("llembas_ide.llembas").status(); io.stdout:write(t .. " live=" .. tostring(live))' -c 'qa!' 2>&1 || true)"
expect "the statusline shows LLeMbas and that suggestions are on" "$out" "◈ LLeMbas · suggest on live=true"
dash='lua local l, d = require("llembas_ide.llembas"), require("llembas_ide.dashboard"); local function notes() local t = {}; for _, r in ipairs(d.content(false)) do t[#t + 1] = r[1] end; return table.concat(t, "|") end; local first = notes(); vim.wait(5000, function() return l.signed_in() ~= nil end, 20); io.stdout:write(first .. " THEN " .. notes())'
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" "$A/.local/bin/llembas-ide" --headless -c "$dash" -c 'qa!' 2>&1 || true)"
expect "the start screen claims nothing before it has looked" "${out%% THEN *}" "LLeMbas: press l to chat, i to sign in."
expect "the start screen of somebody signed in does not ask for a sign-in" "${out##* THEN }" "LLeMbas is signed in: press l to chat."
if has "${out##* THEN }" "needs a server and a sign-in"; then fail "and no longer says one is needed" "$out"; else ok "and no longer says one is needed"; fi
rm -f "$WORK/cli/config/lembas.json"
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" "$A/.local/bin/llembas-ide" --headless -c "$dash" -c 'qa!' 2>&1 || true)"
expect "the start screen of somebody not signed in says what is needed" "${out##* THEN }" "LLeMbas needs a server and a sign-in: press i."
printf '{ "instances": { "home": { "base_url": "https://llembas.example.org" } } }\n' >"$WORK/cli/config/lembas.json"
# One rule for "is the LLeMbas CLI installed": the installer's and the launcher's shell function,
# word for word the same, and the plugin's require("llembas").cli(), in the three places a CLI
# can be: on PATH, in ~/.local/bin without that being on PATH (the state right after a first
# install), and nowhere.
rule_installer="$(sed -n '/^find_cli() {$/,/^}$/p' ide/install.sh)"
rule_launcher="$(sed -n '/^find_cli() {$/,/^}$/p' ide/bin/llembas-ide)"
if [ -n "$rule_installer" ] && [ "$rule_installer" = "$rule_launcher" ]; then
ok "the installer and the launcher find the CLI by the same function, word for word"
else
fail "the installer and the launcher find the CLI by the same function, word for word" "$rule_installer
---
$rule_launcher"
fi
for where in path home nowhere; do
H="$WORK/find-$where"
mkdir -p "$H/.local/bin" "$H/xdg"
p="$CLEAN_PATH"
want=none
case "$where" in
path)
p="$WORK/cli/bin:$CLEAN_PATH"
want="$WORK/cli/bin/lembas"
;;
home)
cp "$WORK/cli/bin/lembas" "$H/.local/bin/lembas"
want="$H/.local/bin/lembas"
;;
esac
by_shell="$(env -i PATH="$p" HOME="$H" bash -c "$rule_installer"'
find_cli || echo none' 2>&1)"
by_plugin="$(env -i PATH="$p" HOME="$H" XDG_STATE_HOME="$H/xdg" XDG_DATA_HOME="$H/xdg" XDG_CACHE_HOME="$H/xdg" XDG_CONFIG_HOME="$H/xdg" TERM=dumb \
"$SYSTEM_NVIM" --headless -u NONE -i NONE --cmd "set rtp+=$REPO/nvim" \
-c 'lua local c = require("llembas").cli(); io.stdout:write(c and vim.fn.exepath(c[1]) or "none")' -c 'qa!' 2>&1)"
if [ "$by_shell" = "$want" ] && [ "$by_plugin" = "$want" ]; then
ok "a CLI $where: the scripts and the plugin agree ($want)"
else
fail "a CLI $where: the scripts and the plugin agree ($want)" "shell: $by_shell
plugin: $by_plugin"
fi
done
# The state right after a first install: the CLI in ~/.local/bin, which is not on PATH.
cp "$WORK/cli/bin/lembas" "$A/.local/bin/lembas"
out="$(env -i PATH="$CLEAN_PATH" HOME="$A" TERM=dumb LANG=C.UTF-8 "$A/.local/bin/llembas-ide" doctor 2>&1 || true)"
expect "doctor finds a CLI that is in ~/.local/bin and not on PATH" "$out" "LLeMbas CLI 2.0.0-beta.99 ($A/.local/bin/lembas)"
expect "doctor: and says that a terminal will not find it" "$out" "$A/.local/bin is not on your PATH"
out="$(env -i PATH="$CLEAN_PATH" HOME="$A" TERM=dumb LANG=C.UTF-8 "$A/.local/bin/llembas-ide" --headless \
-c 'lua local t, live = require("llembas_ide.llembas").status(); io.stdout:write(t .. " live=" .. tostring(live))' -c 'qa!' 2>&1 || true)"
expect "and so does the IDE: LLeMbas is on, not \"no CLI\"" "$out" "◈ LLeMbas · suggest on live=true"
rm -f "$A/.local/bin/lembas"
# The CLI's own installer is run only once it matches its release's signed SHA256SUMS. The
# stand-in installer leaves a mark saying it ran, and with what.
CLIREL="$WORK/cli-releases"
mkdir -p "$CLIREL/v2.0.0-beta.99"
printf '%s\n' '#!/usr/bin/env bash' "echo \"ran ref=\${LEMBAS_REF:-} channel=\${LEMBAS_CHANNEL:-} args=\$*\" >\"$WORK/cli-installer-ran\"" >"$CLIREL/v2.0.0-beta.99/get.sh"
(cd "$CLIREL/v2.0.0-beta.99" && sha256sum get.sh >SHA256SUMS)
ssh-keygen -q -t ed25519 -N '' -C cli -f "$WORK/clikey" >/dev/null
ssh-keygen -q -t ed25519 -N '' -C stranger -f "$WORK/strangerkey" >/dev/null
cli_install() { # the installer over the installation in A, saying yes to the CLI, against a CLI release
as "$A" env LLEMBAS_IDE_CLI_RELEASE_BASE="file://$CLIREL" LLEMBAS_IDE_CLI_VERSION=2.0.0-beta.99 LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/clikey.pub")" \
bash "$REPO/ide/install.sh" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers --yes 2>&1 || true
}
out="$(cli_install)"
expect "a CLI release that is not signed: its installer is not run" "$out" "the LLeMbas CLI's installer could not be checked, so it was not run"
check "…really not" test ! -e "$WORK/cli-installer-ran"
expect "…and the IDE is installed all the same" "$out" "is installed. Start it with: llembas-ide"
ssh-keygen -Y sign -q -f "$WORK/strangerkey" -n lembas-release "$CLIREL/v2.0.0-beta.99/SHA256SUMS" 2>/dev/null
out="$(cli_install)"
expect "a CLI release signed with another key: its installer is not run" "$out" "SHA256SUMS is not signed by the release key"
check "…really not" test ! -e "$WORK/cli-installer-ran"
rm -f "$CLIREL/v2.0.0-beta.99/SHA256SUMS.sig"
ssh-keygen -Y sign -q -f "$WORK/clikey" -n lembas-release "$CLIREL/v2.0.0-beta.99/SHA256SUMS" 2>/dev/null
echo '# one line more' >>"$CLIREL/v2.0.0-beta.99/get.sh"
out="$(cli_install)"
expect "an installer that is not the one the signed list names is not run" "$out" "the LLeMbas CLI's installer does not match its release's SHA256SUMS"
check "…really not" test ! -e "$WORK/cli-installer-ran"
sed -i '$d' "$CLIREL/v2.0.0-beta.99/get.sh"
out="$(cli_install)"
expect "signed by the release key and matching: the CLI's installer is checked" "$out" "the LLeMbas CLI's installer matches its release"
if [ "$(cat "$WORK/cli-installer-ran" 2>/dev/null)" = "ran ref=v2.0.0-beta.99 channel=beta args=--yes" ]; then
ok "…and run, for that release and its channel"
else
fail "…and run, for that release and its channel" "$(cat "$WORK/cli-installer-ran" 2>&1)
$out"
fi
check "and doctor is still content" as "$A" "$A/.local/bin/llembas-ide" doctor
# --- 7. a release: packaged, checked, installed with the pinned Neovim and compiled grammars ----
echo "A release"
check "package-ide.sh writes the release files" scripts/package-ide.sh
REL="$WORK/rel"
mkdir -p "$REL/v$VERSION"
cp "dist/llembas-ide-$VERSION.tar.gz" dist/install.sh dist/SHA256SUMS "$REL/v$VERSION/"
check "SHA256SUMS lists the archive and the installer, and they match" \
bash -c 'cd "$1" && sha256sum -c --quiet SHA256SUMS && grep -q " install.sh$" SHA256SUMS && grep -q " llembas-ide-.*\.tar\.gz$" SHA256SUMS' _ "$REL/v$VERSION"
check "the release's install.sh is the repository's" cmp -s "$REL/v$VERSION/install.sh" ide/install.sh
check "the archive holds the installer, the configuration, the plugin and no tests" \
bash -c 't="$(tar -tzf "$1")"; for f in ide/install.sh ide/plugins.lock ide/config/init.lua nvim/plugin/llembas.lua VERSION LICENSE; do grep -q "^llembas-ide-$2/$f$" <<<"$t" || { echo "missing $f"; exit 1; }; done; ! grep -q "/tests/" <<<"$t"' _ "$REL/v$VERSION/llembas-ide-$VERSION.tar.gz" "$VERSION"
B="$WORK/b"
C="$WORK/c"
mkdir -p "$B" "$C"
# Tampered with: one byte of the archive changed.
mkdir -p "$WORK/bad/v$VERSION"
cp "$REL/v$VERSION"/* "$WORK/bad/v$VERSION/"
printf 'x' >>"$WORK/bad/v$VERSION/llembas-ide-$VERSION.tar.gz"
attempt as "$C" env LLEMBAS_IDE_RELEASE_BASE="file://$WORK/bad" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" --nvim-bin "$SYSTEM_NVIM" --no-parsers
out="$OUT"
refuses "an archive that does not match SHA256SUMS is refused"
expect "in words" "$out" "does not match SHA256SUMS — nothing installed"
out="$(as "$C" env LLEMBAS_IDE_RELEASE_BASE="http://example.org/releases" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" 2>&1 || true)"
expect "a release over plain http is refused" "$out" "only https://"
# Signed releases: a key made here, for this test only.
ssh-keygen -q -t ed25519 -N '' -C test -f "$WORK/key" >/dev/null
ssh-keygen -q -t ed25519 -N '' -C other -f "$WORK/otherkey" >/dev/null
out="$(as "$C" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" --nvim-bin "$SYSTEM_NVIM" --no-parsers 2>&1 || true)"
expect "with a release key set, an unsigned release is refused" "$out" "the release is not signed"
ssh-keygen -Y sign -q -f "$WORK/otherkey" -n lembas-release "$REL/v$VERSION/SHA256SUMS" 2>/dev/null
out="$(as "$C" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" --nvim-bin "$SYSTEM_NVIM" --no-parsers 2>&1 || true)"
expect "one signed with another key is refused" "$out" "SHA256SUMS is not signed by the release key"
if [ -z "$(find "$C" -mindepth 1 | head -n1)" ]; then ok "every refusal leaves nothing behind"; else fail "every refusal leaves nothing behind" "$(find "$C" -mindepth 1 | head)"; fi
rm -f "$REL/v$VERSION/SHA256SUMS.sig"
ssh-keygen -Y sign -q -f "$WORK/key" -n lembas-release "$REL/v$VERSION/SHA256SUMS" 2>/dev/null
if [ "$QUICK" = 1 ]; then
attempt as "$B" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" --nvim-bin "$SYSTEM_NVIM" --no-parsers
out="$OUT"
passes "installs from the release (quick: this machine's Neovim, bundled grammars)"
expect "its signature is checked" "$out" "signature good (release key)"
expect "its checksum is checked" "$out" "checksum good"
report_headless "headless start of the release's install" "$(headless "$B" 0 IDE_TEST_FIRST=1 || true)"
else
attempt as "$B" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION"
out="$OUT"
passes "installs from the release, with the pinned Neovim downloaded and the grammars compiled"
expect "its signature is checked" "$out" "signature good (release key)"
expect "its checksum is checked" "$out" "checksum good"
expect "Neovim's SHA-256 is checked before unpacking" "$out" "check its SHA-256 is"
expect "the grammars are compiled" "$out" "compiled $(grep -c -v -E '^\s*(#|$)' ide/parsers.lock) Treesitter grammars"
out="$(as "$B" "$B/.local/bin/llembas-ide" --version 2>&1 || true)"
expect "the installed Neovim is the pinned one" "$out" "Neovim $(cat ide/neovim.version)"
check "it is the IDE's own copy" test -x "$B/.local/share/llembas-ide/nvim/bin/nvim"
report_headless "headless start on the pinned Neovim with compiled grammars" "$(headless "$B" 1 IDE_TEST_FIRST=1 || true)"
typing "$B" "typing on the pinned Neovim: the completion menu opens, and <Tab> stays LLeMbas's"
layout "$B" "the four bars on the pinned Neovim"
check "the plugin on its own passes its whole suite (scripts/test-nvim.sh)" scripts/test-nvim.sh
attempt as "$B" "$B/.local/bin/llembas-ide" doctor
out="$OUT"
passes "doctor finds it sound"
expect "doctor: the grammars" "$out" "Treesitter grammars compiled"
START_B="$(startup_ms "$B")"
ok "startup on the pinned Neovim, best of three: ${START_B} ms"
# A Neovim download that is not the pinned bytes.
payload_copy "$WORK/wrongsha"
sed -i -E 's/^[0-9a-f]{8}/00000000/' "$WORK/wrongsha/ide/neovim.sha256"
attempt as "$C" bash "$WORK/wrongsha/ide/install.sh" --no-cli --from-dir "$WORK/wrongsha" --no-parsers
out="$OUT"
refuses "a Neovim download with another SHA-256 is refused"
expect "in words" "$out" "not the pinned"
if [ -z "$(find "$C" -mindepth 1 | head -n1)" ]; then ok "and leaves nothing behind"; else fail "and leaves nothing behind" "$(find "$C" -mindepth 1 | head)"; fi
# The oldest supported Neovim with the compiled grammars: the first home, updated in place.
attempt installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM"
out="$OUT"
passes "the first home takes the compiled grammars in an update"
report_headless "headless start on this machine's Neovim with compiled grammars" "$(headless "$A" 1 IDE_TEST_USER=1 || true)"
fi
attempt as "$B" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" "$B/.local/bin/llembas-ide" update --no-cli --version "$VERSION"
out="$OUT"
passes "llembas-ide update runs the installed installer against the release"
expect "and keeps what is already there" "$out" "already installed, unchanged"
if [ "$QUICK" != 1 ]; then
expect "Neovim included" "$out" "keep Neovim $(cat ide/neovim.version)"
expect "and the compiled grammars" "$out" "compiled Treesitter grammars (already installed, same pins)"
fi
# --- 8. somewhere else: --prefix -----------------------------------------------------------------
echo "A prefix of the person's choosing"
D="$WORK/d"
mkdir -p "$D"
attempt installer "$D" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers --prefix "$WORK/opt/my ide"
passes "installs into a directory with a space in its name"
check "the IDE is there and not in the default place" test -d "$WORK/opt/my ide/lib" -a ! -e "$D/.local/share/llembas-ide"
check "doctor is content" as "$D" "$D/.local/bin/llembas-ide" doctor
attempt as "$D" "$D/.local/bin/llembas-ide" uninstall --purge --yes
passes "uninstall --purge --yes"
if [ -z "$(files_in "$D")" ] && [ ! -e "$WORK/opt/my ide" ]; then ok "leaves nothing, and the prefix is gone"; else fail "leaves nothing, and the prefix is gone" "$(files_in "$D"; ls -la "$WORK/opt")"; fi
# --- 9. uninstalling ---------------------------------------------------------------------------
echo "Uninstalling"
attempt as "$A" "$A/.local/bin/llembas-ide" uninstall --yes
out="$OUT"
passes "uninstall --yes"
left="$(files_in "$A" | tr '\n' ' ')"
if [ "$left" = "./.config/llembas-ide/lua/user/init.lua ./.config/llembas-ide/pack/user/start/mine/plugin/mine.lua " ]; then ok "leaves nothing but the person's own file and plugin"; else fail "leaves nothing but the person's own file and plugin" "$left"; fi
check "which still has what the person wrote" grep -q 'llembas_ide_test_user = 42' "$A/.config/llembas-ide/lua/user/init.lua"
attempt as "$B" "$B/.local/bin/llembas-ide" uninstall --purge --yes
out="$OUT"
passes "uninstall --purge --yes"
left="$(files_in "$B")"
if [ -z "$left" ]; then ok "leaves nothing at all"; else fail "leaves nothing at all" "$left"; fi
left="$(cd "$B" && find . -mindepth 1 -type d -name '*llembas*')"
if [ -z "$left" ]; then ok "not even an empty directory of its own"; else fail "not even an empty directory of its own" "$left"; fi
echo
echo "test-ide: $PASSED passed, $FAILED failed$([ "$QUICK" = 1 ] && echo ' (quick)')"
echo "test-ide: startup ${START_A} ms on $("$SYSTEM_NVIM" --version | head -n1)${START_B:+, ${START_B} ms on the pinned NVIM v$(cat ide/neovim.version) with compiled grammars}"
[ "$FAILED" = 0 ]