Phases 2 and 3 of plan 009, plus the parts of phase 1 that could not
land before them. Nothing in the tree imports wails/v2 any more; all
three lint and test configurations are green and `go build .` produces
a running binary.
The point of the migration is one file. backend/events/emit.go probed
ctx.Value("events") — a v2-*private* context key — to decide whether
emitting was safe, because runtime.EventsEmit called log.Fatalf on a
context without the runtime and took the process down with it. v3's
emit takes no context, so that is now application.Get() == nil. D1
held: events.Emit keeps its ctx as the WithSink test seam, and all 45
call sites and 7 test files are untouched.
The bootstrap splits into application.New + Window.NewWithOptions +
Run. Ten bound services implement ServiceStartup instead of being
handed a context by hand from OnStartup, which also stops ten
SetContext methods being exported as bindings. jobs.Registry and
explore.SearchIndex keep theirs — neither is bound, so converting them
would be churn for no binding removed.
Four things differed from the plan and are written up in it: GPU policy
moved to the per-window LinuxWindow options rather than surviving on
LinuxOptions; there is no OnStartup/OnDomReady option, so app-level
wiring hangs off ApplicationStarted; application.NewService is generic,
so FEBindings []any could not survive (the binding generator is a
static analyser and would have seen nothing); and the quit veto had to
be restructured, because v3's dialog answers on a callback rather than
returning the button, so ShouldQuit vetoes, asks, and quits again from
the callback.
Window state saving moves to a WindowClosing hook — the size has to be
read while the window still exists, and v3's OnShutdown has neither
context nor window. backend/logging is deleted rather than ported:
v3 takes a *slog.Logger directly, so the v2 logger.Logger adapter had
no caller left.
Phase 1's tail rides along, now that it can: the Makefile's wails
invocations, all 50 webkit2_41 sites, lefthook, both packaging recipes
and ci.yml's apt lists. v3 builds against GTK4 + WebKitGTK 6.0, which
Arch and ubuntu:24.04 both ship, so the tag is a deletion rather than
a translation.
Phase 4 is next and the branch is not usable until it lands: the app
builds, but frontend/wailsjs/ is v2's tree and nothing regenerates it,
so the frontend cannot reach the backend yet.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UDCbcCZQepnpSQYJ6SxxZm
198 lines
6.2 KiB
Bash
Executable File
198 lines
6.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Start YellowJacket headless, in the background, and return.
|
|
#
|
|
# `wails dev` binds an HTTP + WebSocket dev server on :34115 that serves
|
|
# the real frontend with the real generated bindings on `window.go` and
|
|
# bridges every call and every runtime.EventsEmit to the *same* Go
|
|
# backend the desktop window uses. A browser pointed at it is not a
|
|
# mock. That is what makes this app drivable by a coding agent.
|
|
#
|
|
# Three details are load-bearing:
|
|
#
|
|
# * We run the dev *binary*, not `wails dev`. app_dev.go parses
|
|
# -devserver / -assetdir / -loglevel straight from os.Args, so a
|
|
# `go build -tags "dev"` binary serves the identical
|
|
# devserver with no file watcher, no rebuild supervisor and no
|
|
# reload broadcast: one process, one PID, deterministic startup.
|
|
#
|
|
# * Xvfb is not optional. devserver.Run ends in Frontend.Run(ctx),
|
|
# which opens the GTK window and blocks; no flag suppresses it.
|
|
#
|
|
# * dbus-run-session is not incidental. A private session bus makes
|
|
# backend/mediacontrols register MPRIS for real, so it becomes
|
|
# assertable with busctl. It replaces the bus, not /run/user, so
|
|
# PulseAudio still works and InitSpeaker succeeds.
|
|
#
|
|
# Usage:
|
|
# scripts/dev-headless.sh [--seed NAME|--fresh] [--port N] [--no-build]
|
|
#
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
REPO_ROOT="$PWD"
|
|
RUN_DIR="$REPO_ROOT/.dev"
|
|
PID_FILE="$RUN_DIR/app.pid"
|
|
LOG_FILE="$RUN_DIR/app.log"
|
|
HOME_FILE="$RUN_DIR/app.home"
|
|
SEED_DIR="$RUN_DIR/seeds"
|
|
BIN="$REPO_ROOT/build/bin/yj-dev"
|
|
|
|
PORT=34115
|
|
SEED=""
|
|
FRESH=0
|
|
BUILD=1
|
|
LOG_LEVEL="${YJ_LOG_LEVEL:-debug}"
|
|
STARTUP_TIMEOUT=60
|
|
|
|
usage() {
|
|
sed -n '3,28p' "$0" | sed 's/^# \{0,1\}//'
|
|
exit "${1:-0}"
|
|
}
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--seed)
|
|
SEED="${2:?--seed needs a name}"
|
|
shift 2
|
|
;;
|
|
--fresh)
|
|
FRESH=1
|
|
shift
|
|
;;
|
|
--port)
|
|
PORT="${2:?--port needs a number}"
|
|
shift 2
|
|
;;
|
|
--no-build)
|
|
BUILD=0
|
|
shift
|
|
;;
|
|
-h | --help) usage 0 ;;
|
|
*)
|
|
echo "dev-headless: unknown argument: $1" >&2
|
|
usage 2
|
|
;;
|
|
esac
|
|
done
|
|
|
|
mkdir -p "$RUN_DIR"
|
|
|
|
# ── Refuse to stack instances ────────────────────────────────────────
|
|
# Two backends on one port fails obscurely; two backends on one YJ_HOME
|
|
# corrupts a SQLite database. Check the saved PID, not the port.
|
|
if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
|
|
echo "dev-headless: already running (pid $(cat "$PID_FILE")); " \
|
|
"run 'make dev-stop' first" >&2
|
|
exit 1
|
|
fi
|
|
rm -f "$PID_FILE"
|
|
|
|
# ── Choose the YJ_HOME ───────────────────────────────────────────────
|
|
# A seed is a YJ_HOME that a previous run of the app produced, tarred
|
|
# up (see scripts/seed-sandbox.sh). Restoring it means starting *in*
|
|
# the app instead of on the first-run wizard, which intercepts every
|
|
# pointer event until a library exists.
|
|
if [ -n "$SEED" ] && [ "$FRESH" = 1 ]; then
|
|
echo "dev-headless: --seed and --fresh are mutually exclusive" >&2
|
|
exit 2
|
|
fi
|
|
|
|
if [ -n "$SEED" ]; then
|
|
SEED_TAR="$SEED_DIR/$SEED.tar"
|
|
if [ ! -f "$SEED_TAR" ]; then
|
|
echo "dev-headless: no seed '$SEED' at $SEED_TAR" >&2
|
|
echo " build one with: make sandbox-seed NAME=$SEED" >&2
|
|
exit 1
|
|
fi
|
|
|
|
YJ_HOME="$RUN_DIR/home-$SEED"
|
|
rm -rf "$YJ_HOME"
|
|
mkdir -p "$YJ_HOME"
|
|
tar -xf "$SEED_TAR" -C "$YJ_HOME"
|
|
echo "dev-headless: restored seed '$SEED'"
|
|
elif [ "$FRESH" = 1 ]; then
|
|
# Deliberately empty: the first-run wizard is itself a surface
|
|
# that needs testing.
|
|
YJ_HOME="$RUN_DIR/home-fresh"
|
|
rm -rf "$YJ_HOME"
|
|
mkdir -p "$YJ_HOME"
|
|
echo "dev-headless: fresh YJ_HOME (expect the first-run wizard)"
|
|
else
|
|
YJ_HOME="${YJ_HOME:-$RUN_DIR/home}"
|
|
mkdir -p "$YJ_HOME"
|
|
fi
|
|
|
|
export YJ_HOME
|
|
echo "$YJ_HOME" >"$HOME_FILE"
|
|
|
|
# ── Build ────────────────────────────────────────────────────────────
|
|
if [ "$BUILD" = 1 ]; then
|
|
echo "dev-headless: building frontend + dev binary..."
|
|
(cd frontend && pnpm install --silent && pnpm build >/dev/null)
|
|
go build -tags "dev" -o "$BIN" .
|
|
fi
|
|
|
|
if [ ! -x "$BIN" ]; then
|
|
echo "dev-headless: $BIN missing; drop --no-build" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# ── Launch ───────────────────────────────────────────────────────────
|
|
# setsid puts the app in its own process group so dev-stop can kill the
|
|
# whole tree (xvfb-run, dbus-daemon, the app) by group id. Never
|
|
# `pkill -f`: the pattern matches the invoking shell's own command line
|
|
# and silently drops the rest of the chain.
|
|
: >"$LOG_FILE"
|
|
|
|
# YJ_TESTCTL mounts backend/testctl's /__test/ endpoints. It is opt-in
|
|
# rather than implied by the dev build so that a human's `make dev` does
|
|
# not carry an arbitrary-SQL endpoint on a listening port.
|
|
YJ_TESTCTL=1 \
|
|
YJ_LOG_LEVEL="$LOG_LEVEL" setsid dbus-run-session -- xvfb-run -a \
|
|
"$BIN" \
|
|
-devserver "localhost:$PORT" \
|
|
-assetdir "$REPO_ROOT/frontend/dist" \
|
|
-loglevel Debug \
|
|
>>"$LOG_FILE" 2>&1 &
|
|
|
|
APP_PID=$!
|
|
echo "$APP_PID" >"$PID_FILE"
|
|
|
|
# ── Wait for the dev server ──────────────────────────────────────────
|
|
deadline=$((SECONDS + STARTUP_TIMEOUT))
|
|
until curl -sf -o /dev/null "http://localhost:$PORT/"; do
|
|
if ! kill -0 "$APP_PID" 2>/dev/null; then
|
|
echo "dev-headless: app exited during startup; last log lines:" >&2
|
|
tail -n 30 "$LOG_FILE" >&2
|
|
rm -f "$PID_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$SECONDS" -ge "$deadline" ]; then
|
|
echo "dev-headless: :$PORT did not answer within ${STARTUP_TIMEOUT}s" >&2
|
|
tail -n 30 "$LOG_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
sleep 0.25
|
|
done
|
|
|
|
cat <<EOF
|
|
dev-headless: up
|
|
url http://localhost:$PORT
|
|
pid $APP_PID
|
|
YJ_HOME $YJ_HOME
|
|
log ${LOG_FILE#"$REPO_ROOT"/} (make dev-logs)
|
|
|
|
Drive it with:
|
|
playwright-cli -s=yj open http://localhost:$PORT
|
|
playwright-cli -s=yj snapshot
|
|
playwright-cli -s=yj eval "() => window.__yjEvents.call('queue.Queue.GetState', [], 5000)"
|
|
|
|
A binding call that never settles means wrong argument types: the
|
|
backend logs 'error parsing arguments' and never fires the callback.
|
|
The app log is the only place that shows up, so always use a timeout.
|
|
EOF
|