Skip to content

Commit 82f6f7e

Browse files
authored
refactor: consolidate infra management into justfile + add mobile-dev (block#797)
1 parent 7493406 commit 82f6f7e

10 files changed

Lines changed: 100 additions & 137 deletions

File tree

‎AGENTS.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ organized under `desktop/src/features/`. Biome handles linting and formatting.
244244

245245
```bash
246246
just desktop-dev # web-only dev server (faster iteration)
247-
just desktop-app # full Tauri app with native shell
247+
just dev # full Tauri app with native shell
248248
```
249249

250250
### Workspace Switching
@@ -316,6 +316,12 @@ flutter test
316316

317317
Or from repo root: `just mobile-fmt` (auto-fix), `just mobile-check` (lint + fmt check), `just mobile-test` (tests).
318318

319+
To run the app locally (starts Docker, relay, iOS simulator automatically):
320+
321+
```bash
322+
just mobile-dev
323+
```
324+
319325
### Testing Conventions
320326

321327
- Prefer **widget tests** over unit tests for UI components — test the

‎NOSTR.md‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ Connect any NIP-29 client straight to the relay.
2323
### Quick Start
2424

2525
```bash
26-
# 1. Start infrastructure
27-
docker compose up -d
28-
29-
# 2. (Optional) Enable pubkey allowlist — must be set BEFORE relay startup
26+
# 1. (Optional) Enable pubkey allowlist — must be set BEFORE relay startup
3027
export SPROUT_PUBKEY_ALLOWLIST=true
3128

32-
# 3. Start the relay (runs migrations automatically)
33-
cargo run -p sprout-relay & # relay on :3000
29+
# 2. Start the relay (auto-starts Docker services and runs migrations)
30+
just relay & # relay on :3000
3431

35-
# 4. Add a pubkey to the allowlist (if enabled)
32+
# 3. Add a pubkey to the allowlist (if enabled)
3633
# Insert directly — there is no CLI command for this yet.
3734
PGPASSWORD=sprout_dev psql -h localhost -U sprout -d sprout -c \
3835
"INSERT INTO pubkey_allowlist (pubkey) VALUES (decode('<64-char-hex-pubkey>', 'hex'))"

‎TESTING.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ just test # unit + integration (starts Docker if needed)
88
```
99

1010
`just test` runs unit tests plus integration tests against Postgres and Redis
11-
(started via `docker compose`). Neither task runs the E2E suites in
11+
(started automatically if not already running). Neither task runs the E2E suites in
1212
`sprout-test-client` — those are marked `#[ignore]` and require a running relay:
1313

1414
```bash
@@ -264,7 +264,7 @@ Replies are kind:9 in the same channel; `sprout messages thread --channel <id>
264264
## Configuration reference
265265

266266
The relay reads all configuration from environment variables. Defaults work
267-
out of the box with `docker compose up`. Common overrides:
267+
out of the box with `just setup` or `just relay`. Common overrides:
268268

269269
| Variable | Default | Notes |
270270
|-----------------------------------|-----------------------------|-------|

‎crates/sprout-acp/README.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Supports any agent that speaks [ACP](https://agentclientprotocol.com/) over stdi
1313

1414
## Prerequisites
1515

16-
- A running Sprout relay (`just relay` or a hosted instance)
17-
- Docker services up (`docker compose up -d`) if running locally
16+
- A running Sprout relay (`just relay` starts Docker services automatically, or use a hosted instance)
1817
- A Nostr keypair for the agent (see [Generating Keys](#generating-keys))
1918

2019
Build:

‎crates/sprout-cli/TESTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ docker compose ps
1717
# sprout-typesense healthy
1818
```
1919

20-
If not running: `./scripts/dev-setup.sh` from the repo root.
20+
If not running: `just setup` from the repo root.
2121

2222
Tools: `jq`, `curl`, Rust toolchain.
2323

‎crates/sprout-proxy/README.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ Client (NIP-28) ←→ sprout-proxy :4869 ←→ sprout-relay :3000
1717
### 1. Start infrastructure and relay
1818

1919
```bash
20-
just setup # Docker: Postgres + Redis
21-
just relay # Relay on :3000
20+
just relay # starts Docker services + migrations automatically
2221
```
2322

2423
### 2. Mint a proxy API token

‎justfile‎

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,40 @@ _ensure-sidecar-stubs:
122122
touch "desktop/src-tauri/binaries/${bin}-${TARGET}"
123123
done
124124
125+
# Ensure Docker dev services (Postgres, Redis, etc.) are running and healthy
126+
_ensure-services:
127+
#!/usr/bin/env bash
128+
set -euo pipefail
129+
pg=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' sprout-postgres 2>/dev/null || echo "not_found")
130+
redis=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' sprout-redis 2>/dev/null || echo "not_found")
131+
if [[ "$pg" == "healthy" && "$redis" == "healthy" ]]; then
132+
echo "Services already healthy"
133+
exit 0
134+
fi
135+
echo "Starting services..."
136+
docker compose up -d || true
137+
echo -n "Waiting for services"
138+
for i in $(seq 1 40); do
139+
pg=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' sprout-postgres 2>/dev/null || echo "not_found")
140+
redis=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' sprout-redis 2>/dev/null || echo "not_found")
141+
if [[ "$pg" == "healthy" && "$redis" == "healthy" ]]; then
142+
echo " ready"
143+
exit 0
144+
fi
145+
echo -n "."
146+
sleep 3
147+
done
148+
echo " timed out"
149+
exit 1
150+
151+
# Apply database migrations if pgschema is available
152+
_ensure-migrations: _ensure-services
153+
#!/usr/bin/env bash
154+
set -euo pipefail
155+
if [[ -x bin/pgschema && -f schema/schema.sql ]]; then
156+
bin/pgschema apply --file schema/schema.sql --auto-approve || true
157+
fi
158+
125159
# Run clippy on the desktop Tauri Rust crate
126160
desktop-tauri-clippy: _ensure-sidecar-stubs
127161
cargo clippy --manifest-path {{desktop_tauri_manifest}} --all-targets -- -D warnings
@@ -153,15 +187,15 @@ desktop-release-build target="aarch64-apple-darwin":
153187
desktop-ci: desktop-check desktop-test desktop-tauri-fmt-check desktop-build desktop-tauri-check desktop-tauri-test
154188

155189
# Seed deterministic channel data for desktop Playwright tests
156-
desktop-e2e-seed:
190+
desktop-e2e-seed: _ensure-migrations
157191
./scripts/setup-desktop-test-data.sh
158192

159193
# Run desktop browser smoke tests
160194
desktop-e2e-smoke:
161195
cd {{desktop_dir}} && pnpm test:e2e:smoke
162196

163197
# Run desktop relay-backed e2e tests
164-
desktop-e2e-integration:
198+
desktop-e2e-integration: _ensure-migrations
165199
cd {{desktop_dir}} && pnpm test:e2e:integration
166200

167201
# Run all checks suitable for CI / pre-push (no infra needed)
@@ -188,20 +222,20 @@ test-integration:
188222

189223
# ─── Run ──────────────────────────────────────────────────────────────────────
190224

191-
# Start the relay server
192-
relay:
225+
# Start the relay server (auto-starts Docker services if needed)
226+
relay: _ensure-migrations
193227
cargo run -p sprout-relay
194228

195229
# Start the relay with the built web UI served from it
196-
relay-web:
230+
relay-web: _ensure-migrations
197231
#!/usr/bin/env bash
198232
set -euo pipefail
199233
[[ -d node_modules ]] || pnpm install
200234
pnpm -C web build
201235
SPROUT_WEB_DIR=./web/dist cargo run -p sprout-relay
202236
203237
# Start the relay server in release mode
204-
relay-release:
238+
relay-release: _ensure-migrations
205239
cargo run -p sprout-relay --release
206240

207241
# Start sprout-proxy (dev mode)
@@ -248,10 +282,6 @@ desktop-dev:
248282
echo "Starting frontend dev server on Vite port ${SPROUT_VITE_PORT}, relay ${SPROUT_RELAY_URL}"
249283
pnpm exec vite --port "${SPROUT_VITE_PORT}" --strictPort
250284
251-
# Run the desktop Tauri app (alias for dev)
252-
desktop-app *ARGS:
253-
just dev {{ARGS}}
254-
255285
# ─── Web ─────────────────────────────────────────────────────────────────────
256286

257287
# Run the web frontend dev server (port derived from worktree to avoid collisions)
@@ -266,14 +296,6 @@ web:
266296
cd {{web_dir}}
267297
pnpm exec vite --port "${VITE_PORT}" --strictPort
268298
269-
# Install web JS dependencies (pnpm workspace — installs all packages from root)
270-
web-install:
271-
pnpm install
272-
273-
# Install web JS dependencies reproducibly for CI (pnpm workspace)
274-
web-install-ci:
275-
pnpm install --frozen-lockfile
276-
277299
# Run web lint and format checks
278300
web-check:
279301
cd {{web_dir}} && pnpm check
@@ -318,10 +340,42 @@ mobile-check:
318340
mobile-test:
319341
unset GIT_DIR GIT_WORK_TREE; cd {{mobile_dir}} && flutter test
320342

343+
# Run the mobile app on iOS simulator (starts infra + relay automatically)
344+
mobile-dev:
345+
#!/usr/bin/env bash
346+
set -euo pipefail
347+
just _ensure-migrations
348+
# Start relay in background if not already running
349+
RELAY_PID=""
350+
if ! lsof -i :3000 -sTCP:LISTEN -t &>/dev/null; then
351+
echo "Starting relay in background (log: /tmp/sprout-relay.log)..."
352+
cargo run -p sprout-relay &>/tmp/sprout-relay.log &
353+
RELAY_PID=$!
354+
trap 'if [[ -n "$RELAY_PID" ]]; then kill "$RELAY_PID" 2>/dev/null || true; fi' EXIT
355+
echo -n "Waiting for relay"
356+
for _ in $(seq 1 30); do
357+
lsof -i :3000 -sTCP:LISTEN -t &>/dev/null && break
358+
echo -n "."
359+
sleep 3
360+
done
361+
echo " ready"
362+
else
363+
echo "Relay already running on :3000"
364+
fi
365+
# Open iOS simulator if not already running
366+
if ! pgrep -x Simulator &>/dev/null; then
367+
open -a Simulator
368+
sleep 3
369+
fi
370+
# Run Flutter
371+
cd {{mobile_dir}}
372+
unset GIT_DIR GIT_WORK_TREE
373+
flutter run
374+
321375
# ─── Database ─────────────────────────────────────────────────────────────────
322376

323377
# Apply schema migrations via pgschema
324-
migrate:
378+
migrate: _ensure-services
325379
./bin/pgschema apply --file schema/schema.sql --auto-approve
326380

327381
# ─── Utilities ────────────────────────────────────────────────────────────────

‎mobile/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ flutter pub get
1212
## Run
1313

1414
```bash
15-
flutter run
15+
# From repo root (recommended — starts Docker, relay, and simulator):
16+
just mobile-dev
17+
18+
# Direct (requires services and relay already running):
19+
cd mobile && flutter run
1620
```
1721

1822
## Checks

‎scripts/dev-setup.sh‎

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ set -euo pipefail
1111

1212
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1313
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
14-
TIMEOUT=120 # seconds to wait for services to become healthy
1514

1615
# Colors
1716
RED='\033[0;31m'
@@ -71,53 +70,8 @@ load_env
7170

7271
# ---- Start services ---------------------------------------------------------
7372

74-
log "Starting services..."
75-
docker compose up -d
76-
77-
# ---- Wait for healthy -------------------------------------------------------
78-
79-
wait_healthy() {
80-
local service="$1"
81-
local container="$2"
82-
local elapsed=0
83-
local interval=3
84-
85-
log "Waiting for ${service} to be healthy..."
86-
while true; do
87-
local status
88-
status=$(docker inspect --format='{{.State.Health.Status}}' "${container}" 2>/dev/null || echo "not_found")
89-
90-
case "${status}" in
91-
healthy)
92-
success "${service} is healthy"
93-
return 0
94-
;;
95-
unhealthy)
96-
error "${service} is unhealthy. Check logs: docker logs ${container}"
97-
return 1
98-
;;
99-
not_found)
100-
error "Container ${container} not found"
101-
return 1
102-
;;
103-
esac
104-
105-
if [[ ${elapsed} -ge ${TIMEOUT} ]]; then
106-
error "Timed out waiting for ${service} (${TIMEOUT}s). Check: docker logs ${container}"
107-
return 1
108-
fi
109-
110-
sleep "${interval}"
111-
elapsed=$((elapsed + interval))
112-
echo -n "."
113-
done
114-
}
115-
116-
echo ""
117-
wait_healthy "Postgres" "sprout-postgres"
118-
wait_healthy "Redis" "sprout-redis"
119-
wait_healthy "Typesense" "sprout-typesense"
120-
echo ""
73+
log "Starting services and waiting for health..."
74+
"${REPO_ROOT}/bin/just" _ensure-services
12175

12276
# ---- Run migrations ---------------------------------------------------------
12377

@@ -204,7 +158,7 @@ if [[ -d "${WEB_DIR}" ]]; then
204158
success "Web dependencies installed"
205159
else
206160
warn "pnpm not found — skipping web dependency install."
207-
warn "Run '. ./bin/activate-hermit' to get pnpm, then 'just web-install'."
161+
warn "Run '. ./bin/activate-hermit' to get pnpm, then 'just desktop-install'."
208162
fi
209163
else
210164
warn "Web directory not found at ${WEB_DIR} — skipping."

0 commit comments

Comments
 (0)