From 1c1b3e15709cbe255c45e2e02d1aef9b6f44047e Mon Sep 17 00:00:00 2001 From: AdrianoDev Date: Thu, 30 Apr 2026 18:57:07 +0200 Subject: [PATCH] test(V2): smoke script con bearer testnet --- tests/smoke/run.sh | 126 +++++++++------------------------------------ 1 file changed, 24 insertions(+), 102 deletions(-) diff --git a/tests/smoke/run.sh b/tests/smoke/run.sh index fe18c54..1ca27e3 100755 --- a/tests/smoke/run.sh +++ b/tests/smoke/run.sh @@ -1,111 +1,33 @@ #!/usr/bin/env bash -# Smoke test locale per Cerbero_mcp. -# Presuppone: docker compose up -d già eseguito da repo root. -# Verifica: ogni MCP risponde /health; i 4 exchange espongono environment_info. - +# Smoke test V2: avvia container, verifica /health, /apidocs, e una tool con bearer testnet. set -euo pipefail -cd "$(dirname "$0")/../.." +PORT="${PORT:-9000}" +BASE="http://localhost:${PORT}" -GATEWAY="${GATEWAY:-http://localhost}" -TOKEN_FILE="${TOKEN_FILE:-secrets/observer.token}" +echo "==> healthcheck" +curl -fsS "${BASE}/health" | python -m json.tool -if [ ! -f "$TOKEN_FILE" ]; then - echo "ERROR: token file $TOKEN_FILE not found" >&2 - exit 2 +echo "==> apidocs" +curl -fsS "${BASE}/apidocs" | grep -q "Cerbero MCP" && echo " swagger OK" + +echo "==> openapi.json" +curl -fsS "${BASE}/openapi.json" | python -c "import sys,json;d=json.load(sys.stdin);assert 'BearerAuth' in d['components']['securitySchemes'];print(' bearer scheme OK')" + +if [[ -z "${TESTNET_TOKEN:-}" ]]; then + echo "==> skip tool call (TESTNET_TOKEN non settato)" + exit 0 fi -TOKEN="$(cat "$TOKEN_FILE")" -fail=0 +echo "==> tool senza bearer → 401" +status=$(curl -s -o /dev/null -w "%{http_code}" -X POST "${BASE}/mcp-deribit/tools/get_ticker" \ + -H "Content-Type: application/json" -d '{"instrument_name":"BTC-PERPETUAL"}') +[[ "$status" == "401" ]] && echo " 401 OK" || (echo " expected 401 got $status"; exit 1) -echo "=== /health ===" -for svc in mcp-deribit mcp-bybit mcp-hyperliquid mcp-alpaca mcp-macro mcp-sentiment; do - code=$(curl -s -o /dev/null -w "%{http_code}" \ - -H "Authorization: Bearer $TOKEN" \ - "$GATEWAY/$svc/health" || echo "000") - if [ "$code" = "200" ]; then - echo " $svc: OK" - else - echo " $svc: FAIL ($code)" - fail=$((fail + 1)) - fi -done +echo "==> tool con bearer testnet → routing testnet (può fallire 5xx se testnet down)" +curl -s -o /dev/null -w " http %{http_code}\n" -X POST "${BASE}/mcp-deribit/tools/get_ticker" \ + -H "Authorization: Bearer ${TESTNET_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{"instrument_name":"BTC-PERPETUAL"}' -echo -echo "=== environment_info on 4 exchange MCPs ===" -for ex in deribit bybit hyperliquid alpaca; do - body=$(curl -s -X POST \ - -H "Authorization: Bearer $TOKEN" \ - -H "Content-Type: application/json" \ - -d '{}' \ - "$GATEWAY/mcp-${ex}/tools/environment_info" 2>/dev/null || echo '{}') - - if [ -z "$body" ] || [ "$body" = "{}" ]; then - echo " $ex: FAIL (empty body)" - fail=$((fail + 1)) - continue - fi - - if echo "$body" | jq -e '.environment, .source, .base_url, .max_leverage' > /dev/null 2>&1; then - env=$(echo "$body" | jq -r '.environment') - src=$(echo "$body" | jq -r '.source') - cap=$(echo "$body" | jq -r '.max_leverage') - echo " $ex: OK (env=$env source=$src max_leverage=$cap)" - else - echo " $ex: FAIL (shape mismatch)" - echo " body: $body" - fail=$((fail + 1)) - fi -done - -echo -echo "=== live tool check (read-only contro upstream testnet) ===" - -_check_tool() { - local label="$1" url="$2" body="$3" - local resp - resp=$(curl -s -X POST \ - -H "Authorization: Bearer $TOKEN" \ - -H "Content-Type: application/json" \ - -d "$body" \ - "$url" 2>/dev/null || echo '{}') - if echo "$resp" | jq -e 'has("error") | not' > /dev/null 2>&1 \ - && [ -n "$resp" ] && [ "$resp" != "null" ] && [ "$resp" != "{}" ]; then - echo " $label: OK" - else - echo " $label: FAIL" - echo " body: $(echo "$resp" | head -c 200)" - fail=$((fail + 1)) - fi -} - -_check_tool "deribit get_ticker BTC-PERPETUAL" \ - "$GATEWAY/mcp-deribit/tools/get_ticker" \ - '{"instrument_name":"BTC-PERPETUAL"}' - -_check_tool "bybit get_ticker BTCUSDT" \ - "$GATEWAY/mcp-bybit/tools/get_ticker" \ - '{"symbol":"BTCUSDT","category":"linear"}' - -_check_tool "hyperliquid get_ticker BTC" \ - "$GATEWAY/mcp-hyperliquid/tools/get_ticker" \ - '{"instrument":"BTC"}' - -_check_tool "alpaca get_clock (richiede ALPACA_PAPER credenziali valide)" \ - "$GATEWAY/mcp-alpaca/tools/get_clock" \ - '{}' - -_check_tool "macro get_treasury_yields" \ - "$GATEWAY/mcp-macro/tools/get_treasury_yields" \ - '{}' - -_check_tool "sentiment get_funding_rates BTC" \ - "$GATEWAY/mcp-sentiment/tools/get_funding_rates" \ - '{"asset":"BTC"}' - -echo -if [ "$fail" -gt 0 ]; then - echo "SMOKE FAILED: $fail check(s) failed" - exit 1 -fi -echo "SMOKE OK" +echo "==> SMOKE OK"