From f819dad7b65fad389601a15a764b0845624e32c1 Mon Sep 17 00:00:00 2001 From: PJ Date: Sat, 15 Aug 2026 22:39:38 +0530 Subject: [PATCH] fix(testrun): preflight resolves adb through the sdk, not just PATH --- internal/testrun/preflight.go | 10 ++++++++++ internal/testrun/preflight_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/internal/testrun/preflight.go b/internal/testrun/preflight.go index a65c88b..e95caf8 100644 --- a/internal/testrun/preflight.go +++ b/internal/testrun/preflight.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "os/exec" + + "github.com/priyanshujain/sanderling/internal/android" ) // Preflight runs platform-specific host checks before sidecar/driver setup. @@ -18,7 +20,15 @@ func Preflight(ctx context.Context, platform string) error { type preflightFunc func(name string) error +// preflightCheck resolves adb through the same helper every adb call in a run +// uses, so a host whose SDK is only reachable through $ANDROID_HOME or a +// standard install location is not turned away here and then driven fine by +// the rest of the pipeline. func preflightCheck(name string) error { + if name == "adb" { + _, err := android.AdbBinary() + return err + } if _, err := exec.LookPath(name); err != nil { return fmt.Errorf("%s not found on PATH: %w", name, err) } diff --git a/internal/testrun/preflight_test.go b/internal/testrun/preflight_test.go index e460d07..d2f32f1 100644 --- a/internal/testrun/preflight_test.go +++ b/internal/testrun/preflight_test.go @@ -3,6 +3,8 @@ package testrun import ( "context" "errors" + "os" + "path/filepath" "strings" "testing" ) @@ -49,6 +51,33 @@ func TestPreflight_AndroidNeedsAdbAndJava(t *testing.T) { } } +// Every adb call in an android run resolves through $ANDROID_HOME and the +// standard SDK locations, so a preflight that only looks at PATH turns away a +// host the run itself would drive. +func TestPreflight_AndroidAcceptsAdbUnderAndroidHome(t *testing.T) { + sdk := t.TempDir() + writeExecutable(t, filepath.Join(sdk, "platform-tools", "adb")) + pathDirectory := t.TempDir() + writeExecutable(t, filepath.Join(pathDirectory, "java")) + t.Setenv("PATH", pathDirectory) + t.Setenv("ANDROID_HOME", sdk) + t.Setenv("ANDROID_SDK_ROOT", "") + + if err := Preflight(context.Background(), "android"); err != nil { + t.Fatalf("Preflight with adb under $ANDROID_HOME: %v", err) + } +} + +func writeExecutable(t *testing.T, path string) { + t.Helper() + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + t.Fatalf("mkdir %s: %v", filepath.Dir(path), err) + } + if err := os.WriteFile(path, nil, 0o755); err != nil { + t.Fatalf("write %s: %v", path, err) + } +} + func TestPreflight_iOSNeedsXcrun(t *testing.T) { check := func(name string) error { if name == "xcrun" {