From b0b284926d3d32dd60311609e7f5415af8acd699 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 2 Dec 2026 23:30:14 +1300 Subject: [PATCH] on-dev: commands that use the test database (test, or a run naming DATABASE_URL or 55433) lease docspring-dev itself, never the pool's rented box, which has no Postgres; and refuse inside another host's lease --- AGENTS.md | 4 +++- scripts/on-dev | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 23d2bff5..ea0db5a3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,7 +26,9 @@ design is in `docs/design.md`; read it before changing the architecture, and upd nobody can download. - Fixtures are test data only: synthetic values, or blank template PDFs someone has checked. Never commit a real customer's document or data. -- Build Rust in CI or on a build machine (docspring-dev), not on small agent VMs. +- Build Rust in CI or on a build machine (docspring-dev), not on small agent VMs. Server tests need docspring-dev's + test database: `scripts/on-dev test` (and a `run` with `DATABASE_URL`) leases docspring-dev itself, never the pool's + rented box, which has no Postgres. Point them at a database of your own, `visualci_server_test_`. - VisualCI dev ports on docspring-dev: Rust 5250 (the development default), Vite 5173, previews 5180–5199. 5150 is Talira's dev server: never use it (on 1 Dec 2026 a VisualCI dev server took it, and Talira's localhost and MCP reached VisualCI instead). Production listens on 5150 inside its cluster, which is separate. diff --git a/scripts/on-dev b/scripts/on-dev index fac09f5d..e405c658 100755 --- a/scripts/on-dev +++ b/scripts/on-dev @@ -19,7 +19,8 @@ # lease pool for the whole command (`fleetlayer lease run `, or `-light` for fmt, check and clippy), and # the command builds on the line whose slot name is the member the pool gave: docspring-dev first, a rented box only # when its queue is long. Run inside a lease you took yourself (`fleetlayer lease run docspring-dev-light -- ...`), it -# builds on the line with that lease's slot name. +# builds on the line with that lease's slot name. Commands that use the test database (`test`, and a `run` naming +# 127.0.0.1:55433 or DATABASE_URL) always lease the first line's slot instead of the pool's: only that host has it. set -euo pipefail remote_root=/opt/code/visualci/checkouts dir=$(git rev-parse --show-toplevel) @@ -30,6 +31,11 @@ hosts=$(grep -v '^[[:space:]]*\(#\|$\)' "$dir/.dev-host" 2>/dev/null || true) pool=$(printf '%s\n' "$hosts" | awk '$1 == "pool" {print $2; exit}') hosts=$(printf '%s\n' "$hosts" | awk 'NF && $1 != "pool"') [ -n "$hosts" ] || hosts=docspring-dev.hs +# Tests need the test database, which only the first host has (docspring-dev's Postgres on 127.0.0.1:55433): they +# lease that host's slot rather than the pool's, which may hand out a rented box without one (every database test then +# fails with PoolTimedOut). +db_line=$(printf '%s\n' "$hosts" | head -n 1) +db_kind=$(printf '%s\n' "$db_line" | awk '{print $2}') # Inside a lease: the line whose slot name is the lease's kind (its light twin builds on the same host). kind=${FLEETLAYER_LEASE_KIND:-} line= @@ -38,19 +44,31 @@ line= host=${ON_DEV_HOST:-$(printf '%s\n' "$line" | awk '{print $1}')} die() { echo "scripts/on-dev: $*" >&2; exit 1; } -usage() { sed -n '2,22p' "$0" | sed 's/^# \{0,1\}//' >&2; exit 2; } +usage() { sed -n '2,23p' "$0" | sed 's/^# \{0,1\}//' >&2; exit 2; } [ $# -gt 0 ] || usage cmd=$1; shift +# Whether the command uses the test database: `test`, or a `run` that names it. +needs_db= +case $cmd in + test) needs_db=1 ;; + run) case " $* " in *55433* | *DATABASE_URL=*) needs_db=1 ;; esac ;; +esac + # With a pool and no lease held yet: hold a slot from the pool for the whole command, and run this script again inside # it, where the pool's member picks the host. sync and clean only copy or delete files. case $cmd in sync | clean) ;; *) if [ -n "$pool" ] && [ -z "$kind" ] && [ -z "${ON_DEV_HOST:-}" ]; then case $cmd in fmt | check | clippy) pool_kind=$pool-light ;; *) pool_kind=$pool ;; esac + [ -n "$needs_db" ] && [ -n "$db_kind" ] && pool_kind=$db_kind exec fleetlayer lease run "$pool_kind" --reason "visualci on-dev $cmd ($name)" -- "$0" "$cmd" "$@" fi ;; esac +if [ -n "$needs_db" ] && [ -z "${ON_DEV_HOST:-}" ] && [ "$line" != "$db_line" ]; then + die "$cmd needs the test database, which is on $(printf '%s\n' "$db_line" | awk '{print $1}'), but this lease ($kind) builds on $host: take a ${db_kind:-docspring-dev} lease, or run it outside one" +fi + sync() { ssh "$host" "mkdir -p '$remote'" rsync -a --no-owner --no-group --delete-after --filter=':- .gitignore' --exclude=.git "$dir/" "$host:$remote/"