44
55to test-llm-providers
66 print "Testing Available providers..."
7-
7+
88 llm:set-api-key "AIzaSyDbM-TMmsX_tiP790DF6vLjmRHM1dXOwOw"
9-
9+
1010 llm:set-provider "gemini"
1111
1212 llm:set-model "gemini-2.5-pro"
13-
13+
1414 let result llm:chat "Who are you ?"
1515 print (word "Sync chat result: " result)
16-
17-
18-
16+
17+
18+
1919 print result
2020end
2121
@@ -37,7 +37,7 @@ to test-sync-chat
3737
3838 ; Load config or set manually
3939 carefully [
40- llm:load-config "../ config.txt"
40+ llm:load-config "config.txt"
4141 print "Config loaded successfully"
4242 ] [
4343 print "Config loading failed, setting manually..."
9090to test-providers-list
9191 print "Testing llm:providers primitive..."
9292
93- let providers llm:providers
94- print (word "Available providers: " providers)
93+ ; llm:providers now returns only READY providers (with API keys or reachable)
94+ let ready-providers llm:providers
95+ print (word "Ready providers: " ready-providers)
96+ print (word "Total ready providers: " length ready-providers)
9597
96- ; Verify we have expected providers
97- if member? "openai" providers [
98- print "✓ OpenAI provider available"
99- ]
100- if member? "anthropic" providers [
101- print "✓ Anthropic provider available"
102- ]
103- if member? "gemini" providers [
104- print "✓ Gemini provider available"
98+ ; llm:providers-all returns ALL supported providers
99+ let all- providers llm:providers-all
100+ print (word "All supported providers: " all-providers)
101+ print (word "Total supported providers: " length all-providers)
102+
103+ ; llm:provider-status gives detailed status
104+ print "Provider status details:"
105+ foreach llm:provider-status [ provider-info ->
106+ print provider-info
105107 ]
106- if member? "ollama" providers [
107- print "✓ Ollama provider available"
108+ end
109+
110+ to test-active-config
111+ print "Testing llm:active and llm:config primitives..."
112+
113+ ; Set a provider and model
114+ carefully [
115+ llm:set-provider "openai"
116+ llm:set-model "gpt-4o-mini"
117+
118+ ; Check active configuration
119+ let active llm:active
120+ print (word "Active provider and model: " active)
121+
122+ if item 0 active = "openai" [
123+ print "✓ Active provider is openai"
124+ ]
125+ if item 1 active = "gpt-4o-mini" [
126+ print "✓ Active model is gpt-4o-mini"
127+ ]
128+
129+ ; Show full config (with masked keys)
130+ print "Current configuration:"
131+ print llm:config
132+ ] [
133+ print "Failed to test active config (provider validation failed)"
108134 ]
135+ end
109136
110- print (word "Total providers available: " length providers)
137+ to test-provider-help
138+ print "Testing llm:provider-help primitive..."
139+
140+ ; Get help for each provider
141+ print "\n=== OpenAI Setup Help ==="
142+ print llm:provider-help "openai"
143+
144+ print "\n=== Ollama Setup Help ==="
145+ print llm:provider-help "ollama"
146+
147+ print "\n=== Anthropic Setup Help ==="
148+ print llm:provider-help "anthropic"
149+
150+ print "\n=== Gemini Setup Help ==="
151+ print llm:provider-help "gemini"
111152end
112153
113154to test-provider-switching
@@ -160,6 +201,152 @@ to test-config-loading
160201 ]
161202end
162203
204+ to test-ollama-not-running
205+ print "Testing Ollama provider when server is not running..."
206+
207+ ; Check status - should show reachable: false if Ollama is not running
208+ print "Checking Ollama status in provider-status:"
209+ let status llm:provider-status
210+ foreach status [ provider-info ->
211+ if item 0 provider-info = "ollama" [
212+ print provider-info
213+ ; Expected: ["ollama" ["ready" false] ["reachable" false] ["base-url" "http://localhost:11434"]]
214+ ]
215+ ]
216+
217+ ; Check if Ollama appears in ready providers list
218+ let ready-providers llm:providers
219+ ifelse member? "ollama" ready-providers [
220+ print "✓ Ollama is reachable and ready"
221+ ] [
222+ print "✗ Ollama is NOT in ready providers list (server not running or not installed)"
223+ ]
224+
225+ ; Try to use Ollama when not running (will fail if server is down)
226+ print "\nAttempting to use Ollama provider:"
227+ carefully [
228+ llm:set-provider "ollama"
229+ print "Provider set to Ollama"
230+
231+ ; This will fail if Ollama server is not running
232+ let result llm:chat "test"
233+ print "✓ UNEXPECTED: Chat succeeded (Ollama must be running)"
234+ ] [
235+ print (word "✓ EXPECTED: Error when Ollama not running: " error-message)
236+ ]
237+ end
238+
239+ to test-invalid-config
240+ print "Testing config validation with missing API keys..."
241+
242+ ; First, clear any existing configuration
243+ carefully [
244+ llm:set-provider "openai"
245+ ; Don't set API key
246+
247+ print "Checking provider status without API key:"
248+ let status llm:provider-status
249+ foreach status [ provider-info ->
250+ if item 0 provider-info = "openai" [
251+ print provider-info
252+ ; Expected: ["openai" ["ready" false] ["has-key" false]]
253+ ]
254+ ]
255+
256+ ; Check if OpenAI appears in ready providers
257+ let ready-providers llm:providers
258+ ifelse member? "openai" ready-providers [
259+ print "✗ UNEXPECTED: OpenAI in ready list without API key"
260+ ] [
261+ print "✓ EXPECTED: OpenAI NOT in ready list (no API key)"
262+ ]
263+
264+ ; Try to use provider without API key (should fail)
265+ print "\nAttempting to chat without API key:"
266+ let result llm:chat "test"
267+ print "✗ UNEXPECTED: Chat succeeded without API key"
268+ ] [
269+ print (word "✓ EXPECTED: Error when using provider without API key: " error-message)
270+ ]
271+ end
272+
273+ to test-provider-readiness
274+ print "Testing provider readiness checks..."
275+ print ""
276+
277+ ; Show all providers vs ready providers
278+ print "All supported providers:"
279+ let all-providers llm:providers-all
280+ print all-providers
281+ print ""
282+
283+ print "Ready providers (with API keys or reachable):"
284+ let ready-providers llm:providers
285+ print ready-providers
286+ print ""
287+
288+ ; Show which providers are not ready and why
289+ print "Detailed status for non-ready providers:"
290+ let status llm:provider-status
291+ foreach status [ provider-info ->
292+ let provider-name item 0 provider-info
293+ let is-ready false
294+
295+ ; Check if provider is in ready list
296+ ifelse member? provider-name ready-providers [
297+ ; Skip ready providers
298+ ] [
299+ ; Show why provider is not ready
300+ print (word provider-name " is NOT ready:")
301+ print (word " Status: " provider-info)
302+
303+ ; Suggest how to fix
304+ if provider-name = "ollama" [
305+ print " Fix: Install and start Ollama server, or run: ollama serve"
306+ ]
307+ if provider-name = "openai" or provider-name = "anthropic" or provider-name = "gemini" [
308+ print (word " Fix: Set API key or run: llm:provider-help \"" provider-name "\"")
309+ ]
310+ print ""
311+ ]
312+ ]
313+ end
314+
315+ to test-config-error-messages
316+ print "Testing helpful error messages for config issues..."
317+ print ""
318+
319+ ; Test 1: Provider help for all providers
320+ print "=== Testing provider help messages ==="
321+ foreach ["openai" "anthropic" "gemini" "ollama"] [ provider ->
322+ print (word "\nHelp for " provider ":")
323+ print llm:provider-help provider
324+ ]
325+ print ""
326+
327+ ; Test 2: Invalid provider name
328+ print "=== Testing invalid provider name ==="
329+ carefully [
330+ llm:set-provider "invalid-provider"
331+ print "✗ UNEXPECTED: Set invalid provider succeeded"
332+ ] [
333+ print (word "✓ EXPECTED: Error for invalid provider: " error-message)
334+ ]
335+ print ""
336+
337+ ; Test 3: Show active config
338+ print "=== Testing active config display ==="
339+ carefully [
340+ llm:set-provider "openai"
341+ let active llm:active
342+ print (word "Active configuration: " active)
343+ print "\nFull config summary:"
344+ print llm:config
345+ ] [
346+ print (word "Error getting active config: " error-message)
347+ ]
348+ end
349+
163350to test-multi-provider-complete
164351 print "=== Multi-Provider Extension Test Suite ==="
165352 print ""
@@ -415,6 +602,51 @@ to run-all-model-management-tests
415602 print "========================================"
416603 print " ALL TESTS COMPLETE"
417604 print "========================================"
605+ end
606+
607+ to test-config-validation-complete
608+ print "=== Config Validation and Error Handling Test Suite ==="
609+ print ""
610+
611+ ; Test 1: Provider readiness checks
612+ print "Test 1: Provider Readiness Checks"
613+ print "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
614+ test-provider-readiness
615+ print ""
616+
617+ ; Test 2: Ollama server not running
618+ print "Test 2: Ollama Server Not Running"
619+ print "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
620+ test-ollama-not-running
621+ print ""
622+
623+ ; Test 3: Invalid config (missing API keys)
624+ print "Test 3: Invalid Config (Missing API Keys)"
625+ print "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
626+ test-invalid-config
627+ print ""
628+
629+ ; Test 4: Error messages and help
630+ print "Test 4: Error Messages and Help"
631+ print "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
632+ test-config-error-messages
633+ print ""
634+
635+ ; Test 5: Active config and status
636+ print "Test 5: Active Config and Status"
637+ print "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
638+ test-active-config
639+ print ""
640+
641+ print "=== Config Validation Test Suite Complete ==="
642+ print ""
643+ print "Summary of what was tested:"
644+ print " ✓ Provider readiness checks (llm:providers vs llm:providers-all)"
645+ print " ✓ Ollama server reachability detection"
646+ print " ✓ API key validation and error handling"
647+ print " ✓ Helpful error messages and setup instructions"
648+ print " ✓ Active configuration reporting"
649+ print " ✓ Provider status detailed reporting"
418650end]]> </code >
419651 <widgets >
420652 <view x =" 210" wrappingAllowedX =" true" y =" 10" frameRate =" 30.0" minPycor =" -16" height =" 429" showTickCounter =" true" patchSize =" 13.0" fontSize =" 10" wrappingAllowedY =" true" width =" 429" tickCounterLabel =" ticks" maxPycor =" 16" updateMode =" 0" maxPxcor =" 16" minPxcor =" -16" ></view >
0 commit comments