- users.telegram_* replace the single global binding; one-time /start code per user (web Settings → Telegram, or peppa telegram pair <login>); a chat belongs to one user - agent questions go to the project's owner and members who paired; an answer (button or reply) is accepted only from someone with access to the project; messages are closed for every recipient; /status is scoped - CLI: telegram pair|status|unpair <login>, user ensure mock-<name>; dev stand pairs its test PM per user - tests: several-users journey (bob without access, then as a member); 70 e2e total, green - BREAKING: the old global binding is removed; users pair again in Settings Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
3.0 KiB
Bash
Executable File
59 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Peppa dev stand: isolated DB (peppa_dev), 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 DATABASE_URL="postgres://peppa:peppa@127.0.0.1:5433/peppa_dev"
|
|
export PEPPA_HOME="$HOME/.peppa-dev"
|
|
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() {
|
|
docker exec peppa-postgres psql -U peppa -tAc "select 1 from pg_database where datname='peppa_dev'" | grep -q 1 \
|
|
|| docker exec peppa-postgres createdb -U peppa peppa_dev
|
|
(cd "$ROOT/packages/db" && "$ROOT/packages/db/node_modules/.bin/drizzle-kit" 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 "$ROOT/node_modules/.bin/tsx" "$ROOT/packages/testkit/src/peppa-dev-tg.ts" "$@" ;;
|
|
*) sed -n '2,9p' "$0" | sed 's/^# \{0,1\}//'; exit 1 ;;
|
|
esac
|