Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(lume): install source builds as lume-local, beside the released lume (#5804)

Francesco Bonacci86aae66ff311
diff --git a/libs/lume/Development.md b/libs/lume/Development.md
index f36468c68b..2d58c280f0 100644
--- a/libs/lume/Development.md
+++ b/libs/lume/Development.md
@@ -45,6 +45,39 @@ This workspace is preconfigured with Swift language support, build tasks, and de
4. Build and test your changes locally
5. Commit your changes with clear commit messages
+## Running a Source Build Beside the Released Lume (`lume-local`)
+
+`scripts/install-local.sh` builds Lume from your checkout and installs it as `lume-local`, so you can run it while the released `lume` keeps serving. The two share no file, LaunchAgent, port or log:
+
+| | Released | `lume-local` |
+| --- | --- | --- |
+| Command | `~/.local/bin/lume` | `~/.local/bin/lume-local` |
+| Files | `~/.local/share/lume` | `~/.local/share/lume-local` |
+| LaunchAgent | `com.trycua.lume_daemon` | `com.trycua.lume_daemon.local` |
+| Port | 7777 | 7787 |
+| Home and VMs | `~/.lume` | `~/.lume-local` |
+| Settings | `~/.config/lume/config.yaml` | `~/.lume-local/config.yaml` |
+| Daemon logs | `/tmp/lume_daemon.log` | `/tmp/lume_daemon.local.log` (or `$LUME_LOCAL_LOG_DIR`) |
+| `run --detach` logs | `~/Library/Logs/lume/<vm>.log` | `~/Library/Logs/lume-local/<vm>.log` |
+
+```bash
+libs/lume/scripts/install-local.sh # build and install
+lume-local serve # listens on 127.0.0.1:7787, VMs in ~/.lume-local
+libs/lume/scripts/uninstall-local.sh # remove it; asks before deleting VMs (--yes, --keep-vms)
+```
+
+A binary named `lume-local` implies these defaults, like `cua-driver-local`. Explicit flags and environment still win: `lume-local serve --port 9000`, and for `lume-local`, `LUME_HOME=/path` moves its home, VM directory, settings file, image cache, release-channel file and telemetry identity. `lume-local` has its own home, so it ignores `XDG_CONFIG_HOME`, which every Lume on the Mac shares. The released `lume` is unchanged: `LUME_HOME` still only moves its release-channel file. `lume-local` never updates itself: `update` would run the installer of the released Lume.
+
+`lume-local` uses `LUME_HOME` exactly as given, whitespace included (it is never trimmed into another path), and the scripts refuse a value with leading or trailing whitespace.
+
+The `lume-local` command is a small wrapper that sets `LUME_HOME` to the Local home and `LUME_LOCAL_LOG_DIR` to the daemon's log directory, overriding any values it inherits (often the released Lume's), so the command line and the daemon always agree. The LaunchAgent gets the same two variables, so `lume-local logs` and the logs API read where the daemon writes, also when `LUME_LOCAL_LOG_DIR` moved the logs away from `/tmp`. The installer reads a custom home from `LUME_LOCAL_HOME` (it ignores `LUME_HOME`, which may be the released Lume's) and refuses port 7777. Give `uninstall-local.sh` the same `LUME_LOCAL_HOME`, `LUME_LOCAL_INSTALL_DIR` and `LUME_LOCAL_LOG_DIR` you gave the installer.
+
+Both scripts canonicalise every path they write or delete (`.`, `..` and symlinks resolved) and refuse any that equals, sits inside, or contains a path the released Lume uses (`~/.lume`, `~/.config/lume`, `~/.local/bin/lume`, `~/.local/share/lume`, the stable plist, daemon logs and `~/Library/Logs/lume`). `$HOME/./.lume`, `$HOME/x/../.lume` and a symlink to `~/.lume` are all refused, so `uninstall-local.sh --yes` cannot delete the released Lume's VMs.
+
+Older versions of `install-local.sh` installed over the released `lume`; those files are not touched, so reinstall the released Lume with `install.sh` if you still have one of those builds.
+
+`scripts/tests/local-install-isolation-test.sh` runs both scripts against a fake home with stubbed `swift`, `codesign` and `launchctl`, and checks that nothing of the released Lume changes. `swift test` runs it.
+
## Submitting Pull Requests
1. Push your changes to your fork
diff --git a/libs/lume/scripts/_lume-local-common.sh b/libs/lume/scripts/_lume-local-common.sh
new file mode 100755
index 0000000000..c06c54c2b6
--- /dev/null
+++ b/libs/lume/scripts/_lume-local-common.sh
@@ -0,0 +1,161 @@
+#!/bin/bash
+# Shared by install-local.sh and uninstall-local.sh (sourced, not run).
+#
+# The path guard. Both scripts write or delete paths that come from the
+# environment or the command line (LUME_LOCAL_HOME, --install-dir, ...). A path
+# like "$HOME/./.lume", "$HOME/x/../.lume" or a symlink to ~/.lume names the
+# released Lume's VMs without matching them as a string, so every target is
+# canonicalised first (`.` and `..` resolved, every symlink followed) and then
+# compared with the paths the released Lume owns. A target that equals one of
+# them, sits inside one, or contains one is refused.
+
+# Print the canonical form of the absolute path $1: `.` and `..` resolved, and
+# every symlink followed, including those below the deepest component that
+# exists. Components that do not exist yet are kept as written. Returns 1 when
+# $1 is not absolute or has a symlink loop.
+lume_local_canon() {
+ local queue="$1" resolved="" comp target links=0
+ case "$queue" in
+ /*) ;;
+ *) return 1 ;;
+ esac
+ while :; do
+ while [ "${queue#/}" != "$queue" ]; do queue="${queue#/}"; done
+ [ -z "$queue" ] && break
+ comp="${queue%%/*}"
+ if [ "$comp" = "$queue" ]; then
+ queue=""
+ else
+ queue="${queue#*/}"
+ fi
+ case "$comp" in
+ .) continue ;;
+ ..)
+ resolved="${resolved%/*}"
+ continue
+ ;;
+ esac
+ if [ -L "$resolved/$comp" ]; then
+ links=$((links + 1))
+ [ "$links" -gt 40 ] && return 1
+ target="$(readlink "$resolved/$comp")" || return 1
+ case "$target" in
+ /*) resolved="" ;;
+ esac
+ queue="$target/$queue"
+ continue
+ fi
+ resolved="$resolved/$comp"
+ done
+ printf '%s\n' "${resolved:-/}"
+}
+
+# lume_local_no_edge_space LABEL VALUE: refuse a value that starts or ends with
+# whitespace. The Swift runtime uses LUME_HOME exactly as given, but a path such
+# as "$HOME/.lume " is one typo away from the released Lume's home and no one
+# means it, so it is an error here rather than a quiet near-miss.
+lume_local_no_edge_space() {
+ local label="$1" value="$2" edge='^[[:space:]]|[[:space:]]$'
+ if [[ "$value" =~ $edge ]]; then
+ echo "${RED}Error: $label has leading or trailing whitespace: '$value'.${NORMAL}" >&2
+ return 2
+ fi
+}
+
+# Lower-case $1. APFS is case-insensitive by default, so "$HOME/.LUME" is
+# "$HOME/.lume"; comparing lower-cased also refuses it on a case-sensitive
+# volume, where it would be a different directory nobody needs.
+lume_local_lower() {
+ printf '%s' "$1" | tr '[:upper:]' '[:lower:]'
+}
+
+# The paths the released Lume owns, one per line, canonical. Needs HOME.
+lume_local_stable_paths() {
+ local p
+ for p in \
+ "$HOME/.lume" \
+ "$HOME/.config/lume" \
+ "$HOME/.local/bin/lume" \
+ "$HOME/.local/bin/lume-daemon" \
+ "$HOME/.local/bin/lume-update" \
+ "$HOME/.local/bin/lume_lume.bundle" \
+ "$HOME/.local/share/lume" \
+ "$HOME/Library/Logs/lume" \
+ "$HOME/Library/LaunchAgents/com.trycua.lume_daemon.plist" \
+ "$HOME/Library/LaunchAgents/com.trycua.lume_updater.plist" \
+ "/tmp/lume_daemon.log" \
+ "/tmp/lume_daemon.error.log" \
+ "/tmp/lume_updater.log" \
+ "/tmp/lume_updater.error.log"; do
+ lume_local_canon "$p" || printf '%s\n' "$p"
+ done
+ if [ -n "${XDG_CONFIG_HOME:-}" ]; then
+ case "$XDG_CONFIG_HOME" in
+ /*) lume_local_canon "$XDG_CONFIG_HOME/lume" || true ;;
+ esac
+ fi
+ if [ -n "${LOG_DIR:-}" ]; then
+ case "$LOG_DIR" in
+ /*)
+ lume_local_canon "$LOG_DIR/lume_daemon.log" || true
+ lume_local_canon "$LOG_DIR/lume_daemon.error.log" || true
+ ;;
+ esac
+ fi
+}
+
+# Whether canonical path $1 equals $2 or is inside it (both lower-cased).
+lume_local_within() {
+ [ "$2" = "/" ] && return 0
+ [ "$1" = "$2" ] && return 0
+ case "$1" in
+ "$2"/*) return 0 ;;
+ esac
+ return 1
+}
+
+# lume_local_check LABEL PATH: print the canonical form of PATH and return 0 if
+# it is safe to write or delete; else print why on stderr and return 2.
+# Safe means: absolute, no symlink loop, and not equal to, inside, or an
+# ancestor of anything the released Lume owns.
+lume_local_check() {
+ local label="$1" raw="$2" canon canon_lc i
+ local stable_list stable_lc_list
+ lume_local_no_edge_space "$label" "$raw" || return 2
+ case "$raw" in
+ /*) ;;
+ *)
+ echo "${RED}Error: $label must be an absolute path, got '$raw'.${NORMAL}" >&2
+ return 2
+ ;;
+ esac
+ if ! canon="$(lume_local_canon "$raw")"; then
+ echo "${RED}Error: cannot resolve $label '$raw' (symlink loop?).${NORMAL}" >&2
+ return 2
+ fi
+ canon_lc="$(lume_local_lower "$canon")"
+ # The released Lume's paths, computed once per run, with a lower-cased copy.
+ if [ -z "${LUME_LOCAL_STABLE_PATHS:-}" ]; then
+ LUME_LOCAL_STABLE_PATHS="$(lume_local_stable_paths)"
+ LUME_LOCAL_STABLE_PATHS_LC="$(lume_local_lower "$LUME_LOCAL_STABLE_PATHS")"
+ fi
+ local old_ifs="$IFS"
+ IFS='
+'
+ set -f
+ stable_list=($LUME_LOCAL_STABLE_PATHS)
+ stable_lc_list=($LUME_LOCAL_STABLE_PATHS_LC)
+ set +f
+ IFS="$old_ifs"
+ i=0
+ while [ "$i" -lt "${#stable_list[@]}" ]; do
+ if lume_local_within "$canon_lc" "${stable_lc_list[$i]}" \
+ || lume_local_within "${stable_lc_list[$i]}" "$canon_lc"; then
+ echo "${RED}Error: refusing $label '$raw'${NORMAL}" >&2
+ echo "${RED} It resolves to $canon, which is, is inside, or contains ${stable_list[$i]}, a path the released Lume uses.${NORMAL}" >&2
+ return 2
+ fi
+ i=$((i + 1))
+ done
+ printf '%s\n' "$canon"
+}
diff --git a/libs/lume/scripts/install-local.sh b/libs/lume/scripts/install-local.sh
index d3f1636139..da8e551ba2 100755
--- a/libs/lume/scripts/install-local.sh
+++ b/libs/lume/scripts/install-local.sh
@@ -1,8 +1,37 @@
#!/bin/bash
set -e
-# Lume Local/Debug Installer
-# This script builds and installs Lume from the local source code
+# Lume Local Installer
+#
+# Builds Lume from this checkout and installs it as `lume-local`, next to the
+# released `lume` and sharing nothing with it:
+#
+# released Lume lume-local
+# command ~/.local/bin/lume ~/.local/bin/lume-local
+# files ~/.local/share/lume ~/.local/share/lume-local
+# LaunchAgent com.trycua.lume_daemon com.trycua.lume_daemon.local
+# port 7777 7787
+# home and VMs ~/.lume ~/.lume-local
+# release channel ~/.lume/release-channel ~/.lume-local/release-channel
+# daemon logs /tmp/lume_daemon.log /tmp/lume_daemon.local.log
+#
+# This script never writes a path in the left column. The released Lume is
+# installed by install.sh, which this script does not call or change.
+#
+# Environment (all optional):
+# LUME_LOCAL_HOME home and VM directory (default: ~/.lume-local)
+# LUME_LOCAL_INSTALL_DIR where the `lume-local` command goes
+# (default: ~/.local/bin)
+# LUME_LOCAL_LOG_DIR where the daemon logs go (default: /tmp). The daemon
+# and the `lume-local` command both get it, so
+# `lume-local logs` reads where the daemon writes.
+# LUME_HOME is deliberately ignored: it may point at the released Lume's home.
+# The `lume-local` command sets LUME_HOME (and LUME_LOCAL_LOG_DIR) to the values
+# above, overriding any it inherits, so the CLI and the daemon always agree.
+#
+# Every path is canonicalised (`.`, `..` and symlinks resolved) and refused if it
+# equals, sits inside, or contains a path the released Lume owns
+# (scripts/_lume-local-common.sh).
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
@@ -18,18 +47,38 @@ GREEN=$(tput setaf 2 2>/dev/null || echo "")
BLUE=$(tput setaf 4 2>/dev/null || echo "")
YELLOW=$(tput setaf 3 2>/dev/null || echo "")
+# The path guard shared with uninstall-local.sh
+. "$SCRIPT_DIR/_lume-local-common.sh"
+
# Check if running as root or with sudo
if [ "$(id -u)" -eq 0 ] || [ -n "$SUDO_USER" ]; then
echo "${RED}Error: Do not run this script with sudo or as root.${NORMAL}"
exit 1
fi
-# Default installation directory (user-specific, doesn't require sudo)
+# The names that make this install Local. They match the lume_* names in
+# CuaChannel (libs/cua/crates/cua-home/src/channel.rs) and LumeChannel
+# (src/FileSystem/LumeChannel.swift).
+LOCAL_BIN_NAME="lume-local"
+SERVICE_NAME="com.trycua.lume_daemon.local"
+BUNDLE_ID="com.trycua.lume.local"
+STABLE_PORT=7777
+LOCAL_PORT=7787
+
+# Where the `lume-local` command goes (user-specific, doesn't require sudo)
DEFAULT_INSTALL_DIR="$HOME/.local/bin"
-INSTALL_DIR="${INSTALL_DIR:-$DEFAULT_INSTALL_DIR}"
+INSTALL_DIR="${LUME_LOCAL_INSTALL_DIR:-$DEFAULT_INSTALL_DIR}"
+
+# Where the binary and its resources go. A private directory: the resource
+# bundle must sit next to the binary, and ~/.local/bin/lume_lume.bundle belongs
+# to the released Lume.
+APP_INSTALL_DIR="$HOME/.local/share/lume-local"
+
+# Home and VM directory
+LUME_LOCAL_HOME="${LUME_LOCAL_HOME:-$HOME/.lume-local}"
-# Default .app bundle installation directory
-APP_INSTALL_DIR="$HOME/.local/share/lume"
+# Daemon log directory
+LOG_DIR="${LUME_LOCAL_LOG_DIR:-/tmp}"
# Build configuration (debug or release)
BUILD_CONFIG="debug"
@@ -42,8 +91,8 @@ USE_BRIDGED_ENTITLEMENT=false
# Option to skip background service setup (default: install it)
INSTALL_BACKGROUND_SERVICE=true
-# Default port for lume serve (default: 7777)
-LUME_PORT=7777
+# Port for lume-local serve
+LUME_PORT="$LOCAL_PORT"
# Track whether we're using the .app bundle format
USE_APP_BUNDLE=false
@@ -76,20 +125,26 @@ while [ "$#" -gt 0 ]; do
;;
--help)
echo "${BOLD}${BLUE}Lume Local Installer${NORMAL}"
+ echo "Builds Lume from source and installs it as lume-local, beside the released lume."
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
- echo " --install-dir DIR Install to the specified directory (default: $DEFAULT_INSTALL_DIR)"
- echo " --port PORT Specify the port for lume serve (default: 7777)"
+ echo " --install-dir DIR Put the lume-local command in DIR (default: $DEFAULT_INSTALL_DIR)"
+ echo " --port PORT Specify the port for lume-local serve (default: $LOCAL_PORT)"
echo " --release Build release configuration instead of debug"
echo " --bridged-entitlement Sign with com.apple.vm.networking entitlement (requires proper Apple-approved signing)"
- echo " --no-background-service Do not setup the Lume background service (LaunchAgent)"
+ echo " --no-background-service Do not setup the lume-local background service (LaunchAgent)"
echo " --help Display this help message"
echo ""
+ echo "Installs: $DEFAULT_INSTALL_DIR/lume-local, $APP_INSTALL_DIR,"
+ echo " LaunchAgent $SERVICE_NAME, home and VMs in $LUME_LOCAL_HOME"
+ echo "Never touches: ~/.lume, ~/.local/bin/lume, ~/.local/share/lume, com.trycua.lume_daemon"
+ echo ""
echo "Examples:"
- echo " $0 # Build debug and install to $DEFAULT_INSTALL_DIR"
+ echo " $0 # Build debug and install lume-local"
echo " $0 --release # Build release and install"
- echo " $0 --port 7778 # Use port 7778 for the daemon"
+ echo " $0 --port 7788 # Use port 7788 for the daemon"
+ echo " libs/lume/scripts/uninstall-local.sh # Remove lume-local again"
exit 0
;;
*)
@@ -101,13 +156,51 @@ while [ "$#" -gt 0 ]; do
shift
done
+# Refuse settings that would reach the released Lume.
+case "$LUME_PORT" in
+ ''|*[!0-9]*)
+ echo "${RED}Error: --port must be a number, got '$LUME_PORT'.${NORMAL}" >&2
+ exit 2
+ ;;
+esac
+if [ "$LUME_PORT" -lt 1 ] || [ "$LUME_PORT" -gt 65535 ]; then
+ echo "${RED}Error: --port must be between 1 and 65535, got '$LUME_PORT'.${NORMAL}" >&2
+ exit 2
+fi
+if [ "$LUME_PORT" -eq "$STABLE_PORT" ]; then
+ echo "${RED}Error: port $STABLE_PORT belongs to the released Lume. lume-local uses $LOCAL_PORT.${NORMAL}" >&2
+ exit 2
+fi
+
+# Canonicalise every path this script writes, and refuse any that reaches the
+# released Lume. From here on these are the canonical forms.
+LUME_LOCAL_HOME="$(lume_local_check "LUME_LOCAL_HOME" "$LUME_LOCAL_HOME")" || exit 2
+lume_local_no_edge_space "--install-dir" "$INSTALL_DIR" || exit 2
+lume_local_no_edge_space "LUME_LOCAL_LOG_DIR" "$LOG_DIR" || exit 2
+case "$INSTALL_DIR" in
+ /*) ;;
+ *) echo "${RED}Error: --install-dir must be an absolute path, got '$INSTALL_DIR'.${NORMAL}" >&2; exit 2 ;;
+esac
+LOCAL_BIN="$(lume_local_check "the lume-local command ($INSTALL_DIR/$LOCAL_BIN_NAME)" "$INSTALL_DIR/$LOCAL_BIN_NAME")" || exit 2
+# The command's own directory (an existing symlink named lume-local is replaced,
+# not followed).
+INSTALL_DIR="$(lume_local_canon "$INSTALL_DIR")" || exit 2
+LOCAL_BIN="$INSTALL_DIR/$LOCAL_BIN_NAME"
+APP_INSTALL_DIR="$(lume_local_check "the lume-local files directory" "$APP_INSTALL_DIR")" || exit 2
+PLIST_PATH="$(lume_local_check "the lume-local LaunchAgent plist" "$HOME/Library/LaunchAgents/$SERVICE_NAME.plist")" || exit 2
+LOG_FILE="$(lume_local_check "the lume-local daemon log" "$LOG_DIR/lume_daemon.local.log")" || exit 2
+ERROR_LOG_FILE="$(lume_local_check "the lume-local daemon error log" "$LOG_DIR/lume_daemon.local.error.log")" || exit 2
+# The directory the logs are read from; the daemon and the command both get it.
+LOG_DIR="$(lume_local_canon "$LOG_DIR")" || exit 2
+WRAPPER_MARKER="# lume-local wrapper, managed by libs/lume/scripts/install-local.sh"
+
echo "${BOLD}${BLUE}"
echo " ⠀⣀⣀⡀⠀⠀⠀⠀⢀⣀⣀⣀⡀⠘⠋⢉⠙⣷⠀⠀ ⠀"
echo " ⠀⠀⢀⣴⣿⡿⠋⣉⠁⣠⣾⣿⣿⣿⣿⡿⠿⣦⡈⠀⣿⡇⠃⠀"
echo " ⠀⠀⠀⣽⣿⣧⠀⠃⢰⣿⣿⡏⠙⣿⠿⢧⣀⣼⣷⠀⡿⠃⠀⠀"
echo " ⠀⠀⠀⠉⣿⣿⣦⠀⢿⣿⣿⣷⣾⡏⠀⠀⢹⣿⣿⠀⠀⠀⠀⠀⠀"
echo " ⠀⠀⠀⠀⠀⠉⠛⠁⠈⠿⣿⣿⣿⣷⣄⣠⡼⠟⠁${NORMAL}${BOLD} Lume Local Installer${NORMAL}"
-echo "${BLUE} Build from source${NORMAL}"
+echo "${BLUE} Build from source, installed as $LOCAL_BIN_NAME${NORMAL}"
echo ""
echo "Building ${BOLD}$BUILD_CONFIG${NORMAL} configuration from ${BOLD}$LUME_DIR${NORMAL}"
echo ""
@@ -119,7 +212,7 @@ if ! command -v swift &> /dev/null; then
exit 1
fi
-# Build lume
+# Build lume. The product is called `lume`; it is installed as `lume-local`.
build_lume() {
echo "Building lume ($BUILD_CONFIG)..."
cd "$LUME_DIR"
@@ -132,6 +225,12 @@ build_lume() {
BUILD_PATH="$LUME_DIR/.build/debug"
fi
+ # Stage the installable files under their final names, so what is signed and
+ # launch-checked is exactly what gets installed.
+ STAGE_DIR="$BUILD_PATH/lume-local-stage"
+ rm -rf "$STAGE_DIR"
+ mkdir -p "$STAGE_DIR"
+
# Use local-safe entitlements by default.
ENTITLEMENTS_FILE="$LUME_DIR/resources/lume.local.entitlements"
if [ "$USE_BRIDGED_ENTITLEMENT" = true ]; then
@@ -142,11 +241,10 @@ build_lume() {
# Assemble .app bundle for provisioning profile support
echo "Assembling .app bundle for bridged networking..."
- APP_BUNDLE="$BUILD_PATH/lume.app"
- rm -rf "$APP_BUNDLE"
+ APP_BUNDLE="$STAGE_DIR/$LOCAL_BIN_NAME.app"
mkdir -p "$APP_BUNDLE/Contents/MacOS"
- cp -f "$BUILD_PATH/lume" "$APP_BUNDLE/Contents/MacOS/lume"
+ cp -f "$BUILD_PATH/lume" "$APP_BUNDLE/Contents/MacOS/$LOCAL_BIN_NAME"
# Copy resource bundle to Contents/Resources/.
# It CANNOT go in Contents/MacOS/ (breaks codesign: "bundle format unrecognized")
@@ -158,45 +256,57 @@ build_lume() {
fi
cp -f "$LUME_DIR/resources/AppIcon.icns" "$APP_BUNDLE/Contents/Resources/AppIcon.icns"
- # Stamp Info.plist with version
+ # Stamp Info.plist with the version and the Local identity. A distinct
+ # bundle id keeps macOS from treating this app as the released Lume.
CURRENT_VERSION=$("$BUILD_PATH/lume" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "0.0.0")
sed "s/__VERSION__/$CURRENT_VERSION/g" "$LUME_DIR/resources/Info.plist" > "$APP_BUNDLE/Contents/Info.plist"
+ /usr/libexec/PlistBuddy \
+ -c "Set :CFBundleIdentifier $BUNDLE_ID" \
+ -c "Set :CFBundleExecutable $LOCAL_BIN_NAME" \
+ -c "Set :CFBundleName Lume Local" \
+ -c "Set :CFBundleDisplayName Lume Local" \
+ "$APP_BUNDLE/Contents/Info.plist"
# Embed provisioning profile if available
if [ -f "$LUME_DIR/resources/embedded.provisionprofile" ]; then
cp "$LUME_DIR/resources/embedded.provisionprofile" "$APP_BUNDLE/Contents/embedded.provisionprofile"
else
echo "${YELLOW}Warning: No provisioning profile found at $LUME_DIR/resources/embedded.provisionprofile${NORMAL}"
- echo "${YELLOW}Bridged networking requires a provisioning profile from Apple Developer portal.${NORMAL}"
+ echo "${YELLOW}Bridged networking requires a provisioning profile from Apple Developer portal for $BUNDLE_ID.${NORMAL}"
fi
# Sign the bundle
- clear_signature_metadata "$APP_BUNDLE/Contents/MacOS/lume"
- codesign --force --entitlements "$ENTITLEMENTS_FILE" --sign - "$APP_BUNDLE/Contents/MacOS/lume"
+ clear_signature_metadata "$APP_BUNDLE/Contents/MacOS/$LOCAL_BIN_NAME"
+ codesign --force --entitlements "$ENTITLEMENTS_FILE" --sign - "$APP_BUNDLE/Contents/MacOS/$LOCAL_BIN_NAME"
codesign --force --sign - "$APP_BUNDLE"
# Verify the signed binary can launch from the bundle
- if "$APP_BUNDLE/Contents/MacOS/lume" --version >/dev/null 2>&1; then
+ if "$APP_BUNDLE/Contents/MacOS/$LOCAL_BIN_NAME" --version >/dev/null 2>&1; then
USE_APP_BUNDLE=true
else
echo "${YELLOW}Warning: binary did not launch from .app bundle with bridged entitlement; falling back to standalone binary.${NORMAL}"
ENTITLEMENTS_FILE="$LUME_DIR/resources/lume.local.entitlements"
- clear_signature_metadata "$BUILD_PATH/lume"
- codesign --force --entitlements "$ENTITLEMENTS_FILE" --sign - "$BUILD_PATH/lume"
+ rm -rf "$APP_BUNDLE"
USE_APP_BUNDLE=false
fi
- else
- # Standard standalone binary (no .app bundle needed)
- clear_signature_metadata "$BUILD_PATH/lume"
- codesign --force --entitlements "$ENTITLEMENTS_FILE" --sign - "$BUILD_PATH/lume"
+ fi
+
+ if [ "$USE_APP_BUNDLE" = false ]; then
+ # Standard standalone binary (no .app bundle needed). The resource bundle
+ # sits next to it, where Bundle.lumeResources looks.
+ cp -f "$BUILD_PATH/lume" "$STAGE_DIR/$LOCAL_BIN_NAME"
+ if [ -d "$BUILD_PATH/lume_lume.bundle" ]; then
+ cp -rf "$BUILD_PATH/lume_lume.bundle" "$STAGE_DIR/"
+ fi
+
+ clear_signature_metadata "$STAGE_DIR/$LOCAL_BIN_NAME"
+ codesign --force --identifier "$BUNDLE_ID" --entitlements "$ENTITLEMENTS_FILE" --sign - "$STAGE_DIR/$LOCAL_BIN_NAME"
# Verify the signed binary can launch
- if ! "$BUILD_PATH/lume" --version >/dev/null 2>&1; then
+ if ! "$STAGE_DIR/$LOCAL_BIN_NAME" --version >/dev/null 2>&1; then
echo "${RED}Error: signed binary could not launch; refusing to install it.${NORMAL}"
exit 1
fi
-
- USE_APP_BUNDLE=false
fi
echo "${GREEN}Build complete!${NORMAL}"
@@ -204,51 +314,50 @@ build_lume() {
# Install the binary
install_binary() {
- echo "Installing to $INSTALL_DIR..."
+ echo "Installing to $APP_INSTALL_DIR and $INSTALL_DIR..."
- # Create install directory if it doesn't exist
- mkdir -p "$INSTALL_DIR"
+ mkdir -p "$INSTALL_DIR" "$APP_INSTALL_DIR"
+
+ # Replace the files, not just their contents: a new inode keeps taskgated
+ # from reusing a stale signature cache.
+ rm -rf "$APP_INSTALL_DIR/$LOCAL_BIN_NAME" \
+ "$APP_INSTALL_DIR/$LOCAL_BIN_NAME.app" \
+ "$APP_INSTALL_DIR/lume_lume.bundle"
if [ "$USE_APP_BUNDLE" = true ]; then
- # Install as .app bundle with wrapper script
- mkdir -p "$APP_INSTALL_DIR"
- rm -rf "$APP_INSTALL_DIR/lume.app"
- cp -R "$BUILD_PATH/lume.app" "$APP_INSTALL_DIR/"
-
- # Remove old standalone binary if it's a Mach-O file (migration)
- if [ -f "$INSTALL_DIR/lume" ] && file "$INSTALL_DIR/lume" | grep -q "Mach-O"; then
- rm -f "$INSTALL_DIR/lume"
- fi
- rm -rf "$INSTALL_DIR/lume_lume.bundle"
-
- # Create wrapper script
- cat > "$INSTALL_DIR/lume" <<WRAPPER_EOF
-#!/bin/sh
-exec "$APP_INSTALL_DIR/lume.app/Contents/MacOS/lume" "\$@"
-WRAPPER_EOF
- chmod +x "$INSTALL_DIR/lume"
-
- echo "${GREEN}Installation complete!${NORMAL}"
- echo "Lume installed to ${BOLD}$APP_INSTALL_DIR/lume.app${NORMAL}"
- echo "CLI available at ${BOLD}$INSTALL_DIR/lume${NORMAL}"
+ cp -R "$STAGE_DIR/$LOCAL_BIN_NAME.app" "$APP_INSTALL_DIR/"
+ REAL_BIN="$APP_INSTALL_DIR/$LOCAL_BIN_NAME.app/Contents/MacOS/$LOCAL_BIN_NAME"
else
- # Install as standalone binary
- # Replace the inode so taskgated does not reuse a stale signature cache.
- rm -f "$INSTALL_DIR/lume"
- cp -f "$BUILD_PATH/lume" "$INSTALL_DIR/lume"
- chmod +x "$INSTALL_DIR/lume"
-
- # Copy the resource bundle if it exists (contains unattended presets)
- if [ -d "$BUILD_PATH/lume_lume.bundle" ]; then
- rm -rf "$INSTALL_DIR/lume_lume.bundle"
- cp -rf "$BUILD_PATH/lume_lume.bundle" "$INSTALL_DIR/"
- echo "Resource bundle installed to ${BOLD}$INSTALL_DIR/lume_lume.bundle${NORMAL}"
+ cp -f "$STAGE_DIR/$LOCAL_BIN_NAME" "$APP_INSTALL_DIR/$LOCAL_BIN_NAME"
+ chmod +x "$APP_INSTALL_DIR/$LOCAL_BIN_NAME"
+ if [ -d "$STAGE_DIR/lume_lume.bundle" ]; then
+ cp -rf "$STAGE_DIR/lume_lume.bundle" "$APP_INSTALL_DIR/"
fi
-
- echo "${GREEN}Installation complete!${NORMAL}"
- echo "Lume has been installed to ${BOLD}$INSTALL_DIR/lume${NORMAL}"
+ REAL_BIN="$APP_INSTALL_DIR/$LOCAL_BIN_NAME"
fi
+ # The command is a small wrapper, so nothing but one file lands in a bin
+ # directory the released Lume shares.
+ # It sets LUME_HOME to the validated Local home, overriding whatever the
+ # caller exported (often the released Lume's), so every command uses the same
+ # home as the daemon, including with a custom LUME_LOCAL_HOME. It sets
+ # LUME_LOCAL_LOG_DIR the same way, so `lume-local logs` reads the directory the
+ # daemon writes to.
+ rm -f "$LOCAL_BIN"
+ {
+ printf '#!/bin/sh\n'
+ printf '%s\n' "$WRAPPER_MARKER"
+ printf 'LUME_HOME=%q\n' "$LUME_LOCAL_HOME"
+ printf 'LUME_LOCAL_LOG_DIR=%q\n' "$LOG_DIR"
+ printf 'export LUME_HOME LUME_LOCAL_LOG_DIR\n'
+ printf 'exec %q "$@"\n' "$REAL_BIN"
+ } > "$LOCAL_BIN"
+ chmod +x "$LOCAL_BIN"
+
+ echo "${GREEN}Installation complete!${NORMAL}"
+ echo "lume-local installed to ${BOLD}$APP_INSTALL_DIR${NORMAL}"
+ echo "CLI available at ${BOLD}$LOCAL_BIN${NORMAL}"
+
# Check if the installation directory is in PATH
if [ -n "${PATH##*$INSTALL_DIR*}" ]; then
echo ""
@@ -258,14 +367,20 @@ WRAPPER_EOF
fi
}
+# Create the home and its own release-channel file
+setup_home() {
+ mkdir -p "$LUME_LOCAL_HOME"
+ if [ ! -f "$LUME_LOCAL_HOME/release-channel" ]; then
+ channel_tmp="$LUME_LOCAL_HOME/.release-channel.$$"
+ printf '%s\n' "stable" > "$channel_tmp"
+ mv -f "$channel_tmp" "$LUME_LOCAL_HOME/release-channel"
+ fi
+}
+
# Setup background service (LaunchAgent)
setup_background_service() {
- SERVICE_NAME="com.trycua.lume_daemon"
- PLIST_PATH="$HOME/Library/LaunchAgents/$SERVICE_NAME.plist"
- LUME_BIN="$INSTALL_DIR/lume"
-
echo ""
- echo "Setting up LaunchAgent to run lume daemon..."
+ echo "Setting up LaunchAgent to run lume-local daemon..."
# Create LaunchAgents directory if it doesn't exist
mkdir -p "$HOME/Library/LaunchAgents"
@@ -276,6 +391,8 @@ setup_background_service() {
launchctl unload "$PLIST_PATH" 2>/dev/null || true
fi
+ mkdir -p "$(dirname "$LOG_FILE")" "$(dirname "$ERROR_LOG_FILE")"
+
# Create the plist file
cat <<EOF > "$PLIST_PATH"
<?xml version="1.0" encoding="UTF-8"?>
@@ -286,7 +403,7 @@ setup_background_service() {
<string>$SERVICE_NAME</string>
<key>ProgramArguments</key>
<array>
- <string>$LUME_BIN</string>
+ <string>$LOCAL_BIN</string>
<string>serve</string>
<string>--port</string>
<string>$LUME_PORT</string>
@@ -303,11 +420,15 @@ setup_background_service() {
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.local/bin</string>
<key>HOME</key>
<string>$HOME</string>
+ <key>LUME_HOME</key>
+ <string>$LUME_LOCAL_HOME</string>
+ <key>LUME_LOCAL_LOG_DIR</key>
+ <string>$LOG_DIR</string>
</dict>
<key>StandardOutPath</key>
- <string>/tmp/lume_daemon.log</string>
+ <string>$LOG_FILE</string>
<key>StandardErrorPath</key>
- <string>/tmp/lume_daemon.error.log</string>
+ <string>$ERROR_LOG_FILE</string>
<key>ProcessType</key>
<string>Interactive</string>
<key>SessionType</key>
@@ -318,28 +439,25 @@ EOF
# Set permissions
chmod 644 "$PLIST_PATH"
- touch /tmp/lume_daemon.log /tmp/lume_daemon.error.log
- chmod 644 /tmp/lume_daemon.log /tmp/lume_daemon.error.log
+ touch "$LOG_FILE" "$ERROR_LOG_FILE"
+ chmod 644 "$LOG_FILE" "$ERROR_LOG_FILE"
# Load the LaunchAgent
echo "Loading LaunchAgent..."
launchctl load "$PLIST_PATH"
- echo "${GREEN}Lume daemon LaunchAgent installed and loaded!${NORMAL}"
+ echo "${GREEN}lume-local daemon LaunchAgent installed and loaded!${NORMAL}"
echo "To check status: launchctl list | grep $SERVICE_NAME"
- echo "To view logs: tail -f /tmp/lume_daemon.log"
+ echo "To view logs: tail -f $LOG_FILE"
}
# Remove background service
remove_background_service() {
- SERVICE_NAME="com.trycua.lume_daemon"
- PLIST_PATH="$HOME/Library/LaunchAgents/$SERVICE_NAME.plist"
-
if [ -f "$PLIST_PATH" ]; then
- echo "Removing existing Lume background service (LaunchAgent)..."
+ echo "Removing existing lume-local background service (LaunchAgent)..."
launchctl unload "$PLIST_PATH" 2>/dev/null || true
rm "$PLIST_PATH"
- echo "Lume background service removed."
+ echo "lume-local background service removed."
fi
}
@@ -347,10 +465,12 @@ remove_background_service() {
main() {
build_lume
install_binary
+ setup_home
echo ""
- echo "${GREEN}${BOLD}Lume ($BUILD_CONFIG) has been successfully installed!${NORMAL}"
- echo "Run ${BOLD}lume${NORMAL} to get started."
+ echo "${GREEN}${BOLD}lume-local ($BUILD_CONFIG) has been successfully installed!${NORMAL}"
+ echo "Run ${BOLD}$LOCAL_BIN_NAME${NORMAL} to get started. VMs and settings live in ${BOLD}$LUME_LOCAL_HOME${NORMAL}."
+ echo "The released ${BOLD}lume${NORMAL} (port $STABLE_PORT, ~/.lume) is untouched."
if [ "$USE_BRIDGED_ENTITLEMENT" = false ]; then
echo "${YELLOW}Note: local installer signs without com.apple.vm.networking by default.${NORMAL}"
fi
@@ -363,7 +483,8 @@ main() {
fi
echo ""
- echo "${YELLOW}Note: This is a local build. Auto-updater is not installed.${NORMAL}"
+ echo "${YELLOW}Note: This is a local build. Auto-updater is not installed, and $LOCAL_BIN_NAME never updates itself.${NORMAL}"
+ echo "To remove it: ${BOLD}$SCRIPT_DIR/uninstall-local.sh${NORMAL}"
}
# Run the installation
diff --git a/libs/lume/scripts/tests/local-install-isolation-test.sh b/libs/lume/scripts/tests/local-install-isolation-test.sh
new file mode 100755
index 0000000000..8b77f92b6a
--- /dev/null
+++ b/libs/lume/scripts/tests/local-install-isolation-test.sh
@@ -0,0 +1,602 @@
+#!/bin/bash
+# Isolation test for libs/lume/scripts/install-local.sh and uninstall-local.sh.
+#
+# Runs both scripts against a fake HOME, with swift, codesign and launchctl
+# replaced by stubs, so nothing is built, signed or loaded and the real home is
+# never read. It then checks that the released Lume's files (~/.lume,
+# ~/.local/bin/lume, ~/.local/share/lume, the com.trycua.lume_daemon plist and
+# the config under ~/.config/lume) are byte-for-byte and mtime-for-mtime the
+# same, that launchctl was only ever pointed at the `.local` plist, and that
+# everything the scripts did write is a lume-local path.
+#
+# Usage: libs/lume/scripts/tests/local-install-isolation-test.sh
+# Exit status is 0 when every check passes. macOS only (it reads launchd plists
+# and uses BSD stat).
+
+set -u -o pipefail
+
+HERE="$(cd "$(dirname "$0")" && pwd)"
+REAL_LUME_DIR="$(cd "$HERE/../.." && pwd)"
+
+if [ "$(id -u)" -eq 0 ]; then
+ echo "SKIP: install-local.sh refuses to run as root, so it cannot be tested as root."
+ exit 0
+fi
+
+TMP="$(mktemp -d "${TMPDIR:-/tmp}/lume-local-install-test.XXXXXX")"
+TMP="$(cd -P "$TMP" && pwd -P)" # the scripts print canonical paths; compare like with like
+trap 'rm -rf "$TMP"' EXIT
+
+H="$TMP/home" # the fake HOME
+SRC="$TMP/src/lume" # a copy of the script tree, so builds stay out of the checkout
+BIN="$TMP/bin" # the stubs
+STUB_LOG_DIR="$TMP/stub-logs"
+LOGS="$TMP/logs" # stands in for /tmp
+mkdir -p "$H" "$SRC/scripts" "$SRC/resources" "$BIN" "$STUB_LOG_DIR" "$LOGS"
+
+cp "$REAL_LUME_DIR/scripts/install-local.sh" "$REAL_LUME_DIR/scripts/uninstall-local.sh" \
+ "$REAL_LUME_DIR/scripts/_lume-local-common.sh" "$SRC/scripts/"
+for f in lume.entitlements lume.local.entitlements Info.plist AppIcon.icns; do
+ cp "$REAL_LUME_DIR/resources/$f" "$SRC/resources/$f"
+done
+
+# ---- stubs -----------------------------------------------------------------
+
+cat > "$BIN/swift" <<'STUB'
+#!/bin/sh
+# Fake swift: "builds" a stub lume into .build/<config>.
+config=debug
+prev=
+for a in "$@"; do
+ if [ "$prev" = "-c" ] && [ "$a" = "release" ]; then config=release; fi
+ prev=$a
+done
+echo "swift $*" >> "$STUB_LOG_DIR/swift.log"
+mkdir -p ".build/$config/lume_lume.bundle"
+echo preset > ".build/$config/lume_lume.bundle/presets.txt"
+cat > ".build/$config/lume" <<'LUME'
+#!/bin/sh
+case "$1" in
+ --version) echo "lume version 0.0.0-test" ;;
+ *) echo "stub-lume name=$(basename "$0") args=$* LUME_HOME=${LUME_HOME-unset} LUME_LOCAL_LOG_DIR=${LUME_LOCAL_LOG_DIR-unset}" ;;
+esac
+LUME
+chmod +x ".build/$config/lume"
+STUB
+
+cat > "$BIN/codesign" <<'STUB'
+#!/bin/sh
+echo "codesign $*" >> "$STUB_LOG_DIR/codesign.log"
+STUB
+
+cat > "$BIN/launchctl" <<'STUB'
+#!/bin/sh
+echo "launchctl $*" >> "$STUB_LOG_DIR/launchctl.log"
+STUB
+chmod +x "$BIN/swift" "$BIN/codesign" "$BIN/launchctl"
+
+# ---- helpers ---------------------------------------------------------------
+
+FAILS=0
+CHECKS=0
+
+check() { # description, command...
+ local desc="$1"
+ shift
+ CHECKS=$((CHECKS + 1))
+ if ! "$@" >/dev/null 2>&1; then
+ FAILS=$((FAILS + 1))
+ echo "FAIL: $desc"
+ fi
+}
+
+same() { # description, before, after
+ CHECKS=$((CHECKS + 1))
+ if [ "$2" != "$3" ]; then
+ FAILS=$((FAILS + 1))
+ echo "FAIL: $1"
+ diff <(printf '%s\n' "$2") <(printf '%s\n' "$3") | head -20
+ fi
+}
+
+if stat -f %m / >/dev/null 2>&1; then
+ mtime() { stat -f %m "$1"; }
+else
+ mtime() { stat -c %Y "$1"; }
+fi
+
+# Every entry under the given paths, with content hash and mtime for files.
+fingerprint() {
+ local p f
+ for p in "$@"; do
+ if [ ! -e "$p" ] && [ ! -L "$p" ]; then
+ echo "MISSING $p"
+ continue
+ fi
+ find "$p" -print0 | sort -z | while IFS= read -r -d '' f; do
+ if [ -L "$f" ]; then
+ echo "L $f -> $(readlink "$f")"
+ elif [ -d "$f" ]; then
+ echo "D $f"
+ else
+ echo "F $f $(shasum -a 256 < "$f" | cut -d' ' -f1) $(mtime "$f")"
+ fi
+ done
+ done
+}
+
+# Every file and link under HOME, sorted: what exists, not what it says.
+inventory() {
+ (cd "$1" && find . \( -type f -o -type l \) | sort)
+}
+
+# The paths the released Lume owns.
+stable_paths() {
+ printf '%s\n' \
+ "$1/.lume" \
+ "$1/.config/lume" \
+ "$1/.local/share/lume" \
+ "$1/.local/bin/lume" \
+ "$1/.local/bin/lume_lume.bundle" \
+ "$1/Library/LaunchAgents/com.trycua.lume_daemon.plist" \
+ "$LOGS/lume_daemon.log" \
+ "$LOGS/lume_daemon.error.log" \
+ "$1/Library/Logs/lume"
+}
+
+seed_stable() { # home
+ local home="$1"
+ mkdir -p "$home/.lume/vm1" "$home/.config/lume" "$home/.local/share/lume/lume.app/Contents/MacOS" \
+ "$home/.local/bin/lume_lume.bundle/Contents" "$home/Library/LaunchAgents" "$LOGS"
+ printf 'stable\n' > "$home/.lume/release-channel"
+ printf '{"name":"vm1"}\n' > "$home/.lume/vm1/config.json"
+ printf 'disk\n' > "$home/.lume/vm1/disk.img"
+ printf 'defaultLocationName: "home"\n' > "$home/.config/lume/config.yaml"
+ printf '#!/bin/sh\nexit 0\n' > "$home/.local/share/lume/lume.app/Contents/MacOS/lume"
+ printf '#!/bin/sh\nexec stable\n' > "$home/.local/bin/lume"
+ chmod +x "$home/.local/bin/lume"
+ printf 'resources\n' > "$home/.local/bin/lume_lume.bundle/Contents/stable.txt"
+ printf '<plist>stable daemon 7777</plist>\n' > "$home/Library/LaunchAgents/com.trycua.lume_daemon.plist"
+ printf 'stable log\n' > "$LOGS/lume_daemon.log"
+ printf 'stable err\n' > "$LOGS/lume_daemon.error.log"
+ mkdir -p "$home/Library/Logs/lume"
+ printf 'released detached run\n' > "$home/Library/Logs/lume/vm1.log"
+ # An old mtime, so any write shows up as a change.
+ find "$home" "$LOGS" -type f -exec touch -t 202001010000 {} +
+}
+
+# Run a script from the copied tree under the fake HOME, with only the stubs
+# on PATH. Extra VAR=value arguments go before the script.
+run() { # [VAR=value...] script args...
+ local extra=()
+ while [ "$#" -gt 0 ] && [[ "$1" == *=* ]]; do
+ extra+=("$1")
+ shift
+ done
+ local script="$1"
+ shift
+ env -i HOME="$H" PATH="$BIN:/usr/bin:/bin:/usr/sbin:/sbin" TERM=dumb \
+ STUB_LOG_DIR="$STUB_LOG_DIR" LUME_LOCAL_LOG_DIR="$LOGS" \
+ ${extra[@]+"${extra[@]}"} \
+ /bin/bash "$SRC/scripts/$script" "$@"
+}
+
+reset_logs() { rm -f "$STUB_LOG_DIR"/*.log; }
+
+# Whether every path in $1 (a newline list, relative to HOME) is a lume-local path.
+only_local_paths() {
+ local p
+ while IFS= read -r p; do
+ [ -z "$p" ] && continue
+ case "$p" in
+ ./.local/bin/lume-local) ;;
+ ./.local/share/lume-local/*) ;;
+ ./.lume-local/*) ;;
+ ./Library/LaunchAgents/com.trycua.lume_daemon.local.plist) ;;
+ *) echo "unexpected path: $p" >&2; return 1 ;;
+ esac
+ done <<< "$1"
+}
+
+# The value after --port in a plist's ProgramArguments.
+plist_port() {
+ grep -A1 -x ' <string>--port</string>' "$1" | sed -n 's/.*<string>\(.*\)<\/string>.*/\1/p' | tail -1
+}
+
+# The value of an EnvironmentVariables key in a plist.
+plist_env() { # plist, key
+ grep -A1 "<key>$2</key>" "$1" | sed -n 's/.*<string>\(.*\)<\/string>.*/\1/p' | tail -1
+}
+
+PLIST="$H/Library/LaunchAgents/com.trycua.lume_daemon.local.plist"
+
+# ---- 1. install into a home that already has the released Lume ---------------
+
+seed_stable "$H"
+STABLE_BEFORE="$(fingerprint $(stable_paths "$H"))"
+INVENTORY_BEFORE="$(inventory "$H")"
+reset_logs
+
+OUT="$(run install-local.sh 2>&1)"
+check "install-local.sh succeeds" test $? -eq 0
+[ -n "${DEBUG_TEST_OUTPUT:-}" ] && echo "$OUT"
+
+same "install leaves every released-Lume path untouched" \
+ "$STABLE_BEFORE" "$(fingerprint $(stable_paths "$H"))"
+
+ADDED="$(diff <(printf '%s\n' "$INVENTORY_BEFORE") <(inventory "$H") | sed -n 's/^> //p')"
+REMOVED="$(diff <(printf '%s\n' "$INVENTORY_BEFORE") <(inventory "$H") | sed -n 's/^< //p')"
+check "install removed nothing" test -z "$REMOVED"
+check "install wrote only lume-local paths" only_local_paths "$ADDED"
+
+check "lume-local command exists" test -x "$H/.local/bin/lume-local"
+check "lume-local command is the managed wrapper" grep -q 'lume-local wrapper, managed by' "$H/.local/bin/lume-local"
+check "lume-local binary is named lume-local" test -x "$H/.local/share/lume-local/lume-local"
+check "resource bundle sits next to the binary" test -d "$H/.local/share/lume-local/lume_lume.bundle"
+check "release-channel file is in the local home" grep -qx stable "$H/.lume-local/release-channel"
+check "the plist is the .local plist" test -f "$PLIST"
+check "plist label is com.trycua.lume_daemon.local" grep -q '<string>com.trycua.lume_daemon.local</string>' "$PLIST"
+check "plist serves on 7787" test "$(plist_port "$PLIST")" = 7787
+check "plist runs lume-local" grep -q "<string>$H/.local/bin/lume-local</string>" "$PLIST"
+check "plist sets LUME_HOME to the local home" test "$(plist_env "$PLIST" LUME_HOME)" = "$H/.lume-local"
+check "plist logs to the .local logs" grep -q "<string>$LOGS/lume_daemon.local.log</string>" "$PLIST"
+check "plist tells the daemon where its logs are" test "$(plist_env "$PLIST" LUME_LOCAL_LOG_DIR)" = "$LOGS"
+check "plist never names port 7777" bash -c "! grep -q 7777 '$PLIST'"
+check "stable plist content is unchanged" grep -q 'stable daemon 7777' "$H/Library/LaunchAgents/com.trycua.lume_daemon.plist"
+
+check "launchctl was called" test -s "$STUB_LOG_DIR/launchctl.log"
+check "launchctl only saw the .local plist" bash -c "! grep -v 'com.trycua.lume_daemon.local.plist' '$STUB_LOG_DIR/launchctl.log'"
+check "launchctl loaded the .local plist" grep -q "^launchctl load $PLIST\$" "$STUB_LOG_DIR/launchctl.log"
+check "codesign used the local identifier" grep -q -- '--identifier com.trycua.lume.local' "$STUB_LOG_DIR/codesign.log"
+check "codesign never touched the install dirs" bash -c "! grep -q '$H' '$STUB_LOG_DIR/codesign.log'"
+
+# The wrapper's runtime environment: it runs the lume-local binary, and sets
+# LUME_HOME to the Local home whatever the caller exported (typically the
+# released Lume's).
+wrapper() { # [VAR=value...] wrapper-path args...
+ local extra=()
+ while [ "$#" -gt 0 ] && [[ "$1" == *=* ]]; do
+ extra+=("$1")
+ shift
+ done
+ env -i PATH="$BIN:/usr/bin:/bin:/usr/sbin:/sbin" ${extra[@]+"${extra[@]}"} "$@"
+}
+check "the wrapper runs the lume-local binary with the Local home" test \
+ "$(wrapper HOME="$H" "$H/.local/bin/lume-local" serve 2>&1)" = "stub-lume name=lume-local args=serve LUME_HOME=$H/.lume-local LUME_LOCAL_LOG_DIR=$LOGS"
+check "the wrapper overrides an inherited released-Lume LUME_HOME" test \
+ "$(wrapper HOME="$H" LUME_HOME="$H/.lume" "$H/.local/bin/lume-local" serve 2>&1)" = "stub-lume name=lume-local args=serve LUME_HOME=$H/.lume-local LUME_LOCAL_LOG_DIR=$LOGS"
+check "the wrapper overrides an inherited LUME_HOME that points elsewhere" test \
+ "$(wrapper HOME="$H" LUME_HOME=/somewhere/else "$H/.local/bin/lume-local" ls 2>&1)" = "stub-lume name=lume-local args=ls LUME_HOME=$H/.lume-local LUME_LOCAL_LOG_DIR=$LOGS"
+check "the wrapper passes arguments through untouched" test \
+ "$(wrapper HOME="$H" "$H/.local/bin/lume-local" run 'a b' --x=1 2>&1)" = "stub-lume name=lume-local args=run a b --x=1 LUME_HOME=$H/.lume-local LUME_LOCAL_LOG_DIR=$LOGS"
+
+# ---- 2. install again, on another port: idempotent, still only .local --------
+
+reset_logs
+run install-local.sh --port 7790 >/dev/null 2>&1
+check "second install succeeds" test $? -eq 0
+same "second install leaves every released-Lume path untouched" \
+ "$STABLE_BEFORE" "$(fingerprint $(stable_paths "$H"))"
+check "second install moved the plist to the new port" test "$(plist_port "$PLIST")" = 7790
+check "second install unloaded the old .local service" grep -q "^launchctl unload $PLIST\$" "$STUB_LOG_DIR/launchctl.log"
+check "launchctl only saw the .local plist the second time" bash -c "! grep -v 'com.trycua.lume_daemon.local.plist' '$STUB_LOG_DIR/launchctl.log'"
+check "the home's release-channel is not rewritten" grep -qx stable "$H/.lume-local/release-channel"
+
+# ---- 3. refused settings write nothing ----------------------------------------
+
+H2="$TMP/home2"
+mkdir -p "$H2"
+seed_stable "$H2"
+S2_BEFORE="$(fingerprint $(stable_paths "$H2"))"
+I2_BEFORE="$(inventory "$H2")"
+reset_logs
+
+H_SAVE="$H"
+H="$H2"
+run install-local.sh --port 7777 >/dev/null 2>&1
+check "port 7777 is refused" test $? -ne 0
+run install-local.sh --port abc >/dev/null 2>&1
+check "a non-numeric port is refused" test $? -ne 0
+run LUME_LOCAL_HOME="$H2/.lume" install-local.sh >/dev/null 2>&1
+check "the released home is refused as the local home" test $? -ne 0
+run LUME_LOCAL_HOME="$H2/.lume/local" install-local.sh >/dev/null 2>&1
+check "a path inside the released home is refused" test $? -ne 0
+run LUME_LOCAL_HOME="$H2" install-local.sh >/dev/null 2>&1
+check "HOME itself is refused as the local home" test $? -ne 0
+run LUME_LOCAL_HOME="relative/path" install-local.sh >/dev/null 2>&1
+check "a relative local home is refused" test $? -ne 0
+same "refused installs wrote nothing" "$I2_BEFORE" "$(inventory "$H2")"
+same "refused installs left the released Lume alone" "$S2_BEFORE" "$(fingerprint $(stable_paths "$H2"))"
+check "refused installs never ran swift" test ! -e "$STUB_LOG_DIR/swift.log"
+
+# A LUME_HOME in the environment belongs to the released Lume: it is ignored.
+run LUME_HOME="$TMP/not-ours" install-local.sh >/dev/null 2>&1
+check "install with LUME_HOME set succeeds" test $? -eq 0
+check "LUME_HOME in the environment is ignored" test ! -e "$TMP/not-ours"
+check "the local home is still ~/.lume-local" test -f "$H2/.lume-local/release-channel"
+same "install with LUME_HOME set left the released Lume alone" \
+ "$S2_BEFORE" "$(fingerprint $(stable_paths "$H2"))"
+
+# --no-background-service removes only the .local plist.
+reset_logs
+run install-local.sh --no-background-service >/dev/null 2>&1
+check "install without a service succeeds" test $? -eq 0
+check "the .local plist is gone" test ! -e "$H2/Library/LaunchAgents/com.trycua.lume_daemon.local.plist"
+check "the stable plist stays" test -f "$H2/Library/LaunchAgents/com.trycua.lume_daemon.plist"
+check "launchctl only saw the .local plist without a service" bash -c "! grep -v 'com.trycua.lume_daemon.local.plist' '$STUB_LOG_DIR/launchctl.log'"
+same "install without a service left the released Lume alone" \
+ "$S2_BEFORE" "$(fingerprint $(stable_paths "$H2"))"
+H="$H_SAVE"
+
+# ---- 3b. aliases of the released Lume's paths are refused ---------------------
+#
+# A raw-string guard accepts "$HOME/./.lume", "$HOME/x/../.lume" or a symlink to
+# ~/.lume, and then `uninstall-local.sh --yes` deletes the released Lume's VMs.
+# Every target is canonicalised first.
+
+expect_refused() { # description, then the run() arguments
+ local desc="$1" rc out
+ shift
+ reset_logs
+ out="$(run "$@" 2>&1)"
+ rc=$?
+ # Exit status 2 is the guard's; anything else would be a failure for another reason.
+ check "$desc is refused" test "$rc" -eq 2
+ check "$desc says why" grep -q 'Error: ' <<< "$out"
+ check "$desc ran no build and no launchctl" test ! -e "$STUB_LOG_DIR/swift.log" -a ! -e "$STUB_LOG_DIR/launchctl.log"
+}
+
+H4="$TMP/home4"
+mkdir -p "$H4/work"
+seed_stable "$H4"
+ln -s "$H4/.lume" "$H4/alias-to-stable" # a symlink to the released home
+ln -s "$H4" "$H4/home-link" # a symlink to HOME
+ln -s "$H4/.local/share/lume" "$H4/share-alias" # a symlink to the released app files
+ln -s .lume "$H4/.lume-local" # the default Local home, already aliasing the released home
+S4_BEFORE="$(fingerprint $(stable_paths "$H4"))"
+I4_BEFORE="$(inventory "$H4")"
+H_SAVE="$H"
+H="$H4"
+
+ALIASES=(
+ "$H4/./.lume"
+ "$H4/.lume/../.lume"
+ "$H4/work/../.lume"
+ "$H4/.lume/"
+ "$H4/.lume//vm1"
+ "$H4/.LUME"
+ "$H4/alias-to-stable"
+ "$H4/alias-to-stable/vm1"
+ "$H4/alias-to-stable/../.lume"
+ "$H4/home-link/.lume"
+ "$H4/home-link/./work/../.lume/vm1"
+ "$H4/home-link"
+ "$H4/.local"
+ "$H4/.local/share"
+ "$H4/.local/share/lume"
+ "$H4/share-alias/x"
+ "$H4/.config"
+ "$H4/.config/lume/sub"
+ "$H4/Library"
+ "$H4/Library/LaunchAgents/com.trycua.lume_daemon.plist"
+ "$H4/Library/Logs/lume"
+ "$H4/Library/Logs"
+ "$H4/Library/Logs/lume/vm1.log"
+ # Leading or trailing whitespace: the Swift runtime must never see a path
+ # that the guard read as a different directory from the one it uses.
+ "$H4/.lume "
+ "$H4/.lume "
+ "$H4/.lume"$'\t'
+ "$H4/.lume"$'\n'
+ "$H4/.lume/vm1 "
+ "$H4/alias-to-stable "
+)
+for alias_path in "${ALIASES[@]}"; do
+ expect_refused "install with LUME_LOCAL_HOME=${alias_path#$H4}" LUME_LOCAL_HOME="$alias_path" install-local.sh
+ expect_refused "uninstall --yes with LUME_LOCAL_HOME=${alias_path#$H4}" LUME_LOCAL_HOME="$alias_path" uninstall-local.sh --yes
+done
+
+# The default Local home is a symlink to the released home.
+expect_refused "install when ~/.lume-local is a symlink to ~/.lume" install-local.sh
+expect_refused "uninstall --yes when ~/.lume-local is a symlink to ~/.lume" uninstall-local.sh --yes
+
+# The command, its files, its plist and its logs.
+expect_refused "install with --install-dir at the released command" install-local.sh --install-dir "$H4/.local/bin/lume"
+expect_refused "install with --install-dir inside the released home" install-local.sh --install-dir "$H4/.lume"
+expect_refused "install with --install-dir through a symlink to the released home" install-local.sh --install-dir "$H4/alias-to-stable/vm1"
+expect_refused "install with --install-dir at the released files" install-local.sh --install-dir "$H4/.local/share/lume"
+expect_refused "uninstall --yes with --install-dir at the released command" uninstall-local.sh --yes --install-dir "$H4/.local/bin/lume"
+expect_refused "install with the log directory inside the released home" LUME_LOCAL_LOG_DIR="$H4/alias-to-stable" LUME_LOCAL_HOME="$H4/safe-home" install-local.sh
+expect_refused "install with whitespace around --install-dir" LUME_LOCAL_HOME="$H4/safe-home" install-local.sh --install-dir "$H4/bin "
+expect_refused "uninstall --yes with whitespace around --install-dir" LUME_LOCAL_HOME="$H4/safe-home" uninstall-local.sh --yes --install-dir "$H4/bin "
+expect_refused "install with whitespace around LUME_LOCAL_LOG_DIR" LUME_LOCAL_HOME="$H4/safe-home" LUME_LOCAL_LOG_DIR="$LOGS " install-local.sh
+expect_refused "uninstall --yes with whitespace around LUME_LOCAL_LOG_DIR" LUME_LOCAL_HOME="$H4/safe-home" LUME_LOCAL_LOG_DIR="$LOGS "$'\t' uninstall-local.sh --yes
+expect_refused "install with a relative LUME_LOCAL_HOME" LUME_LOCAL_HOME="relative/.lume" install-local.sh
+expect_refused "install with a relative --install-dir" LUME_LOCAL_HOME="$H4/safe-home" install-local.sh --install-dir relative/bin
+
+same "refused aliases wrote nothing" "$I4_BEFORE" "$(inventory "$H4")"
+same "refused aliases left every released-Lume path untouched" "$S4_BEFORE" "$(fingerprint $(stable_paths "$H4"))"
+check "the released VM is intact after every refused uninstall" test "$(cat "$H4/.lume/vm1/config.json")" = '{"name":"vm1"}'
+check "the released home still holds its VM disk" test -f "$H4/.lume/vm1/disk.img"
+
+# Symlinks planted where the installer writes.
+H5="$TMP/home5"
+mkdir -p "$H5"
+seed_stable "$H5"
+H="$H5"
+ln -s ../share/lume "$H5/.local/share/lume-local" # its files directory is the released one
+S5_BEFORE="$(fingerprint $(stable_paths "$H5"))"
+I5_BEFORE="$(inventory "$H5")"
+expect_refused "install when the lume-local files directory is a symlink to the released one" install-local.sh
+expect_refused "uninstall --yes when the lume-local files directory is a symlink to the released one" uninstall-local.sh --yes
+rm "$H5/.local/share/lume-local"
+ln -s com.trycua.lume_daemon.plist "$H5/Library/LaunchAgents/com.trycua.lume_daemon.local.plist"
+I5_BEFORE="$(inventory "$H5")"
+expect_refused "install when the .local plist is a symlink to the released plist" install-local.sh
+expect_refused "uninstall --yes when the .local plist is a symlink to the released plist" uninstall-local.sh --yes
+rm "$H5/Library/LaunchAgents/com.trycua.lume_daemon.local.plist"
+ln -s lume "$H5/.local/bin/lume-local" # the command is a symlink to the released one
+I5_BEFORE="$(inventory "$H5")"
+expect_refused "install when lume-local is a symlink to the released lume" install-local.sh
+expect_refused "uninstall --yes when lume-local is a symlink to the released lume" uninstall-local.sh --yes
+rm "$H5/.local/bin/lume-local"
+I5_BEFORE="$(inventory "$H5")"
+rm -f "$LOGS/lume_daemon.local.log" "$LOGS/lume_daemon.local.error.log"
+ln -s lume_daemon.log "$LOGS/lume_daemon.local.log" # the daemon log is the released daemon's log
+expect_refused "install when the .local daemon log is a symlink to the released log" install-local.sh
+expect_refused "uninstall --yes when the .local daemon log is a symlink to the released log" uninstall-local.sh --yes
+rm "$LOGS/lume_daemon.local.log"
+ln -s lume_daemon.error.log "$LOGS/lume_daemon.local.error.log"
+expect_refused "install when the .local daemon error log is a symlink to the released one" install-local.sh
+expect_refused "uninstall --yes when the .local daemon error log is a symlink to the released one" uninstall-local.sh --yes
+rm "$LOGS/lume_daemon.local.error.log"
+ln -s lume "$H5/Library/Logs/lume-local" # the run-logs directory is the released one
+I5_BEFORE="$(inventory "$H5")"
+expect_refused "uninstall --yes when the lume-local run-logs directory is a symlink to the released one" uninstall-local.sh --yes
+rm "$H5/Library/Logs/lume-local"
+I5_BEFORE="$(inventory "$H5")"
+same "planted symlinks: nothing was written" "$I5_BEFORE" "$(inventory "$H5")"
+same "planted symlinks: the released Lume is untouched" "$S5_BEFORE" "$(fingerprint $(stable_paths "$H5"))"
+
+# A custom Local home is canonicalised, reaches the daemon and the command, and
+# is what an inherited LUME_HOME is replaced with.
+H6="$TMP/home6"
+mkdir -p "$H6/real-vms"
+seed_stable "$H6"
+ln -s real-vms "$H6/vms-link"
+mkdir -p "$H6/real-logs"
+ln -s real-logs "$H6/logs-link"
+S6_BEFORE="$(fingerprint $(stable_paths "$H6"))"
+H="$H6"
+run LUME_LOCAL_HOME="$H6/./vms-link/../vms-link/local home" LUME_LOCAL_LOG_DIR="$H6/./logs-link/../logs-link/run logs" install-local.sh >/dev/null 2>&1
+check "install with a custom home and log directory (through symlinks, with spaces) succeeds" test $? -eq 0
+LOGS6="$H6/real-logs/run logs"
+P6="$H6/Library/LaunchAgents/com.trycua.lume_daemon.local.plist"
+check "the custom home is canonical in the plist" test "$(plist_env "$P6" LUME_HOME)" = "$H6/real-vms/local home"
+check "the custom home exists and has its release-channel" test -f "$H6/real-vms/local home/release-channel"
+check "no default Local home was made beside it" test ! -e "$H6/.lume-local"
+# The configured log directory is persisted for the readers: the daemon gets it
+# (so the logs API reads where it writes) and so does the command (`lume-local logs`).
+check "the custom log directory is canonical in the plist's environment" test "$(plist_env "$P6" LUME_LOCAL_LOG_DIR)" = "$LOGS6"
+check "the plist writes the daemon log in the custom directory" grep -q "<string>$LOGS6/lume_daemon.local.log</string>" "$P6"
+check "the plist writes the daemon error log in the custom directory" grep -q "<string>$LOGS6/lume_daemon.local.error.log</string>" "$P6"
+check "the daemon logs exist in the custom directory" test -f "$LOGS6/lume_daemon.local.log" -a -f "$LOGS6/lume_daemon.local.error.log"
+check "the wrapper overrides an inherited LUME_LOCAL_LOG_DIR with the configured one" test \
+ "$(wrapper HOME="$H6" LUME_LOCAL_LOG_DIR=/somewhere/else "$H6/.local/bin/lume-local" logs 2>&1)" = "stub-lume name=lume-local args=logs LUME_HOME=$H6/real-vms/local home LUME_LOCAL_LOG_DIR=$LOGS6"
+check "the wrapper uses the custom home, not an inherited released-Lume LUME_HOME" test \
+ "$(wrapper HOME="$H6" LUME_HOME="$H6/.lume" "$H6/.local/bin/lume-local" ls 2>&1)" = "stub-lume name=lume-local args=ls LUME_HOME=$H6/real-vms/local home LUME_LOCAL_LOG_DIR=$LOGS6"
+check "the wrapper uses the custom home when LUME_HOME is unset" test \
+ "$(wrapper HOME="$H6" "$H6/.local/bin/lume-local" ls 2>&1)" = "stub-lume name=lume-local args=ls LUME_HOME=$H6/real-vms/local home LUME_LOCAL_LOG_DIR=$LOGS6"
+same "install with a custom home left the released Lume alone" "$S6_BEFORE" "$(fingerprint $(stable_paths "$H6"))"
+mkdir -p "$H6/real-vms/local home/vm-x"
+printf '{}\n' > "$H6/real-vms/local home/vm-x/config.json"
+run LUME_LOCAL_HOME="$H6/vms-link/local home" LUME_LOCAL_LOG_DIR="$H6/logs-link/run logs" uninstall-local.sh --yes >/dev/null 2>&1
+check "uninstall --yes with the same custom home succeeds" test $? -eq 0
+check "uninstall removed the daemon logs from the custom directory" test ! -e "$LOGS6/lume_daemon.local.log" -a ! -e "$LOGS6/lume_daemon.local.error.log"
+check "uninstall removed the custom home" test ! -e "$H6/real-vms/local home"
+check "uninstall kept the directory that held it" test -d "$H6/real-vms"
+same "uninstall of the custom home left the released Lume alone" "$S6_BEFORE" "$(fingerprint $(stable_paths "$H6"))"
+H="$H_SAVE"
+
+# ---- 4. bridged-entitlement build: an .app named lume-local -------------------
+
+if [ -x /usr/libexec/PlistBuddy ]; then
+ H3="$TMP/home3"
+ mkdir -p "$H3"
+ seed_stable "$H3"
+ S3_BEFORE="$(fingerprint $(stable_paths "$H3"))"
+ reset_logs
+ H="$H3"
+ run install-local.sh --bridged-entitlement --no-background-service >/dev/null 2>&1
+ check "bridged install succeeds" test $? -eq 0
+ APP="$H3/.local/share/lume-local/lume-local.app"
+ check "bridged install makes lume-local.app" test -x "$APP/Contents/MacOS/lume-local"
+ check "bridged app has the local bundle id" test \
+ "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$APP/Contents/Info.plist")" = com.trycua.lume.local
+ check "bridged app executable is lume-local" test \
+ "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "$APP/Contents/Info.plist")" = lume-local
+ check "bridged wrapper runs the app's lume-local with the Local home" test \
+ "$(wrapper HOME="$H3" LUME_HOME="$H3/.lume" "$H3/.local/bin/lume-local" ls 2>&1)" = "stub-lume name=lume-local args=ls LUME_HOME=$H3/.lume-local LUME_LOCAL_LOG_DIR=$LOGS"
+ check "bridged install leaves no stale standalone binary" test ! -e "$H3/.local/share/lume-local/lume-local"
+ same "bridged install left the released Lume alone" \
+ "$S3_BEFORE" "$(fingerprint $(stable_paths "$H3"))"
+ H="$H_SAVE"
+fi
+
+# ---- 5. uninstall -------------------------------------------------------------
+
+# 5a. Answering no removes nothing.
+INV_INSTALLED="$(inventory "$H")"
+reset_logs
+printf 'n\n' | run uninstall-local.sh >/dev/null 2>&1
+check "uninstall answered no succeeds" test $? -eq 0
+same "uninstall answered no removes nothing" "$INV_INSTALLED" "$(inventory "$H")"
+check "uninstall answered no never called launchctl" test ! -e "$STUB_LOG_DIR/launchctl.log"
+
+# 5b. Yes to removal, no to deleting the VMs: the home and its VMs stay.
+mkdir -p "$H/.lume-local/vm-local"
+printf '{"name":"vm-local"}\n' > "$H/.lume-local/vm-local/config.json"
+printf 'disk\n' > "$H/.lume-local/vm-local/disk.img"
+reset_logs
+# Logs of a detached `lume-local run`: lume-local's own directory, beside (not in) the released Lume's.
+mkdir -p "$H/Library/Logs/lume-local"
+printf 'local detached run\n' > "$H/Library/Logs/lume-local/vm-local.log"
+check "the released Lume's detached-run log is in a different directory" test "$(cat "$H/Library/Logs/lume/vm1.log")" = "released detached run"
+printf 'y\nn\n' | run uninstall-local.sh >/dev/null 2>&1
+check "uninstall keeping VMs succeeds" test $? -eq 0
+check "uninstall removed the command" test ! -e "$H/.local/bin/lume-local"
+check "uninstall removed the files" test ! -e "$H/.local/share/lume-local"
+check "uninstall removed the .local plist" test ! -e "$PLIST"
+check "uninstall removed the .local logs" test ! -e "$LOGS/lume_daemon.local.log"
+check "uninstall removed lume-local's detached-run logs" test ! -e "$H/Library/Logs/lume-local"
+check "uninstall kept the released Lume's detached-run logs" test -f "$H/Library/Logs/lume/vm1.log"
+check "uninstall kept the local VMs" test -f "$H/.lume-local/vm-local/config.json"
+check "launchctl only saw the .local plist on uninstall" bash -c "! grep -v 'com.trycua.lume_daemon.local.plist' '$STUB_LOG_DIR/launchctl.log'"
+same "uninstall left every released-Lume path untouched" \
+ "$STABLE_BEFORE" "$(fingerprint $(stable_paths "$H"))"
+
+# 5c. --yes deletes everything local, VMs included.
+reset_logs
+run install-local.sh >/dev/null 2>&1
+check "reinstall after uninstall succeeds" test $? -eq 0
+check "reinstall found the kept VMs" test -f "$H/.lume-local/vm-local/config.json"
+reset_logs
+run uninstall-local.sh --yes >/dev/null 2>&1
+check "uninstall --yes succeeds" test $? -eq 0
+check "uninstall --yes deleted the local home" test ! -e "$H/.lume-local"
+same "after uninstall --yes only the released Lume's files remain" \
+ "$INVENTORY_BEFORE" "$(inventory "$H")"
+same "uninstall --yes left every released-Lume path untouched" \
+ "$STABLE_BEFORE" "$(fingerprint $(stable_paths "$H"))"
+check "launchctl only saw the .local plist on uninstall --yes" bash -c "! grep -v 'com.trycua.lume_daemon.local.plist' '$STUB_LOG_DIR/launchctl.log'"
+
+# 5d. --yes --keep-vms keeps the home.
+run install-local.sh >/dev/null 2>&1
+mkdir -p "$H/.lume-local/vm-keep"
+printf '{}\n' > "$H/.lume-local/vm-keep/config.json"
+run uninstall-local.sh --yes --keep-vms >/dev/null 2>&1
+check "uninstall --yes --keep-vms succeeds" test $? -eq 0
+check "uninstall --yes --keep-vms kept the VMs" test -f "$H/.lume-local/vm-keep/config.json"
+check "uninstall --yes --keep-vms removed the command" test ! -e "$H/.local/bin/lume-local"
+rm -rf "$H/.lume-local"
+
+# 5e. A file named lume-local that is not ours is left alone.
+printf '#!/bin/sh\necho mine\n' > "$H/.local/bin/lume-local"
+run uninstall-local.sh --yes >/dev/null 2>&1
+check "uninstall with a foreign lume-local succeeds" test $? -eq 0
+check "uninstall leaves a lume-local it did not install" grep -q mine "$H/.local/bin/lume-local"
+rm -f "$H/.local/bin/lume-local"
+
+# 5f. Uninstall refuses the released home.
+run LUME_LOCAL_HOME="$H/.lume" uninstall-local.sh --yes >/dev/null 2>&1
+check "uninstall refuses the released home" test $? -ne 0
+same "uninstall of the released home removed nothing" \
+ "$STABLE_BEFORE" "$(fingerprint $(stable_paths "$H"))"
+
+# ---- result -------------------------------------------------------------------
+
+if [ "$FAILS" -ne 0 ]; then
+ echo "$FAILS of $CHECKS checks failed."
+ exit 1
+fi
+echo "All $CHECKS checks passed."
diff --git a/libs/lume/scripts/uninstall-local.sh b/libs/lume/scripts/uninstall-local.sh
new file mode 100755
index 0000000000..512ff222e7
--- /dev/null
+++ b/libs/lume/scripts/uninstall-local.sh
@@ -0,0 +1,217 @@
+#!/bin/bash
+set -e
+
+# Lume Local Uninstaller
+#
+# Removes only what install-local.sh installed as `lume-local`:
+#
+# ~/.local/bin/lume-local the command
+# ~/.local/share/lume-local the binary and its resources
+# ~/Library/LaunchAgents/com.trycua.lume_daemon.local.plist
+# /tmp/lume_daemon.local*.log the daemon logs
+# ~/Library/Logs/lume-local logs of detached runs (`run --detach`)
+# ~/.lume-local home: VMs, settings, cache (asks first)
+#
+# The released Lume (~/.local/bin/lume, ~/.local/share/lume, ~/.lume, the
+# com.trycua.lume_daemon LaunchAgent) is never read or changed.
+#
+# Usage: uninstall-local.sh [--yes] [--keep-vms] [--install-dir DIR]
+#
+# Every path is canonicalised (`.`, `..` and symlinks resolved) and refused if it
+# equals, sits inside, or contains a path the released Lume owns, so
+# `--yes` can never delete the released Lume's VMs through an alias such as
+# `$HOME/./.lume` or a symlink to it (scripts/_lume-local-common.sh).
+#
+# Environment (all optional; give the same values you gave install-local.sh):
+# LUME_LOCAL_HOME, LUME_LOCAL_INSTALL_DIR, LUME_LOCAL_LOG_DIR
+# LUME_HOME is deliberately ignored: it may point at the released Lume's home.
+
+# Get the directory where this script is located
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+
+# Define colors for output
+BOLD=$(tput bold 2>/dev/null || echo "")
+NORMAL=$(tput sgr0 2>/dev/null || echo "")
+RED=$(tput setaf 1 2>/dev/null || echo "")
+GREEN=$(tput setaf 2 2>/dev/null || echo "")
+YELLOW=$(tput setaf 3 2>/dev/null || echo "")
+BLUE=$(tput setaf 4 2>/dev/null || echo "")
+
+# The path guard shared with install-local.sh
+. "$SCRIPT_DIR/_lume-local-common.sh"
+
+LOCAL_BIN_NAME="lume-local"
+SERVICE_NAME="com.trycua.lume_daemon.local"
+WRAPPER_MARKER="# lume-local wrapper, managed by libs/lume/scripts/install-local.sh"
+
+INSTALL_DIR="${LUME_LOCAL_INSTALL_DIR:-$HOME/.local/bin}"
+APP_INSTALL_DIR="$HOME/.local/share/lume-local"
+LUME_LOCAL_HOME="${LUME_LOCAL_HOME:-$HOME/.lume-local}"
+LOG_DIR="${LUME_LOCAL_LOG_DIR:-/tmp}"
+
+ASSUME_YES=false
+KEEP_VMS=false
+
+while [ "$#" -gt 0 ]; do
+ case "$1" in
+ --yes|-y)
+ ASSUME_YES=true
+ ;;
+ --keep-vms)
+ KEEP_VMS=true
+ ;;
+ --install-dir)
+ INSTALL_DIR="$2"
+ shift
+ ;;
+ --help|-h)
+ echo "${BOLD}${BLUE}Lume Local Uninstaller${NORMAL}"
+ echo "Removes lume-local. The released lume is never touched."
+ echo "Usage: $0 [OPTIONS]"
+ echo ""
+ echo "Options:"
+ echo " --yes, -y Answer yes to every question, including deleting the VMs in $LUME_LOCAL_HOME"
+ echo " --keep-vms Never delete $LUME_LOCAL_HOME (VMs, settings, cache), even with --yes"
+ echo " --install-dir DIR Where the lume-local command was installed (default: $INSTALL_DIR)"
+ echo " --help Display this help message"
+ echo ""
+ echo "Without --yes, it asks before removing lume-local, and again before deleting any VMs."
+ exit 0
+ ;;
+ *)
+ echo "${RED}Unknown option: $1${NORMAL}"
+ echo "Use --help for usage information"
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# Canonicalise every path this script deletes (`.`, `..` and symlinks resolved),
+# and refuse any that equals, sits inside, or contains a path the released Lume
+# owns. From here on these are the canonical forms.
+LUME_LOCAL_HOME="$(lume_local_check "LUME_LOCAL_HOME" "$LUME_LOCAL_HOME")" || exit 2
+lume_local_no_edge_space "--install-dir" "$INSTALL_DIR" || exit 2
+lume_local_no_edge_space "LUME_LOCAL_LOG_DIR" "$LOG_DIR" || exit 2
+case "$INSTALL_DIR" in
+ /*) ;;
+ *) echo "${RED}Error: --install-dir must be an absolute path, got '$INSTALL_DIR'.${NORMAL}" >&2; exit 2 ;;
+esac
+lume_local_check "the lume-local command ($INSTALL_DIR/$LOCAL_BIN_NAME)" "$INSTALL_DIR/$LOCAL_BIN_NAME" >/dev/null || exit 2
+INSTALL_DIR="$(lume_local_canon "$INSTALL_DIR")" || exit 2
+LOCAL_BIN="$INSTALL_DIR/$LOCAL_BIN_NAME"
+APP_INSTALL_DIR="$(lume_local_check "the lume-local files directory" "$APP_INSTALL_DIR")" || exit 2
+PLIST_PATH="$(lume_local_check "the lume-local LaunchAgent plist" "$HOME/Library/LaunchAgents/$SERVICE_NAME.plist")" || exit 2
+LOG_FILE="$(lume_local_check "the lume-local daemon log" "$LOG_DIR/lume_daemon.local.log")" || exit 2
+ERROR_LOG_FILE="$(lume_local_check "the lume-local daemon error log" "$LOG_DIR/lume_daemon.local.error.log")" || exit 2
+RUN_LOG_DIR="$(lume_local_check "the lume-local run logs directory" "$HOME/Library/Logs/lume-local")" || exit 2
+
+# Ask a yes/no question. Defaults to no. --yes answers yes.
+confirm() {
+ if [ "$ASSUME_YES" = true ]; then
+ return 0
+ fi
+ local reply
+ read -r -p "$1 [y/N] " reply || reply=""
+ case "$reply" in
+ y|Y|yes|YES) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
+# Whether $LOCAL_BIN is the wrapper install-local.sh wrote.
+is_our_wrapper() {
+ [ -f "$LOCAL_BIN" ] && [ ! -L "$LOCAL_BIN" ] && grep -qF "$WRAPPER_MARKER" "$LOCAL_BIN" 2>/dev/null
+}
+
+echo "${BOLD}${BLUE}Lume Local Uninstaller${NORMAL}"
+echo ""
+echo "This removes lume-local: the command, its files, its LaunchAgent ($SERVICE_NAME) and logs."
+echo "The released lume, ~/.lume and port 7777 are not touched."
+echo ""
+
+if ! confirm "Remove lume-local?"; then
+ echo "Uninstall cancelled."
+ exit 0
+fi
+
+# Decide about the VMs now, so nothing is half done if the answer is no.
+DELETE_HOME=false
+if [ -d "$LUME_LOCAL_HOME" ]; then
+ VM_COUNT=$(find "$LUME_LOCAL_HOME" -mindepth 2 -maxdepth 2 -name config.json 2>/dev/null | wc -l | tr -d ' ')
+ echo ""
+ echo "${BOLD}$LUME_LOCAL_HOME${NORMAL} holds $VM_COUNT VM(s), plus settings and cache."
+ if [ "$KEEP_VMS" = true ]; then
+ echo "Keeping it (--keep-vms)."
+ elif confirm "Delete $LUME_LOCAL_HOME and everything in it, including the VMs?"; then
+ DELETE_HOME=true
+ else
+ echo "Keeping it."
+ fi
+fi
+
+echo ""
+echo "${BOLD}Stopping lume-local services...${NORMAL}"
+
+# Stop and remove the LaunchAgent. This also ends the daemon and the VMs it
+# hosts.
+if [ -f "$PLIST_PATH" ]; then
+ echo " Unloading lume-local daemon..."
+ launchctl unload "$PLIST_PATH" 2>/dev/null || true
+ rm -f "$PLIST_PATH"
+ echo " ${GREEN}Removed daemon LaunchAgent${NORMAL}"
+else
+ echo " Daemon LaunchAgent not found (skipped)"
+fi
+
+# VMs started outside the daemon are still running; stop them before their
+# files go.
+if [ "$DELETE_HOME" = true ] && is_our_wrapper; then
+ echo " Attempting to stop running lume-local VMs..."
+ "$LOCAL_BIN" ls 2>/dev/null | grep -E "running|starting" | awk '{print $1}' | while read -r vm; do
+ "$LOCAL_BIN" stop "$vm" 2>/dev/null || true
+ done
+fi
+
+echo ""
+echo "${BOLD}Removing lume-local files...${NORMAL}"
+
+if is_our_wrapper; then
+ rm -f "$LOCAL_BIN"
+ echo " ${GREEN}Removed $LOCAL_BIN${NORMAL}"
+elif [ -e "$LOCAL_BIN" ] || [ -L "$LOCAL_BIN" ]; then
+ echo " ${YELLOW}$LOCAL_BIN was not installed by install-local.sh (left in place)${NORMAL}"
+else
+ echo " $LOCAL_BIN not found (skipped)"
+fi
+
+if [ -d "$APP_INSTALL_DIR" ]; then
+ rm -rf "$APP_INSTALL_DIR"
+ echo " ${GREEN}Removed $APP_INSTALL_DIR${NORMAL}"
+else
+ echo " $APP_INSTALL_DIR not found (skipped)"
+fi
+
+for logfile in "$LOG_FILE" "$ERROR_LOG_FILE"; do
+ if [ -f "$logfile" ]; then
+ rm -f "$logfile"
+ echo " ${GREEN}Removed $logfile${NORMAL}"
+ fi
+done
+
+if [ -d "$RUN_LOG_DIR" ]; then
+ rm -rf "$RUN_LOG_DIR"
+ echo " ${GREEN}Removed $RUN_LOG_DIR${NORMAL}"
+fi
+
+if [ "$DELETE_HOME" = true ]; then
+ rm -rf "$LUME_LOCAL_HOME"
+ echo " ${GREEN}Removed $LUME_LOCAL_HOME (VMs, settings, cache)${NORMAL}"
+fi
+
+echo ""
+echo "${GREEN}${BOLD}lume-local has been uninstalled.${NORMAL}"
+if [ -d "$LUME_LOCAL_HOME" ]; then
+ echo "Kept $LUME_LOCAL_HOME. Delete it yourself if you no longer need those VMs."
+fi
+echo ""
diff --git a/libs/lume/src/Commands/CheckUpdate.swift b/libs/lume/src/Commands/CheckUpdate.swift
index 18ce95f1b9..45c5cf14d7 100644
--- a/libs/lume/src/Commands/CheckUpdate.swift
+++ b/libs/lume/src/Commands/CheckUpdate.swift
@@ -22,7 +22,7 @@ struct CheckUpdate: AsyncParsableCommand {
if json {
try printJSON(LumeVersionCheck.disabledState())
} else {
- print("Update checks disabled by LUME_UPDATE_CHECK.")
+ print("\(LumeVersionCheck.updateChecksDisabledReason()).")
}
return
}
@@ -69,7 +69,7 @@ struct Update: AsyncParsableCommand {
if json {
try printJSON(LumeVersionCheck.disabledState())
} else {
- print("Update checks disabled by LUME_UPDATE_CHECK.")
+ print("\(LumeVersionCheck.updateChecksDisabledReason()).")
}
return
}
diff --git a/libs/lume/src/Commands/DetachedRun.swift b/libs/lume/src/Commands/DetachedRun.swift
index 043fe1826e..c89081810b 100644
--- a/libs/lume/src/Commands/DetachedRun.swift
+++ b/libs/lume/src/Commands/DetachedRun.swift
@@ -98,13 +98,19 @@ enum DetachedVMRunner {
return childArguments
}
- static func defaultLogURL(vmName: String) -> URL {
+ /// `<vm>.log` in `~/Library/Logs/lume`, or `~/Library/Logs/lume-local` for
+ /// `lume-local`, so a Local detached run never appends to the released
+ /// Lume's logs.
+ static func defaultLogURL(
+ vmName: String,
+ channel: LumeChannel = .current,
+ userHome: URL = FileManager.default.homeDirectoryForCurrentUser
+ ) -> URL {
let allowed = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-_."))
let safeName = String(
vmName.unicodeScalars.map { allowed.contains($0) ? Character(String($0)) : "_" }
)
- return FileManager.default.homeDirectoryForCurrentUser
- .appendingPathComponent("Library/Logs/lume", isDirectory: true)
+ return channel.lumeLogDir(userHome: userHome)
.appendingPathComponent("\(safeName).log")
}
diff --git a/libs/lume/src/Commands/Logs.swift b/libs/lume/src/Commands/Logs.swift
index d659eba527..8ec71c6ca3 100644
--- a/libs/lume/src/Commands/Logs.swift
+++ b/libs/lume/src/Commands/Logs.swift
@@ -129,7 +129,7 @@ struct Logs: ParsableCommand {
var follow: Bool = false
func run() throws {
- let logPath = "/tmp/lume_daemon.log"
+ let logPath = LumeChannel.current.lumeDaemonLogPath()
print("=== Info Logs ===")
@@ -159,7 +159,7 @@ struct Logs: ParsableCommand {
var follow: Bool = false
func run() throws {
- let logPath = "/tmp/lume_daemon.error.log"
+ let logPath = LumeChannel.current.lumeDaemonErrorLogPath()
print("=== Error Logs ===")
@@ -368,8 +368,8 @@ struct Logs: ParsableCommand {
}
func run() throws {
- let infoLogPath = "/tmp/lume_daemon.log"
- let errorLogPath = "/tmp/lume_daemon.error.log"
+ let infoLogPath = LumeChannel.current.lumeDaemonLogPath()
+ let errorLogPath = LumeChannel.current.lumeDaemonErrorLogPath()
if follow {
// Use custom tailing implementation for both logs
diff --git a/libs/lume/src/Commands/Serve.swift b/libs/lume/src/Commands/Serve.swift
index 3b0324b690..f4d3d3cd85 100644
--- a/libs/lume/src/Commands/Serve.swift
+++ b/libs/lume/src/Commands/Serve.swift
@@ -7,7 +7,7 @@ struct Serve: AsyncParsableCommand {
)
@Option(help: "Port to listen on (HTTP mode only)")
- var port: UInt16 = 7777
+ var port: UInt16 = LumeChannel.current.lumePort
@Flag(name: .long, help: "Run as MCP server (stdio transport) for AI agent integration")
var mcp: Bool = false
@@ -45,7 +45,7 @@ struct Serve: AsyncParsableCommand {
// Create a user-friendly error message that includes the suggestion
let message = """
\(error.localizedDescription)
- Try using a different port: lume serve --port \(suggestedPort)
+ Try using a different port: \(LumeChannel.current.lumeBinName) serve --port \(suggestedPort)
"""
// Log the message (without the "ERROR:" prefix that ArgumentParser will add)
diff --git a/libs/lume/src/FileSystem/LumeChannel.swift b/libs/lume/src/FileSystem/LumeChannel.swift
new file mode 100644
index 0000000000..0261d99410
--- /dev/null
+++ b/libs/lume/src/FileSystem/LumeChannel.swift
@@ -0,0 +1,270 @@
+import Foundation
+
+/// Which Lume this process is: the released one, or the source build that
+/// `scripts/install-local.sh` installs beside it as `lume-local`.
+///
+/// The two never share a file, launchd label, port or log. Every name that
+/// differs lives here, so nothing else hard-codes `.lume` or `7777`. The
+/// accessors carry the same names as the `lume_*` methods of `CuaChannel`
+/// (`libs/cua/crates/cua-home/src/channel.rs`), which is how Cua Spaces picks
+/// the Lume that belongs to its own channel.
+///
+/// | | Stable | Local |
+/// |---|---|---|
+/// | binary | `lume` | `lume-local` |
+/// | LaunchAgent | `com.trycua.lume_daemon` | `com.trycua.lume_daemon.local` |
+/// | port | 7777 | 7787 |
+/// | home and VMs | `~/.lume` | `~/.lume-local` |
+///
+/// The channel is the name the binary runs under, like `cua-driver-local`: a
+/// process named `lume-local` is Local, anything else is Stable. Explicit
+/// flags and `LUME_HOME` always win over the channel's defaults; see
+/// `LumeLayout`.
+enum LumeChannel: String, CaseIterable, Sendable {
+ case stable
+ case local
+
+ /// The binary name that selects `.local`.
+ static let localBinName = "lume-local"
+
+ // MARK: - Names
+
+ /// The Lume binary's file name: `lume` or `lume-local`.
+ var lumeBinName: String {
+ switch self {
+ case .stable: return "lume"
+ case .local: return Self.localBinName
+ }
+ }
+
+ /// The Lume server's port.
+ var lumePort: UInt16 {
+ switch self {
+ case .stable: return 7777
+ case .local: return 7787
+ }
+ }
+
+ /// The Lume server's URL (`LUME_API`'s default).
+ var lumeAPI: String {
+ "http://127.0.0.1:\(lumePort)"
+ }
+
+ /// The name of the directory under the user's home that holds Lume's
+ /// VMs and state: `.lume` or `.lume-local`.
+ var lumeDirName: String {
+ switch self {
+ case .stable: return ".lume"
+ case .local: return ".lume-local"
+ }
+ }
+
+ /// Where Lume keeps its VMs by default: `~/.lume` or `~/.lume-local`.
+ func lumeDir(userHome: URL = FileManager.default.homeDirectoryForCurrentUser) -> URL {
+ userHome.appendingPathComponent(lumeDirName, isDirectory: true)
+ }
+
+ /// The launchd label of the Lume daemon.
+ var lumeDaemonLabel: String {
+ switch self {
+ case .stable: return "com.trycua.lume_daemon"
+ case .local: return "com.trycua.lume_daemon.local"
+ }
+ }
+
+ /// The environment variable that moves the Local daemon's logs. The
+ /// installer sets it (in the LaunchAgent and in the `lume-local` command)
+ /// when the logs go somewhere other than `/tmp`. Stable ignores it.
+ static let localLogDirVariable = "LUME_LOCAL_LOG_DIR"
+
+ /// The directory the daemon's LaunchAgent writes its logs in, and where
+ /// `logs` and the logs API read them: `/tmp`, or for Local the absolute
+ /// `LUME_LOCAL_LOG_DIR` when set.
+ func lumeDaemonLogDir(
+ environment: [String: String] = ProcessInfo.processInfo.environment
+ ) -> String {
+ guard self == .local,
+ let dir = environment[Self.localLogDirVariable],
+ dir.hasPrefix("/")
+ else { return "/tmp" }
+ return URL(fileURLWithPath: dir, isDirectory: true).standardizedFileURL.path
+ }
+
+ /// The daemon's stdout log, as written by its LaunchAgent.
+ func lumeDaemonLogPath(
+ environment: [String: String] = ProcessInfo.processInfo.environment
+ ) -> String {
+ let name = self == .stable ? "lume_daemon.log" : "lume_daemon.local.log"
+ return "\(lumeDaemonLogDir(environment: environment))/\(name)"
+ }
+
+ /// The daemon's stderr log, as written by its LaunchAgent.
+ func lumeDaemonErrorLogPath(
+ environment: [String: String] = ProcessInfo.processInfo.environment
+ ) -> String {
+ let name = self == .stable ? "lume_daemon.error.log" : "lume_daemon.local.error.log"
+ return "\(lumeDaemonLogDir(environment: environment))/\(name)"
+ }
+
+ /// Where `run --detach` writes `<vm>.log` by default:
+ /// `~/Library/Logs/lume` or `~/Library/Logs/lume-local`.
+ func lumeLogDir(
+ userHome: URL = FileManager.default.homeDirectoryForCurrentUser
+ ) -> URL {
+ userHome.appendingPathComponent("Library/Logs", isDirectory: true)
+ .appendingPathComponent(self == .stable ? "lume" : "lume-local", isDirectory: true)
+ }
+
+ /// Whether this Lume can update itself. A source build has no release to
+ /// update to, and the update path runs the stable installer, which would
+ /// replace the stable Lume.
+ var supportsSelfUpdate: Bool {
+ self == .stable
+ }
+
+ // MARK: - Resolution
+
+ /// The channel of this process.
+ static var current: LumeChannel {
+ resolve(executablePaths: ownExecutablePaths())
+ }
+
+ /// The channel for a process known by `executablePaths`: Local when any of
+ /// them is `lume-local` (or inside `lume-local.app`), else Stable.
+ static func resolve(executablePaths: [String]) -> LumeChannel {
+ executablePaths.contains(where: pathIsLocal) ? .local : .stable
+ }
+
+ /// Whether `path` names the Local binary.
+ static func pathIsLocal(_ path: String) -> Bool {
+ let url = URL(fileURLWithPath: path)
+ if url.lastPathComponent == localBinName { return true }
+ return url.pathComponents.contains("\(localBinName).app")
+ }
+
+ /// The paths this process is known by: `argv[0]` (which keeps the name a
+ /// symlink was started under), the executable the system reports, and that
+ /// path with symlinks resolved.
+ static func ownExecutablePaths() -> [String] {
+ var paths: [String] = []
+ if let argv0 = CommandLine.arguments.first, !argv0.isEmpty {
+ paths.append(argv0)
+ }
+ if let executable = Bundle.main.executablePath {
+ paths.append(executable)
+ paths.append(URL(fileURLWithPath: executable).resolvingSymlinksInPath().path)
+ }
+ return paths
+ }
+}
+
+/// Where this Lume keeps its files.
+///
+/// **Stable** keeps them where it always has: VMs and cache in `~/.lume`, the
+/// settings file in `$XDG_CONFIG_HOME/lume` (else `~/.config/lume`), and the
+/// release-channel file in `$LUME_HOME` when that is set, else `~/.lume`.
+/// `LUME_HOME` moves nothing else for Stable.
+///
+/// **Local** (a binary named `lume-local`) has a home of its own, `~/.lume-local`,
+/// and `LUME_HOME` moves all of it: the VM directory, the settings file, the
+/// image cache, the release-channel file and the telemetry identity. Local
+/// also keeps its settings file in that home and ignores `XDG_CONFIG_HOME`:
+/// that variable is shared by every Lume on the Mac, so honouring it would
+/// point Local at Stable's `config.yaml`, and with it at Stable's VMs.
+struct LumeLayout: Equatable, Sendable {
+ let channel: LumeChannel
+ /// The VM directory and state root, as an absolute path.
+ let homeDir: URL
+ /// `homeDir` as settings store it: `~/.lume` or `~/.lume-local` for a
+ /// default home, so the settings file stays portable, else the absolute
+ /// override.
+ let homeSetting: String
+ /// The directory of the settings file (`config.yaml`).
+ let configDir: URL
+ /// The release-channel file (`stable` or `nightly`, the update track).
+ let releaseChannelFile: URL
+
+ /// Whether the settings file lives in `homeDir` rather than in the shared
+ /// XDG config directory.
+ var configInHome: Bool { configDir == homeDir }
+
+ /// The default image cache, as settings store it.
+ var cacheSetting: String { "\(homeSetting)/cache" }
+
+ /// The channel's default server port.
+ var port: UInt16 { channel.lumePort }
+
+ /// The layout for `channel` under `environment`, with `userHome` standing
+ /// in for `~`.
+ static func resolve(
+ channel: LumeChannel,
+ environment: [String: String],
+ userHome: URL
+ ) -> LumeLayout {
+ switch channel {
+ case .stable:
+ let home = channel.lumeDir(userHome: userHome)
+ // Exactly the release-channel rule Lume had before channels:
+ // LUME_HOME, when non-empty, is where that one file lives.
+ let channelDir: URL
+ if let override = environment["LUME_HOME"], !override.isEmpty {
+ channelDir = URL(fileURLWithPath: override)
+ } else {
+ channelDir = home
+ }
+ return LumeLayout(
+ channel: channel,
+ homeDir: home,
+ homeSetting: "~/\(channel.lumeDirName)",
+ configDir: xdgConfigDir(environment: environment, userHome: userHome),
+ releaseChannelFile: channelDir.appendingPathComponent(LumeReleaseChannel.fileName)
+ )
+ case .local:
+ // LUME_HOME is used exactly as given, whitespace included. Trimming
+ // it here would turn a path the installer's guard accepted
+ // ("~/.lume ", with a trailing space) into the released Lume's
+ // home. A value of only whitespace counts as unset.
+ let raw = environment["LUME_HOME"]
+ let home: URL
+ let setting: String
+ if let raw, !raw.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
+ home = URL(fileURLWithPath: expandTilde(raw, userHome: userHome)).standardizedFileURL
+ setting = home.path
+ } else {
+ home = channel.lumeDir(userHome: userHome)
+ setting = "~/\(channel.lumeDirName)"
+ }
+ return LumeLayout(
+ channel: channel,
+ homeDir: home,
+ homeSetting: setting,
+ configDir: home,
+ releaseChannelFile: home.appendingPathComponent(LumeReleaseChannel.fileName)
+ )
+ }
+ }
+
+ /// The layout of this process.
+ static var current: LumeLayout {
+ resolve(
+ channel: .current,
+ environment: ProcessInfo.processInfo.environment,
+ userHome: FileManager.default.homeDirectoryForCurrentUser
+ )
+ }
+
+ /// `$XDG_CONFIG_HOME/lume`, else `~/.config/lume`: where Stable has always
+ /// kept its settings.
+ private static func xdgConfigDir(environment: [String: String], userHome: URL) -> URL {
+ if let xdg = environment["XDG_CONFIG_HOME"] {
+ return URL(fileURLWithPath: "\(xdg)/lume", isDirectory: true)
+ }
+ return userHome.appendingPathComponent(".config/lume", isDirectory: true)
+ }
+
+ private static func expandTilde(_ path: String, userHome: URL) -> String {
+ if path == "~" { return userHome.path }
+ if path.hasPrefix("~/") { return userHome.path + String(path.dropFirst()) }
+ return path
+ }
+}
diff --git a/libs/lume/src/FileSystem/Settings.swift b/libs/lume/src/FileSystem/Settings.swift
index 2d893ec382..1f7cafa59d 100644
--- a/libs/lume/src/FileSystem/Settings.swift
+++ b/libs/lume/src/FileSystem/Settings.swift
@@ -15,19 +15,25 @@ struct LumeSettings: Codable, Sendable {
// For backward compatibility
var homeDirectory: String {
- defaultLocation?.path ?? "~/.lume"
+ defaultLocation?.path ?? LumeLayout.current.homeSetting
}
- static let defaultSettings = LumeSettings(
- vmLocations: [
- VMLocation(name: "home", path: "~/.lume")
- ],
- defaultLocationName: "home",
- cacheDirectory: "~/.lume/cache",
- cachingEnabled: false,
- registry: .defaultConfig,
- telemetryEnabled: true
- )
+ /// The settings of a Lume that has no settings file yet: VMs and cache in
+ /// the layout's home (`~/.lume`, or `~/.lume-local` / `LUME_HOME` for `lume-local`).
+ static func defaults(layout: LumeLayout = .current) -> LumeSettings {
+ LumeSettings(
+ vmLocations: [
+ VMLocation(name: "home", path: layout.homeSetting)
+ ],
+ defaultLocationName: "home",
+ cacheDirectory: layout.cacheSetting,
+ cachingEnabled: false,
+ registry: .defaultConfig,
+ telemetryEnabled: true
+ )
+ }
+
+ static var defaultSettings: LumeSettings { defaults() }
/// Gets all locations sorted by name
var sortedLocations: [VMLocation] {
@@ -39,8 +45,6 @@ final class SettingsManager: @unchecked Sendable {
// MARK: - Constants
private enum Constants {
- // Default path for config
- static let fallbackConfigDir = "~/.config/lume"
static let configFileName = "config.yaml"
}
@@ -48,15 +52,15 @@ final class SettingsManager: @unchecked Sendable {
static let shared = SettingsManager()
private let fileManager: FileManager
+ private let layoutProvider: @Sendable () -> LumeLayout
- // Get the config directory following XDG spec
+ private var layout: LumeLayout { layoutProvider() }
+
+ // The config directory. lume-local keeps its settings in its own home;
+ // the released Lume follows the XDG spec, as it always has (`LumeLayout`
+ // decides).
private var configDir: String {
- // Check XDG_CONFIG_HOME environment variable first
- if let xdgConfigHome = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"] {
- return "\(xdgConfigHome)/lume"
- }
- // Fall back to default
- return (Constants.fallbackConfigDir as NSString).expandingTildeInPath
+ layout.configDir.path
}
// Path to config file
@@ -66,8 +70,12 @@ final class SettingsManager: @unchecked Sendable {
// MARK: - Initialization
- init(fileManager: FileManager = .default) {
+ init(
+ fileManager: FileManager = .default,
+ layout: (@Sendable () -> LumeLayout)? = nil
+ ) {
self.fileManager = fileManager
+ self.layoutProvider = layout ?? { LumeLayout.current }
ensureConfigDirectoryExists()
}
@@ -79,16 +87,7 @@ final class SettingsManager: @unchecked Sendable {
}
// No settings file found, use defaults
- let defaultSettings = LumeSettings(
- vmLocations: [
- VMLocation(name: "home", path: "~/.lume")
- ],
- defaultLocationName: "home",
- cacheDirectory: "~/.lume/cache",
- cachingEnabled: false,
- registry: .defaultConfig,
- telemetryEnabled: true
- )
+ let defaultSettings = LumeSettings.defaults(layout: layout)
// Try to save default settings
try? saveSettings(defaultSettings)
@@ -314,7 +313,7 @@ final class SettingsManager: @unchecked Sendable {
// A real implementation would use a proper YAML library
var defaultLocationName = "home"
- var cacheDirectory = "~/.lume/cache"
+ var cacheDirectory = layout.cacheSetting
var cachingEnabled = false // default to false to save disk space
var telemetryEnabled = true // default to true for anonymous usage tracking
var vmLocations: [VMLocation] = []
@@ -482,7 +481,7 @@ final class SettingsManager: @unchecked Sendable {
// Ensure at least one location exists
if vmLocations.isEmpty {
- vmLocations.append(VMLocation(name: "home", path: "~/.lume"))
+ vmLocations.append(VMLocation(name: "home", path: layout.homeSetting))
}
// Build registry config
diff --git a/libs/lume/src/Server/Handlers.swift b/libs/lume/src/Server/Handlers.swift
index aa5d1c05bb..64bf7ad649 100644
--- a/libs/lume/src/Server/Handlers.swift
+++ b/libs/lume/src/Server/Handlers.swift
@@ -1010,45 +1010,13 @@ extension Server {
func handleGetLogs(type: String?, lines: Int?) async throws -> HTTPResponse {
do {
- let logType = type?.lowercased() ?? "all"
- let infoPath = "/tmp/lume_daemon.log"
- let errorPath = "/tmp/lume_daemon.error.log"
-
- let fileManager = FileManager.default
- var response: [String: String] = [:]
-
- // Function to read log files
- func readLogFile(path: String) -> String? {
- guard fileManager.fileExists(atPath: path) else {
- return nil
- }
-
- do {
- let content = try String(contentsOfFile: path, encoding: .utf8)
-
- // If lines parameter is provided, return only the specified number of lines from the end
- if let lineCount = lines {
- let allLines = content.components(separatedBy: .newlines)
- let startIndex = max(0, allLines.count - lineCount)
- let lastLines = Array(allLines[startIndex...])
- return lastLines.joined(separator: "\n")
- }
-
- return content
- } catch {
- return "Error reading log file: \(error.localizedDescription)"
- }
- }
-
- // Get logs based on requested type
- if logType == "info" || logType == "all" {
- response["info"] = readLogFile(path: infoPath) ?? "Info log file not found"
- }
-
- if logType == "error" || logType == "all" {
- response["error"] = readLogFile(path: errorPath) ?? "Error log file not found"
- }
-
+ let channel = LumeChannel.current
+ let response = DaemonLogs.response(
+ type: type,
+ lines: lines,
+ infoPath: channel.lumeDaemonLogPath(),
+ errorPath: channel.lumeDaemonErrorLogPath()
+ )
return try .json(response)
} catch {
return .badRequest(message: error.localizedDescription)
diff --git a/libs/lume/src/Server/Server.swift b/libs/lume/src/Server/Server.swift
index fecc02d197..c73a7fefa1 100644
--- a/libs/lume/src/Server/Server.swift
+++ b/libs/lume/src/Server/Server.swift
@@ -185,7 +185,7 @@ final class Server: @unchecked Sendable {
// MARK: - Initialization
- init(port: UInt16 = 7777) {
+ init(port: UInt16 = LumeChannel.current.lumePort) {
self.portNumber = port
self.controller = LumeController()
self.routes = []
diff --git a/libs/lume/src/Telemetry/TelemetryClient.swift b/libs/lume/src/Telemetry/TelemetryClient.swift
index 2eaa59cdf4..47907c2645 100644
--- a/libs/lume/src/Telemetry/TelemetryClient.swift
+++ b/libs/lume/src/Telemetry/TelemetryClient.swift
@@ -87,9 +87,7 @@ final class TelemetryClient: @unchecked Sendable {
poster: Poster? = nil,
preferenceProvider: (@Sendable () -> Bool)? = nil
) {
- self.homeDirectory =
- homeDirectory
- ?? FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".lume")
+ self.homeDirectory = homeDirectory ?? LumeLayout.current.homeDir
self.poster = poster
self.preferenceProvider =
preferenceProvider ?? { settingsManager.getSettings().telemetryEnabled }
diff --git a/libs/lume/src/Update/ReleaseChannel.swift b/libs/lume/src/Update/ReleaseChannel.swift
index a7df3718d3..dffcc44e0e 100644
--- a/libs/lume/src/Update/ReleaseChannel.swift
+++ b/libs/lume/src/Update/ReleaseChannel.swift
@@ -38,13 +38,11 @@ enum LumeReleaseChannel: String, Codable, CaseIterable {
try Data("\(channel.rawValue)\n".utf8).write(to: url, options: .atomic)
}
+ /// `$LUME_HOME/release-channel` for the released Lume (as it always was),
+ /// else `~/.lume/release-channel`; `<home>/release-channel` for `lume-local`,
+ /// where the home is `LUME_HOME` or `~/.lume-local`.
static func stateFileURL() -> URL {
- if let override = ProcessInfo.processInfo.environment["LUME_HOME"], !override.isEmpty {
- return URL(fileURLWithPath: override).appendingPathComponent(fileName)
- }
- return FileManager.default.homeDirectoryForCurrentUser
- .appendingPathComponent(".lume")
- .appendingPathComponent(fileName)
+ LumeLayout.current.releaseChannelFile
}
static func plainVersion(_ version: String) -> [Int]? {
diff --git a/libs/lume/src/Update/VersionCheck.swift b/libs/lume/src/Update/VersionCheck.swift
index 4c70f1f703..d805987fab 100644
--- a/libs/lume/src/Update/VersionCheck.swift
+++ b/libs/lume/src/Update/VersionCheck.swift
@@ -10,8 +10,9 @@ enum LumeVersionCheck {
private static let cacheRefreshSeconds: TimeInterval = 20 * 60 * 60
private static let updateCheckEnv = "LUME_UPDATE_CHECK"
private static let installScriptURLEnv = "LUME_INSTALL_SCRIPT_URL"
- private static let backgroundServicePlistPath =
- "Library/LaunchAgents/com.trycua.lume_daemon.plist"
+ private static var backgroundServicePlistPath: String {
+ "Library/LaunchAgents/\(LumeChannel.current.lumeDaemonLabel).plist"
+ }
struct State: Codable {
let currentVersion: String
@@ -169,13 +170,24 @@ enum LumeVersionCheck {
)
}
- static func updateChecksEnabled() -> Bool {
+ static func updateChecksEnabled(channel: LumeChannel = .current) -> Bool {
+ // lume-local is a source build: there is no release to move it to, and
+ // the update path runs the stable installer, which replaces `lume`.
+ guard channel.supportsSelfUpdate else { return false }
guard let value = ProcessInfo.processInfo.environment[updateCheckEnv]?.lowercased() else {
return true
}
return !["0", "false", "no", "off"].contains(value)
}
+ /// Why `updateChecksEnabled()` is false.
+ static func updateChecksDisabledReason(channel: LumeChannel = .current) -> String {
+ channel.supportsSelfUpdate
+ ? "Update checks disabled by LUME_UPDATE_CHECK"
+ : "\(channel.lumeBinName) is a source build and has no update feed; "
+ + "rebuild it with libs/lume/scripts/install-local.sh"
+ }
+
static func disabledState() -> State {
State(
currentVersion: Lume.Version.current,
@@ -188,7 +200,7 @@ enum LumeVersionCheck {
cacheHit: false,
installCommand: nil,
releaseNotesURL: nil,
- error: "Update checks disabled by LUME_UPDATE_CHECK"
+ error: updateChecksDisabledReason()
)
}
diff --git a/libs/lume/src/Utils/DaemonLogs.swift b/libs/lume/src/Utils/DaemonLogs.swift
new file mode 100644
index 0000000000..aa3e23ba7a
--- /dev/null
+++ b/libs/lume/src/Utils/DaemonLogs.swift
@@ -0,0 +1,49 @@
+import Foundation
+
+/// Reads the daemon's log files for `GET /lume/logs`. The paths come from
+/// `LumeChannel` (so `lume-local` reads its own, wherever `LUME_LOCAL_LOG_DIR`
+/// put them), and are passed in so the reader can be tested against any
+/// directory.
+enum DaemonLogs {
+ /// `info` and/or `error`, per `type` (`info`, `error`, or `all`, the
+ /// default), each the last `lines` lines of its file when given.
+ static func response(
+ type: String?,
+ lines: Int?,
+ infoPath: String,
+ errorPath: String
+ ) -> [String: String] {
+ let logType = type?.lowercased() ?? "all"
+ var response: [String: String] = [:]
+
+ if logType == "info" || logType == "all" {
+ response["info"] = read(path: infoPath, lines: lines) ?? "Info log file not found"
+ }
+ if logType == "error" || logType == "all" {
+ response["error"] = read(path: errorPath, lines: lines) ?? "Error log file not found"
+ }
+ return response
+ }
+
+ private static func read(path: String, lines: Int?) -> String? {
+ guard FileManager.default.fileExists(atPath: path) else {
+ return nil
+ }
+
+ do {
+ let content = try String(contentsOfFile: path, encoding: .utf8)
+
+ // If lines parameter is provided, return only the specified number of lines from the end
+ if let lineCount = lines {
+ let allLines = content.components(separatedBy: .newlines)
+ let startIndex = max(0, allLines.count - lineCount)
+ let lastLines = Array(allLines[startIndex...])
+ return lastLines.joined(separator: "\n")
+ }
+
+ return content
+ } catch {
+ return "Error reading log file: \(error.localizedDescription)"
+ }
+ }
+}
diff --git a/libs/lume/src/Utils/LumeServeProcess.swift b/libs/lume/src/Utils/LumeServeProcess.swift
index cc72de4375..5f921da4cc 100644
--- a/libs/lume/src/Utils/LumeServeProcess.swift
+++ b/libs/lume/src/Utils/LumeServeProcess.swift
@@ -8,7 +8,9 @@ import Foundation
/// a signal would end the server and every VM it hosts, so `stop` asks the
/// server to stop the one VM instead.
enum LumeServeProcess {
- static let defaultPort: UInt16 = 7777
+ /// The port `serve` listens on when no `--port` is given: 7777 for
+ /// `lume`, 7787 for `lume-local`.
+ static var defaultPort: UInt16 { LumeChannel.current.lumePort }
/// The port `pid` serves the Lume API on, or nil when `pid` is not a
/// `lume serve` process (a detached `lume run`, say) or cannot be read.
@@ -19,7 +21,10 @@ enum LumeServeProcess {
/// The API port in a `lume serve` command line (`argv`, program first),
/// or nil when the command is not `serve`.
- static func apiPort(fromArguments arguments: [String]) -> UInt16? {
+ static func apiPort(
+ fromArguments arguments: [String],
+ defaultPort: UInt16 = LumeServeProcess.defaultPort
+ ) -> UInt16? {
guard arguments.count >= 2, arguments[1] == "serve" else { return nil }
var port = defaultPort
var index = 2
diff --git a/libs/lume/tests/DetachedRunTests.swift b/libs/lume/tests/DetachedRunTests.swift
index fa24ca5485..d17d3148d0 100644
--- a/libs/lume/tests/DetachedRunTests.swift
+++ b/libs/lume/tests/DetachedRunTests.swift
@@ -41,3 +41,14 @@ func detachedDefaultLogPath() {
let path = DetachedVMRunner.defaultLogURL(vmName: "example/vm:latest").path
#expect(path.hasSuffix("/Library/Logs/lume/example_vm_latest.log"))
}
+
+@Test("A Local detached run logs to lume-local's own directory, never the released Lume's")
+func detachedLocalLogPath() {
+ let home = URL(fileURLWithPath: "/Users/dev", isDirectory: true)
+ #expect(
+ DetachedVMRunner.defaultLogURL(vmName: "example/vm:latest", channel: .local, userHome: home).path
+ == "/Users/dev/Library/Logs/lume-local/example_vm_latest.log")
+ #expect(
+ DetachedVMRunner.defaultLogURL(vmName: "example/vm:latest", channel: .stable, userHome: home).path
+ == "/Users/dev/Library/Logs/lume/example_vm_latest.log")
+}
diff --git a/libs/lume/tests/LocalInstallScriptTests.swift b/libs/lume/tests/LocalInstallScriptTests.swift
new file mode 100644
index 0000000000..aa3e23c9fb
--- /dev/null
+++ b/libs/lume/tests/LocalInstallScriptTests.swift
@@ -0,0 +1,36 @@
+import Foundation
+import Testing
+
+/// Runs `scripts/tests/local-install-isolation-test.sh`, which installs and
+/// uninstalls `lume-local` into a fake HOME (swift, codesign and launchctl are
+/// stubs) and checks that the released Lume's files, LaunchAgent and port are
+/// never touched. It lives here so `swift test` runs it in CI.
+private let isolationScript: URL = URL(fileURLWithPath: #filePath)
+ .deletingLastPathComponent() // tests/
+ .deletingLastPathComponent() // libs/lume/
+ .appendingPathComponent("scripts/tests/local-install-isolation-test.sh")
+
+@Test(
+ "install-local.sh and uninstall-local.sh never touch the released Lume",
+ .enabled(if: FileManager.default.isExecutableFile(atPath: isolationScript.path))
+)
+func localInstallIsolation() throws {
+ let process = Process()
+ process.executableURL = URL(fileURLWithPath: "/bin/bash")
+ process.arguments = [isolationScript.path]
+ // Keep anything outside the script's own fake HOME from leaking in.
+ var environment = ProcessInfo.processInfo.environment
+ for name in ["LUME_HOME", "LUME_LOCAL_HOME", "LUME_LOCAL_INSTALL_DIR", "LUME_LOCAL_LOG_DIR", "SUDO_USER"] {
+ environment.removeValue(forKey: name)
+ }
+ process.environment = environment
+ let output = Pipe()
+ process.standardOutput = output
+ process.standardError = output
+
+ try process.run()
+ let log = String(decoding: output.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self)
+ process.waitUntilExit()
+
+ #expect(process.terminationStatus == 0, "\(log)")
+}
diff --git a/libs/lume/tests/LumeChannelTests.swift b/libs/lume/tests/LumeChannelTests.swift
new file mode 100644
index 0000000000..f9b46614c4
--- /dev/null
+++ b/libs/lume/tests/LumeChannelTests.swift
@@ -0,0 +1,489 @@
+import Foundation
+import Testing
+
+@testable import lume
+
+/// Path and port resolution for the Stable and Local Lume (`lume` and
+/// `lume-local`). The two must never resolve to a shared path, label, port or
+/// log, so the isolation test below walks both channels and checks the sets
+/// are disjoint.
+
+private let fakeHome = URL(fileURLWithPath: "/Users/dev", isDirectory: true)
+
+@Suite("Lume channel and layout")
+struct LumeChannelTests {
+ // MARK: - Names
+
+ @Test("Stable names are the released Lume's names")
+ func stableNames() {
+ let c = LumeChannel.stable
+ #expect(c.lumeBinName == "lume")
+ #expect(c.lumePort == 7777)
+ #expect(c.lumeAPI == "http://127.0.0.1:7777")
+ #expect(c.lumeDir(userHome: fakeHome).path == "/Users/dev/.lume")
+ #expect(c.lumeDaemonLabel == "com.trycua.lume_daemon")
+ #expect(c.lumeDaemonLogPath(environment: [:]) == "/tmp/lume_daemon.log")
+ #expect(c.lumeDaemonErrorLogPath(environment: [:]) == "/tmp/lume_daemon.error.log")
+ #expect(c.lumeLogDir(userHome: fakeHome).path == "/Users/dev/Library/Logs/lume")
+ #expect(c.supportsSelfUpdate)
+ }
+
+ @Test("Local names are the designed names")
+ func localNames() {
+ let c = LumeChannel.local
+ #expect(c.lumeBinName == "lume-local")
+ #expect(c.lumePort == 7787)
+ #expect(c.lumeAPI == "http://127.0.0.1:7787")
+ #expect(c.lumeDir(userHome: fakeHome).path == "/Users/dev/.lume-local")
+ #expect(c.lumeDaemonLabel == "com.trycua.lume_daemon.local")
+ #expect(c.lumeDaemonLogPath(environment: [:]) == "/tmp/lume_daemon.local.log")
+ #expect(c.lumeDaemonErrorLogPath(environment: [:]) == "/tmp/lume_daemon.local.error.log")
+ #expect(c.lumeLogDir(userHome: fakeHome).path == "/Users/dev/Library/Logs/lume-local")
+ #expect(!c.supportsSelfUpdate)
+ }
+
+ @Test("The API URL names the port")
+ func apiNamesItsPort() {
+ for c in LumeChannel.allCases {
+ #expect(c.lumeAPI == "http://127.0.0.1:\(c.lumePort)")
+ }
+ }
+
+ @Test("Stable and Local share no path, label, port or log")
+ func channelsAreDisjoint() {
+ func names(_ c: LumeChannel) -> [String] {
+ [
+ c.lumeBinName,
+ c.lumeDir(userHome: fakeHome).path,
+ c.lumeDaemonLabel,
+ c.lumeDaemonLogPath(environment: [:]),
+ c.lumeDaemonErrorLogPath(environment: [:]),
+ c.lumeLogDir(userHome: fakeHome).path,
+ String(c.lumePort),
+ LumeLayout.resolve(channel: c, environment: [:], userHome: fakeHome)
+ .releaseChannelFile.path,
+ ]
+ }
+ // (`Set` is Lume's own `set` command here, hence `Swift.Set`.)
+ #expect(Swift.Set(names(.stable)).isDisjoint(with: Swift.Set(names(.local))))
+ // Local's directory must not sit inside Stable's either: removing
+ // `~/.lume` would take Local's VMs with it.
+ let stableDir = LumeChannel.stable.lumeDir(userHome: fakeHome).path + "/"
+ #expect(!LumeChannel.local.lumeDir(userHome: fakeHome).path.hasPrefix(stableDir))
+ }
+
+ // MARK: - Resolving the channel from the binary's name
+
+ @Test("A binary named lume-local is Local")
+ func nameSelectsLocal() {
+ #expect(LumeChannel.resolve(executablePaths: ["lume-local"]) == .local)
+ #expect(LumeChannel.resolve(executablePaths: ["/Users/dev/.local/bin/lume-local"]) == .local)
+ #expect(
+ LumeChannel.resolve(
+ executablePaths: ["/Users/dev/.local/share/lume-local/lume-local.app/Contents/MacOS/lume"]
+ ) == .local)
+ }
+
+ @Test("Any other name is Stable")
+ func otherNamesAreStable() {
+ #expect(LumeChannel.resolve(executablePaths: []) == .stable)
+ #expect(LumeChannel.resolve(executablePaths: ["lume"]) == .stable)
+ #expect(LumeChannel.resolve(executablePaths: ["/Users/dev/.local/bin/lume"]) == .stable)
+ #expect(LumeChannel.resolve(executablePaths: ["/usr/bin/xctest"]) == .stable)
+ // Only the exact name counts.
+ #expect(LumeChannel.resolve(executablePaths: ["lume-local-old"]) == .stable)
+ #expect(LumeChannel.resolve(executablePaths: ["/Users/dev/lume-local/lume"]) == .stable)
+ #expect(LumeChannel.resolve(executablePaths: ["/Users/dev/.lume-local/lume"]) == .stable)
+ }
+
+ @Test("One name of the process being lume-local is enough")
+ func anyKnownPathCounts() {
+ // `lume-local` linked to the build product: argv[0] keeps the link's
+ // name even when the resolved path does not.
+ #expect(
+ LumeChannel.resolve(executablePaths: ["lume-local", "/src/lume/.build/debug/lume"])
+ == .local)
+ }
+
+ @Test("This test process is Stable")
+ func currentProcessIsStable() {
+ #expect(LumeChannel.current == .stable)
+ }
+
+ // MARK: - Home and VM directory
+
+ @Test("Stable without LUME_HOME uses ~/.lume and the XDG settings file")
+ func stableDefaults() {
+ let l = LumeLayout.resolve(channel: .stable, environment: [:], userHome: fakeHome)
+ #expect(l.homeDir.path == "/Users/dev/.lume")
+ #expect(l.configDir.path == "/Users/dev/.config/lume")
+ let xdg = LumeLayout.resolve(
+ channel: .stable, environment: ["XDG_CONFIG_HOME": "/Users/dev/cfg"], userHome: fakeHome)
+ #expect(xdg.configDir.path == "/Users/dev/cfg/lume")
+ #expect(l.homeSetting == "~/.lume")
+ #expect(l.cacheSetting == "~/.lume/cache")
+ #expect(l.configInHome == false)
+ #expect(l.releaseChannelFile.path == "/Users/dev/.lume/release-channel")
+ #expect(l.port == 7777)
+ }
+
+ @Test("Local without LUME_HOME implies ~/.lume-local, port 7787 and its own settings file")
+ func localDefaults() {
+ let l = LumeLayout.resolve(channel: .local, environment: [:], userHome: fakeHome)
+ #expect(l.homeDir.path == "/Users/dev/.lume-local")
+ #expect(l.homeSetting == "~/.lume-local")
+ #expect(l.cacheSetting == "~/.lume-local/cache")
+ #expect(l.configInHome == true)
+ #expect(l.configDir.path == "/Users/dev/.lume-local")
+ #expect(l.releaseChannelFile.path == "/Users/dev/.lume-local/release-channel")
+ #expect(l.port == 7787)
+ // XDG_CONFIG_HOME is shared with Stable, so Local ignores it.
+ let xdg = LumeLayout.resolve(
+ channel: .local, environment: ["XDG_CONFIG_HOME": "/Users/dev/cfg"], userHome: fakeHome)
+ #expect(xdg.configDir.path == "/Users/dev/.lume-local")
+ }
+
+ @Test("Local: LUME_HOME moves the home, the VM directory, the cache and the release channel")
+ func localLumeHomeOverrides() {
+ let l = LumeLayout.resolve(
+ channel: .local,
+ environment: ["LUME_HOME": "/Volumes/vms/lume", "XDG_CONFIG_HOME": "/Users/dev/cfg"],
+ userHome: fakeHome
+ )
+ #expect(l.homeDir.path == "/Volumes/vms/lume")
+ #expect(l.homeSetting == "/Volumes/vms/lume")
+ #expect(l.cacheSetting == "/Volumes/vms/lume/cache")
+ #expect(l.configInHome == true)
+ #expect(l.configDir.path == "/Volumes/vms/lume")
+ #expect(l.releaseChannelFile.path == "/Volumes/vms/lume/release-channel")
+ // The channel's port does not move with the home.
+ #expect(l.port == 7787)
+ }
+
+ @Test("Stable: LUME_HOME only moves the release-channel file, as it always did")
+ func stableLumeHomeOnlyMovesTheReleaseChannel() {
+ for xdg in [nil, "/Users/dev/cfg", ""] {
+ var base: [String: String] = [:]
+ if let xdg { base["XDG_CONFIG_HOME"] = xdg }
+ var moved = base
+ moved["LUME_HOME"] = "/Volumes/vms/lume"
+
+ let plain = LumeLayout.resolve(channel: .stable, environment: base, userHome: fakeHome)
+ let withHome = LumeLayout.resolve(channel: .stable, environment: moved, userHome: fakeHome)
+
+ // The VM directory, cache, settings location and settings file
+ // are what they are without LUME_HOME.
+ #expect(withHome.homeDir == plain.homeDir)
+ #expect(withHome.homeDir.path == "/Users/dev/.lume")
+ #expect(withHome.homeSetting == "~/.lume")
+ #expect(withHome.cacheSetting == "~/.lume/cache")
+ #expect(withHome.configDir == plain.configDir)
+ #expect(withHome.configInHome == false)
+ // Only the release-channel file follows it.
+ #expect(plain.releaseChannelFile.path == "/Users/dev/.lume/release-channel")
+ #expect(withHome.releaseChannelFile.path == "/Volumes/vms/lume/release-channel")
+ }
+ }
+
+ @Test("Stable keeps its legacy rules for LUME_HOME and XDG_CONFIG_HOME verbatim")
+ func stableLegacyRules() {
+ func layout(_ env: [String: String]) -> LumeLayout {
+ LumeLayout.resolve(channel: .stable, environment: env, userHome: fakeHome)
+ }
+ // LUME_HOME is used as given (no trimming, no standardizing); an empty
+ // one is ignored.
+ #expect(layout(["LUME_HOME": "/data/a/../lume"]).releaseChannelFile.path == "/data/a/../lume/release-channel")
+ #expect(layout(["LUME_HOME": ""]).releaseChannelFile.path == "/Users/dev/.lume/release-channel")
+ // XDG_CONFIG_HOME is joined with /lume whenever it is set.
+ #expect(layout(["XDG_CONFIG_HOME": "/Users/dev/cfg"]).configDir.path == "/Users/dev/cfg/lume")
+ #expect(layout([:]).configDir.path == "/Users/dev/.config/lume")
+ }
+
+ @Test("Local: LUME_HOME beats the channel default, and does not change the port")
+ func lumeHomeBeatsLocalDefault() {
+ let l = LumeLayout.resolve(
+ channel: .local,
+ environment: ["LUME_HOME": "/tmp/other"],
+ userHome: fakeHome
+ )
+ #expect(l.homeDir.path == "/tmp/other")
+ #expect(l.port == 7787)
+ }
+
+ @Test("Local: LUME_HOME expands a leading tilde and tidies the path")
+ func lumeHomeTilde() {
+ func home(_ raw: String) -> String {
+ LumeLayout.resolve(
+ channel: .local, environment: ["LUME_HOME": raw], userHome: fakeHome
+ ).homeDir.path
+ }
+ #expect(home("~/vms") == "/Users/dev/vms")
+ #expect(home("~") == "/Users/dev")
+ #expect(home("/data/lume/") == "/data/lume")
+ #expect(home("/data/a/../lume") == "/data/lume")
+ // `~user` is not ours to expand.
+ #expect(home("/data/~lume") == "/data/~lume")
+ }
+
+ @Test("Local: an empty or blank LUME_HOME is ignored")
+ func emptyLumeHomeIsIgnored() {
+ for raw in ["", " ", "\n"] {
+ let local = LumeLayout.resolve(
+ channel: .local, environment: ["LUME_HOME": raw], userHome: fakeHome)
+ #expect(local.homeDir.path == "/Users/dev/.lume-local")
+ #expect(local.configInHome == true)
+ }
+ }
+
+ @Test("Local uses LUME_HOME verbatim: a trailing or leading space never becomes Stable's home")
+ func localLumeHomeIsNotTrimmed() {
+ let stableHome = LumeChannel.stable.lumeDir(userHome: fakeHome).path
+ for raw in ["/Users/dev/.lume ", "/Users/dev/.lume\t", "/Users/dev/.lume\n", " /Users/dev/.lume", "/Users/dev/.lume "] {
+ let l = LumeLayout.resolve(
+ channel: .local, environment: ["LUME_HOME": raw], userHome: fakeHome)
+ #expect(l.homeDir.path != stableHome, "LUME_HOME=\(raw.debugDescription) resolved to Stable's home")
+ #expect(l.homeSetting != stableHome)
+ #expect(l.configDir.path != LumeLayout.resolve(
+ channel: .stable, environment: [:], userHome: fakeHome).configDir.path)
+ #expect(l.homeDir.path.contains(".lume"))
+ }
+ // The guard-accepted spelling keeps its space.
+ #expect(
+ LumeLayout.resolve(
+ channel: .local, environment: ["LUME_HOME": "/Users/dev/.lume "], userHome: fakeHome
+ ).homeDir.lastPathComponent == ".lume ")
+ }
+
+ // MARK: - Daemon logs and detached-run logs
+
+ @Test("Local reads its daemon logs from LUME_LOCAL_LOG_DIR; Stable ignores it")
+ func localDaemonLogDir() {
+ let env = ["LUME_LOCAL_LOG_DIR": "/var/tmp/lume-logs"]
+ #expect(LumeChannel.local.lumeDaemonLogDir(environment: env) == "/var/tmp/lume-logs")
+ #expect(
+ LumeChannel.local.lumeDaemonLogPath(environment: env)
+ == "/var/tmp/lume-logs/lume_daemon.local.log")
+ #expect(
+ LumeChannel.local.lumeDaemonErrorLogPath(environment: env)
+ == "/var/tmp/lume-logs/lume_daemon.local.error.log")
+ // A trailing slash does not double up.
+ #expect(
+ LumeChannel.local.lumeDaemonLogPath(environment: ["LUME_LOCAL_LOG_DIR": "/var/tmp/lume-logs/"])
+ == "/var/tmp/lume-logs/lume_daemon.local.log")
+ // Unset, empty or relative falls back to /tmp.
+ for value in [nil, "", "relative/logs"] {
+ var e: [String: String] = [:]
+ if let value { e["LUME_LOCAL_LOG_DIR"] = value }
+ #expect(LumeChannel.local.lumeDaemonLogDir(environment: e) == "/tmp")
+ }
+ // Stable's logs do not move.
+ #expect(LumeChannel.stable.lumeDaemonLogDir(environment: env) == "/tmp")
+ #expect(LumeChannel.stable.lumeDaemonLogPath(environment: env) == "/tmp/lume_daemon.log")
+ #expect(LumeChannel.stable.lumeDaemonErrorLogPath(environment: env) == "/tmp/lume_daemon.error.log")
+ }
+
+ @Test("The logs readers (API and CLI) follow a custom Local log directory")
+ func logReadersFollowACustomLogDir() throws {
+ let root = FileManager.default.temporaryDirectory
+ .appendingPathComponent("lume-logs-\(UUID().uuidString)", isDirectory: true)
+ defer { try? FileManager.default.removeItem(at: root) }
+ let custom = root.appendingPathComponent("custom", isDirectory: true)
+ try FileManager.default.createDirectory(at: custom, withIntermediateDirectories: true)
+ try "one\ntwo\nthree".write(
+ to: custom.appendingPathComponent("lume_daemon.local.log"), atomically: true, encoding: .utf8)
+ try "boom".write(
+ to: custom.appendingPathComponent("lume_daemon.local.error.log"), atomically: true, encoding: .utf8)
+
+ let env = ["LUME_LOCAL_LOG_DIR": custom.path]
+ let info = LumeChannel.local.lumeDaemonLogPath(environment: env)
+ let error = LumeChannel.local.lumeDaemonErrorLogPath(environment: env)
+
+ // GET /lume/logs
+ let all = DaemonLogs.response(type: nil, lines: nil, infoPath: info, errorPath: error)
+ #expect(all["info"] == "one\ntwo\nthree")
+ #expect(all["error"] == "boom")
+ let tail = DaemonLogs.response(type: "info", lines: 2, infoPath: info, errorPath: error)
+ #expect(tail["info"] == "two\nthree")
+ #expect(tail["error"] == nil)
+
+ // lume-local logs info|error|all
+ #expect(Logs.readLogFile(path: info) == "one\ntwo\nthree")
+ #expect(Logs.readLogFile(path: error) == "boom")
+
+ // Without the variable the same readers look in /tmp, not in the custom directory.
+ let fallback = LumeChannel.local.lumeDaemonLogPath(environment: [:])
+ #expect(fallback == "/tmp/lume_daemon.local.log")
+ #expect(!fallback.hasPrefix(custom.path))
+ }
+
+ // MARK: - Settings
+
+ @Test("Default settings put the VMs and the cache in the layout's home")
+ func defaultSettingsFollowTheLayout() {
+ let stable = LumeSettings.defaults(
+ layout: .resolve(channel: .stable, environment: [:], userHome: fakeHome))
+ #expect(stable.vmLocations == [VMLocation(name: "home", path: "~/.lume")])
+ #expect(stable.cacheDirectory == "~/.lume/cache")
+
+ let local = LumeSettings.defaults(
+ layout: .resolve(channel: .local, environment: [:], userHome: fakeHome))
+ #expect(local.vmLocations == [VMLocation(name: "home", path: "~/.lume-local")])
+ #expect(local.defaultLocation?.path == "~/.lume-local")
+ #expect(local.cacheDirectory == "~/.lume-local/cache")
+
+ let moved = LumeSettings.defaults(
+ layout: .resolve(
+ channel: .local, environment: ["LUME_HOME": "/data/lume"], userHome: fakeHome))
+ #expect(moved.vmLocations == [VMLocation(name: "home", path: "/data/lume")])
+ #expect(moved.cacheDirectory == "/data/lume/cache")
+
+ // Stable's defaults do not follow LUME_HOME.
+ let stableWithHome = LumeSettings.defaults(
+ layout: .resolve(
+ channel: .stable, environment: ["LUME_HOME": "/data/lume"], userHome: fakeHome))
+ #expect(stableWithHome.vmLocations == [VMLocation(name: "home", path: "~/.lume")])
+ #expect(stableWithHome.cacheDirectory == "~/.lume/cache")
+ }
+
+ @Test("A Local settings manager reads and writes only its own home")
+ func localSettingsStayInTheLocalHome() throws {
+ let root = FileManager.default.temporaryDirectory
+ .appendingPathComponent("lume-channel-\(UUID().uuidString)", isDirectory: true)
+ defer { try? FileManager.default.removeItem(at: root) }
+ let xdg = root.appendingPathComponent("xdg", isDirectory: true)
+ let userHome = root.appendingPathComponent("home", isDirectory: true)
+
+ // XDG_CONFIG_HOME is set, and is shared by every Lume on the Mac.
+ let layout = LumeLayout.resolve(
+ channel: .local, environment: ["XDG_CONFIG_HOME": xdg.path], userHome: userHome)
+ let manager = SettingsManager(fileManager: .default, layout: { layout })
+ let settings = manager.getSettings()
+
+ #expect(settings.defaultLocation?.path == "~/.lume-local")
+ #expect(settings.cacheDirectory == "~/.lume-local/cache")
+ // The settings file is in the Local home, not under XDG_CONFIG_HOME.
+ #expect(
+ FileManager.default.fileExists(
+ atPath: userHome.appendingPathComponent(".lume-local/config.yaml").path))
+ #expect(!FileManager.default.fileExists(atPath: xdg.appendingPathComponent("lume").path))
+ #expect(!FileManager.default.fileExists(atPath: userHome.appendingPathComponent(".lume").path))
+ #expect(
+ !FileManager.default.fileExists(atPath: userHome.appendingPathComponent(".config").path))
+
+ // And it round-trips from there.
+ try manager.setCachingEnabled(true)
+ #expect(manager.isCachingEnabled())
+ #expect(SettingsManager(fileManager: .default, layout: { layout }).isCachingEnabled())
+ }
+
+ @Test("A Stable settings manager keeps its settings file under XDG_CONFIG_HOME")
+ func stableSettingsKeepTheirPlace() {
+ let root = FileManager.default.temporaryDirectory
+ .appendingPathComponent("lume-channel-\(UUID().uuidString)", isDirectory: true)
+ defer { try? FileManager.default.removeItem(at: root) }
+ let xdg = root.appendingPathComponent("xdg", isDirectory: true)
+ let userHome = root.appendingPathComponent("home", isDirectory: true)
+
+ let layout = LumeLayout.resolve(
+ channel: .stable, environment: ["XDG_CONFIG_HOME": xdg.path], userHome: userHome)
+ let settings = SettingsManager(fileManager: .default, layout: { layout }).getSettings()
+
+ #expect(settings.defaultLocation?.path == "~/.lume")
+ #expect(
+ FileManager.default.fileExists(
+ atPath: xdg.appendingPathComponent("lume/config.yaml").path))
+ #expect(!FileManager.default.fileExists(atPath: userHome.appendingPathComponent(".lume-local").path))
+ }
+
+ @Test("A Stable settings manager ignores LUME_HOME: same settings file, same VM and cache locations")
+ func stableSettingsIgnoreLumeHome() throws {
+ let root = FileManager.default.temporaryDirectory
+ .appendingPathComponent("lume-channel-\(UUID().uuidString)", isDirectory: true)
+ defer { try? FileManager.default.removeItem(at: root) }
+ let xdg = root.appendingPathComponent("xdg", isDirectory: true)
+ let userHome = root.appendingPathComponent("home", isDirectory: true)
+ let lumeHome = root.appendingPathComponent("elsewhere", isDirectory: true)
+
+ // The settings Stable already has, in its XDG directory.
+ let xdgLume = xdg.appendingPathComponent("lume", isDirectory: true)
+ try FileManager.default.createDirectory(at: xdgLume, withIntermediateDirectories: true)
+ try """
+ defaultLocationName: "mine"
+ cacheDirectory: "/data/cache"
+
+ vmLocations:
+ - name: "mine"
+ path: "/data/vms"
+ """.write(to: xdgLume.appendingPathComponent("config.yaml"), atomically: true, encoding: .utf8)
+
+ let layout = LumeLayout.resolve(
+ channel: .stable,
+ environment: ["XDG_CONFIG_HOME": xdg.path, "LUME_HOME": lumeHome.path],
+ userHome: userHome)
+ let settings = SettingsManager(fileManager: .default, layout: { layout }).getSettings()
+
+ #expect(settings.defaultLocation?.path == "/data/vms")
+ #expect(settings.cacheDirectory == "/data/cache")
+ // Nothing was created under LUME_HOME, which only holds the release channel.
+ #expect(!FileManager.default.fileExists(atPath: lumeHome.path))
+ #expect(layout.releaseChannelFile.path == lumeHome.appendingPathComponent("release-channel").path)
+
+ // With no settings file at all, the defaults are still Stable's.
+ let bare = LumeLayout.resolve(
+ channel: .stable,
+ environment: ["XDG_CONFIG_HOME": root.appendingPathComponent("none").path, "LUME_HOME": lumeHome.path],
+ userHome: userHome)
+ let defaults = SettingsManager(fileManager: .default, layout: { bare }).getSettings()
+ #expect(defaults.defaultLocation?.path == "~/.lume")
+ #expect(defaults.cacheDirectory == "~/.lume/cache")
+ }
+
+ @Test("A settings file without a cache or a location falls back to the layout's home")
+ func parsedSettingsFallBackToTheLayout() throws {
+ let root = FileManager.default.temporaryDirectory
+ .appendingPathComponent("lume-channel-\(UUID().uuidString)", isDirectory: true)
+ defer { try? FileManager.default.removeItem(at: root) }
+ let userHome = root.appendingPathComponent("home", isDirectory: true)
+ let layout = LumeLayout.resolve(channel: .local, environment: [:], userHome: userHome)
+
+ try FileManager.default.createDirectory(at: layout.homeDir, withIntermediateDirectories: true)
+ try "cachingEnabled: true\n".write(
+ to: layout.homeDir.appendingPathComponent("config.yaml"),
+ atomically: true, encoding: .utf8)
+
+ let settings = SettingsManager(fileManager: .default, layout: { layout }).getSettings()
+ #expect(settings.cachingEnabled)
+ #expect(settings.defaultLocation?.path == "~/.lume-local")
+ #expect(settings.cacheDirectory == "~/.lume-local/cache")
+ }
+
+ // MARK: - Port
+
+ @Test("A serve command line without --port uses the channel's port")
+ func serveDefaultPortFollowsTheChannel() {
+ let line = ["/Users/dev/.local/share/lume-local/lume-local", "serve"]
+ #expect(LumeServeProcess.apiPort(fromArguments: line, defaultPort: LumeChannel.local.lumePort) == 7787)
+ #expect(LumeServeProcess.apiPort(fromArguments: line, defaultPort: LumeChannel.stable.lumePort) == 7777)
+ // An explicit --port always wins.
+ let flagged = line + ["--port", "9100"]
+ #expect(LumeServeProcess.apiPort(fromArguments: flagged, defaultPort: 7787) == 9100)
+ #expect(LumeServeProcess.apiPort(fromArguments: line + ["--port=9101"], defaultPort: 7787) == 9101)
+ }
+
+ @Test("lume serve defaults to the channel's port and --port overrides it")
+ func serveCommandDefaultsToTheChannelPort() throws {
+ let defaults = try Serve.parse([])
+ #expect(defaults.port == LumeChannel.current.lumePort)
+ let explicit = try Serve.parse(["--port", "9200"])
+ #expect(explicit.port == 9200)
+ }
+
+ // MARK: - Updates
+
+ @Test("Local has no update path")
+ func localDoesNotUpdate() {
+ #expect(!LumeVersionCheck.updateChecksEnabled(channel: .local))
+ #expect(LumeVersionCheck.updateChecksDisabledReason(channel: .local).contains("lume-local"))
+ #expect(LumeVersionCheck.updateChecksDisabledReason(channel: .stable).contains("LUME_UPDATE_CHECK"))
+ }
+}