Skip to content

Commit f90c23e

Browse files
akoclaude
andcommitted
fix: use short temp paths for Unix socket tests on macOS
t.TempDir() on macOS produces paths that exceed the 104-108 character limit for Unix domain sockets, causing bind failures. Use /tmp directly for socket paths in tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f478129 commit f90c23e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

cmd/mxcli/tui/agent_listener_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tui
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"net"
67
"os"
78
"path/filepath"
@@ -12,8 +13,21 @@ import (
1213
tea "github.com/charmbracelet/bubbletea"
1314
)
1415

16+
// shortSockPath returns a socket path short enough for Unix domain sockets
17+
// (max 104-108 chars depending on OS). t.TempDir() on macOS produces paths
18+
// that exceed this limit.
19+
func shortSockPath(t *testing.T) string {
20+
t.Helper()
21+
dir, err := os.MkdirTemp("/tmp", "sock")
22+
if err != nil {
23+
t.Fatalf("MkdirTemp: %v", err)
24+
}
25+
t.Cleanup(func() { os.RemoveAll(dir) })
26+
return filepath.Join(dir, fmt.Sprintf("%d.sock", os.Getpid()))
27+
}
28+
1529
func TestAgentListenerAcceptsConnection(t *testing.T) {
16-
sockPath := filepath.Join(t.TempDir(), "test.sock")
30+
sockPath := shortSockPath(t)
1731

1832
var mu sync.Mutex
1933
var received []tea.Msg
@@ -82,7 +96,7 @@ func TestAgentListenerAcceptsConnection(t *testing.T) {
8296
}
8397

8498
func TestAgentListenerCleansUpSocket(t *testing.T) {
85-
sockPath := filepath.Join(t.TempDir(), "test.sock")
99+
sockPath := shortSockPath(t)
86100
listener, err := NewAgentListener(sockPath, func(tea.Msg) {}, false)
87101
if err != nil {
88102
t.Fatalf("NewAgentListener: %v", err)
@@ -98,7 +112,7 @@ func TestAgentListenerCleansUpSocket(t *testing.T) {
98112
}
99113

100114
func TestAgentListenerInvalidJSON(t *testing.T) {
101-
sockPath := filepath.Join(t.TempDir(), "test.sock")
115+
sockPath := shortSockPath(t)
102116
listener, err := NewAgentListener(sockPath, func(tea.Msg) {}, false)
103117
if err != nil {
104118
t.Fatalf("NewAgentListener: %v", err)
@@ -133,7 +147,7 @@ func TestAgentListenerInvalidJSON(t *testing.T) {
133147
}
134148

135149
func TestAgentListenerValidationError(t *testing.T) {
136-
sockPath := filepath.Join(t.TempDir(), "test.sock")
150+
sockPath := shortSockPath(t)
137151
listener, err := NewAgentListener(sockPath, func(tea.Msg) {}, false)
138152
if err != nil {
139153
t.Fatalf("NewAgentListener: %v", err)

0 commit comments

Comments
 (0)