#!/bin/sh
set -eu

echo "Running release smoke checks for learning_ai_invt_trdg"

# ---------------------------------------------------------------------------
# Backend — static contract verification (no live infrastructure required)
# ---------------------------------------------------------------------------
echo ""
echo "[smoke] Backend contract checks..."
(
  cd backend
  npm run check:api-contract
  npm run check:audit-repository
  npm run check:websocket-contract
  npm run check:session-rule-normalization
)

# ---------------------------------------------------------------------------
# Web — typecheck + production build + auth/kill-switch DOM tests
# ---------------------------------------------------------------------------
echo ""
echo "[smoke] Web typecheck and build..."
pnpm --filter @bytelyst/trading-web typecheck
pnpm --filter @bytelyst/trading-web build

echo ""
echo "[smoke] Web DOM smoke tests..."
(
  cd web
  pnpm vitest run \
    src/components/Login.dom.test.tsx \
    src/components/ResetPassword.dom.test.tsx \
    src/components/ProductAccessibilityGate.dom.test.tsx \
    src/components/ChatControl.dom.test.tsx \
    src/components/EntryForm.dom.test.tsx \
    src/hooks/useWebSocket.dom.test.tsx \
    src/hooks/useTabFeatureFlags.dom.test.tsx \
    src/components/AuthContext.dom.test.tsx
)

# ---------------------------------------------------------------------------
# Mobile — typecheck (compilation against shared platform contracts)
# ---------------------------------------------------------------------------
echo ""
echo "[smoke] Mobile typecheck..."
pnpm --filter @bytelyst/trading-mobile typecheck

echo ""
echo "[smoke] All release smoke checks passed."
