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

@@ -6,6 +6,8 @@ import (
"strings"
"testing"
"time"
"gitea.lab.audasmedia.com.au/sam/artemis_control/internal/adb"
)
const sample = `# a comment
@@ -155,7 +157,17 @@ func TestSpotifyRecipeIsValid(t *testing.T) {
t.Fatalf("step %d uses unknown verb %q", i+1, s.Verb)
}
}
// The recipe must wait for playback, not assume it.
// The recipe must confirm it is in Spotify before it trusts a text match,
// and it must wait for playback rather than assume it.
var sawForeground bool
for _, s := range rec.Steps {
if s.Verb == "foreground" {
sawForeground = true
}
}
if !sawForeground {
t.Fatal("spotify_play must pin the foreground app before matching text")
}
last := rec.Steps[len(rec.Steps)-1]
if last.Verb != "wait" || last.Args[0] != "Pause" {
t.Fatalf("the last step must confirm playback, got %+v", last)
@@ -192,3 +204,31 @@ func TestLoadAndList(t *testing.T) {
t.Fatalf("Find unknown task: %v", err)
}
}
func TestForegroundStep(t *testing.T) {
rec, err := Parse("app: com.spotify.music\nsteps:\n - launch\n - foreground 30s\n")
if err != nil {
t.Fatalf("Parse: %v", err)
}
fg := rec.Steps[1]
if fg.Verb != "foreground" || len(fg.Args) != 0 || fg.Timeout != 30*time.Second {
t.Fatalf("foreground step = %+v", fg)
}
}
// TestStepDurationsAreRecorded guards the run log (FR-10): a step's duration
// must reach the caller, not be swallowed by the return value.
func TestStepDurationsAreRecorded(t *testing.T) {
rec := &Recipe{StepTimeout: time.Second}
step := Step{Verb: "sleep", Timeout: 50 * time.Millisecond}
sr := executeStep(adb.New(""), rec, step, 2, nil, 0, 0, time.Now().Add(time.Minute), func(string, ...any) {})
if !sr.OK {
t.Fatalf("sleep step failed: %s", sr.Error)
}
if sr.Index != 3 {
t.Fatalf("index = %d, want 3", sr.Index)
}
if sr.Duration < 40*time.Millisecond || sr.DurationMS < 40 {
t.Fatalf("duration not recorded: %v (%d ms)", sr.Duration, sr.DurationMS)
}
}