From 81b88689f11cc8f89a59e706d57b70a24519b232 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Fri, 6 Nov 2026 11:57:38 -0800 Subject: [PATCH 1/2] fix: fail playback when the speaker omits the enqueued track Play-now called Play and ignored the error when AddURIToQueue left out FirstTrackNumberEnqueued, so the command exited 0 without selecting the new queue item. Return that omission instead. Signed-off-by: Sebastien Tardif --- CHANGELOG.md | 3 +++ internal/sonos/queue.go | 8 ++++++ internal/sonos/smapi_enqueue.go | 6 ++--- internal/sonos/smapi_enqueue_test.go | 35 ++++++++++++++++++++++++++ internal/sonos/spotify.go | 7 ++---- internal/sonos/spotify_enqueue_test.go | 34 +++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5682fe..5829ba6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased] +### Fixed +- `sonos open`, `play-spotify`, and SMAPI open no longer report success when the speaker omits the enqueued track number. Playback is not started on an unknown queue position. + ## [0.3.5] - 2026-10-23 **Highlights:** Fix the reachable crypto/x509 vulnerability GO-2026-6809 with Go 1.27.3, explain SMAPI API-client identity rejections, and correctly label initial watch events. diff --git a/internal/sonos/queue.go b/internal/sonos/queue.go index 679dea7..aaf025b 100644 --- a/internal/sonos/queue.go +++ b/internal/sonos/queue.go @@ -72,6 +72,14 @@ func (c *Client) PlayFromQueueTrack(ctx context.Context, oneBasedTrackNumber int return c.playFromQueueTrack(ctx, oneBasedTrackNumber) } +func (c *Client) startEnqueuedPlayback(ctx context.Context, firstTrack int) error { + if firstTrack <= 0 { + // The queue was not cleared, so track 1 can be an older item. + return errors.New("speaker did not report the enqueued track number") + } + return c.playFromQueueTrack(ctx, firstTrack) +} + func (c *Client) playFromQueueTrack(ctx context.Context, oneBasedTrackNumber int) error { dd, err := c.GetDeviceDescription(ctx) if err != nil { diff --git a/internal/sonos/smapi_enqueue.go b/internal/sonos/smapi_enqueue.go index 351d5f4..94254f5 100644 --- a/internal/sonos/smapi_enqueue.go +++ b/internal/sonos/smapi_enqueue.go @@ -42,12 +42,10 @@ func (c *Client) EnqueueSMAPIItem(ctx context.Context, svc MusicServiceDescripto if err != nil { return 0, err } - if opts.PlayNow && first > 0 { - if err := c.playFromQueueTrack(ctx, first); err != nil { + if opts.PlayNow { + if err := c.startEnqueuedPlayback(ctx, first); err != nil { return first, err } - } else if opts.PlayNow { - _ = c.Play(ctx) } return first, nil } diff --git a/internal/sonos/smapi_enqueue_test.go b/internal/sonos/smapi_enqueue_test.go index 0d46825..d488936 100644 --- a/internal/sonos/smapi_enqueue_test.go +++ b/internal/sonos/smapi_enqueue_test.go @@ -68,6 +68,41 @@ func TestEnqueueSMAPIItem(t *testing.T) { } } +func TestEnqueueSMAPIItem_PlayNowMissingTrackNumber(t *testing.T) { + t.Parallel() + + var actions []string + c := &Client{ + IP: "192.0.2.1", + HTTP: &http.Client{Transport: roundTripperFunc(func(r *http.Request) (*http.Response, error) { + action := r.Header.Get("SOAPACTION") + actions = append(actions, action) + if strings.Contains(action, "AddURIToQueue") { + return httpResponse(200, ``), nil + } + if strings.Contains(action, "Play") { + return httpResponse(200, ``), nil + } + t.Fatalf("unexpected action %s", action) + return nil, nil + })}, + } + + _, err := c.EnqueueSMAPIItem(context.Background(), + MusicServiceDescriptor{ID: "2311", Name: "Spotify"}, + SMAPIItem{ID: "track-1", Title: "Song"}, + EnqueueOptions{PlayNow: true}, + ) + if err == nil || !strings.Contains(err.Error(), "did not report the enqueued track number") { + t.Fatalf("error = %v", err) + } + for _, action := range actions { + if strings.Contains(action, "Play") { + t.Fatalf("started playback without a track number: %v", actions) + } + } +} + func TestEnqueueSMAPIItemValidation(t *testing.T) { t.Parallel() diff --git a/internal/sonos/spotify.go b/internal/sonos/spotify.go index 11dee37..bb3ab41 100644 --- a/internal/sonos/spotify.go +++ b/internal/sonos/spotify.go @@ -122,13 +122,10 @@ func (c *Client) EnqueueSpotify(ctx context.Context, input string, opts EnqueueO lastErr = err continue } - if opts.PlayNow && first > 0 { - if err := c.playFromQueueTrack(ctx, first); err != nil { + if opts.PlayNow { + if err := c.startEnqueuedPlayback(ctx, first); err != nil { return first, err } - } else if opts.PlayNow { - // If the speaker doesn't report a first track number, just call Play. - _ = c.Play(ctx) } return first, nil } diff --git a/internal/sonos/spotify_enqueue_test.go b/internal/sonos/spotify_enqueue_test.go index c060d9e..a76eee7 100644 --- a/internal/sonos/spotify_enqueue_test.go +++ b/internal/sonos/spotify_enqueue_test.go @@ -195,3 +195,37 @@ func TestClientEnqueueSpotify_TrackFallbacksToLegacyURI(t *testing.T) { t.Fatalf("attempted URIs mismatch: got %v want %v", attemptedURIs, expected) } } + +func TestClientEnqueueSpotify_PlayNowMissingTrackNumber(t *testing.T) { + t.Parallel() + + var actions []string + c := &Client{ + IP: "192.0.2.1", + HTTP: &http.Client{Transport: roundTripperFunc(func(r *http.Request) (*http.Response, error) { + if r.Method == http.MethodGet { + return httpResponse(200, `uuid:RINCON_ABC1400`), nil + } + action := r.Header.Get("SOAPACTION") + actions = append(actions, action) + if strings.Contains(action, "#AddURIToQueue") { + return httpResponse(200, ``), nil + } + if strings.Contains(action, "#Play") { + return httpResponse(200, ``), nil + } + t.Fatalf("unexpected SOAPACTION %q", action) + return nil, nil + })}, + } + + _, err := c.EnqueueSpotify(context.Background(), "spotify:track:abc123", EnqueueOptions{PlayNow: true}) + if err == nil || !strings.Contains(err.Error(), "did not report the enqueued track number") { + t.Fatalf("error = %v", err) + } + for _, action := range actions { + if strings.Contains(action, "#Play") || strings.Contains(action, "#Seek") { + t.Fatalf("started playback without a track number: %v", actions) + } + } +} From 161dcb7a859e8926c30824dbcc7326e660fef126 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Sat, 7 Nov 2026 14:57:41 -0800 Subject: [PATCH 2/2] fix: explain how to play a track queued without a position Playback stops before Play when the speaker omits the new queue index. The error now says the track is already queued and names sonos queue list and sonos queue play. Signed-off-by: Sebastien Tardif --- internal/sonos/queue.go | 2 +- internal/sonos/smapi_enqueue_test.go | 2 +- internal/sonos/spotify_enqueue_test.go | 30 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/internal/sonos/queue.go b/internal/sonos/queue.go index aaf025b..9e85277 100644 --- a/internal/sonos/queue.go +++ b/internal/sonos/queue.go @@ -75,7 +75,7 @@ func (c *Client) PlayFromQueueTrack(ctx context.Context, oneBasedTrackNumber int func (c *Client) startEnqueuedPlayback(ctx context.Context, firstTrack int) error { if firstTrack <= 0 { // The queue was not cleared, so track 1 can be an older item. - return errors.New("speaker did not report the enqueued track number") + return errors.New("playback was not started because the speaker did not report the new queue position; the track is already on the queue. Run sonos queue list, then sonos queue play for this speaker. Do not enqueue the track again") } return c.playFromQueueTrack(ctx, firstTrack) } diff --git a/internal/sonos/smapi_enqueue_test.go b/internal/sonos/smapi_enqueue_test.go index d488936..8a8ff8b 100644 --- a/internal/sonos/smapi_enqueue_test.go +++ b/internal/sonos/smapi_enqueue_test.go @@ -93,7 +93,7 @@ func TestEnqueueSMAPIItem_PlayNowMissingTrackNumber(t *testing.T) { SMAPIItem{ID: "track-1", Title: "Song"}, EnqueueOptions{PlayNow: true}, ) - if err == nil || !strings.Contains(err.Error(), "did not report the enqueued track number") { + if err == nil || !enqueueMissingPositionMessage(err) { t.Fatalf("error = %v", err) } for _, action := range actions { diff --git a/internal/sonos/spotify_enqueue_test.go b/internal/sonos/spotify_enqueue_test.go index a76eee7..5e29356 100644 --- a/internal/sonos/spotify_enqueue_test.go +++ b/internal/sonos/spotify_enqueue_test.go @@ -220,7 +220,7 @@ func TestClientEnqueueSpotify_PlayNowMissingTrackNumber(t *testing.T) { } _, err := c.EnqueueSpotify(context.Background(), "spotify:track:abc123", EnqueueOptions{PlayNow: true}) - if err == nil || !strings.Contains(err.Error(), "did not report the enqueued track number") { + if err == nil || !enqueueMissingPositionMessage(err) { t.Fatalf("error = %v", err) } for _, action := range actions { @@ -229,3 +229,31 @@ func TestClientEnqueueSpotify_PlayNowMissingTrackNumber(t *testing.T) { } } } + +func TestStartEnqueuedPlaybackMissingPosition(t *testing.T) { + t.Parallel() + + err := (&Client{}).startEnqueuedPlayback(context.Background(), 0) + if !enqueueMissingPositionMessage(err) { + t.Fatalf("error = %v", err) + } +} + +func enqueueMissingPositionMessage(err error) bool { + if err == nil { + return false + } + msg := err.Error() + for _, part := range []string{ + "playback was not started", + "already on the queue", + "sonos queue list", + "sonos queue play ", + "Do not enqueue the track again", + } { + if !strings.Contains(msg, part) { + return false + } + } + return true +}