From 20dab0ae2fc2aad0caca728ded8e4d9828969bd3 Mon Sep 17 00:00:00 2001 From: PJ Date: Sat, 6 Jun 2026 23:45:13 +0530 Subject: [PATCH] refactor(testrun): defer the java preflight check to the physical-device path --- internal/testrun/preflight.go | 18 +++++++++++++++--- internal/testrun/preflight_test.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/internal/testrun/preflight.go b/internal/testrun/preflight.go index 558f8b4..87dc88a 100644 --- a/internal/testrun/preflight.go +++ b/internal/testrun/preflight.go @@ -41,18 +41,30 @@ func runPreflight(ctx context.Context, platform string, check preflightFunc) err } return nil case "ios": + // Simulator runs drive the native companion and need no JVM. The java + // requirement is deferred to the physical-device path in buildDriver. if err := check("xcrun"); err != nil { return preflightFailure("ios", err) } - if err := check("java"); err != nil { - return preflightFailure("ios", err) - } return nil default: return fmt.Errorf("preflight: unknown platform %q", platform) } } +// preflightDevice runs the extra host checks the JVM sidecar path needs once we +// know a run targets a physical iOS device. Android already requires java in +// the top-level Preflight, so this only matters for ios. +func preflightDevice(platform string) error { + if platform != "ios" { + return nil + } + if err := preflightCheck("java"); err != nil { + return preflightFailure("ios", err) + } + return nil +} + func preflightFailure(platform string, cause error) error { return fmt.Errorf( "preflight: %w\nrun `sanderling doctor --platform=%s` for full host-readiness checks", diff --git a/internal/testrun/preflight_test.go b/internal/testrun/preflight_test.go index d84d033..a213303 100644 --- a/internal/testrun/preflight_test.go +++ b/internal/testrun/preflight_test.go @@ -49,7 +49,7 @@ func TestPreflight_AndroidNeedsAdbAndJava(t *testing.T) { } } -func TestPreflight_iOSNeedsXcrunAndJava(t *testing.T) { +func TestPreflight_iOSNeedsXcrun(t *testing.T) { check := func(name string) error { if name == "xcrun" { return errors.New("xcrun not found") @@ -65,6 +65,25 @@ func TestPreflight_iOSNeedsXcrunAndJava(t *testing.T) { } } +func TestPreflight_iOSDoesNotRequireJava(t *testing.T) { + checked := []string{} + check := func(name string) error { + checked = append(checked, name) + if name == "java" { + return errors.New("java not found") + } + return nil + } + if err := runPreflight(context.Background(), "ios", check); err != nil { + t.Fatalf("ios preflight should pass without java, got %v", err) + } + for _, name := range checked { + if name == "java" { + t.Errorf("ios preflight must not check java; simulator runs need no JVM") + } + } +} + func TestPreflight_AllOK(t *testing.T) { check := func(name string) error { return nil } for _, platform := range []string{"web", "android", "ios"} { @@ -74,6 +93,14 @@ func TestPreflight_AllOK(t *testing.T) { } } +func TestPreflightDevice_NonIosIsNoop(t *testing.T) { + for _, platform := range []string{"web", "android"} { + if err := preflightDevice(platform); err != nil { + t.Errorf("%s: preflightDevice should be a no-op, got %v", platform, err) + } + } +} + func TestPreflight_UnknownPlatform(t *testing.T) { check := func(string) error { return nil } if err := runPreflight(context.Background(), "fuchsia", check); err == nil {