6249d8a251
- New src/ai_assist.nim module with DeepSeek/OpenAI/MiMo API support - AI explains compiler errors automatically when compilation fails - New CLI command: cljnim ai '<description>' for code generation - REPL :ai command for interactive AI assistance - API keys read from environment vars (DEEPSEEK_API_KEY, OPENAI_API_KEY, MIMO_API_KEY) - Tests for prompt building and response formatting - Updated README with AI integration docs
46 lines
1.6 KiB
Nim
46 lines
1.6 KiB
Nim
# Tests for AI assistance module (no real API calls)
|
|
|
|
import unittest, strutils
|
|
import os
|
|
import ai_assist
|
|
|
|
suite "AI Config Detection":
|
|
test "detectConfig returns empty when no env vars set":
|
|
# Note: this test assumes no API keys are set in test environment
|
|
# If keys ARE set, it will detect them
|
|
let cfg = detectConfig()
|
|
# At minimum, the function should not crash
|
|
check cfg.timeoutMs >= 0
|
|
|
|
test "hasAiConfig returns false when no keys set (if env empty)":
|
|
let key = getEnv("DEEPSEEK_API_KEY", "")
|
|
let okey = getEnv("OPENAI_API_KEY", "")
|
|
let mkey = getEnv("MIMO_API_KEY", "")
|
|
if key.len == 0 and okey.len == 0 and mkey.len == 0:
|
|
check hasAiConfig() == false
|
|
|
|
suite "Prompt Building":
|
|
test "buildErrorPrompt includes filename and source":
|
|
let prompt = buildErrorPrompt("type mismatch", "(defn foo [x] x)", "test.clj")
|
|
check "test.clj" in prompt
|
|
check "type mismatch" in prompt
|
|
check "(defn foo [x] x)" in prompt
|
|
|
|
test "buildGenerationPrompt includes description":
|
|
let prompt = buildGenerationPrompt("reverse a list")
|
|
check "reverse a list" in prompt
|
|
check "Clojure" in prompt
|
|
|
|
suite "Response Formatting":
|
|
test "formatSuggestion shows error when not ok":
|
|
let resp = AiResponse(ok: false, suggestion: "No key configured")
|
|
let formatted = formatSuggestion(resp)
|
|
check "💡 AI:" in formatted
|
|
check "No key configured" in formatted
|
|
|
|
test "formatSuggestion shows suggestion when ok":
|
|
let resp = AiResponse(ok: true, suggestion: "Use (reverse coll)")
|
|
let formatted = formatSuggestion(resp)
|
|
check "💡 AI Suggestion:" in formatted
|
|
check "Use (reverse coll)" in formatted
|