sub2api/backend/internal/pkg/windsurf/spawn_error_test.go

49 lines
1.5 KiB
Go

package windsurf
import (
"errors"
"runtime"
"strings"
"testing"
)
func TestWrapSpawnError_PreservesOriginalError(t *testing.T) {
orig := errors.New("exec: no such file")
wrapped := wrapSpawnError("test-key", "/opt/ls", orig)
if !errors.Is(wrapped, orig) {
t.Errorf("wrapped error should unwrap to original, got %v", wrapped)
}
if !strings.Contains(wrapped.Error(), "test-key") {
t.Errorf("wrapped error should mention the instance key, got %v", wrapped)
}
if !strings.Contains(wrapped.Error(), "/opt/ls") {
t.Errorf("wrapped error should mention the binary path, got %v", wrapped)
}
}
// Platform-specific hint assertions: these only run on their native OS.
// Cross-platform CI (Phase 0.2 matrix) exercises each branch natively.
func TestWrapSpawnError_PlatformHint(t *testing.T) {
err := wrapSpawnError("k", "/tmp/ls", errors.New("operation not permitted"))
msg := err.Error()
switch runtime.GOOS {
case "darwin":
for _, want := range []string{"Gatekeeper", "xattr", "com.apple.quarantine"} {
if !strings.Contains(msg, want) {
t.Errorf("darwin hint missing %q: %v", want, err)
}
}
case "windows":
for _, want := range []string{"Defender", "quarantined"} {
if !strings.Contains(msg, want) {
t.Errorf("windows hint missing %q: %v", want, err)
}
}
default:
// Linux and other Unix: plain error, no extra hint.
if strings.Contains(msg, "Gatekeeper") || strings.Contains(msg, "Defender") {
t.Errorf("non-mac/non-windows error should not contain platform-specific hints, got %v", err)
}
}
}