Files
jcoffey-dev bdc54f11c8 The interface: inbuxa on its own, six screens, the plan before anything
`inbuxa` with no arguments (or `inbuxa install` with no options) opens the
installer spec's interface in the terminal: what it found on this machine,
the names, which components go here and how, what answers on 80 and 443,
the whole plan, and the install. It fills in the same plan.Options the
flags do, builds the plan with plan.Build and installs with apply.Run: it
is a way of choosing, not a second installer. The plan screen shows the
command that does the same without it, and nothing happens until a "y".

- Components: what the machine can't do is greyed out with the reason
  beside it; what it lacks and the installer can add (docker, compose) is
  offered and added, with --install-deps in the command. The defaults are
  the flags' defaults. Front ends without a server here point to join.
- Reach offers Caddy or your own web server. --proxy snippets is left out:
  the plan describes it, but nothing writes those files yet (now said in
  the README).
- The install screen ticks off apply's steps with its output underneath,
  asks before stopping a running install, and ends on the credentials and
  addresses, printed again once the terminal is given back.
- Without root it refuses at the plan, saying why. Without a terminal it
  says which flags do the same, exit 2. A window under 60x16 says so.

The terminal layer is ours and the standard library's (installer spec §8,
decision 1): raw mode, size and SIGWINCH through syscall, key decoding,
full redraws, NO_COLOR honored, the terminal restored on every way out.

Also: the survey's text moved to plan.SurveyText, which the first screen
and `inbuxa survey` share; and plan.Available now says host installs of the
console and the webmail aren't built, so --console host is refused at the
plan instead of after it.

Tests: key decoding, fitting and wrapping, and the wizard driven by keys
against an installer that changes nothing (defaults, loopback, the server
on the host, refusals, root and the y, stopping, a machine without docker,
a small window), under -race. e2e/cases/interface.sh drives the binary in a
pseudo-terminal on a fresh Debian 13 lab through a whole loopback install:
22/22. install-local, install-host, install-public, status-export and
topology pass unchanged.
2026-10-12 09:11:28 -07:00

126 lines
5.3 KiB
Bash

#!/bin/bash
# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# The interface, driven the way a person drives it: `inbuxa` with no
# arguments in a terminal (a pseudo-terminal here), keys pressed one screen at
# a time, on a machine with nothing on it. Loopback evaluation, everything
# else as it comes.
#
# What only the interface can get wrong is checked: each screen arrives, the
# machine's missing container runtime is offered rather than refused, the
# plan shows the command that does the same, nothing happens before the "y",
# the install finishes on screen, the terminal is given back, and the
# summary is left in it. Then what install-local.sh checks of the result.
#
# Run from the host with: e2e/vm/run.sh e2e/cases/interface.sh
set -uo pipefail
pass=0; fail=0
ok() { echo " ok $*"; pass=$((pass+1)); }
bad() { echo " FAIL $*"; fail=$((fail+1)); }
DIR=/var/lib/inbuxa
command -v python3 >/dev/null || { bad "no python3 on this machine to drive a terminal with"; echo "==> $pass passed, $fail failed"; exit 1; }
cat > /tmp/drive.py <<'PY'
import os, pty, re, select, struct, sys, time, fcntl, termios
pid, fd = pty.fork()
if pid == 0:
os.environ["TERM"] = "xterm-256color"
os.execv("/tmp/inbuxa", ["/tmp/inbuxa"])
fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 32, 110, 0, 0))
seen = ""
def plain(s):
return re.sub(r"\x1b\[[0-9;?]*[A-Za-z]", "", s)
def pump(t):
global seen
end = time.time() + t
while time.time() < end:
r, _, _ = select.select([fd], [], [], 0.1)
if r:
try:
seen += os.read(fd, 65536).decode("utf-8", "replace")
except OSError:
return False
return True
def frame():
return plain(seen.split("\x1b[H")[-1])
def wait_for(text, timeout, label):
# Words, not lines: the interface wraps to the window, and a phrase can
# be split across two lines of it.
end = time.time() + timeout
while time.time() < end:
if text in " ".join(frame().replace("|", " ").split()):
print("OK", label); return True
if not pump(0.5):
break
print("FAIL", label, "-- never saw:", text)
print("\n".join(" | " + l for l in frame().split("\r\n")[:30]))
return False
def keys(s):
os.write(fd, s.encode()); pump(0.4)
ENTER, DOWN = "\r", "\x1b[B"
ok = wait_for("What this machine allows", 30, "screen 1: what it found")
keys(ENTER)
ok &= wait_for("Where it will be reached", 10, "screen 2: names")
keys(DOWN * 6 + " ")
ok &= wait_for("example.test", 5, "loopback fills an evaluation domain")
keys(ENTER)
ok &= wait_for("What goes on this machine", 10, "screen 3: components")
ok &= wait_for("will install what is missing", 5, "the missing runtime is offered, not refused")
keys(ENTER)
ok &= wait_for("publishes nothing", 10, "screen 4: reach, on loopback")
keys(ENTER)
ok &= wait_for("Nothing has happened yet", 10, "screen 5: the plan")
keys("\x1b[6~" * 4)
ok &= wait_for("--local --domain example.test --install-deps --yes", 5, "the plan shows the command that does the same")
keys(ENTER)
ok &= wait_for("Install now?", 5, "a confirmation before anything happens")
print("OK nothing installed before the y" if not os.path.exists("/var/lib/inbuxa/compose.yaml") else "FAIL something was written before the y")
keys("y")
ok &= wait_for("Done.", 1500, "screen 6: the install finishes on screen")
keys("q")
pump(2)
after = plain(seen.split("\x1b[?1049l")[-1]) if "\x1b[?1049l" in seen else ""
print("OK the terminal is given back" if "\x1b[?1049l" in seen and "\x1b[?25h" in seen else "FAIL the terminal was not restored")
print("OK the summary is left in the terminal" if "administrator" in after and "credentials.txt" in after else "FAIL no summary after the interface closed: " + repr(after[-300:]))
_, status = os.waitpid(pid, 0)
code = os.waitstatus_to_exitcode(status)
print(("OK" if code == 0 else "FAIL") + f" exit status {code}")
PY
echo "==> the interface, from a machine with nothing on it"
OUT="$(python3 /tmp/drive.py 2>&1)"
while IFS= read -r line; do
case "$line" in
OK\ *) ok "${line#OK }" ;;
FAIL\ *) bad "${line#FAIL }" ;;
*) echo "$line" ;;
esac
done <<<"$OUT"
echo
echo "==> what it installed"
rt() { command -v docker >/dev/null 2>&1 && echo docker || echo podman; }
STATE="$($(rt) compose -f $DIR/compose.yaml ps --format '{{.Service}} {{.State}}' 2>/dev/null)"
for s in server console webmail; do
grep -q "^$s running" <<<"$STATE" && ok "$s is running" || { bad "$s is not running"; echo "$STATE" | sed 's/^/ /'; }
done
[ "$(stat -c %a $DIR/credentials.txt 2>/dev/null)" = 600 ] && ok "credentials.txt, 600" || bad "credentials.txt missing or not 600"
grep -q '"shapes"' /etc/inbuxa/install.json 2>/dev/null && ok "the install is recorded" || bad "no install record"
/tmp/inbuxa status >/dev/null 2>&1 && ok "status: intent and reality agree" || bad "status disagrees"
curl -fsS http://127.0.0.1:8080/api/health 2>/dev/null | grep -q '"ok":true' && ok "the webmail is healthy" || bad "the webmail is not healthy"
echo
echo "==> without a terminal it says which flags do the same"
OUT="$(/tmp/inbuxa </dev/null 2>&1)"; rc=$?
[ $rc -eq 2 ] && grep -q "install --help" <<<"$OUT" && ok "no terminal: a sentence, exit 2" || bad "no terminal: exit $rc, $OUT"
echo
echo "==> $pass passed, $fail failed"
[ "$fail" -eq 0 ]