#!/bin/bash
echo "=== 测试实例 extensions ==="
curl -sS -H "Authorization: Bearer dev-admin-token" \
  "http://127.0.0.1:19088/api/v1/instances/friend-4f864178/extensions" 2>/dev/null
echo ""

echo "=== 测试实例状态 ==="
curl -sS -H "Authorization: Bearer dev-admin-token" \
  "http://127.0.0.1:19088/api/v1/instances/friend-4f864178" 2>/dev/null | python3 -c "
import json,sys
d=json.load(sys.stdin)
inst=d.get('instance',d)
print('config_state:', inst.get('config_state',''))
print('extension_state:', inst.get('extension_state',''))
print('health_state:', inst.get('health_state',''))
print('process_state:', inst.get('process_state',''))
print('last_error:', inst.get('last_error','')[:200])
"

echo ""
echo "=== 容器内插件列表 ==="
docker exec friend-deploy-f67b3ed2-e3c sh -c \
  'curl -sS -H "Authorization: Bearer yunwo-panel-2026" http://127.0.0.1:8000/api/plugins 2>/dev/null' \
  | python3 -c "
import json,sys
d=json.load(sys.stdin)
if isinstance(d, list):
    for p in d:
        print(f\"  name={p.get('name','')} status={p.get('status','')} managed={p.get('managed','')}\")
else:
    print(json.dumps(d, indent=2)[:500])
" 2>/dev/null || echo "no plugins endpoint or error"

echo ""
echo "=== 主实例对比 ==="
curl -sS -H "Authorization: Bearer dev-admin-token" \
  "http://127.0.0.1:19088/api/v1/instances/friend-043bd076/extensions" 2>/dev/null
