From 75281d8e1650b67731c0f5bb2a14fe5b6b86191d Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 11 Jun 2026 09:32:12 +0530 Subject: [PATCH] refactor(runner,android): drop unused bringToForeground return; grep no-match yields empty bringToForeground's bool return was read by no caller. FocusedWindowPackage's on-device grep exited 1 on no match, surfacing as an error instead of the documented ""; add || true. --- internal/android/android.go | 5 +++-- internal/runner/runner.go | 8 +++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/android/android.go b/internal/android/android.go index 8f59522..719c2fa 100644 --- a/internal/android/android.go +++ b/internal/android/android.go @@ -456,8 +456,9 @@ func FocusedWindowPackage(ctx context.Context, serial string) (string, error) { } // Grep the focus line on-device: the full dumpsys window output is large and // this runs on the per-step scope guard, so transferring it whole would add - // latency to every step. - output, err := exec.CommandContext(ctx, adb, adbArgs(serial, "shell", "dumpsys window | grep mCurrentFocus")...).Output() + // latency to every step. `|| true` keeps a no-match (grep exit 1) from + // surfacing as an error so it yields "" per the contract. + output, err := exec.CommandContext(ctx, adb, adbArgs(serial, "shell", "dumpsys window | grep mCurrentFocus || true")...).Output() if err != nil { return "", err } diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 6352b66..bcb1bfb 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -535,18 +535,16 @@ func awaitForeground(ctx context.Context, options Options, logger *slog.Logger, // bringToForeground returns the app under test to the foreground. It first // presses BACK to dismiss any modal system dialog (a relaunch alone does not -// close one), then relaunches and waits for the UI to settle. Returns true -// when the relaunch itself succeeded. -func bringToForeground(ctx context.Context, options Options, logger *slog.Logger, stepIndex int) bool { +// close one), then relaunches and waits for the UI to settle. +func bringToForeground(ctx context.Context, options Options, logger *slog.Logger, stepIndex int) { if err := options.Driver.PressKey(ctx, "back"); err != nil { logger.Warn("dismiss key before relaunch failed", "step", stepIndex, "err", err) } if err := options.Driver.Launch(ctx, options.BundleID, false, nil); err != nil { logger.Warn("relaunch failed", "step", stepIndex, "err", err) - return false + return } settleForForeground(ctx, options) - return true } // settleForForeground waits one idle window for the UI to settle, bounding the