From d6d7f7074f4438929d6818bd73c30028d5bdc841 Mon Sep 17 00:00:00 2001 From: PJ Date: Tue, 9 Jun 2026 18:22:55 +0530 Subject: [PATCH] refactor(doctor): dedup usbmuxd socket path via ioscompanion seam --- cmd/sanderling/doctor.go | 10 ++-------- internal/driver/ioscompanion/usbmux.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/sanderling/doctor.go b/cmd/sanderling/doctor.go index 41f8ef0..d642c3e 100644 --- a/cmd/sanderling/doctor.go +++ b/cmd/sanderling/doctor.go @@ -134,6 +134,7 @@ func checkSimctl(ctx context.Context) error { var ( doctorConnectedDevices = ios.ConnectedDevices doctorVerifySigning = ioscompanion.VerifyDeviceSigning + doctorVerifyUsbmuxd = ioscompanion.VerifyUsbmuxdSocket ) // checkDevicectl exercises `xcrun devicectl --version`: devicectl is an xcrun @@ -145,17 +146,10 @@ func checkDevicectl(ctx context.Context) error { return nil } -// usbmuxdSocketPath is the macOS usbmuxd unix socket. It ships with the OS, so -// the device tunnel needs nothing installed. -const usbmuxdSocketPath = "/var/run/usbmuxd" - // checkUsbmuxd confirms the macOS usbmuxd socket is present: the native device // tunnel speaks to it directly instead of shelling out to a third-party client. func checkUsbmuxd(_ context.Context) error { - if _, err := os.Stat(usbmuxdSocketPath); err != nil { - return fmt.Errorf("usbmuxd socket not found at %s: %w", usbmuxdSocketPath, err) - } - return nil + return doctorVerifyUsbmuxd() } // checkDeviceConnected confirms at least one physical iOS device is connected diff --git a/internal/driver/ioscompanion/usbmux.go b/internal/driver/ioscompanion/usbmux.go index e96d526..7ae9120 100644 --- a/internal/driver/ioscompanion/usbmux.go +++ b/internal/driver/ioscompanion/usbmux.go @@ -15,6 +15,7 @@ import ( "fmt" "io" "net" + "os" "sort" "strconv" "strings" @@ -24,6 +25,16 @@ import ( // an installed dependency. const usbmuxdSocket = "/var/run/usbmuxd" +// VerifyUsbmuxdSocket reports whether the macOS usbmuxd socket is present. The +// doctor calls it so the device preflight confirms the tunnel's transport +// before a run reaches the build step. +func VerifyUsbmuxdSocket() error { + if _, err := os.Stat(usbmuxdSocket); err != nil { + return fmt.Errorf("usbmuxd socket not found at %s: %w", usbmuxdSocket, err) + } + return nil +} + // usbmux message framing: a 16-byte little-endian header (length including the // header, protocol version, payload type, request tag) precedes an XML plist. const (