feat: Phase 4 — spotify_radio, and a bound on logs/runs.jsonl
spotify_radio opens a track's own context menu and starts its song radio.
The labels came from a fresh uiautomator dump on the phone, not from a guess:
the entry is "Go to song radio" and it sits below the fold, so the recipe
scrolls before it matches.
Recipe format:
- menu_row "{query}" finds the row like tap_row, then presses the action
button inside that row's own subtree (ui.Row.Action), so the More options
button of any other row is never a candidate. It records the row as {row}.
- a step can name its own failure: wait ... else "reason". The named reason
comes first and the screen's labels still follow (FR-8).
- scroll up|down moves the current list.
- playing with no title waits for the media session to be PLAYING. A radio
changes track every few minutes, so a title match would fail on a working
radio; spotify_play still passes the title it wants.
ui:
- pickBestMatch ignores a match with no usable bounds. An element scrolled out
of its list reports [0,0][0,0], and tapping its "centre" would be a blind tap
in the corner. A wait now only succeeds once the element is on screen.
Run log (FR-10): appendRunLog rotates runs.jsonl when a write would pass
ARTEMIS_LOG_MAX_BYTES (default 1 MiB), keeping ARTEMIS_LOG_KEEP (default 5)
files. History is bounded, never deleted wholesale, and the per-entry cap of
6 screen labels of 60 characters is unchanged.
Live evidence in docs/phase-4-song-radio.md: ok:true in 56.6s, the menu that
opened belonged to the pressed row, the station name "Honky Tonk Women Radio"
on the phone, and the radio playing past its seed track (Layla) per the media
session and dumpsys audio. Both new failure modes were demonstrated failing
with distinct reasons. The mini-bar's transport label stays "Play" while
playing on this build, which is why playback is confirmed from the media
session.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
// app: com.spotify.music the package the recipe drives
|
||||
// param: query a parameter the caller must supply (repeatable)
|
||||
// row_id: com.spotify:id/row_root container id for list rows (optional)
|
||||
// row_menu: More options label of a row's own action button (optional)
|
||||
// step_timeout: 20s default per-step timeout (FR-11)
|
||||
// total_timeout: 120s whole-recipe timeout (FR-11)
|
||||
//
|
||||
@@ -34,18 +35,35 @@
|
||||
// - wait exact "Pause" 60s retry 3
|
||||
// if it never appears, re-run the step above and
|
||||
// wait again (a busy phone can drop a tap)
|
||||
// - playing "{query}" 30s retry 3
|
||||
// wait until the app's media session is PLAYING and its
|
||||
// title matches the text; with no text, wait for PLAYING
|
||||
// alone (a radio plays a different track every few minutes)
|
||||
// - wait_gone "Recents" 30s wait until no element matches the text
|
||||
// - tap "Search" tap the element whose text matches (FR-4)
|
||||
// - tap exact "Pause" tap an element whose text matches exactly
|
||||
// - tap_if "Clear search query" tap it when it is on screen, else skip
|
||||
// - tap_row "{query}" 30s tap the list row that best matches the text
|
||||
// - menu_row "{query}" 30s open the More options menu of that row
|
||||
// - scroll down scroll the current list ("down" or "up")
|
||||
// - type "{query}" type into the focused field
|
||||
// - key enter send a named key event
|
||||
// - back / home press a system key
|
||||
// - sleep 1s wait a fixed time
|
||||
//
|
||||
// A step may name its own failure reason with "else":
|
||||
//
|
||||
// - wait "Go to song radio" 20s else "this track offers no Song radio"
|
||||
//
|
||||
// {name} placeholders are replaced with the value of parameter "name". The
|
||||
// trailing "30s" on wait/tap/tap_row steps is that step's timeout.
|
||||
//
|
||||
// tap_row and menu_row also record the row they chose as "row", so a later step
|
||||
// can refer to it with {row} — for example to check that the context menu that
|
||||
// opened belongs to the row that was pressed:
|
||||
//
|
||||
// - menu_row "{query}" 40s
|
||||
// - wait "{row}" 20s else "the context menu opened on the wrong row"
|
||||
package recipe
|
||||
|
||||
import (
|
||||
@@ -65,6 +83,7 @@ type Recipe struct {
|
||||
App string
|
||||
Params []string
|
||||
RowID string
|
||||
RowMenu string
|
||||
StepTimeout time.Duration
|
||||
TotalTimeout time.Duration
|
||||
Guards []Guard
|
||||
@@ -87,13 +106,20 @@ type Step struct {
|
||||
// Retry, on a wait step, re-runs the preceding step and waits again, up to
|
||||
// this many extra times. A busy phone can drop a tap.
|
||||
Retry int
|
||||
Line int
|
||||
// Reason, when set with "else", is the step's named failure (FR-8). A wait
|
||||
// for a label a screen may simply not offer reads better as "this track
|
||||
// offers no Song radio" than as "text did not appear".
|
||||
Reason string
|
||||
Line int
|
||||
}
|
||||
|
||||
// Defaults used when a recipe does not set its own timeouts.
|
||||
// Defaults used when a recipe does not set its own timeouts or labels.
|
||||
const (
|
||||
DefaultStepTimeout = 20 * time.Second
|
||||
DefaultTotalTimeout = 120 * time.Second
|
||||
// DefaultRowMenu is the label of a row's own action button. Spotify's list
|
||||
// row action carries the content description "More options for song ...".
|
||||
DefaultRowMenu = "More options"
|
||||
)
|
||||
|
||||
// validKeys are the directive names a recipe file may use.
|
||||
@@ -103,6 +129,7 @@ var validKeys = map[string]bool{
|
||||
"app": true,
|
||||
"param": true,
|
||||
"row_id": true,
|
||||
"row_menu": true,
|
||||
"step_timeout": true,
|
||||
"total_timeout": true,
|
||||
}
|
||||
@@ -116,11 +143,13 @@ var verbs = map[string]struct {
|
||||
"launch": {0, 1, false, false},
|
||||
"foreground": {0, 1, false, false},
|
||||
"wait": {1, 2, false, true},
|
||||
"playing": {1, 2, false, false},
|
||||
"playing": {0, 2, false, false},
|
||||
"wait_gone": {1, 2, false, true},
|
||||
"tap": {1, 2, false, true},
|
||||
"tap_if": {1, 1, false, true},
|
||||
"tap_row": {1, 2, false, true},
|
||||
"menu_row": {1, 2, false, false},
|
||||
"scroll": {1, 1, false, false},
|
||||
"type": {1, 1, false, false},
|
||||
"key": {1, 1, false, false},
|
||||
"back": {0, 0, false, false},
|
||||
@@ -202,6 +231,7 @@ func Parse(src string) (*Recipe, error) {
|
||||
rec := &Recipe{
|
||||
StepTimeout: DefaultStepTimeout,
|
||||
TotalTimeout: DefaultTotalTimeout,
|
||||
RowMenu: DefaultRowMenu,
|
||||
}
|
||||
|
||||
for i, raw := range strings.Split(src, "\n") {
|
||||
@@ -262,6 +292,11 @@ func (rec *Recipe) parseDirective(line string, lineNo int) error {
|
||||
rec.Params = append(rec.Params, value)
|
||||
case "row_id":
|
||||
rec.RowID = value
|
||||
case "row_menu":
|
||||
if value == "" {
|
||||
return fmt.Errorf("line %d: row_menu needs a label", lineNo)
|
||||
}
|
||||
rec.RowMenu = value
|
||||
case "step_timeout":
|
||||
d, err := parseDuration(value)
|
||||
if err != nil {
|
||||
@@ -340,6 +375,20 @@ func parseStep(body string, lineNo int) (*Step, error) {
|
||||
break
|
||||
}
|
||||
|
||||
// "else \"reason\"" names this step's own failure, so a screen that simply
|
||||
// lacks a label can fail with the reason a human needs (FR-8).
|
||||
for i := 0; i < len(args); i++ {
|
||||
if !strings.EqualFold(args[i], "else") {
|
||||
continue
|
||||
}
|
||||
if i+1 >= len(args) {
|
||||
return nil, fmt.Errorf("line %d: else needs a reason, as in else \"that track has no radio\"", lineNo)
|
||||
}
|
||||
step.Reason = args[i+1]
|
||||
args = append(args[:i], args[i+2:]...)
|
||||
break
|
||||
}
|
||||
|
||||
// A trailing duration is the step timeout, except for sleep where the
|
||||
// duration is the step itself.
|
||||
if !spec.durArg && len(args) > spec.min {
|
||||
|
||||
Reference in New Issue
Block a user