Skip to content

Commit 5808545

Browse files
author
Test
committed
test: skip Ollama tests when daemon not running
- Add IsRunning() helper to check Ollama availability - Skip tests automatically if daemon unreachable - Fixes test failures in environments without Ollama
1 parent 7b9010d commit 5808545

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

internal/feedback/feedback.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -356,23 +356,23 @@ func GetBestModels(agent string, minSamples int) []string {
356356
}
357357

358358
type AnonymizedEvent struct {
359-
Date string `json:"date"`
360-
Sentiment string `json:"sentiment"`
361-
Backend string `json:"backend"`
362-
Model string `json:"model"`
363-
Agent string `json:"agent"`
364-
Language string `json:"language,omitempty"`
365-
Complexity string `json:"complexity,omitempty"`
359+
Date string `json:"date"`
360+
Sentiment string `json:"sentiment"`
361+
Backend string `json:"backend"`
362+
Model string `json:"model"`
363+
Agent string `json:"agent"`
364+
Language string `json:"language,omitempty"`
365+
Complexity string `json:"complexity,omitempty"`
366366
}
367367

368368
func Anonymize(events []Event) []AnonymizedEvent {
369369
var anonymized []AnonymizedEvent
370-
370+
371371
for _, e := range events {
372372
if e.Model == "" || e.Agent == "" {
373373
continue
374374
}
375-
375+
376376
var action string
377377
switch strings.ToLower(e.Agent) {
378378
case "editor":
@@ -386,14 +386,14 @@ func Anonymize(events []Event) []AnonymizedEvent {
386386
default:
387387
action = e.Agent
388388
}
389-
389+
390390
complexity := "simple"
391391
if strings.Contains(strings.ToLower(e.Context), "complex") ||
392392
strings.Contains(strings.ToLower(e.Task), "refactor") ||
393393
strings.Contains(strings.ToLower(e.Task), "reorganize") {
394394
complexity = "complex"
395395
}
396-
396+
397397
var lang string
398398
taskLower := strings.ToLower(e.Task)
399399
if strings.Contains(taskLower, ".go") {
@@ -409,7 +409,7 @@ func Anonymize(events []Event) []AnonymizedEvent {
409409
} else if strings.Contains(taskLower, ".ex") || strings.Contains(taskLower, ".exs") {
410410
lang = "elixir"
411411
}
412-
412+
413413
anonymized = append(anonymized, AnonymizedEvent{
414414
Date: e.Timestamp.Format("2006-01-02"),
415415
Sentiment: string(e.Sentiment),
@@ -420,7 +420,7 @@ func Anonymize(events []Event) []AnonymizedEvent {
420420
Complexity: complexity,
421421
})
422422
}
423-
423+
424424
return anonymized
425425
}
426426

@@ -429,21 +429,21 @@ func ExportAnonymized(outputPath string) error {
429429
if err != nil {
430430
return fmt.Errorf("failed to load feedback: %w", err)
431431
}
432-
432+
433433
if len(events) == 0 {
434434
return fmt.Errorf("no feedback events found")
435435
}
436-
436+
437437
anonymized := Anonymize(events)
438-
438+
439439
data, err := json.MarshalIndent(anonymized, "", " ")
440440
if err != nil {
441441
return fmt.Errorf("failed to marshal anonymized feedback: %w", err)
442442
}
443-
443+
444444
if err := os.WriteFile(outputPath, data, 0644); err != nil {
445445
return fmt.Errorf("failed to write export file: %w", err)
446446
}
447-
447+
448448
return nil
449449
}

internal/ollama/install.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os/exec"
99
"strings"
10+
"time"
1011
)
1112

1213
type InstalledModel struct {
@@ -109,3 +110,13 @@ func CheckAndInstall(modelName string, autoInstall bool, progressCallback func(s
109110

110111
return Install(modelName, progressCallback)
111112
}
113+
114+
func IsRunning() bool {
115+
client := &http.Client{Timeout: 2 * time.Second}
116+
resp, err := client.Get("http://localhost:11434/api/tags")
117+
if err != nil {
118+
return false
119+
}
120+
defer resp.Body.Close()
121+
return resp.StatusCode == http.StatusOK
122+
}

internal/ollama/install_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import (
66
)
77

88
func TestIsInstalled(t *testing.T) {
9-
if os.Getenv("CI") == "true" {
9+
if os.Getenv("CI") == "true" || os.Getenv("GITHUB_ACTIONS") == "true" {
1010
t.Skip("Skipping integration test in CI (requires Ollama service)")
1111
}
12+
if !IsRunning() {
13+
t.Skip("Skipping test: Ollama daemon not running")
14+
}
1215

1316
tests := []struct {
1417
name string
@@ -50,9 +53,12 @@ func TestIsInstalled(t *testing.T) {
5053
}
5154

5255
func TestCheckAndInstall(t *testing.T) {
53-
if os.Getenv("CI") == "true" {
56+
if os.Getenv("CI") == "true" || os.Getenv("GITHUB_ACTIONS") == "true" {
5457
t.Skip("Skipping integration test in CI (requires Ollama service)")
5558
}
59+
if !IsRunning() {
60+
t.Skip("Skipping test: Ollama daemon not running")
61+
}
5662

5763
tests := []struct {
5864
name string

0 commit comments

Comments
 (0)