Files
ai-setup/tests/test_fixes.sh

140 lines
6.1 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")
HELPERS_SECTION=$(awk '/^cat > "\$HELPERS_FILE"/,/^HELPEREOF/' "$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
}
# ── global rules: Karpathy-style guidelines and native rule files ───────────
test_global_rules_include_quality_guidelines() {
karpathy_line=$(grep -n '^## 1\. Think Before Coding$' "$SCRIPT" | head -1 | cut -d: -f1)
global_line=$(grep -n '^# Global Rules for All AI Agents$' "$SCRIPT" | head -1 | cut -d: -f1)
if [ -n "$karpathy_line" ] \
&& [ -n "$global_line" ] \
&& [ "$karpathy_line" -lt "$global_line" ] \
&& grep -q 'Always reply in Russian' "$SCRIPT" \
&& grep -q 'Plain git diff visibility' "$SCRIPT"; then
ok "global rules: include English Karpathy guidelines before translated user rules"
else
fail "global rules: missing English Karpathy guidelines or translated user rules"
fi
}
test_native_rule_files_generated() {
if grep -q 'cp "$CONFIG_DIR/global_rules.md" "$HOME/.codex/AGENTS.md"' "$SCRIPT" \
&& grep -q 'cp "$CONFIG_DIR/global_rules.md" "$HOME/.kimi-code/AGENTS.md"' "$SCRIPT" \
&& grep -q 'cp "$CONFIG_DIR/global_rules.md" "$HOME/.claude/CLAUDE.md"' "$SCRIPT" \
&& grep -q 'cp "$CONFIG_DIR/global_rules.md" "$HOME/.gemini/GEMINI.md"' "$SCRIPT" \
&& echo "$HELPERS_SECTION" | grep -q 'echo "$global_rendered" > "$HOME/.codex/AGENTS.md"' \
&& echo "$HELPERS_SECTION" | grep -q 'echo "$global_rendered" > "$HOME/.kimi-code/AGENTS.md"' \
&& echo "$HELPERS_SECTION" | grep -q 'echo "$global_rendered" > "$HOME/.claude/CLAUDE.md"' \
&& echo "$HELPERS_SECTION" | grep -q 'echo "$global_rendered" > "$HOME/.gemini/GEMINI.md"' \
&& ! echo "$HELPERS_SECTION" | grep -q 'echo "$rendered" >'; then
ok "global rules: setup and launchers write native rule files from global_rules.md"
else
fail "global rules: setup and launchers must write native rule files from global_rules.md"
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_global_rules_include_quality_guidelines
test_native_rule_files_generated
test_fix7_trap_tmp
echo ""
echo "Results: $PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ] && exit 0 || exit 1