peppa/packages/testkit/bin/peppa-dev
Асель 3a282b8054 PEP-36 stage 2: SQLite (node:sqlite, WAL) instead of Postgres
- packages/db: schema on sqlite-core (timestamps as epoch ms → Date, JSON as text,
  booleans 0/1), one baseline migration; node:sqlite client under drizzle's
  better-sqlite3 session (busy_timeout first, WAL, BEGIN IMMEDIATE, retries on
  SQLITE_BUSY, lazy open, async transaction callbacks refused); PEPPA_DB
  (default ~/.peppa/peppa.db)
- live updates: notify() pokes the bot over a unix socket; the bot also watches
  PRAGMA data_version every second (writes by other processes)
- Postgres specifics ported: createTask transaction is synchronous, no
  `for update skip locked`, `count(*)`, json_extract instead of ->>, json_each
  instead of @>
- `peppa db migrate` and `peppa db migrate-to-sqlite <file>` (read-only
  snapshot of Postgres, FK order from the schema, row count + foreign key
  checks, file appears only when they pass); old Postgres schema kept in
  packages/cli/legacy-pg-migrations for the migration and its test
- daily VACUUM INTO backup from the watchdog (7 copies, admin alert on failure)
- tests: a temp SQLite file per test file; storage.test.ts (20 processes,
  per-project numbering across processes, socket/data_version, migration from
  Postgres incl. a dangling foreign key, backups); two test races fixed
- CI: no per-run Postgres database; PEPPA_TEST_PG only for the migration test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 17:23:24 +05:00

57 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Peppa dev stand: isolated DB (~/.peppa-dev/peppa.db), tmux server (-L peppa-dev), state dir
# (~/.peppa-dev), the Peppa bot against mock-telegram, mock agents by default.
# Lets an agent play the PM in Telegram without a human and without touching prod.
#
# peppa-dev up | down | status
# peppa-dev peppa <args> Peppa CLI against the stand (give projects to the test PM:
# peppa-dev peppa project owner <KEY> mock-pm)
# peppa-dev tg messages|click|reply|send|callbacks ...
set -euo pipefail
ROOT="$(cd "$(dirname "$(readlink -f "$0")")/../../.." && pwd)"
PORT="${PEPPA_DEV_TG_PORT:-3190}"
export PEPPA_ROOT="$ROOT"
export PEPPA_HOME="$HOME/.peppa-dev"
export PEPPA_DB="$PEPPA_HOME/peppa.db"
export PEPPA_WORKSPACES="$HOME/.peppa-dev/workspaces"
export PEPPA_TMUX_SOCKET="peppa-dev"
export TELEGRAM_BOT_TOKEN="mock-123:TOKEN"
export TELEGRAM_API_URL="http://127.0.0.1:$PORT"
export PEPPA_CLAUDE_BIN="${PEPPA_DEV_CLAUDE_BIN:-$ROOT/packages/testkit/bin/mock-claude}"
export PEPPA_CODEX_BIN="${PEPPA_DEV_CODEX_BIN:-$ROOT/packages/testkit/bin/mock-codex}"
export PEPPA_HOOK_WAIT_SEC="${PEPPA_HOOK_WAIT_SEC:-30}"
export PEPPA_WEB_URL="http://peppa-dev.local"
mkdir -p "$PEPPA_HOME" "$PEPPA_WORKSPACES"
TM=(tmux -L peppa-dev)
PEPPA="$ROOT/packages/cli/bin/peppa"
up() {
"$PEPPA" db migrate >/dev/null
"${TM[@]}" has-session -t dev-mock-tg 2>/dev/null || "${TM[@]}" new-session -d -s dev-mock-tg "$ROOT/packages/testkit/bin/mock-telegram --port $PORT"
"${TM[@]}" set-option -s exit-empty off
for _ in $(seq 1 40); do curl -sf "$TELEGRAM_API_URL/_mock/messages" >/dev/null && break; sleep 0.25; done
"${TM[@]}" has-session -t dev-bot 2>/dev/null || "${TM[@]}" new-session -d -s dev-bot "$ROOT/apps/bot/bin/peppa-bot"
for _ in $(seq 1 40); do "$PEPPA" telegram status 2>/dev/null | grep -q '^bot: @' && break; sleep 0.25; done
"$PEPPA" user ensure mock-pm >/dev/null
if ! "$PEPPA" telegram status | grep -q '^mock-pm: chat'; then
code=$("$PEPPA" telegram pair mock-pm | grep -o 'start=[A-Za-z0-9_-]*' | cut -d= -f2)
curl -sf -X POST "$TELEGRAM_API_URL/_mock/send" -H 'Content-Type: application/json' -d "{\"text\":\"/start $code\"}" >/dev/null
for _ in $(seq 1 40); do "$PEPPA" telegram status | grep -q '^mock-pm: chat' && break; sleep 0.25; done
fi
status
}
status() {
echo "processes:"; "${TM[@]}" ls -F ' #{session_name}' 2>/dev/null || echo " (stand is down)"
"$PEPPA" telegram status 2>/dev/null | sed 's/^/ /' || true
}
case "${1:-}" in
up) up ;;
down) "${TM[@]}" kill-server 2>/dev/null || true; echo "stand is down" ;;
status) status ;;
peppa) shift; exec "$PEPPA" "$@" ;;
tg) shift; exec "${PEPPA_NODE:-node}" --import "$ROOT/scripts/lib/require-node.mjs" "$ROOT/packages/testkit/src/peppa-dev-tg.ts" "$@" ;;
*) sed -n '2,9p' "$0" | sed 's/^# \{0,1\}//'; exit 1 ;;
esac