Address Cody review round 6: executable runbook, static client install, README
CODY-011 deploy/install.sh performs the ownership-sensitive sequence: the
release is copied to app.new, that one directory is given to the
hermeven user, npm ci runs unprivileged, and the finished tree is
handed back to root:root with group/other write removed. Secrets,
state and model directories are never touched. The guide now gives
exact commands, including the C/C++ toolchain a clean host needs
(found by running it on one).
CODY-012 install.sh builds the phone page with the bridge address preset
and installs it root-owned into /opt/hermeven/www for Caddy. The
guide explains the web build versus the .ehpk package and when
each is needed.
CODY-013 README states which commit was deployed, what was checked, and
what remains unverified.
Also corrects a wrong diagnosis recorded in the previous commit: the phone
page that showed "Browser preview" had been opened in Chrome, not in the
Even app. Host detection keeps a short precautionary wait (2.5 s) and its
comments no longer claim an observed Even-app delay.
tests/deploy/runbook-proof.sh proves the guide on a disposable Ubuntu 24.04
host with systemd.
Not reviewed.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
# Disposable Ubuntu 24.04 host with systemd as PID 1, for proving docs/deploy-droplet.md.
|
||||
# Only the operating system and systemd are prepared here. Everything the guide tells the
|
||||
# operator to install (Caddy, git, Node.js, Hermeven) is installed by the proof script.
|
||||
FROM ubuntu:24.04
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get update -qq && apt-get install -y -qq systemd systemd-sysv dbus >/dev/null && apt-get clean
|
||||
STOPSIGNAL SIGRTMIN+3
|
||||
CMD ["/sbin/init"]
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env bash
|
||||
# Proves the server-side steps of docs/deploy-droplet.md on a disposable Ubuntu 24.04 host
|
||||
# (a privileged Docker container running systemd). Opt-in: needs Docker and network access.
|
||||
#
|
||||
# tests/deploy/runbook-proof.sh
|
||||
#
|
||||
# It deploys the CURRENT COMMIT (HEAD), from an empty /opt/hermeven, by running the commands
|
||||
# the guide gives. Hermes is not present in the container, so the bridge starts with the agent
|
||||
# unreachable; that is expected and is not what this proves.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/../.."
|
||||
NAME=hermeven-runbook-proof
|
||||
IMAGE=hermeven-runbook-host:24.04
|
||||
SHA=$(git rev-parse HEAD)
|
||||
[ -z "$(git status --porcelain)" ] || { echo "Commit or stash changes first: the proof deploys HEAD." >&2; exit 1; }
|
||||
|
||||
cleanup() { docker rm -f "$NAME" >/dev/null 2>&1 || true; rm -f "$BUNDLE"; }
|
||||
BUNDLE=$(mktemp --suffix=.bundle)
|
||||
trap cleanup EXIT
|
||||
docker rm -f "$NAME" >/dev/null 2>&1 || true
|
||||
|
||||
echo "### host image"
|
||||
docker build -q -t "$IMAGE" tests/deploy >/dev/null
|
||||
docker run -d --name "$NAME" --privileged --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw --tmpfs /run --tmpfs /run/lock "$IMAGE" >/dev/null
|
||||
for _ in $(seq 1 30); do docker exec "$NAME" systemctl is-system-running 2>/dev/null | grep -qE 'running|degraded' && break; sleep 1; done
|
||||
in_host() { docker exec -i "$NAME" bash -euo pipefail -c "$1"; }
|
||||
in_host '. /etc/os-release; echo "$PRETTY_NAME"; test ! -e /opt/hermeven && echo "/opt/hermeven does not exist"; id hermeven 2>&1 | head -1 || true'
|
||||
|
||||
echo "### step 2: packages (Caddy, git, Node.js with checksum)"
|
||||
in_host 'export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update -qq >/dev/null && apt-get install -y -qq caddy git curl xz-utils ca-certificates build-essential python3 >/dev/null 2>&1
|
||||
V=$(curl -fsSL https://nodejs.org/dist/latest-v22.x/SHASUMS256.txt | grep -oE "v22\.[0-9]+\.[0-9]+" | head -1)
|
||||
cd /tmp && curl -fsSLO https://nodejs.org/dist/$V/node-$V-linux-x64.tar.xz
|
||||
curl -fsSL https://nodejs.org/dist/$V/SHASUMS256.txt | grep " node-$V-linux-x64.tar.xz\$" | sha256sum -c -
|
||||
mkdir -p /opt/node-$V && tar -xJf node-$V-linux-x64.tar.xz -C /opt/node-$V --strip-components=1
|
||||
ln -sfn /opt/node-$V /opt/node && /opt/node/bin/node -v
|
||||
caddy version | head -1'
|
||||
|
||||
echo "### step 3: get the release onto the server (git clone of $SHA)"
|
||||
git bundle create "$BUNDLE" HEAD >/dev/null 2>&1
|
||||
docker cp "$BUNDLE" "$NAME":/root/release.bundle
|
||||
in_host "git clone -q /root/release.bundle /root/hermeven-src 2>/dev/null && git -C /root/hermeven-src checkout -q $SHA && git -C /root/hermeven-src rev-parse HEAD"
|
||||
|
||||
echo "### step 4: deploy/install.sh"
|
||||
in_host '/root/hermeven-src/deploy/install.sh --bridge-url https://localhost >/tmp/install.log 2>&1 || { echo "install.sh FAILED:"; tail -25 /tmp/install.log; exit 1; }; grep -E "^==>|^Installed|^Phone page|^Not started" /tmp/install.log'
|
||||
|
||||
echo "### ownership and permissions after install"
|
||||
in_host 'echo "DEPLOYED_SHA: $(cat /opt/hermeven/app/DEPLOYED_SHA)"
|
||||
echo "app tree owner: $(stat -c "%U:%G %a" /opt/hermeven/app)"
|
||||
echo "not root-owned in app: $(find /opt/hermeven/app ! -user root | wc -l) group/other-writable in app: $(find /opt/hermeven/app -perm /022 ! -type l | wc -l)"
|
||||
echo "node_modules present: $(test -d /opt/hermeven/app/node_modules && echo yes)"
|
||||
runuser -u hermeven -- test -w /opt/hermeven/app && echo "hermeven CAN write app (BAD)" || echo "hermeven cannot write the app tree"
|
||||
runuser -u hermeven -- sh -c "touch /opt/hermeven/app/services/bridge/src/x 2>/dev/null" && echo "hermeven CAN create files in src (BAD)" || echo "hermeven cannot create files in the source"
|
||||
echo "www: $(stat -c "%U:%G %a" /opt/hermeven/www) index $(stat -c "%U %a" /opt/hermeven/www/index.html) files=$(find /opt/hermeven/www -type f | wc -l)"
|
||||
runuser -u hermeven -- test -w /opt/hermeven/www && echo "hermeven CAN write www (BAD)" || echo "hermeven cannot write www"
|
||||
runuser -u caddy -- test -r /opt/hermeven/www/index.html && echo "caddy can read www"
|
||||
echo "state dir: $(stat -c "%U:%G %a" /var/lib/hermeven)"
|
||||
echo "secrets dir entries: $(ls -A /etc/hermeven | wc -l) (install.sh wrote none)"
|
||||
echo "models dir: $(test -e /opt/hermeven/models && echo exists || echo "not created by install.sh")"'
|
||||
|
||||
echo "### steps 5, 6: configuration and speech model"
|
||||
in_host 'install -m 0600 -o hermeven -g hermeven /opt/hermeven/app/deploy/bridge.env.example /etc/hermeven/bridge.env
|
||||
sed -i "s/^HERMES_API_KEY=.*/HERMES_API_KEY=proof-run-not-a-real-key/" /etc/hermeven/bridge.env
|
||||
stat -c "%U:%G %a %n" /etc/hermeven/bridge.env
|
||||
cd /opt/hermeven/app/services/bridge
|
||||
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env /opt/node/bin/node --import tsx src/cli.ts fetch-model | tail -1
|
||||
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env /opt/node/bin/node --import tsx src/cli.ts verify-model | tail -1
|
||||
echo "models owner: $(stat -c "%U:%G" /opt/hermeven/models)"'
|
||||
|
||||
echo "### step 8: start the bridge under systemd"
|
||||
in_host 'systemd-analyze verify /etc/systemd/system/hermeven-bridge.service && echo "systemd-analyze verify: ok"
|
||||
systemctl enable --now hermeven-bridge 2>/dev/null
|
||||
for _ in $(seq 1 60); do journalctl -u hermeven-bridge --no-pager 2>/dev/null | grep -q "stt.ready\|stt.load_failed" && break; sleep 1; done
|
||||
echo "unit: $(systemctl is-active hermeven-bridge) (running as $(systemctl show hermeven-bridge -p User --value), MainPID uid $(stat -c %U /proc/$(systemctl show hermeven-bridge -p MainPID --value)))"
|
||||
journalctl -u hermeven-bridge --no-pager | grep -oE "\"msg\":\"(Server listening[^\"]*|stt\.[a-z_]+)\"|\"reason\":\"[a-z]+\"" | tr "\n" " "; echo
|
||||
echo "healthz (direct): $(curl -sS -m 5 http://127.0.0.1:8787/healthz)"
|
||||
echo "state files: $(stat -c "%a" /var/lib/hermeven) $(stat -c "%U %a %n" /var/lib/hermeven/* | tr "\n" ";")"'
|
||||
|
||||
echo "### step 9: HTTPS through Caddy (hostname replaced by localhost; certificate from Caddy's local CA)"
|
||||
in_host 'caddy fmt --diff /opt/hermeven/app/deploy/Caddyfile.example >/tmp/fmt.diff 2>&1; echo "caddy fmt --diff on the example: exit $?, $(grep -cE "^[-+]" /tmp/fmt.diff || true) changed line(s)"
|
||||
sed "s/^bridge\.example\.com {/localhost {/" /opt/hermeven/app/deploy/Caddyfile.example > /etc/caddy/Caddyfile
|
||||
caddy validate --config /etc/caddy/Caddyfile 2>&1 | tail -1
|
||||
systemctl restart caddy; sleep 4; echo "caddy: $(systemctl is-active caddy)"
|
||||
ASSET=$(curl -sSk https://localhost/ | grep -oE "assets/index-[A-Za-z0-9_-]+\.js" | head -1)
|
||||
echo "GET / -> $(curl -sSk -o /dev/null -w "%{http_code} %{content_type}" https://localhost/)"
|
||||
echo "GET /$ASSET -> $(curl -sSk -o /dev/null -w "%{http_code} %{content_type} %{size_download} bytes" https://localhost/$ASSET)"
|
||||
echo "GET /healthz -> $(curl -sSk https://localhost/healthz)"
|
||||
echo "GET /v1/device -> $(curl -sSk -o /dev/null -w "%{http_code}" https://localhost/v1/device) (no credential)"
|
||||
echo "headers on /:"; curl -sSkI https://localhost/ | grep -iE "^(strict-transport-security|x-content-type-options|referrer-policy|server):" | sed "s/^/ /"
|
||||
echo "headers on the asset:"; curl -sSkI https://localhost/$ASSET | grep -iE "^(strict-transport-security|x-content-type-options|referrer-policy|server):" | sed "s/^/ /"
|
||||
echo "bridge address built into the page: $(grep -c "https://localhost" /opt/hermeven/www/$ASSET) occurrence(s) of https://localhost"
|
||||
echo "CORS for a foreign origin: $(curl -sSkI -H "Origin: https://evil.example" https://localhost/v1/device | grep -ci "^access-control-allow-origin" || true) allow-origin header(s)"'
|
||||
echo "### done: $SHA"
|
||||
@@ -2,8 +2,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { HOST_WAIT_MS, PLATFORM_READY_EVENT, waitForEvenHost, watchForLateHost, type HostWindow } from '../../apps/even-client/src/device/hostDetect.ts';
|
||||
|
||||
/**
|
||||
* Found on the first real-phone run (2026-11-21): the Even app's connection was not yet on
|
||||
* `window` when the page's script started, and the page wrongly chose browser-preview mode.
|
||||
* Host detection waits briefly for the Even app's connection instead of deciding on the first
|
||||
* instant. This is a precaution: no real phone has yet been observed providing it late.
|
||||
*/
|
||||
function fakeWindow() {
|
||||
const listeners = new Map<string, Set<() => void>>();
|
||||
@@ -28,7 +28,7 @@ describe('detecting the Even app host', () => {
|
||||
expect(win.listenerCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('appears shortly after the page starts (the real phone): found, not mistaken for a browser', async () => {
|
||||
it('appears shortly after the page starts: found, not mistaken for a browser', async () => {
|
||||
const win = fakeWindow();
|
||||
const detecting = waitForEvenHost(win);
|
||||
await vi.advanceTimersByTimeAsync(800);
|
||||
|
||||
Reference in New Issue
Block a user