Files
HomerandClaude Opus 5.5 805dfe2f1f Should-fix, second part: with AI off the settings list and the status start nothing; a shell over ssh keeps its suggestions; tests
- S5: with AI off, LLeMbas: settings and LLeMbas: autocomplete status no
  longer ask the CLI what it can do (they use what is known), and forgetting
  a directory's settings is an AI key like the others. A test switches
  everything with AI off and counts no process, then the AI switch: the
  store keeps it and the settings are read.
- S1/S2: while the pane's own shell runs ssh, a shell on the other machine
  that says it is at its prompt may have suggestions drawn - nothing else
  follows from its word (no mark, no history, the file untouched).
- Tests: M3 (a display that ends gives the question back with what it
  said; a split that fails; an ask line already open waits), S4 (two
  windows, two directories), S6 (an updated CLI is seen), S7 (question card:
  number, n, words; the approve key does not answer it), S15 (numbered
  asks; an ask that just changed is not answered; a cut value), S17 (a
  shell over ssh: the display opens here, version 1 for an engine of 1).
- The smoke test asks for configure_pane, real_path and local_dir, and
  hands the status over without a directory.
- Texts: "choose chat model" and "chat model" for the list and the
  selector; "the LLeMbas CLI's own choice"; the built-in configuration's
  comment says what a person's file starts from.

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

209 lines
13 KiB
Bash
Executable File

#!/usr/bin/env bash
# Smoke test of built binaries, with no display: the identity (names, directories, variables),
# the built-in LLeMbas layer, and the `cli` commands the LLeMbas CLI drives a pane with.
#
# llembas/tests/smoke.sh <dir with llembas-term, llembas-term-mux-server>
#
# Starts a headless mux server in a scratch HOME, talks to it, and stops it. Nothing of the
# person's own is read or written. CI runs it on what it has just built.
set -uo pipefail
BIN="$(cd "${1:?usage: smoke.sh <dir with the binaries>}" && pwd)"
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
TERMINAL="${SMOKE_TERMINAL:-$BIN/llembas-term}"
MUX="${SMOKE_MUX:-$BIN/llembas-term-mux-server}"
# The names under test; SMOKE_PREFIX=WEZTERM runs the same steps against upstream's binaries.
P="${SMOKE_PREFIX:-LLEMBAS_TERM}"
APPDIR="${SMOKE_APPDIR:-llembas-term}"
work="$(mktemp -d)"
pid=""
failed=0
# shellcheck disable=SC2317 # reached through the trap
cleanup() {
if [ -n "$pid" ]; then kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; fi
rm -rf "${work:?}"
}
trap cleanup EXIT
mkdir -p "$work/home" "$work/run" "$work/cfg"
chmod 700 "$work/run"
clean() { env -i PATH=/usr/bin:/bin HOME="$work/home" XDG_RUNTIME_DIR="$work/run" XDG_CONFIG_HOME="$work/cfg" "$@"; }
ok() { echo "ok $1"; }
# On GitHub a failure is also an annotation on the run: a line, with newlines made visible.
note() { [ -z "${GITHUB_ACTIONS:-}" ] || printf '::error title=smoke::%s\n' "$(printf '%s' "$1" | head -c 900 | tr '\n\r' ' ' | sed 's/%/%25/g')"; }
bad() { echo "FAIL $1"; note "$1"; failed=1; }
expect() { # name, text, pattern
if printf '%s' "$2" | grep -Eq -- "$3"; then ok "$1"; else bad "$1: wanted /$3/ in: $2"; fi
}
version="$(tr -d '[:space:]' < "$ROOT/VERSION")"
if [ "$P" = LLEMBAS_TERM ]; then
expect "--version names us and our version" "$(clean "$TERMINAL" --version)" "^llembas-term ${version//./\\.} \(based on WezTerm .+\)$"
expect "mux server --version" "$(clean "$MUX" --version)" "^llembas-term-mux-server ${version//./\\.}"
fi
# A WezTerm that started us must not be passed on, nor talked to; nor what this terminal
# exported under its earlier name (LLEMBAS_TTY…, up to 1.0.0-beta.5), when one of those started us.
# (exec, so that the process id we keep is the server's own and stopping it stops the server)
(
exec env -i PATH=/usr/bin:/bin HOME="$work/home" XDG_RUNTIME_DIR="$work/run" XDG_CONFIG_HOME="$work/cfg" \
WEZTERM_PANE=77 WEZTERM_UNIX_SOCKET="$work/run/not-ours" WEZTERM_CONFIG_FILE="$work/nope.lua" \
LLEMBAS_TTY=1.0.0-beta.5 LLEMBAS_TTY_PANE=77 LLEMBAS_TTY_EXECUTABLE=/nonexistent/old LLEMBAS_TTY_STATUS_DIR="$work/run/old" \
LLEMBAS_TTY_UNIX_SOCKET="$work/run/not-ours" LLEMBAS_TTY_AUTOCOMPLETE=1 LLEMBAS_TTY_CLI=/nonexistent/lembas \
"$MUX"
) > "$work/server.txt" 2>&1 &
pid=$!
sock="$work/run/$APPDIR/sock"
for _ in $(seq 40); do
[ -S "$sock" ] && break
kill -0 "$pid" 2>/dev/null || break
sleep 0.25
done
if [ -S "$sock" ]; then ok "the server listens in its own runtime directory ($APPDIR)"; else bad "no socket at $sock; the server said: $(tail -c 600 "$work/server.txt"); in the runtime directory: $(cd "$work/run" && find . | head -20 | tr '\n' ' ')"; cat "$work/server.txt"; exit 1; fi
cli() { clean "$TERMINAL" cli --no-auto-start "$@"; }
# shellcheck disable=SC2016 # the pane's shell expands these, not this one
pane="$(cli spawn --new-window -- sh -c 'printf "%s\n" "id=[$'"$P"'_PANE]" "ver=[$LLEMBAS_TERM]" "exe=[$'"$P"'_EXECUTABLE]" "sock=[$'"$P"'_UNIX_SOCKET]" "term=[$TERM_PROGRAM]" "wez=[${WEZTERM_PANE-unset}/${WEZTERM_UNIX_SOCKET-unset}]" "old=[${LLEMBAS_TTY-unset}/${LLEMBAS_TTY_PANE-unset}/${LLEMBAS_TTY_EXECUTABLE-unset}/${LLEMBAS_TTY_STATUS_DIR-unset}/${LLEMBAS_TTY_UNIX_SOCKET-unset}/${LLEMBAS_TTY_AUTOCOMPLETE-unset}/${LLEMBAS_TTY_CLI-unset}]"; exec cat')"
expect "cli spawn gives a pane id" "$pane" '^[0-9]+$'
sleep 1
# One value a line, and the lines joined again: a pane is 80 columns wide and wraps a long path,
# which is the pane's doing and not what is under test.
text="$(cli get-text --pane-id "$pane" | tr -d '\n')"
expect "the pane knows its own id" "$text" "id=\[$pane\]"
expect "TERM_PROGRAM stays WezTerm" "$text" 'term=\[WezTerm\]'
if [ "$P" = LLEMBAS_TERM ]; then
expect "LLEMBAS_TERM is our version" "$text" "ver=\[${version//./\\.}\]"
expect "LLEMBAS_TERM_EXECUTABLE is the launcher" "$text" "exe=\[$BIN/llembas-term\]"
expect "the socket variable is ours" "$text" "sock=\[$sock\]"
expect "WezTerm's variables are not passed on" "$text" 'wez=\[unset/unset\]'
expect "nor the variables of the terminal's earlier name" "$text" 'old=\[unset/unset/unset/unset/unset/unset/unset\]'
fi
# What the LLeMbas CLI's terminal tools do: type into a pane, read it back.
printf 'typed by the cli\n' | cli send-text --pane-id "$pane" --no-paste
sleep 0.5
expect "send-text --no-paste arrives, get-text reads it" "$(cli get-text --pane-id "$pane")" 'typed by the cli'
expect "cli list shows the pane" "$(cli list)" "(^|[^0-9])$pane([^0-9]|$)"
kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null
if kill -0 "$pid" 2>/dev/null; then bad "the server did not stop"; else ok "the server stops when told"; fi
pid=""
if [ "$P" = LLEMBAS_TERM ]; then
# The built-in configuration applied the layer: its keys are bound. And a person's own file
# in our own directory is the one read; --skip-config gives the plain terminal.
# (show-keys is the gui binary's; it needs its libraries but no display.)
if keys="$(clean "$TERMINAL" show-keys --lua 2>"$work/keys-err.txt")"; then
expect "built-in configuration binds the ask key" "$keys" "llembas-ask"
expect "the key for the list of chat models" "$keys" "key = 'M', action = act.EmitEvent 'llembas-model-key'"
expect "the key for the list of autocomplete models" "$keys" "mods = 'ALT\|CTRL', key = 'm', action = act.EmitEvent 'llembas-autocomplete-model-key'"
expect "the mode key" "$keys" "llembas-mode-next-key"
expect "the palette chord, which LLeMbas IDE has too" "$keys" "key = 'P', action = act.EmitEvent 'llembas-pass-ctrl-shift-p'"
expect "the terminal's palette on a chord of its own" "$keys" "key = 'P', action = act.EmitEvent 'llembas-palette'"
plain="$(clean "$TERMINAL" --skip-config show-keys --lua 2>/dev/null)"
if printf '%s' "$plain" | grep -q llembas-ask; then bad "--skip-config still has the layer"; else ok "--skip-config is the plain terminal"; fi
# A person's file of the terminal's earlier name is read where it is while there is none
# of the new name, with the modules beside it, and they are told to move it.
mkdir -p "$work/cfg/llembas-tty"
echo "return { key = 'F7' }" > "$work/cfg/llembas-tty/mine.lua"
cat > "$work/cfg/llembas-tty/llembas-tty.lua" <<'LUA'
local wezterm = require 'wezterm'
local config = wezterm.config_builder()
require('llembas').apply(config, { keys = { ask = { key = require('mine').key, mods = 'NONE' } } })
return config
LUA
before="$(sha256sum < "$work/cfg/llembas-tty/llembas-tty.lua")"
old="$(clean "$TERMINAL" show-keys --lua 2>"$work/keys-err.txt")"
expect "a configuration file of the old name is read while there is none of the new" "$old" "F7"
expect "and the person is told where to move it" "$(tr -d '\n' < "$work/keys-err.txt")" "earlier name.*llembas-tty\.lua.*$work/cfg/llembas-term/llembas-term\.lua"
if [ "$(sha256sum < "$work/cfg/llembas-tty/llembas-tty.lua")" = "$before" ] && [ ! -e "$work/cfg/llembas-term/llembas-term.lua" ]; then ok "it is not moved or copied for them"; else bad "the old configuration file was touched, or a new one made"; fi
mkdir -p "$work/cfg/llembas-term"
cat > "$work/cfg/llembas-term/llembas-term.lua" <<'LUA'
local wezterm = require 'wezterm'
local config = wezterm.config_builder()
require('llembas').apply(config, { keys = { ask = { key = 'F9', mods = 'NONE' }, resume = false } })
return config
LUA
own="$(clean "$TERMINAL" show-keys --lua 2>"$work/keys-err.txt")"
expect "a person's own file in our directory is read, and require 'llembas' works there" "$own" "F9"
if printf '%s' "$own" | grep -q "F7"; then bad "the file of the old name was read though one of the new name exists"; else ok "and it wins over a file of the old name"; fi
# The terminal's own drawing part is there for the layer (wezterm.llembas), takes what the
# layer tells it, and the layer applied over it still binds its keys.
cat > "$work/cfg/llembas-term/llembas-term.lua" <<'LUA'
local wezterm = require 'wezterm'
local config = wezterm.config_builder()
local n = wezterm.llembas
local out = { 'module=' .. type(n) }
if type(n) == 'table' then
for _, name in ipairs { 'ask_line', 'ask_active', 'ask_prefix', 'configure', 'configure_pane', 'notice', 'hint', 'status', 'complete_status', 'data_dir', 'real_path', 'local_dir', 'set_private', 'command_ended', 'clear_history' } do
out[#out + 1] = name .. '=' .. type(n[name])
end
local ok, err = pcall(n.configure, {
suggestions = true, highlight = true, ai_complete = false, cli = '/opt/x/lembas', ac_model = 'local/fast',
ac_timeout_ms = 4000, ac_debug = true, input_mark = true, history = true, history_max = 10,
colors = { ghost = 8, command = '#00ff00', unknown = false },
})
out[#out + 1] = 'configure=' .. tostring(ok) .. (ok and '' or (' ' .. tostring(err)))
-- what is on in one pane, by its own directory's settings
local okp, errp = pcall(n.configure_pane, 3, { suggestions = false, highlight = true, ai_complete = false, ac_model = '', input_mark = false })
out[#out + 1] = 'configure_pane=' .. tostring(okp) .. (okp and '' or (' ' .. tostring(errp)))
local ok2 = pcall(n.set_private, 3, true)
out[#out + 1] = 'set_private=' .. tostring(ok2)
-- a word that stands, set and taken away again; the autocomplete in words
local ok3, err3 = pcall(function()
n.hint(3, 'Enter runs', true, 4)
n.hint(3, nil)
-- where a pane's shell stands, and that it is no longer followed
n.status(3, '77.5', 4, 'prompt', wezterm.home_dir)
-- known, with no input mark to write
n.status(3, '77.5', 5, 'running', nil)
n.status(3, nil)
end)
out[#out + 1] = 'hint=' .. tostring(ok3) .. (ok3 and '' or (' ' .. tostring(err3)))
local ok4, status = pcall(n.complete_status)
status = ok4 and tostring(status) or ''
out[#out + 1] = 'status=' .. tostring(status:find('engine: /opt/x/lembas', 1, true) ~= nil
and status:find('model: local/fast', 1, true) ~= nil
and status:find('given 4000 ms', 1, true) ~= nil
and status:find('AI autocomplete (or AI) is off', 1, true) ~= nil
and status:find('the next request is given 20000 ms', 1, true) ~= nil
and status:find('not yet', 1, true) ~= nil)
local ok5, dir = pcall(n.data_dir)
out[#out + 1] = 'data_dir=' .. tostring(ok5 and type(dir) == 'string' and dir:sub(1, 1) == '/')
end
require('llembas').apply(config, { autocomplete = true })
local f = io.open(wezterm.home_dir .. '/native.txt', 'w')
f:write(table.concat(out, ' '))
f:close()
return config
LUA
native_keys="$(clean "$TERMINAL" show-keys --lua 2>"$work/keys-err.txt")"
native="$(cat "$work/home/native.txt" 2>/dev/null)"
expect "wezterm.llembas is there, with every function the layer uses" "$native" '^module=table ask_line=function ask_active=function ask_prefix=function configure=function configure_pane=function notice=function hint=function status=function complete_status=function data_dir=function real_path=function local_dir=function set_private=function command_ended=function clear_history=function configure=true configure_pane=true set_private=true hint=true status=true data_dir=true$'
expect "the layer applies over it" "$native_keys" "llembas-ask"
if [ -e "$work/home/.local/share/llembas-term/command-history" ]; then bad "a command history was written though no command ran"; else ok "no command history is written before a command ran"; fi
# What the terminal itself kept under its earlier name is carried over once, at the first
# start in a home that has no data directory of the new name; the old files stay.
h2="$work/home2"
mkdir -p "$h2/.local/share/llembas-tty" "$work/cfg2"
printf '# llembas-tty history 1\n1700000000\t0\t/home/user\tls -la\n' > "$h2/.local/share/llembas-tty/command-history"
: > "$h2/.local/share/llembas-tty/settings-chosen"
echo '[]' > "$h2/.local/share/llembas-tty/recent-commands.json"
clean2() { env -i PATH=/usr/bin:/bin HOME="$h2" XDG_RUNTIME_DIR="$work/run" XDG_CONFIG_HOME="$work/cfg2" "$@"; }
clean2 "$TERMINAL" show-keys --lua >/dev/null 2>"$work/carry-err.txt"
new="$h2/.local/share/llembas-term"
if cmp -s "$new/command-history" "$h2/.local/share/llembas-tty/command-history" && [ -f "$new/settings-chosen" ]; then ok "the command history and the settings mark are carried over"; else bad "not carried over: $(find "$new" -maxdepth 1 2>&1 | tr '\n' ' '); said: $(head -c 400 "$work/carry-err.txt")"; fi
if [ -e "$new/recent-commands.json" ]; then bad "a file that is not the terminal's own two was carried over"; else ok "and nothing else"; fi
if [ -f "$h2/.local/share/llembas-tty/command-history" ] && [ -f "$h2/.local/share/llembas-tty/settings-chosen" ]; then ok "the old files stay where they were"; else bad "an old file is gone"; fi
expect "what was carried over is said in the log" "$(tr -d '\n' < "$work/carry-err.txt")" "carried over.*command-history, settings-chosen"
echo 'changed since' > "$new/command-history"
clean2 "$TERMINAL" show-keys --lua >/dev/null 2>&1
expect "a second start writes over nothing" "$(cat "$new/command-history")" '^changed since$'
else
bad "show-keys did not run: $(head -5 "$work/keys-err.txt")"
fi
fi
[ "$failed" -eq 0 ] && echo "smoke: all passed"
exit "$failed"