A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.
TypeScript
feat(package): build self-contained Linux packages in containers
Alan Buscaglia01a47301b67c
diff --git a/apps/desktop/src-tauri/tauri.linux.conf.json b/apps/desktop/src-tauri/tauri.linux.conf.jsonnew file mode 100644index 0000000..606f377--- /dev/null+++ b/apps/desktop/src-tauri/tauri.linux.conf.json@@ -0,0 +1,14 @@+{+ "$schema": "https://schema.tauri.app/config/2",+ "bundle": {+ "targets": ["deb"],+ "publisher": "Gentleman Programming",+ "shortDescription": "Always-on desktop assistant backed by Gentle Shell",+ "longDescription": "A floating rose, a panel, and a tray icon for an assistant that runs Gentle Shell with Engram memory. The package carries its own Node.js runtime, engine, and Engram.",+ "linux": {+ "deb": {+ "section": "utils"+ }+ }+ }+}diff --git a/docker/linux-package/Dockerfile b/docker/linux-package/Dockerfilenew file mode 100644index 0000000..ba624b1--- /dev/null+++ b/docker/linux-package/Dockerfile@@ -0,0 +1,53 @@+# Builds Gentle Dot's Linux packages (S29.3). The image holds only the toolchain; the repository+# is mounted read-only at /src and `build-deb.sh` builds from a copy of it. Debian 12 (glibc 2.36)+# sets the oldest glibc the packaged app needs. Driven by scripts/package/package-linux.mjs:+# docker build --platform linux/arm64 -t gentle-dot-linux-builder:arm64 docker/linux-package+FROM debian:bookworm++ARG NODE_VERSION=24.14.1+ARG PNPM_VERSION=11.5.0+ARG RUST_TOOLCHAIN=stable++ENV DEBIAN_FRONTEND=noninteractive \+ RUSTUP_HOME=/usr/local/rustup \+ CARGO_HOME=/usr/local/cargo \+ COREPACK_HOME=/usr/local/corepack \+ COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \+ PATH=/usr/local/cargo/bin:/usr/local/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin++# Tauri 2 Linux prerequisites (as in scripts/linux/setup-debian.sh), plus git for the runtime's+# daemon commit, and lsof, procps, and Xvfb for smoke runs.+RUN apt-get update \+ && apt-get install -y --no-install-recommends \+ build-essential ca-certificates curl file git pkg-config wget xz-utils \+ libwebkit2gtk-4.1-dev libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev \+ lsof procps xauth xvfb \+ && rm -rf /var/lib/apt/lists/*++# Node.js from the official tarball, checked against the release's SHASUMS256.txt.+RUN set -eu; \+ case "$(dpkg --print-architecture)" in \+ arm64) node_arch=arm64 ;; \+ amd64) node_arch=x64 ;; \+ *) echo "unsupported architecture" >&2; exit 1 ;; \+ esac; \+ archive="node-v${NODE_VERSION}-linux-${node_arch}.tar.xz"; \+ cd /tmp; \+ curl -fsSLO "https://nodejs.org/dist/v${NODE_VERSION}/${archive}"; \+ curl -fsSLO "https://nodejs.org/dist/v${NODE_VERSION}/SHASUMS256.txt"; \+ grep " ${archive}\$" SHASUMS256.txt | sha256sum -c -; \+ mkdir -p /usr/local/node; \+ tar -xJf "${archive}" -C /usr/local/node --strip-components=1; \+ rm "${archive}" SHASUMS256.txt; \+ corepack enable; \+ corepack install -g "pnpm@${PNPM_VERSION}"; \+ node --version; pnpm --version++RUN curl -fsSL https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal \+ --default-toolchain "${RUST_TOOLCHAIN}" \+ && rustc --version && cargo --version++RUN git config --system --add safe.directory '*'++COPY build-deb.sh /usr/local/bin/gentle-dot-build-deb+WORKDIR /workdiff --git a/docker/linux-package/build-deb.sh b/docker/linux-package/build-deb.shnew file mode 100755index 0000000..73163b0--- /dev/null+++ b/docker/linux-package/build-deb.sh@@ -0,0 +1,57 @@+#!/usr/bin/env bash+# Runs inside gentle-dot-linux-builder (see Dockerfile). Copies the working tree mounted at /src,+# stages the runtime for this container's architecture (S29.5), builds the .deb with Tauri, and+# leaves it with the runtime's MANIFEST.json in /out (an empty folder). Optional: ENGRAM_VERSION=x.y.z.+set -euo pipefail++case "$(dpkg --print-architecture)" in+arm64) target=linux-arm64 ;;+amd64) target=linux-x64 ;;+*)+ echo "build-deb: unsupported architecture $(dpkg --print-architecture)" >&2+ exit 1+ ;;+esac+runtime=/work/build/runtime/linux+step() { printf '\n==> %s (%s s)\n' "$1" "$SECONDS"; }++step "Copying the working tree from /src (tracked and untracked files, minus .gitignore)"+cd /src+# Files deleted in the working tree but still in the index are skipped (--ignore-failed-read).+git ls-files -z --cached --others --exclude-standard -- . ':!:.codegraph' ':!:.atl' |+ tar --null --files-from=- --ignore-failed-read -cf - 2>/dev/null | tar -xf - -C /work+cp -a /src/.git /work/.git+cd /work++step "pnpm install"+pnpm install --frozen-lockfile --store-dir /pnpm-store++step "Staging the $target runtime"+node scripts/package/stage-runtime.mjs --target "$target" --out "$runtime" \+ ${ENGRAM_VERSION:+--engram-version "$ENGRAM_VERSION"}++step "Building the .deb"+# The runtime is mapped here rather than in tauri.linux.conf.json: Tauri merges that file into+# every Linux build, and tauri-build fails when a resource is missing, as in source builds.+resources="{\"bundle\":{\"resources\":{\"$runtime/\":\"runtime/\"}}}"+pnpm --filter @gentle-dot/desktop tauri build --bundles deb --config "$resources"++step "Checking the result"+binary=apps/desktop/src-tauri/target/release/gentle-dot+deb=$(find apps/desktop/src-tauri/target/release/bundle/deb -maxdepth 1 -name '*.deb' -newer "$runtime/MANIFEST.json")+[ "$(printf '%s\n' "$deb" | grep -c .)" = 1 ] || {+ echo "build-deb: expected one new .deb, found: ${deb:-none}" >&2+ exit 1+}+if ldd "$binary" | grep 'not found'; then+ echo "build-deb: the binary has unresolved libraries" >&2+ exit 1+fi+echo "newest glibc symbol the binary needs: $(objdump -T "$binary" | grep -o 'GLIBC_[0-9.]*' | sort -uV | tail -1)"+dpkg-deb --info "$deb"+echo "files in the package: $(dpkg-deb --contents "$deb" | wc -l)"+echo "files in the staged runtime: $(find "$runtime" -type f | wc -l)"++cp "$deb" /out/+cp "$runtime/MANIFEST.json" /out/runtime-MANIFEST.json+step "Done: /out/$(basename "$deb")"diff --git a/docker/linux-package/check-package.sh b/docker/linux-package/check-package.shnew file mode 100755index 0000000..b1e960d--- /dev/null+++ b/docker/linux-package/check-package.sh@@ -0,0 +1,69 @@+#!/usr/bin/env bash+# Runs as root inside a clean distro container (debian:bookworm, ubuntu:24.04, or archlinux):+# installs the package given as $1 with the distro's package manager, then, as a new non-root user,+# smoke-tests the installed app (S29.4). The scripts come from the repository mounted at /src.+# 1. the installed runtime's daemon on a temp HOME with a private Engram; the installed tree is+# root-owned, so this is the real read-only case;+# 2. the same on a read-only copy (`smoke-runtime.mjs --read-only`);+# 3. the installed binary under Xvfb, until its daemon reports idle on a free port.+set -euo pipefail++package=$1+step() { printf '\n==> %s (%s s)\n' "$1" "$SECONDS"; }++step "Installing $(basename "$package")"+case "$package" in+*.deb)+ export DEBIAN_FRONTEND=noninteractive+ apt-get update -qq+ apt-get install -y --no-install-recommends "$package"+ installed_files() { dpkg -L gentle-dot; }+ install_tools() { apt-get install -y -qq --no-install-recommends lsof procps xauth xvfb >/dev/null; }+ ;;+*.pkg.tar.*)+ # pacman's download sandbox fails under emulation ("error restricting syscalls via seccomp"),+ # as on an Apple Silicon Mac; this throwaway container turns it off.+ sed -i '/^\[options\]/a DisableSandbox' /etc/pacman.conf+ pacman -Sy --noconfirm >/dev/null+ pacman -U --noconfirm "$package"+ installed_files() { pacman -Qlq gentle-dot; }+ install_tools() { pacman -S --noconfirm --needed lsof procps-ng xorg-server-xvfb xorg-xauth >/dev/null; }+ ;;+*)+ echo "check-package: unknown package type $package" >&2+ exit 1+ ;;+esac++installed_files >/tmp/gentle-dot-files+binary=$(grep -m1 '/bin/gentle-dot$' /tmp/gentle-dot-files)+cli=$(grep -m1 '/runtime/daemon/cli.mjs$' /tmp/gentle-dot-files)+runtime=$(dirname "$(dirname "$cli")")+node="$runtime/node/bin/node"+echo "binary: $binary"+echo "runtime: $runtime ($(du -sh "$runtime" | cut -f1), owner $(stat -c %U "$runtime"))"+# Only the package and its declared dependencies are installed at this point.+if ldd "$binary" | grep 'not found'; then+ echo "check-package: the installed binary has unresolved libraries" >&2+ exit 1+fi+echo "ldd: every library of $binary resolves"+"$node" --version+"$runtime/bin/engram" version+"$runtime/bin/pi" --version++step "Installing the smoke tools (lsof, ps, Xvfb)"+install_tools+useradd --create-home tester+run_as_tester() { runuser -u tester -- env -i PATH=/usr/bin:/bin "$@"; }++step "Daemon smoke on the installed runtime (root-owned, read-only for tester)"+run_as_tester "$node" /src/scripts/package/smoke-runtime.mjs --runtime "$runtime"++step "Daemon smoke on a read-only copy"+run_as_tester "$node" /src/scripts/package/smoke-runtime.mjs --runtime "$runtime" --read-only++step "App launch under Xvfb"+run_as_tester "$node" /src/scripts/package/linux-app-smoke.mjs --binary "$binary" --runtime "$runtime"++step "All checks passed"diff --git a/docs/linux-testing.md b/docs/linux-testing.mdindex 5d22b12..ca3598c 100644--- a/docs/linux-testing.md+++ b/docs/linux-testing.md@@ -1,6 +1,6 @@# Testing Gentle Dot on Linux-Thanks for testing! This guide walks you through installing Gentle Dot from source and checking that it works on your desktop. It takes about 30 minutes, most of it waiting for the first build.+Thanks for testing! This guide walks you through installing Gentle Dot, from a package or from source, and checking that it works on your desktop. With a package it takes about 20 minutes; from source, about 30, most of it waiting for the first build.We test three setups. Pick the one you have:@@ -22,9 +22,19 @@ The tray icon, the floating rose, the panel, and the toggle shortcut should workWrite down the answer for the report (for example `wayland / ubuntu:GNOME` or `wayland / Hyprland`).2. Have an API key ready for one model provider (for example OpenAI, OpenRouter, or Anthropic). You need it in step 8.-3. Get the source code: clone the repository or unpack the archive you were sent, then open a terminal in its folder.+3. Get the files: the package for your system (see below), or, to install from source, the source code (clone the repository or unpack the archive you were sent, then open a terminal in its folder). The Hyprland snippets in step 3 are in the source, under `scripts/linux/hyprland/`.-## What the setup script does+## Package or source++| | Package | From source |+|---|---|---|+| A. Debian or B. Ubuntu | `gentle-dot_<version>_amd64.deb` (or `_arm64.deb`; `dpkg --print-architecture` tells which) | `scripts/linux/setup-debian.sh` |+| C. Omarchy (x86_64) | `gentle-dot-<version>-1-x86_64.pkg.tar.zst` | `scripts/linux/setup-arch.sh` |+| The app command | `gentle-dot`, that is `/usr/bin/gentle-dot` | `~/.local/bin/gentle-dot` |++The package needs nothing else installed: it carries its own Node.js, assistant engine, and Engram (in `/usr/lib/Gentle Dot/runtime`). In the steps below, **the app command** means `/usr/bin/gentle-dot` if you installed the package and `~/.local/bin/gentle-dot` if you built from source. To remove the package later, run `sudo apt remove gentle-dot` or `sudo pacman -R gentle-dot`; your assistant data in `~/.gentle-dot` stays.++## What the setup script does (from source only)| Step | Uses sudo? ||---|---|@@ -53,18 +63,20 @@ Do each step in order and note **Pass**, **Fail**, or **Partial** for each one.### 1. Install-| Your setup | Command |-|---|---|-| A. Debian or B. Ubuntu | `scripts/linux/setup-debian.sh` |-| C. Omarchy | `scripts/linux/setup-arch.sh` |+| Your setup | Package | From source |+|---|---|---|+| A. Debian or B. Ubuntu | `sudo apt install ./gentle-dot_<version>_<arch>.deb` | `scripts/linux/setup-debian.sh` |+| C. Omarchy | `sudo pacman -U gentle-dot-<version>-1-x86_64.pkg.tar.zst` | `scripts/linux/setup-arch.sh` |-**Expected:** each step prints a numbered heading (`==> 1. Checking the system` and so on). The script explains why it needs sudo before it asks for your password. It ends with `Done.` and asks "Start Gentle Dot now?". Answer **no** for now.+**Expected with a package:** the package manager lists the libraries it adds (WebKitGTK and tray support), installs them, and finishes without errors. With `apt`, keep the `./` in front of the file name. A note that `_apt` could not access the file is harmless.++**Expected from source:** each step prints a numbered heading (`==> 1. Checking the system` and so on). The script explains why it needs sudo before it asks for your password. It ends with `Done.` and asks "Start Gentle Dot now?". Answer **no** for now.If the build fails, copy the last 40 lines of the output into the report.### 2. Run the installer again-Run the same command a second time.+**From source only** (with a package, write N/A). Run the same command a second time.**Expected:** it finishes in under a minute, says "All present" for the system libraries, and does not ask for sudo.@@ -82,11 +94,13 @@ ls ~/.config/hypr/hyprland.lua ~/.config/hypr/hyprland.conf 2>/dev/null- If you have `hyprland.lua` (Omarchy 4, or Hyprland 0.55 and later), use [`scripts/linux/hyprland/gentle-dot.lua`](../scripts/linux/hyprland/gentle-dot.lua). Paste it at the end of `~/.config/hypr/hyprland.lua`. Omarchy 4 configures Hyprland in Lua: see `config/hypr/hyprland.lua` and `default/hypr/helpers.lua` (`o.window`, `o.bind`) in the Omarchy repository, tag [v4.0.4](https://github.com/basecamp/omarchy/tree/v4.0.4/config/hypr), released 2026-09-15 and checked on 2026-10-08.- If you have only `hyprland.conf`, use [`scripts/linux/hyprland/gentle-dot.conf`](../scripts/linux/hyprland/gentle-dot.conf). Paste it at the end of `~/.config/hypr/hyprland.conf`. It has one block for Hyprland 0.53 and 0.54, and one for 0.48 to 0.52 (before 0.48, write `windowrulev2` instead of `windowrule`). Keep only the block for your version.+The snippets call `/usr/bin/gentle-dot`, the packaged app. If you built from source, switch to the `~/.local/bin/gentle-dot` line the snippet shows right below it.+Hyprland reloads the file when you save it. If it shows a configuration error, write the error message in the report.### 4. First launch-Open **Gentle Dot** from your app menu (or run `~/.local/bin/gentle-dot` in a terminal, which also shows its log messages).+Open **Gentle Dot** from your app menu (or run the app command in a terminal, which also shows its log messages).**Expected:**- Within a few seconds, a black circle with a glowing pink rose appears at the right edge of the screen, vertically centered.@@ -133,16 +147,17 @@ gnome-extensions enable [email protected]**GNOME:** open Settings → Keyboard → View and Customize Shortcuts → Custom Shortcuts → Add Shortcut:- Name: `Gentle Dot`-- Command: `/home/<you>/.local/bin/gentle-dot --toggle` (the full path; the setup script printed it)+- Command: `/usr/bin/gentle-dot --toggle` with the package, or `/home/<you>/.local/bin/gentle-dot --toggle` from source (the full path; the setup script printed it)- Shortcut: `Super + Alt + D`Or set the same shortcut from a terminal:```sh+app=/usr/bin/gentle-dot # from source: app=$HOME/.local/bin/gentle-dotpath=/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/gentle-dot/gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['$path']"gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:$path name 'Gentle Dot'-gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:$path command "$HOME/.local/bin/gentle-dot --toggle"+gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:$path command "$app --toggle"gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:$path binding '<Super><Alt>d'```@@ -150,7 +165,7 @@ The first `gsettings` line replaces any custom shortcuts you already have. If yo**Hyprland:** the binding is already in the snippet from step 3.-**Expected:** pressing `Super + Alt + D` while any other app has focus shows the panel; pressing it again hides it. Also run `~/.local/bin/gentle-dot --toggle` in a terminal: it toggles the panel and returns right away.+**Expected:** pressing `Super + Alt + D` while any other app has focus shows the panel; pressing it again hides it. Also run the app command with `--toggle` (for example `gentle-dot --toggle`) in a terminal: it toggles the panel and returns right away.The app's own `Alt + Space` shortcut works only on an X11 session. On Wayland, desktops do not let apps register global shortcuts, which is why you set one in your desktop settings instead. On GNOME, `Alt + Space` is also the window menu.@@ -205,16 +220,16 @@ Some things Wayland does not allow at all, and we already work around them: apps3. what happened instead,4. the output of `echo "$XDG_SESSION_TYPE $GDK_BACKEND $WAYLAND_DISPLAY $DISPLAY"`, run in the same terminal you started the app from.-For a quick comparison on GNOME, you can start the app as a native Wayland client with `GDK_BACKEND=wayland ~/.local/bin/gentle-dot`, and note which steps change.+For a quick comparison on GNOME, you can start the app as a native Wayland client with `GDK_BACKEND=wayland gentle-dot` (from source: `GDK_BACKEND=wayland ~/.local/bin/gentle-dot`), and note which steps change.## Troubleshooting| Symptom | Try ||---|---|-| The panel or rose is blank, or the app prints `Failed to create GBM buffer` (often with NVIDIA) | Quit the app, then start it with `WEBKIT_DISABLE_DMABUF_RENDERER=1 ~/.local/bin/gentle-dot`. Note in the report whether it helped. |+| The panel or rose is blank, or the app prints `Failed to create GBM buffer` (often with NVIDIA) | Quit the app, then start it with `WEBKIT_DISABLE_DMABUF_RENDERER=1` before the app command, for example `WEBKIT_DISABLE_DMABUF_RENDERER=1 gentle-dot`. Note in the report whether it helped. || The rose stays dimmed | Look at `~/.gentle-dot/daemon.log` and attach it (see below). || No tray icon on GNOME | Check that the AppIndicator extension is on: `gnome-extensions list --enabled` |-| `gentle-dot: command not found` | Use the full path, `~/.local/bin/gentle-dot` |+| `gentle-dot: command not found` | Use the full path: `/usr/bin/gentle-dot` with the package, `~/.local/bin/gentle-dot` from source |## Report template@@ -229,7 +244,8 @@ Session type: (output of: echo "$XDG_SESSION_TYPE / $XDG_CURRENTHyprland config: (hyprland.lua or hyprland.conf; Omarchy only)GPU and driver: (output of: lspci -k | grep -A 2 -E "VGA|3D")CPU architecture: (output of: uname -m)-Source version: (output of: git rev-parse --short HEAD, or the archive name)+Install method: (package file name, or "source")+Source version: (from source: output of git rev-parse --short HEAD, or the archive name)| # | Step | Result (Pass / Fail / Partial) | Notes ||---|----------------------------|--------------------------------|-------|@@ -259,7 +275,7 @@ Logs: (see below)### Logs to attach-- The terminal output of `~/.local/bin/gentle-dot`, if you started it from a terminal.+- The terminal output of the app command, if you started it from a terminal.- The assistant log, with the access key removed. The key is a secret: never share `~/.gentle-dot/token`. This command copies the log and masks the key:```shdiff --git a/packaging/arch/Dockerfile b/packaging/arch/Dockerfilenew file mode 100644index 0000000..6cf04fd--- /dev/null+++ b/packaging/arch/Dockerfile@@ -0,0 +1,13 @@+# makepkg in a container, for the Arch package (packaging/arch/PKGBUILD). The official archlinux+# image is amd64-only. Driven by scripts/package/package-linux.mjs:+# docker build --platform linux/amd64 -t gentle-dot-arch-builder:latest packaging/arch+FROM archlinux:latest++# pacman's download sandbox fails under emulation ("error restricting syscalls via seccomp: 22"),+# as on an Apple Silicon Mac; it is turned off in this throwaway build image only.+RUN sed -i '/^\[options\]/a DisableSandbox' /etc/pacman.conf \+ && pacman -Syu --noconfirm --needed base-devel \+ && pacman -Scc --noconfirm \+ && useradd --create-home builder++COPY build.sh /usr/local/bin/gentle-dot-build-archdiff --git a/packaging/arch/PKGBUILD b/packaging/arch/PKGBUILDnew file mode 100644index 0000000..1bf74af--- /dev/null+++ b/packaging/arch/PKGBUILD@@ -0,0 +1,22 @@+# Gentle Dot for Arch Linux and Omarchy: repackages the self-contained .deb (S29.3).+# `node scripts/package/package-linux.mjs --arch amd64` builds the .deb, fills in pkgver and the+# checksum, and runs makepkg in an archlinux container. By hand: put gentle-dot_<pkgver>_amd64.deb+# next to this file, then run `updpkgsums && makepkg -si`.+# The app carries its own Node.js, engine, and Engram under /usr/lib/Gentle Dot/runtime.+pkgname=gentle-dot+pkgver=0.1.0+pkgrel=1+pkgdesc="Always-on desktop assistant backed by Gentle Shell"+arch=('x86_64' 'aarch64')+depends=('gtk3' 'webkit2gtk-4.1' 'libayatana-appindicator')+# Keep the bundled binaries (Node.js, Engram, native modules) byte for byte as in the .deb.+options=('!strip' '!debug')+source_x86_64=("${pkgname}_${pkgver}_amd64.deb")+source_aarch64=("${pkgname}_${pkgver}_arm64.deb")+sha256sums_x86_64=('SKIP')+sha256sums_aarch64=('SKIP')++package() {+ # makepkg unpacked the .deb into control.tar.*, data.tar.*, and debian-binary.+ bsdtar -xf "$srcdir"/data.tar.* -C "$pkgdir"+}diff --git a/packaging/arch/build.sh b/packaging/arch/build.shnew file mode 100755index 0000000..8af318b--- /dev/null+++ b/packaging/arch/build.sh@@ -0,0 +1,15 @@+#!/usr/bin/env bash+# Runs inside gentle-dot-arch-builder: /build holds a filled-in PKGBUILD and the .deb it names.+# makepkg refuses to run as root, so it runs as `builder` on a copy; the package lands in /build.+set -euo pipefail++work=$(mktemp -d /home/builder/pkg.XXXXXX)+cp /build/PKGBUILD /build/*.deb "$work"/+chown -R builder: "$work"+cd "$work"+# The dependencies matter on install, not here: the .deb is only unpacked.+runuser -u builder -- makepkg --nodeps --noconfirm --cleanbuild+pkg=$(find "$work" -maxdepth 1 -name 'gentle-dot-*.pkg.tar.zst')+pacman -Qip "$pkg"+echo "files in the package: $(bsdtar -tf "$pkg" | wc -l)"+cp "$pkg" /build/diff --git a/scripts/linux/hyprland/gentle-dot.conf b/scripts/linux/hyprland/gentle-dot.confindex 0ea7ad1..ef9bbed 100644--- a/scripts/linux/hyprland/gentle-dot.conf+++ b/scripts/linux/hyprland/gentle-dot.conf@@ -16,4 +16,7 @@ windowrule = match:title ^(Gentle Dot Panel)$, float on, pin on, size 420 640, m# windowrule = float, pin, size 420 640, move 100%-w-92 10%, noborder, noshadow, noblur, opacity 1 override 1 override, title:^(Gentle Dot Panel)$# --- Every version: SUPER + ALT + D toggles the panel.-bind = SUPER ALT, D, exec, ~/.local/bin/gentle-dot --toggle+# Installed from the package (.deb or Arch package): /usr/bin/gentle-dot.+bind = SUPER ALT, D, exec, /usr/bin/gentle-dot --toggle+# Built from source with scripts/linux/setup-*.sh: use this line instead of the one above.+# bind = SUPER ALT, D, exec, ~/.local/bin/gentle-dot --togglediff --git a/scripts/linux/hyprland/gentle-dot.lua b/scripts/linux/hyprland/gentle-dot.luaindex 42cc958..e24741c 100644--- a/scripts/linux/hyprland/gentle-dot.lua+++ b/scripts/linux/hyprland/gentle-dot.lua@@ -5,7 +5,10 @@-- ~/.config/hypr/gentle-dot.lua and add `require("hypr.gentle-dot")` at the end of hyprland.lua.-- Using hyprland.conf instead? See gentle-dot.conf next to this file.-local toggle = (os.getenv("HOME") or "") .. "/.local/bin/gentle-dot --toggle"+-- Installed from the package (.deb or Arch package): /usr/bin/gentle-dot.+local toggle = "/usr/bin/gentle-dot --toggle"+-- Built from source with scripts/linux/setup-*.sh: use this line instead of the one above.+-- local toggle = (os.getenv("HOME") or "") .. "/.local/bin/gentle-dot --toggle"-- The rose: a 72 px transparent window with no border, shadow, or blur.hl.window_rule({diff --git a/scripts/package/linux-app-smoke.mjs b/scripts/package/linux-app-smoke.mjsnew file mode 100755index 0000000..2b3c28a--- /dev/null+++ b/scripts/package/linux-app-smoke.mjs@@ -0,0 +1,139 @@+#!/usr/bin/env node+// Launches an installed Gentle Dot binary under Xvfb on a clean HOME, as a desktop session would,+// and waits until the daemon the app spawned reports idle on a free port:+// `node scripts/package/linux-app-smoke.mjs --binary /usr/bin/gentle-dot [--runtime <dir>] [--timeout <s>]`.+// Runs inside a Linux container (docker/linux-package/check-package.sh); needs xvfb-run and lsof.+import { execFileSync, spawn } from "node:child_process";+import { existsSync, mkdirSync, mkdtempSync, openSync, readFileSync } from "node:fs";+import { createServer } from "node:net";+import { tmpdir } from "node:os";+import { join } from "node:path";++const SYSTEM_PATH = "/usr/bin:/bin:/usr/sbin:/sbin";+const RESERVED_PORTS = new Set([4317, 7437, 7438]);++const args = process.argv.slice(2).filter((arg) => arg !== "--");+const flag = (name) => (args.includes(name) ? args[args.indexOf(name) + 1] : undefined);+const say = (line) => process.stdout.write(`${line}\n`);+const sleep = (ms) => new Promise((done) => setTimeout(done, ms));++function freePort() {+ return new Promise((done, fail) => {+ const server = createServer().listen(0, "127.0.0.1", () => {+ const { port } = server.address();+ server.close(() => (RESERVED_PORTS.has(port) ? freePort().then(done, fail) : done(port)));+ });+ });+}++/** The command line of the process listening on `port`, when `lsof` can tell. */+function listener(port) {+ try {+ const pid = execFileSync("lsof", ["-t", "-n", "-P", `-iTCP:${port}`, "-sTCP:LISTEN"], {+ encoding: "utf8",+ env: { PATH: SYSTEM_PATH },+ })+ .trim()+ .split("\n")[0];+ return execFileSync("ps", ["-o", "command=", "-p", pid], { encoding: "utf8" }).trim();+ } catch {+ return undefined;+ }+}++async function health(port) {+ try {+ const response = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(2000) });+ return await response.json();+ } catch {+ return undefined;+ }+}++async function main() {+ const binary = flag("--binary");+ if (!binary || !existsSync(binary))+ throw new Error(+ "usage: linux-app-smoke --binary <installed gentle-dot> [--runtime <dir>] [--timeout <s>]",+ );+ const runtime = flag("--runtime");+ const timeoutMs = Number(flag("--timeout") ?? 240) * 1000;+ const scratch = mkdtempSync(join(tmpdir(), "gentle-dot-app-smoke-"));+ const home = join(scratch, "home");+ const dataDir = join(scratch, "data");+ const runDir = join(scratch, "run");+ mkdirSync(home);+ mkdirSync(runDir, { mode: 0o700 });+ const port = await freePort();+ const engramPort = await freePort();+ say(`scratch ${scratch}`);+ say(`app port ${port}, private Engram port ${engramPort}`);++ const logFile = join(scratch, "app.log");+ const log = openSync(logFile, "a");+ const started = Date.now();+ // A new process group, so stopping it stops Xvfb, the app, and the daemon the app spawned.+ const app = spawn("xvfb-run", ["-a", "-s", "-screen 0 1280x800x24", binary], {+ detached: true,+ env: {+ HOME: home,+ PATH: SYSTEM_PATH,+ XDG_RUNTIME_DIR: runDir,+ GENTLE_DOT_PORT: String(port),+ GENTLE_DOT_DATA_DIR: dataDir,+ GENTLE_DOT_ENGRAM: "private",+ GENTLE_DOT_ENGRAM_PORT: String(engramPort),+ },+ stdio: ["ignore", log, log],+ });+ let exited = false;+ app.on("exit", () => {+ exited = true;+ });+ say(`xvfb-run pid ${app.pid}, log ${logFile}`);++ let state;+ while (Date.now() - started < timeoutMs && !exited) {+ state = (await health(port))?.agentState;+ if (state === "idle" || state === "error") break;+ await sleep(1000);+ }+ const seconds = ((Date.now() - started) / 1000).toFixed(1);+ say(+ `app ${exited ? "exited early" : "running"}; /health on ${port}: agentState ${state ?? "unknown"} after ${seconds} s`,+ );+ const daemon = listener(port);+ say(`daemon: ${daemon ?? "not listening"}`);+ const fromRuntime = runtime ? daemon?.includes(join(runtime, "daemon", "cli.mjs")) === true : true;+ if (runtime) say(`daemon launched from the packaged runtime: ${fromRuntime}`);+ const engram = listener(engramPort);+ say(`engram on ${engramPort}: ${engram ?? "not listening"}`);++ if (!exited) {+ process.kill(-app.pid, "SIGTERM");+ for (let i = 0; i < 100 && !exited; i++) await sleep(100);+ }+ await sleep(1000);+ const daemonLeft = listener(port);+ const engramLeft = listener(engramPort);+ say(+ `after stop: daemon ${daemonLeft ? "still listening" : "stopped"}, engram ${engramLeft ? "still listening" : "stopped"}`,+ );+ const daemonLog = join(dataDir, "daemon.log");+ if (existsSync(daemonLog)) {+ const lines = readFileSync(daemonLog, "utf8").trim().split("\n");+ say(`daemon.log: ${lines.length} lines, last: ${lines.at(-1)}`);+ }+ const appLines = readFileSync(logFile, "utf8").trim().split("\n").filter(Boolean);+ say(`app output: ${appLines.length} lines`);+ for (const line of appLines.slice(-8)) say(` ${line}`);++ const ok = state === "idle" && fromRuntime && !daemonLeft && !engramLeft;+ say(ok ? "app smoke: ok" : "app smoke: FAILED");+ process.exit(ok ? 0 : 1);+}++main().catch((error) => {+ process.stderr.write(`linux-app-smoke: ${error.message}\n`);+ process.exit(1);+});diff --git a/scripts/package/linux-check.mjs b/scripts/package/linux-check.mjsnew file mode 100755index 0000000..54838b9--- /dev/null+++ b/scripts/package/linux-check.mjs@@ -0,0 +1,67 @@+#!/usr/bin/env node+// Installs the Linux packages from build/linux/ in clean distribution containers and smoke-tests+// them as a non-root user (S29.4; docker/linux-package/check-package.sh):+// `node scripts/package/linux-check.mjs --arch <arm64|amd64> [--distro debian,ubuntu,arch] [--out <dir>]`.+import { spawnSync } from "node:child_process";+import { existsSync, readFileSync } from "node:fs";+import { join, resolve } from "node:path";+import { fileURLToPath } from "node:url";+import { ARCHES, DISTROS, formatDuration, packageFileFor, parseCheckArgs } from "./linux-lib.mjs";++const REPO = fileURLToPath(new URL("../..", import.meta.url));+const say = (line) => process.stdout.write(`${line}\n`);++function main() {+ const { arch, distros, out: outOption } = parseCheckArgs(process.argv.slice(2));+ const out = resolve(process.env.INIT_CWD ?? process.cwd(), outOption ?? join(REPO, "build", "linux"));+ const version = JSON.parse(+ readFileSync(join(REPO, "apps", "desktop", "src-tauri", "tauri.conf.json"), "utf8"),+ ).version;+ const results = [];+ for (const distro of distros) {+ const file = packageFileFor(distro, version, arch);+ const { image } = DISTROS[distro];+ if (!existsSync(join(out, file))) {+ results.push([distro, `missing ${join(out, file)}; run package-linux --arch ${arch} first`, 0]);+ continue;+ }+ say(`\n=== ${distro} (${image}, linux/${arch}): ${file}`);+ const started = Date.now();+ const result = spawnSync(+ "docker",+ [+ "run",+ "--rm",+ "--name",+ `gentle-dot-linux-check-${distro}-${arch}`,+ "--platform",+ ARCHES[arch].platform,+ "-v",+ `${REPO}:/src:ro`,+ "-v",+ `${out}:/pkg:ro`,+ image,+ "bash",+ "/src/docker/linux-package/check-package.sh",+ `/pkg/${file}`,+ ],+ { stdio: "inherit" },+ );+ results.push([+ distro,+ result.status === 0 ? "passed" : `FAILED (exit ${result.status})`,+ Date.now() - started,+ ]);+ }+ say("\nSummary");+ for (const [distro, outcome, ms] of results)+ say(` ${distro.padEnd(8)} ${outcome}${ms ? ` in ${formatDuration(ms)}` : ""}`);+ process.exit(results.every(([, outcome]) => outcome === "passed") ? 0 : 1);+}++try {+ main();+} catch (error) {+ process.stderr.write(`linux-check: ${error.message}\n`);+ process.exit(1);+}diff --git a/scripts/package/linux-lib.mjs b/scripts/package/linux-lib.mjsnew file mode 100644index 0000000..e126667--- /dev/null+++ b/scripts/package/linux-lib.mjs@@ -0,0 +1,144 @@+// Pure helpers for the Linux packages (S29.3): `package-linux.mjs` builds them in containers+// and `linux-check.mjs` installs them in clean ones.++/** The architectures a Linux package is built for, with each tool's name for them. */+export const ARCHES = Object.freeze({+ arm64: { platform: "linux/arm64", deb: "arm64", runtime: "linux-arm64", pacman: "aarch64" },+ amd64: { platform: "linux/amd64", deb: "amd64", runtime: "linux-x64", pacman: "x86_64" },+});++/**+ * The clean distributions a package is checked on. The official `archlinux` image exists only+ * for amd64, so the Arch package is built and checked for amd64 alone.+ */+export const DISTROS = Object.freeze({+ debian: { image: "debian:bookworm", format: "deb", arches: ["arm64", "amd64"] },+ ubuntu: { image: "ubuntu:24.04", format: "deb", arches: ["arm64", "amd64"] },+ arch: { image: "archlinux:latest", format: "pacman", arches: ["amd64"] },+});++export const PKGREL = 1;++export const PACKAGE_USAGE =+ "usage: package-linux --arch <arm64|amd64> [--out <dir>] [--engram-version <x.y.z>] [--no-arch-package]";+export const CHECK_USAGE =+ "usage: linux-check --arch <arm64|amd64> [--distro <debian|ubuntu|arch>[,…]] [--out <dir>]";++/** Reads `--name value` pairs and bare switches; throws with `usage` on anything unexpected. */+function readFlags(argv, valued, switches, usage) {+ const args = argv.filter((arg) => arg !== "--");+ const options = {};+ for (let i = 0; i < args.length; i++) {+ if (Object.hasOwn(switches, args[i])) {+ options[switches[args[i]]] = true;+ continue;+ }+ const name = valued[args[i]];+ const value = args[i + 1];+ if (!name || value === undefined || value.startsWith("--"))+ throw new Error(`Unexpected argument ${args[i]}.\n${usage}`);+ options[name] = value;+ i++;+ }+ return options;+}++function checkArch(arch, usage) {+ if (!arch) throw new Error(`Missing --arch.\n${usage}`);+ if (!Object.hasOwn(ARCHES, arch))+ throw new Error(`Unknown architecture ${arch}; expected one of ${Object.keys(ARCHES).join(", ")}.`);+}++/** `package-linux` options: the architecture, and whether to build the Arch package (amd64 only). */+export function parsePackageArgs(argv) {+ const options = readFlags(+ argv,+ { "--arch": "arch", "--out": "out", "--engram-version": "engramVersion" },+ { "--no-arch-package": "noArchPackage" },+ PACKAGE_USAGE,+ );+ checkArch(options.arch, PACKAGE_USAGE);+ if (options.engramVersion !== undefined && !/^\d+\.\d+\.\d+$/.test(options.engramVersion))+ throw new Error(`--engram-version must be x.y.z, got ${options.engramVersion}.`);+ const { noArchPackage, ...rest } = options;+ return { ...rest, archPackage: !noArchPackage && DISTROS.arch.arches.includes(options.arch) };+}++/** `linux-check` options: the architecture and the distributions, by default every one it supports. */+export function parseCheckArgs(argv) {+ const options = readFlags(+ argv,+ { "--arch": "arch", "--distro": "distro", "--out": "out" },+ {},+ CHECK_USAGE,+ );+ checkArch(options.arch, CHECK_USAGE);+ const supported = Object.keys(DISTROS).filter((name) => DISTROS[name].arches.includes(options.arch));+ if (options.distro === undefined) return { arch: options.arch, out: options.out, distros: supported };+ const distros = options.distro.split(",").filter(Boolean);+ for (const name of distros) {+ if (!Object.hasOwn(DISTROS, name))+ throw new Error(`Unknown distribution ${name}; expected one of ${Object.keys(DISTROS).join(", ")}.`);+ if (!supported.includes(name))+ throw new Error(`${name} is checked only on ${DISTROS[name].arches.join(", ")}, not ${options.arch}.`);+ }+ return { arch: options.arch, out: options.out, distros };+}++export function debFileName(version, arch) {+ return `gentle-dot_${version}_${ARCHES[arch].deb}.deb`;+}++export function archPackageFileName(version, arch, pkgrel = PKGREL) {+ return `gentle-dot-${version}-${pkgrel}-${ARCHES[arch].pacman}.pkg.tar.zst`;+}++/** The file `linux-check` installs on `distro`. */+export function packageFileFor(distro, version, arch) {+ return DISTROS[distro].format === "deb" ? debFileName(version, arch) : archPackageFileName(version, arch);+}++export function builderImage(arch) {+ return `gentle-dot-linux-builder:${arch}`;+}++export const ARCH_BUILDER_IMAGE = "gentle-dot-arch-builder:latest";++/** Named volumes that keep downloads and compiled crates between builds, and where they mount. */+export function cacheVolumes(arch) {+ return [+ { name: `gentle-dot-linux-${arch}-cargo`, target: "/usr/local/cargo/registry" },+ { name: `gentle-dot-linux-${arch}-target`, target: "/work/apps/desktop/src-tauri/target" },+ { name: `gentle-dot-linux-${arch}-cache`, target: "/work/.cache" },+ { name: `gentle-dot-linux-${arch}-pnpm`, target: "/pnpm-store" },+ ];+}++/**+ * The repository's PKGBUILD with this build's version, release, and the checksum of the+ * .deb it repackages; throws when a field to fill is missing.+ */+export function fillPkgbuild(pkgbuild, { version, arch, sha256, pkgrel = PKGREL }) {+ if (!/^[0-9a-f]{64}$/.test(sha256)) throw new Error(`Not a SHA-256: ${sha256}`);+ const sums = `sha256sums_${ARCHES[arch].pacman}`;+ const fields = [+ [/^pkgver=.*$/m, `pkgver=${version}`],+ [/^pkgrel=.*$/m, `pkgrel=${pkgrel}`],+ [new RegExp(`^${sums}=.*$`, "m"), `${sums}=('${sha256}')`],+ ];+ let filled = pkgbuild;+ for (const [pattern, line] of fields) {+ if (!pattern.test(filled)) throw new Error(`The PKGBUILD has no ${line.split("=")[0]} line.`);+ filled = filled.replace(pattern, line);+ }+ return filled;+}++export function formatSize(bytes) {+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`;+}++export function formatDuration(ms) {+ const seconds = Math.round(ms / 1000);+ return seconds < 60 ? `${seconds} s` : `${Math.floor(seconds / 60)} min ${seconds % 60} s`;+}diff --git a/scripts/package/package-linux.mjs b/scripts/package/package-linux.mjsnew file mode 100755index 0000000..7d186e5--- /dev/null+++ b/scripts/package/package-linux.mjs@@ -0,0 +1,173 @@+#!/usr/bin/env node+// Builds the self-contained Linux packages (S29.3) in Docker, from any machine with Docker:+// `node scripts/package/package-linux.mjs --arch <arm64|amd64> [--out <dir>] [--engram-version <x.y.z>]+// [--no-arch-package]`. It builds the .deb in a Debian 12 container of that architecture (amd64 on an+// Apple Silicon Mac runs emulated) and, for amd64, the Arch package from it. Artifacts land in+// build/linux/; `linux-check.mjs` installs them in clean containers.+import { spawnSync } from "node:child_process";+import { createHash } from "node:crypto";+import {+ chmodSync,+ copyFileSync,+ mkdirSync,+ mkdtempSync,+ readdirSync,+ readFileSync,+ rmSync,+ statSync,+ writeFileSync,+} from "node:fs";+import { tmpdir } from "node:os";+import { join, resolve } from "node:path";+import { fileURLToPath } from "node:url";+import {+ ARCH_BUILDER_IMAGE,+ ARCHES,+ archPackageFileName,+ builderImage,+ cacheVolumes,+ debFileName,+ fillPkgbuild,+ formatDuration,+ formatSize,+ parsePackageArgs,+} from "./linux-lib.mjs";++const REPO = fileURLToPath(new URL("../..", import.meta.url));+const say = (line) => process.stdout.write(`${line}\n`);++function docker(args) {+ const result = spawnSync("docker", args, { stdio: "inherit" });+ if (result.status !== 0)+ throw new Error(+ `docker ${args.slice(0, 2).join(" ")} failed (${result.error?.message ?? `exit ${result.status}`}).`,+ );+}++/** Runs `step` and records how long it took. */+function timed(timings, label, step) {+ const started = Date.now();+ say(`\n=== ${label}`);+ const value = step();+ timings.push([label, Date.now() - started]);+ return value;+}++function sha256(path) {+ return createHash("sha256").update(readFileSync(path)).digest("hex");+}++function buildDeb({ arch, engramVersion }, scratch, timings) {+ const { platform } = ARCHES[arch];+ timed(timings, `Builder image ${builderImage(arch)}`, () =>+ docker([+ "build",+ "--platform",+ platform,+ "-t",+ builderImage(arch),+ join(REPO, "docker", "linux-package"),+ ]),+ );+ const volumes = cacheVolumes(arch).flatMap(({ name, target }) => ["-v", `${name}:${target}`]);+ const env = engramVersion ? ["-e", `ENGRAM_VERSION=${engramVersion}`] : [];+ timed(timings, `.deb for ${arch} (stage the runtime, tauri build)`, () =>+ docker([+ "run",+ "--rm",+ "--name",+ `gentle-dot-linux-build-${arch}`,+ "--platform",+ platform,+ "-v",+ `${REPO}:/src:ro`,+ "-v",+ `${scratch}:/out`,+ ...volumes,+ ...env,+ builderImage(arch),+ "gentle-dot-build-deb",+ ]),+ );+ const built = readdirSync(scratch).filter((name) => name.endsWith(".deb"));+ if (built.length !== 1) throw new Error(`Expected one .deb in ${scratch}, found ${built.length}.`);+ return { deb: join(scratch, built[0]), manifest: join(scratch, "runtime-MANIFEST.json") };+}++function buildArchPackage(deb, version, scratch, timings) {+ const arch = "amd64";+ const work = join(scratch, "arch");+ mkdirSync(work);+ const debName = debFileName(version, arch);+ copyFileSync(deb, join(work, debName));+ const pkgbuild = readFileSync(join(REPO, "packaging", "arch", "PKGBUILD"), "utf8");+ writeFileSync(join(work, "PKGBUILD"), fillPkgbuild(pkgbuild, { version, arch, sha256: sha256(deb) }));+ chmodSync(work, 0o777);+ timed(timings, `Arch builder image ${ARCH_BUILDER_IMAGE}`, () =>+ docker([+ "build",+ "--platform",+ ARCHES[arch].platform,+ "-t",+ ARCH_BUILDER_IMAGE,+ join(REPO, "packaging", "arch"),+ ]),+ );+ timed(timings, "Arch package (makepkg)", () =>+ docker([+ "run",+ "--rm",+ "--name",+ "gentle-dot-arch-build",+ "--platform",+ ARCHES[arch].platform,+ "-v",+ `${work}:/build`,+ ARCH_BUILDER_IMAGE,+ "gentle-dot-build-arch",+ ]),+ );+ return join(work, archPackageFileName(version, arch));+}++function main() {+ const options = parsePackageArgs(process.argv.slice(2));+ const { arch } = options;+ const out = resolve(process.env.INIT_CWD ?? process.cwd(), options.out ?? join(REPO, "build", "linux"));+ const version = JSON.parse(+ readFileSync(join(REPO, "apps", "desktop", "src-tauri", "tauri.conf.json"), "utf8"),+ ).version;+ // Docker Desktop shares the system temp folder with containers.+ const scratch = mkdtempSync(join(tmpdir(), `gentle-dot-linux-${arch}-`));+ const started = Date.now();+ const timings = [];+ say(`Gentle Dot ${version} for linux/${arch}; scratch ${scratch}`);++ const built = buildDeb(options, scratch, timings);+ mkdirSync(out, { recursive: true });+ const artifacts = [join(out, debFileName(version, arch))];+ copyFileSync(built.deb, artifacts[0]);+ copyFileSync(built.manifest, join(out, `runtime-${ARCHES[arch].runtime}.json`));+ if (options.archPackage) {+ const pkg = buildArchPackage(built.deb, version, scratch, timings);+ artifacts.push(join(out, archPackageFileName(version, arch)));+ copyFileSync(pkg, artifacts[1]);+ } else say(`\nNo Arch package for ${arch} (the archlinux image is amd64-only, or --no-arch-package).`);+ rmSync(scratch, { recursive: true });++ say("\nTimings");+ for (const [label, ms] of timings) say(` ${formatDuration(ms).padStart(12)} ${label}`);+ say(` ${formatDuration(Date.now() - started).padStart(12)} total`);+ say("\nArtifacts");+ for (const path of artifacts) {+ const { size } = statSync(path);+ say(` ${path} ${formatSize(size)} (${size} bytes) sha256 ${sha256(path)}`);+ }+}++try {+ main();+} catch (error) {+ process.stderr.write(`package-linux: ${error.message}\n`);+ process.exit(1);+}diff --git a/scripts/package/test-linux/linux-lib.test.ts b/scripts/package/test-linux/linux-lib.test.tsnew file mode 100644index 0000000..c71f9d0--- /dev/null+++ b/scripts/package/test-linux/linux-lib.test.ts@@ -0,0 +1,118 @@+import { readFileSync } from "node:fs";+import { describe, expect, it } from "vitest";+import {+ archPackageFileName,+ builderImage,+ cacheVolumes,+ debFileName,+ fillPkgbuild,+ formatDuration,+ packageFileFor,+ parseCheckArgs,+ parsePackageArgs,+} from "../linux-lib.mjs";++const SHA = "a".repeat(64);++describe("parsePackageArgs", () => {+ it("builds the Arch package for amd64 only, unless --no-arch-package", () => {+ expect(parsePackageArgs(["--", "--arch", "amd64"])).toEqual({ arch: "amd64", archPackage: true });+ expect(parsePackageArgs(["--arch", "arm64"])).toEqual({ arch: "arm64", archPackage: false });+ expect(parsePackageArgs(["--arch", "amd64", "--no-arch-package", "--out", "/tmp/o"])).toEqual({+ arch: "amd64",+ out: "/tmp/o",+ archPackage: false,+ });+ });++ it("passes an Engram version through", () => {+ expect(parsePackageArgs(["--arch", "arm64", "--engram-version", "3.2.1"]).engramVersion).toBe("3.2.1");+ });++ it("refuses a missing or unknown architecture, unknown flags, and a flag without a value", () => {+ expect(() => parsePackageArgs([])).toThrow(/Missing --arch/);+ expect(() => parsePackageArgs(["--arch", "x86_64"])).toThrow(/Unknown architecture x86_64/);+ expect(() => parsePackageArgs(["--arch", "arm64", "--sign"])).toThrow(/Unexpected argument --sign/);+ expect(() => parsePackageArgs(["--arch", "--out", "/tmp/o"])).toThrow(/Unexpected argument --arch/);+ expect(() => parsePackageArgs(["--arch", "arm64", "--engram-version", "latest"])).toThrow(/x\.y\.z/);+ });+});++describe("parseCheckArgs", () => {+ it("checks every distribution an architecture supports by default", () => {+ expect(parseCheckArgs(["--arch", "amd64"]).distros).toEqual(["debian", "ubuntu", "arch"]);+ expect(parseCheckArgs(["--arch", "arm64"]).distros).toEqual(["debian", "ubuntu"]);+ });++ it("takes a comma-separated list and refuses Arch on arm64", () => {+ expect(parseCheckArgs(["--arch", "amd64", "--distro", "arch,debian"]).distros).toEqual([+ "arch",+ "debian",+ ]);+ expect(() => parseCheckArgs(["--arch", "arm64", "--distro", "arch"])).toThrow(/only on amd64/);+ expect(() => parseCheckArgs(["--arch", "arm64", "--distro", "fedora"])).toThrow(+ /Unknown distribution fedora/,+ );+ });+});++describe("artifact names", () => {+ it("follow Debian and pacman conventions for each architecture", () => {+ expect(debFileName("0.1.0", "arm64")).toBe("gentle-dot_0.1.0_arm64.deb");+ expect(debFileName("0.1.0", "amd64")).toBe("gentle-dot_0.1.0_amd64.deb");+ expect(archPackageFileName("0.1.0", "amd64")).toBe("gentle-dot-0.1.0-1-x86_64.pkg.tar.zst");+ expect(archPackageFileName("0.2.0", "arm64", 3)).toBe("gentle-dot-0.2.0-3-aarch64.pkg.tar.zst");+ });++ it("pick the package each distribution installs", () => {+ expect(packageFileFor("ubuntu", "0.1.0", "arm64")).toBe("gentle-dot_0.1.0_arm64.deb");+ expect(packageFileFor("arch", "0.1.0", "amd64")).toBe("gentle-dot-0.1.0-1-x86_64.pkg.tar.zst");+ });++ it("name images and cache volumes per architecture", () => {+ expect(builderImage("amd64")).toBe("gentle-dot-linux-builder:amd64");+ const volumes = cacheVolumes("arm64");+ expect(volumes.map((volume) => volume.name)).toEqual([+ "gentle-dot-linux-arm64-cargo",+ "gentle-dot-linux-arm64-target",+ "gentle-dot-linux-arm64-cache",+ "gentle-dot-linux-arm64-pnpm",+ ]);+ expect(volumes.every((volume) => volume.target.startsWith("/"))).toBe(true);+ });+});++describe("fillPkgbuild", () => {+ const pkgbuild = readFileSync(new URL("../../../packaging/arch/PKGBUILD", import.meta.url), "utf8");++ it("fills in the version, release, and the checksum for the built architecture only", () => {+ const filled = fillPkgbuild(pkgbuild, { version: "0.2.0", arch: "amd64", sha256: SHA });+ expect(filled).toMatch(/^pkgver=0\.2\.0$/m);+ expect(filled).toMatch(/^pkgrel=1$/m);+ expect(filled).toMatch(new RegExp(`^sha256sums_x86_64=\\('${SHA}'\\)$`, "m"));+ expect(filled).toMatch(/^sha256sums_aarch64=\('SKIP'\)$/m);+ expect(filled).toMatch(/^source_x86_64=\("\$\{pkgname\}_\$\{pkgver\}_amd64\.deb"\)$/m);+ });++ it("names the .deb that debFileName produces", () => {+ const filled = fillPkgbuild(pkgbuild, { version: "0.1.0", arch: "amd64", sha256: SHA });+ const source = /^source_x86_64=\("\$\{pkgname\}_\$\{pkgver\}_(\w+)\.deb"\)$/m.exec(filled);+ expect(`gentle-dot_0.1.0_${source?.[1]}.deb`).toBe(debFileName("0.1.0", "amd64"));+ });++ it("refuses a bad checksum or a PKGBUILD without the fields", () => {+ expect(() => fillPkgbuild(pkgbuild, { version: "0.1.0", arch: "amd64", sha256: "abc" })).toThrow(+ /SHA-256/,+ );+ expect(() => fillPkgbuild("pkgname=x\n", { version: "0.1.0", arch: "amd64", sha256: SHA })).toThrow(+ /pkgver/,+ );+ });+});++describe("formatDuration", () => {+ it("prints seconds, then minutes and seconds", () => {+ expect(formatDuration(4_400)).toBe("4 s");+ expect(formatDuration(125_000)).toBe("2 min 5 s");+ });+});diff --git a/vitest.config.ts b/vitest.config.tsindex c3ee0e2..c2ebcad 100644--- a/vitest.config.ts+++ b/vitest.config.ts@@ -10,6 +10,7 @@ export default defineConfig({"packages/protocol/test/**/*.test.ts","packages/daemon/test/**/*.test.ts","scripts/package/test/**/*.test.ts",+ "scripts/package/test-linux/**/*.test.ts",],environment: "node",testTimeout: 20_000,