test(V2): add /mcp unified-interface smoke script

tests/smoke/run_unified.sh exercises the common interface against a live
server + real upstreams (Deribit/Hyperliquid public endpoints):
get_instruments (single + fan-out, asserting fees/history_start),
get_historical for both venues, and a 422 for an unsupported exchange.
Refresh tests/smoke/README.md (drop stale Bybit/Alpaca references).

Verified green end-to-end.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Adriano
2026-05-29 10:31:15 +00:00
parent 652e50ad99
commit 2272d5520b
2 changed files with 78 additions and 17 deletions
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
# Smoke test interfaccia comune /mcp contro un server vivo + upstream reali.
# get_instruments e get_historical di Deribit/Hyperliquid sono pubblici, ma il
# bearer (testnet o mainnet) e X-Bot-Tag sono comunque richiesti dall'auth.
set -euo pipefail
PORT="${PORT:-9000}"
BASE="${GATEWAY:-http://localhost:${PORT}}"
TOKEN="${MAINNET_TOKEN:-${TESTNET_TOKEN:-}}"
TAG="${BOT_TAG:-smoke}"
if [[ -z "${TOKEN}" ]]; then
echo "==> skip: né MAINNET_TOKEN né TESTNET_TOKEN settati"
exit 0
fi
PY="$(command -v python3 || command -v python)"
auth=(-H "Authorization: Bearer ${TOKEN}" -H "X-Bot-Tag: ${TAG}" -H "Content-Type: application/json")
start="$(date -u -d '7 days ago' +%F)"
end="$(date -u +%F)"
# post PATH JSON_BODY EXPECTED_STATUS PY_ASSERT
post() {
local path="$1" body="$2" want="$3" assert="${4:-}"
local resp status out
resp="$(curl -s -w '\n%{http_code}' -X POST "${BASE}${path}" "${auth[@]}" -d "${body}")"
status="$(printf '%s' "${resp}" | tail -n1)"
out="$(printf '%s' "${resp}" | sed '$d')"
if [[ "${status}" != "${want}" ]]; then
echo " FAIL ${path}: atteso HTTP ${want}, got ${status}"
printf '%s\n' "${out}" | head -c 400; echo
exit 1
fi
if [[ -n "${assert}" ]]; then
printf '%s' "${out}" | "${PY}" -c "import sys,json; d=json.load(sys.stdin); ${assert}" \
|| { echo " FAIL ${path}: assert"; exit 1; }
fi
echo " OK ${path} → HTTP ${status}"
}
echo "==> get_instruments exchange=deribit (fees + history_start live)"
post "/mcp/tools/get_instruments" '{"exchange":"deribit","currency":"BTC","kind":"future"}' 200 \
"assert d['instruments'], 'no instruments'; i=d['instruments'][0]; assert i['exchange']=='deribit'; assert 'fees' in i and 'history_start' in i; print(' ', i['symbol'], i['fees'], i['history_start'])"
echo "==> get_instruments fan-out (deribit + hyperliquid)"
post "/mcp/tools/get_instruments" '{}' 200 \
"exs={i['exchange'] for i in d['instruments']}; assert {'deribit','hyperliquid'} <= exs, exs; print(' venues:', sorted(exs), '| failed:', d['failed_sources'])"
echo "==> get_historical deribit BTC-PERPETUAL 1h"
post "/mcp/tools/get_historical" "{\"exchange\":\"deribit\",\"instrument\":\"BTC-PERPETUAL\",\"interval\":\"1h\",\"start_date\":\"${start}\",\"end_date\":\"${end}\"}" 200 \
"assert d['exchange']=='deribit'; assert d['candles'], 'no candles'; c=d['candles'][0]; assert {'timestamp','open','high','low','close','volume'} <= set(c); print(' candles:', len(d['candles']))"
echo "==> get_historical hyperliquid BTC 1h"
post "/mcp/tools/get_historical" "{\"exchange\":\"hyperliquid\",\"instrument\":\"BTC\",\"interval\":\"1h\",\"start_date\":\"${start}\",\"end_date\":\"${end}\"}" 200 \
"assert d['exchange']=='hyperliquid'; assert d['candles'], 'no candles'; print(' candles:', len(d['candles']))"
echo "==> get_historical exchange non supportato → 422"
post "/mcp/tools/get_historical" "{\"exchange\":\"bybit\",\"instrument\":\"BTCUSDT\",\"interval\":\"1h\",\"start_date\":\"${start}\",\"end_date\":\"${end}\"}" 422
echo "==> SMOKE /mcp OK"