ddgs / test_scripts /run_smoke.sh
dromerosm's picture
Restructure project for public HF deployment
2aa3e66
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VENV_DIR="$ROOT_DIR/.venv"
python3 -m venv "$VENV_DIR"
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
python -m pip install --upgrade pip >/dev/null
python -m pip install -e "$ROOT_DIR" >/dev/null
if [ -x "$ROOT_DIR/test_scripts/update_venv_cert.sh" ]; then
CERT_OUT=$("$ROOT_DIR/test_scripts/update_venv_cert.sh")
CERT_BUNDLE=$(printf "%s\n" "$CERT_OUT" | grep "^CERT_BUNDLE=" | tail -n 1 | cut -d= -f2- || true)
if [ -n "$CERT_BUNDLE" ]; then
export SSL_CERT_FILE="$CERT_BUNDLE"
export REQUESTS_CA_BUNDLE="$CERT_BUNDLE"
export DDGS_VERIFY=true
fi
fi
# Debug SSL bundle configuration
if [ -n "${SSL_CERT_FILE:-}" ]; then
echo "SSL_CERT_FILE=$SSL_CERT_FILE"
fi
if [ -n "${REQUESTS_CA_BUNDLE:-}" ]; then
echo "REQUESTS_CA_BUNDLE=$REQUESTS_CA_BUNDLE"
fi
if [ -n "${SSL_CERT_FILE:-}" ] && [ -f "$SSL_CERT_FILE" ]; then
echo "SSL cert bundle size: $(wc -c < "$SSL_CERT_FILE") bytes"
fi
# Help output
DDS_HELP_OUT=$(ddgs-search --help | head -n 5)
echo "$DDS_HELP_OUT" >/dev/null
# Simple search (network required). If network/cert errors occur, skip with success.
set +e
ERR_FILE="$ROOT_DIR/.ddgs_search_err"
DDS_OUT=$(ddgs-search "openai" --max-results 1 --format json 2>"$ERR_FILE")
STATUS=$?
set -e
if [ "$STATUS" -ne 0 ]; then
if grep -q "CERTIFICATE_VERIFY_FAILED\\|TLS handshake failed\\|client error\\|relative URL without a base" "$ERR_FILE"; then
echo "SKIP: network/cert error running live search" >&2
exit 0
fi
cat "$ERR_FILE" >&2
exit "$STATUS"
fi
export DDS_OUT
python - <<'PY'
import json, os
payload = json.loads(os.environ["DDS_OUT"])
assert isinstance(payload, list)
if payload:
assert "markdown" in payload[0]
print("OK: received", len(payload), "result(s)")
PY