#!/usr/bin/env bash
# 격리 스택 상태 표: 유닛 · 포트 · 컨테이너 · 로그인 · 화면 · 대표 RBAC 차이.
set -uo pipefail
here=$(cd "$(dirname "$0")" && pwd)
. "$here/lib.sh"

echo "== 유닛 (systemd --user)"
printf '%-22s %-10s %s\n' 유닛 상태 포트
for spec in "rbac-live-srv-off:$SRV_OFF_PORT" "rbac-live-srv-on:$SRV_ON_PORT" "rbac-live-adm-off:$ADM_OFF_PORT" "rbac-live-adm-on:$ADM_ON_PORT" "rbac-live-proxy-off:$PROXY_OFF_PORT" "rbac-live-proxy-on:$PROXY_ON_PORT"; do
  u=${spec%%:*}; p=${spec##*:}
  st=$(systemctl --user is-active "$u.service" 2>/dev/null || true)
  ls=$(port_listening "$p" && echo listen || echo closed)
  printf '%-22s %-10s %s/%s\n' "$u" "${st:-inactive}" "$p" "$ls"
done

echo "== 컨테이너"
docker ps --filter "name=rbac-live-" --format '{{.Names}}  {{.Image}}  {{.Ports}}  {{.Status}}' || true

echo "== 로그인 · 화면 · RBAC 스모크 (프록시 경유)"
if [ -f "$L/.accounts.tsv" ] && port_listening "$PROXY_OFF_PORT"; then
  node "$here/smoke.js" 2>&1 || true
else
  echo "스택이 떠 있지 않다 (up.sh 필요)"
fi
echo "계정표: $ACCOUNTS_TXT (권한 0600) · 접속: VSCode 포트 포워딩 5197 · 5297 → http://localhost:5197 (OFF) · http://localhost:5297 (ON)"
