refactor(testrun): defer the java preflight check to the physical-device path

This commit is contained in:
pj committed 2026-06-06 23:45:13 +05:30
1 parent 75d4294601
commit 20dab0ae2f
2 files changed
+43 -4

No files matched your search

+15 -3
View File
@@ -41,18 +41,30 @@ func runPreflight(ctx context.Context, platform string, check preflightFunc) err
} }
return nil return nil
case "ios": 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 { if err := check("xcrun"); err != nil {
return preflightFailure("ios", err) return preflightFailure("ios", err)
} }
if err := check("java"); err != nil {
return preflightFailure("ios", err)
}
return nil return nil
default: default:
return fmt.Errorf("preflight: unknown platform %q", platform) 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 { func preflightFailure(platform string, cause error) error {
return fmt.Errorf( return fmt.Errorf(
"preflight: %w\nrun `sanderling doctor --platform=%s` for full host-readiness checks", "preflight: %w\nrun `sanderling doctor --platform=%s` for full host-readiness checks",
+28 -1
View File
@@ -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 { check := func(name string) error {
if name == "xcrun" { if name == "xcrun" {
return errors.New("xcrun not found") 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) { func TestPreflight_AllOK(t *testing.T) {
check := func(name string) error { return nil } check := func(name string) error { return nil }
for _, platform := range []string{"web", "android", "ios"} { 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) { func TestPreflight_UnknownPlatform(t *testing.T) {
check := func(string) error { return nil } check := func(string) error { return nil }
if err := runPreflight(context.Background(), "fuchsia", check); err == nil { if err := runPreflight(context.Background(), "fuchsia", check); err == nil {