Files
ai-setup/tests/test_fixes.sh

106 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# tests/test_fixes.sh — unit tests for code-review fixes in ai-setup.sh
# Run: bash tests/test_fixes.sh
set -euo pipefail
SCRIPT="$(cd "$(dirname "$0")/.." && pwd)/ai-setup.sh"
PASS=0; FAIL=0
ok() { echo "[PASS] $1"; PASS=$((PASS+1)); }
fail() { echo "[FAIL] $1"; FAIL=$((FAIL+1)); }
# Extract sections
GPT_SECTION=$(awk '/^cat > "\$BIN_DIR\/ai-gpt"/,/^GPTEOF/' "$SCRIPT")
KIMI_SECTION=$(awk '/^cat > "\$BIN_DIR\/ai-kimi"/,/^KIMIEOF/' "$SCRIPT")
GEMINI_SECTION=$(awk '/^cat > "\$BIN_DIR\/ai-gemini"/,/^GEMINIEOF/' "$SCRIPT")
# ── ai-gpt: auto-install codex ────────────────────────────────────────────
test_gpt_autoinstall() {
if echo "$GPT_SECTION" | grep -q 'curl -fsSL https://chatgpt.com/codex/install.sh'; then
ok "ai-gpt: auto-installs codex via official install script"
else
fail "ai-gpt: missing codex auto-install"
fi
}
# ── ai-gpt: no proxy logic (simplified launcher) ──────────────────────────
test_gpt_no_proxy() {
if echo "$GPT_SECTION" | grep -q 'ANTHROPIC_BASE_URL'; then
fail "ai-gpt: still contains proxy logic (ANTHROPIC_BASE_URL)"
else
ok "ai-gpt: proxy logic removed (no ANTHROPIC_BASE_URL)"
fi
}
# ── ai-kimi: auto-install kimi ────────────────────────────────────────────
test_kimi_autoinstall() {
if echo "$KIMI_SECTION" | grep -q 'curl -fsSL https://code.kimi.com/kimi-code/install.sh'; then
ok "ai-kimi: auto-installs kimi via official install script"
else
fail "ai-kimi: missing kimi auto-install"
fi
}
# ── ai-kimi: no proxy logic (simplified launcher) ─────────────────────────
test_kimi_no_proxy() {
if echo "$KIMI_SECTION" | grep -q 'ANTHROPIC_BASE_URL'; then
fail "ai-kimi: still contains proxy logic (ANTHROPIC_BASE_URL)"
else
ok "ai-kimi: proxy logic removed (no ANTHROPIC_BASE_URL)"
fi
}
# ── ai-kimi: Artemox config generation ───────────────────────────────────
test_kimi_artemox_config() {
if echo "$KIMI_SECTION" | grep -q 'api.artemox.com/v1' \
&& echo "$KIMI_SECTION" | grep -q 'config.toml' \
&& echo "$KIMI_SECTION" | grep -q 'default_model = "artemox/kimi-k2.6"'; then
ok "ai-kimi: configures Artemox provider and kimi-k2.6 model"
else
fail "ai-kimi: missing Artemox config generation"
fi
}
# ── ai-gemini: native launcher generation ─────────────────────────────────
test_gemini_native_launcher() {
if echo "$GEMINI_SECTION" | grep -q 'antigravity CLI (agy)' \
&& echo "$GEMINI_SECTION" | grep -q 'https://antigravity.google/cli/install.sh'; then
ok "ai-gemini: native agy launcher is generated"
else
fail "ai-gemini: missing native agy launcher generation"
fi
}
# ── Fix 7: trap quotes $TMP correctly ────────────────────────────────────────
test_fix7_trap_tmp() {
if grep -q "trap 'rm -rf \"\$TMP\"' EXIT" "$SCRIPT"; then
ok "Fix7: trap uses single quotes with quoted \"\$TMP\""
else
fail "Fix7: trap still uses double quotes or \$TMP still unquoted at execution"
fi
}
# ── bash syntax of the whole script ─────────────────────────────────────────
test_script_syntax() {
if bash -n "$SCRIPT" 2>&1; then
ok "syntax: ai-setup.sh passes 'bash -n'"
else
fail "syntax: ai-setup.sh has syntax errors"
fi
}
# ── run all tests ─────────────────────────────────────────────────────────────
test_script_syntax
test_gpt_autoinstall
test_gpt_no_proxy
test_kimi_autoinstall
test_kimi_no_proxy
test_kimi_artemox_config
test_gemini_native_launcher
test_fix7_trap_tmp
echo ""
echo "Results: $PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ] && exit 0 || exit 1