#!/usr/bin/env bash
set -euo pipefail

# shellcheck source=../lib/common.sh
source "$(dirname "$0")/../lib/common.sh"

BASE="${TEST_BASE_URL:-$LM_URL}"
export LM_URL="$BASE"

echo "==> Docker up"
"$(dirname "$0")/up.sh"

echo "==> Đợi server ($BASE)"
if ! wait_for_health "$BASE"; then
  echo "Container không phản hồi tại $BASE" >&2
  exit 1
fi

echo "==> API smoke"
"$LM_SCRIPTS/test/smoke.sh" "$BASE"

echo "==> pytest"
TEST_BASE_URL="$BASE" python3 -m pytest "$LM_ROOT/tests/test_api_integration.py" -q

echo
echo "Docker tests OK."
