diff options
Diffstat (limited to 'internal/llm')
| -rw-r--r-- | internal/llm/copilot_http_test.go | 5 | ||||
| -rw-r--r-- | internal/llm/ollama_test.go | 8 | ||||
| -rw-r--r-- | internal/llm/openai_http_test.go | 8 | ||||
| -rw-r--r-- | internal/llm/openai_sse_negative_test.go | 3 |
4 files changed, 23 insertions, 1 deletions
diff --git a/internal/llm/copilot_http_test.go b/internal/llm/copilot_http_test.go index 53f831c..180e43e 100644 --- a/internal/llm/copilot_http_test.go +++ b/internal/llm/copilot_http_test.go @@ -10,12 +10,14 @@ import ( "testing" "time" "encoding/base64" + "os" ) type rtFunc2 func(*http.Request) (*http.Response, error) func (f rtFunc2) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) } func TestCopilot_EnsureSession_AndChat_Success(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } // Mock chat endpoint chatSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/chat/completions" { t.Fatalf("unexpected path: %s", r.URL.Path) } @@ -73,6 +75,7 @@ func TestCopilot_CodeCompletion_Success(t *testing.T) { } func TestCopilot_Chat_MultiChoice_And_ErrorBody(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } // Chat multi-choice: return two choices; client returns first content srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _ = json.NewEncoder(w).Encode(map[string]any{ @@ -109,6 +112,7 @@ func TestCopilot_Chat_MultiChoice_And_ErrorBody(t *testing.T) { } func TestCopilot_Chat_NoChoices_Error(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _ = json.NewEncoder(w).Encode(map[string]any{"choices": []any{}}) })) @@ -127,6 +131,7 @@ func TestCopilot_Chat_NoChoices_Error(t *testing.T) { } func TestCopilot_Chat_DecodeError_StatusOK(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } // Chat returns 200 but invalid JSON; expect decode error srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "{invalid") diff --git a/internal/llm/ollama_test.go b/internal/llm/ollama_test.go index 8d77a58..15f9cff 100644 --- a/internal/llm/ollama_test.go +++ b/internal/llm/ollama_test.go @@ -9,6 +9,7 @@ import ( "strings" "testing" "time" + "os" ) func TestBuildOllamaRequest_OptionsAndStream(t *testing.T) { @@ -40,6 +41,7 @@ func TestOllama_NameAndModel(t *testing.T) { } func TestOllamaChat_Success(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost || r.URL.Path != "/api/chat" { t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path) } w.Header().Set("Content-Type", "application/json") @@ -54,6 +56,7 @@ func TestOllamaChat_Success(t *testing.T) { } func TestOllamaChat_EmptyContent(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _ = json.NewEncoder(w).Encode(map[string]any{"message": map[string]string{"role":"assistant","content":""}, "done": true}) })) @@ -66,6 +69,7 @@ func TestOllamaChat_EmptyContent(t *testing.T) { } func TestOllamaChat_Non2xx(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } // API error string ts1 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(400) @@ -102,6 +106,7 @@ func TestOllamaChat_HTTPError(t *testing.T) { } func TestOllamaChat_DecodeError(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("{bad json}")) })) @@ -119,6 +124,7 @@ func TestHandleOllamaNon2xx_OK(t *testing.T) { } func TestOllamaChatStream_Success(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") // two JSON objects back-to-back @@ -136,6 +142,7 @@ func TestOllamaChatStream_Success(t *testing.T) { } func TestOllamaChatStream_ErrorEvent(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _ = json.NewEncoder(w).Encode(map[string]any{"error":"oops"}) })) @@ -148,6 +155,7 @@ func TestOllamaChatStream_ErrorEvent(t *testing.T) { } func TestOllamaChatStream_DecodeError(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("{not json}")) })) diff --git a/internal/llm/openai_http_test.go b/internal/llm/openai_http_test.go index 808bb2b..ac7b897 100644 --- a/internal/llm/openai_http_test.go +++ b/internal/llm/openai_http_test.go @@ -9,9 +9,11 @@ import ( "testing" "strings" "time" + "os" ) func TestOpenAI_Chat_Success(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/chat/completions" { t.Fatalf("unexpected path: %s", r.URL.Path) } _ = json.NewEncoder(w).Encode(map[string]any{"choices": []map[string]any{{"index":0, "message": map[string]string{"role":"assistant","content":"OK"}}}}) @@ -29,6 +31,7 @@ func TestOpenAI_Chat_MissingKey(t *testing.T) { } func TestOpenAI_ChatStream_SSE(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Return SSE-like stream w.Header().Set("Content-Type", "text/event-stream") @@ -49,6 +52,7 @@ func TestHandleOpenAINon2xx_NoErrorBody(t *testing.T) { } func TestOpenAI_ChatStream_SSE_ErrorChunk(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/event-stream") io.WriteString(w, "data: {\"error\":{\"message\":\"oops\"}}\n\n") @@ -64,6 +68,7 @@ func TestOpenAI_ChatStream_SSE_ErrorChunk(t *testing.T) { } func TestOpenAI_Chat_NoChoices_Error(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _ = json.NewEncoder(w).Encode(map[string]any{"choices": []any{}}) })) @@ -76,6 +81,7 @@ func TestOpenAI_Chat_NoChoices_Error(t *testing.T) { } func TestOpenAI_ChatStream_SSE_EmptyDelta_NoError(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/event-stream") io.WriteString(w, "data: {\\\"choices\\\":[{\\\"delta\\\":{\\\"content\\\":\\\"\\\"}}]}\\n\\n") @@ -92,6 +98,7 @@ func TestOpenAI_ChatStream_SSE_EmptyDelta_NoError(t *testing.T) { } func TestOpenAI_Chat_DecodeError_StatusOK(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } // Return status 200 but invalid JSON body; Chat should return an error srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) @@ -106,6 +113,7 @@ func TestOpenAI_Chat_DecodeError_StatusOK(t *testing.T) { } func TestOpenAI_Chat_MultiChoiceAndErrorBody(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } // Multi-choice success: return two choices with different finish reasons srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _ = json.NewEncoder(w).Encode(map[string]any{ diff --git a/internal/llm/openai_sse_negative_test.go b/internal/llm/openai_sse_negative_test.go index 22b938c..8da5526 100644 --- a/internal/llm/openai_sse_negative_test.go +++ b/internal/llm/openai_sse_negative_test.go @@ -6,9 +6,11 @@ import ( "net/http" "net/http/httptest" "testing" + "os" ) func TestOpenAI_ChatStream_SSE_MalformedChunk(t *testing.T) { + if os.Getenv("HEXAI_TEST_SKIP_NET") == "1" { t.Skip("skip network-bound tests in restricted environments") } // Malformed JSON chunk should be skipped; no onDelta calls; no error. srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/event-stream") @@ -24,4 +26,3 @@ func TestOpenAI_ChatStream_SSE_MalformedChunk(t *testing.T) { } if got != "" { t.Fatalf("expected no deltas for malformed chunk, got %q", got) } } - |
