Files
jr-sql-ai/scripts/selftest-native.sh
T

61 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_OVERRIDE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
export ROOT_OVERRIDE
# shellcheck disable=SC1091
source "${ROOT_OVERRIDE}/scripts/common.sh"
init_log selftest-native
print_header "selftest-native: START"
need_cmd curl
need_cmd python
need_cmd ollama
need_cmd grep
load_env
check_for_legacy_docker_ollama
[[ -x "$SQLAI_BIN" ]] || fail "bin/sqlai missing or not executable at ${SQLAI_BIN}" 60
log "selftest-native: waiting for Ollama API at ${OLLAMA_URL}"
wait_for_ollama_api "$OLLAMA_URL" 120 || fail "Ollama API not reachable at ${OLLAMA_URL}" 61
ok "selftest-native: Ollama API reachable"
tags="$(fetch_tags)"
[[ -n "$tags" ]] || fail "/api/tags returned empty body" 62
printf '%s' "$tags" | is_json || fail "/api/tags did not return valid JSON" 63
ok "selftest-native: /api/tags returned valid JSON"
if model_in_tags "$EXPERT_MODEL" "$tags"; then
ok "selftest-native: expert model present: ${EXPERT_MODEL}"
else
fail "expert model missing: ${EXPERT_MODEL}" 64
fi
if [[ -n "${BASE_MODEL}" ]]; then
if model_in_tags "$BASE_MODEL" "$tags"; then
ok "selftest-native: base model present: ${BASE_MODEL}"
else
fail "base model missing: ${BASE_MODEL}" 65
fi
fi
log "selftest-native: warmup request via sqlai"
set +e
"$SQLAI_BIN" ask --text "Warmup: reply with exactly 'OK'." --no-metrics
rc=$?
set -e
[[ "$rc" -eq 0 ]] || warn "warmup failed rc=${rc}"
log "selftest-native: real query via sqlai"
set +e
out="$("$SQLAI_BIN" ask --text "Give a concise checklist to troubleshoot parameter sniffing in SQL Server 2022. Keep it technical." --no-metrics 2>&1)"
rc=$?
set -e
[[ "$rc" -eq 0 ]] || fail "real query failed rc=${rc}" 66
[[ -n "${out//[[:space:]]/}" ]] || fail "real query returned empty output" 67
ok "selftest-native: real query returned non-empty output"
print_footer "selftest-native: END status=OK log=${LOG_FILE}"