fix: record step durations, and pin the foreground app before matching text

Two defects found by running spotify_play against the real phone.

- Step durations were always zero in the run log: executeStep returned a copy,
  so the deferred assignment never reached the caller (FR-10). It now returns a
  named value, with a regression test.
- The phone was sitting on the Android Settings app, and wait "Search" was
  satisfied by Settings' own "Search Settings" entry, so the recipe tapped the
  Settings search bar. New "foreground" step waits until the recipe's app really
  is in front; spotify_play uses it right after launch.

docs/phase-3-spotify-recipe.md now logs all six live attempts and states
plainly that the end-to-end playback run has not completed: the phone is
showing a Settings "Verify that it's you" biometric prompt, which needs Sam and
is left untouched.
This commit is contained in:
2026-10-16 13:29:07 +11:00
parent 2604fea483
commit 767844cacc
5 changed files with 124 additions and 22 deletions

View File

@@ -113,10 +113,10 @@ func Run(r *adb.Runner, rec *Recipe, opts Options) *RunResult {
}
func executeStep(r *adb.Runner, rec *Recipe, step Step, index int, params map[string]string,
w, h int, deadline time.Time, logf func(string, ...any)) StepResult {
w, h int, deadline time.Time, logf func(string, ...any)) (sr StepResult) {
started := time.Now()
sr := StepResult{Index: index + 1, Verb: step.Verb, Args: step.Args}
sr = StepResult{Index: index + 1, Verb: step.Verb, Args: step.Args}
defer func() {
sr.Duration = time.Since(started)
sr.DurationMS = sr.Duration.Milliseconds()
@@ -160,6 +160,33 @@ func executeStep(r *adb.Runner, rec *Recipe, step Step, index int, params map[st
sr.Detail = "launched " + pkg
return nil
case "foreground":
// Confirm the recipe's app is really in front. Without this, a text
// like "Search" can match whatever app happened to be open.
pkg := rec.App
if len(args) == 1 {
pkg = args[0]
}
if pkg == "" {
return fmt.Errorf("foreground needs an app: add an \"app:\" setting or pass a package")
}
fgDeadline := time.Now().Add(timeout)
for {
fg, ferr := ui.ForegroundPackage(r)
if ferr == nil && fg == pkg {
sr.Detail = "foreground is " + pkg
return nil
}
if time.Now().After(fgDeadline) {
got := "unknown"
if ferr == nil {
got = fg
}
return fmt.Errorf("%s never came to the foreground within %s (foreground=%s)", pkg, timeout, got)
}
time.Sleep(400 * time.Millisecond)
}
case "wait":
node, err := ui.WaitForText(r, args[0], step.Exact, timeout)
if err != nil {