Skip to content

Commit 44b9daf

Browse files
committed
fix(llm): wrap platform-correct errno in tests
The previous commit gated isNetworkError on platform-specific connectionErrnos but left the tests wrapping syscall.ECONNREFUSED directly. On Windows that's an APPLICATION_ERROR-prefixed invented constant, not the WSA value the production check uses, so the tests failed on windows-11-arm CI. Reach into connectionErrnos[0] for the representative connection-refused sentinel; it resolves to syscall.ECONNREFUSED on POSIX and windows.WSAECONNREFUSED on Windows.
1 parent aafc277 commit 44b9daf

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

internal/llm/client_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"net/http/httptest"
1515
"os"
1616
"strings"
17-
"syscall"
1817
"testing"
1918
"testing/synctest"
2019
"time"
@@ -417,7 +416,7 @@ func TestPingServerDownCloud(t *testing.T) {
417416
// Use wrapError directly: a ECONNREFUSED wrapped in ProviderError
418417
// from a cloud provider should say "cannot reach ... check your
419418
// base_url" and NOT mention ollama.
420-
inner := fmt.Errorf("dial tcp: %w", syscall.ECONNREFUSED)
419+
inner := fmt.Errorf("dial tcp: %w", connectionErrnos[0])
421420
c := &Client{providerName: "openai"}
422421
err := c.wrapError(anyllmerrors.NewProviderError("openai", inner))
423422
require.Error(t, err)
@@ -478,7 +477,7 @@ func TestCreateProviderAllSupported(t *testing.T) {
478477
// TestWrapErrorProviderError exercises the wrapError path for ProviderError.
479478
func TestWrapErrorProviderError(t *testing.T) {
480479
t.Parallel()
481-
connErr := fmt.Errorf("dial tcp: %w", syscall.ECONNREFUSED)
480+
connErr := fmt.Errorf("dial tcp: %w", connectionErrnos[0])
482481
tests := []struct {
483482
provider string
484483
wantMsg string
@@ -501,29 +500,32 @@ func TestWrapErrorProviderError(t *testing.T) {
501500
}
502501
}
503502

504-
// TestIsNetworkError verifies that wrapped syscall sentinels are
505-
// recognized via errors.Is, regardless of how deeply they are wrapped.
503+
// TestIsNetworkError verifies that wrapped platform-correct syscall
504+
// sentinels are recognized via errors.Is, regardless of how deeply
505+
// they are wrapped. Uses connectionErrnos to stay correct across
506+
// Linux/macOS (POSIX errnos) and Windows (WSA errnos), since
507+
// syscall.ECONNREFUSED on Windows is an invented APPLICATION_ERROR
508+
// constant that doesn't match the WSA value.
506509
func TestIsNetworkError(t *testing.T) {
507510
t.Parallel()
511+
refused := connectionErrnos[0]
508512
cases := []struct {
509513
name string
510514
err error
511515
want bool
512516
}{
513-
{"bare ECONNREFUSED", syscall.ECONNREFUSED, true},
514-
{"bare ENETUNREACH", syscall.ENETUNREACH, true},
515-
{"bare EHOSTUNREACH", syscall.EHOSTUNREACH, true},
517+
{"bare connection-refused errno", refused, true},
516518
{
517-
"net.OpError wrapping ECONNREFUSED",
519+
"net.OpError wrapping connection-refused errno",
518520
&net.OpError{
519521
Op: "dial", Net: "tcp",
520-
Err: &os.SyscallError{Syscall: "connect", Err: syscall.ECONNREFUSED},
522+
Err: &os.SyscallError{Syscall: "connect", Err: refused},
521523
},
522524
true,
523525
},
524526
{
525-
"fmt.Errorf wrapping EHOSTUNREACH",
526-
fmt.Errorf("dial tcp: %w", syscall.EHOSTUNREACH),
527+
"fmt.Errorf wrapping connection-refused errno",
528+
fmt.Errorf("dial tcp: %w", refused),
527529
true,
528530
},
529531
{"unrelated error", errors.New("something else broke"), false},

0 commit comments

Comments
 (0)