Skip to content

fix(cli): fetch Spotify state only where read - #735

Merged
LargeModGames merged 3 commits into
mainfrom
fix/cli-probe-per-subcommand
Oct 10, 2026
Merged

LargeModGames merged 3 commits into
mainfrom
fix/cli-probe-per-subcommand

Conversation

@LargeModGames

@LargeModGames LargeModGames commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

Every spotatui playback, play, list and search run fetched the Spotify device list and the current playback before it looked at the subcommand. This PR makes each subcommand fetch only what it reads:

  1. A probe plan per subcommand (probe_plan in src/cli/handle.rs). search, list --playlists and list --liked fetch nothing first, so a rate limit on the device list no longer fails them. list --devices fetches the devices. play fetches both (the start seeds its shuffle state from the playback). playback fetches the devices (the saved-device retry from fix(cli): retry player commands on the saved device #465 still needs the re-pin) and fetches the playback first only for --toggle, --like, --dislike, --shuffle, --repeat and the share flags. --seek and the status line already fetch their own.
  2. The status line no longer fetches Liked Songs. get_status dispatched GetCurrentSavedTracks, which nothing read and which also started the background walk over every liked page.
  3. play --uri refuses a URI it cannot start. A clap value parser accepts spotify:track:, spotify:album:, spotify:artist:, spotify:playlist: and spotify:show: (the five kinds the command dispatches). Any other value stops in argument parsing, before boot, with exit 2 and no Spotify request. A qobuz:, file:, subsonic:, youtube:, radio: or applemusic: URI gets a message that names its scheme; any other value gets the list of accepted kinds. Before, such a URI dispatched nothing, spent five Spotify requests and printed the Spotify status line.

Deliberate behaviour changes:

  1. spotatui search, list --playlists and list --liked no longer fail when the device-list request fails.
  2. spotatui play --uri <not a Spotify track/album/artist/playlist/show URI> exits 2 with a usage error (was: exit 0 or 1 after five requests). This includes spotify:episode:, which dispatched nothing before.

Test-only change outside src/cli: the new HTTP tests share the global pacing limiter in requests.rs with every other HTTP test, and they pushed a_stalled_response_gives_up_at_the_deadline_as_a_transient_error over its 3 s bound (the pacing wait sits inside its 300 ms deadline, so its request was never sent). A #[cfg(test)] thread-local SKIP_PACING, checked first in pace_spotify_api_call, lets the three timing tests (stalled, stalled 401, 429) skip the shared queue. Production code is unchanged.

Testing

  • cargo fmt --all -- --check
  • cargo clippy -D warnings on slim, headless, headless-streaming, mcp-only, ai-dj-only, default, default + all-sources, gui: all clean
  • cargo test --no-default-features --features telemetry,tui: 1481 passed (run twice)
  • cargo test --no-default-features --features telemetry: 1032 passed
  • cargo test --no-default-features --features telemetry,tui,mcp-server: 1608 passed
  • cargo test --no-default-features --features telemetry,tui,ai-dj: 1761 passed
  • cargo test: 1887 passed
  • cargo test --features all-sources: 2067 passed, 1 failed (infra::local::tests::uri_round_trip, the known Windows-only failure)
  • cargo test on the gui leg list: 1603 passed, bindings unchanged

New tests: the probe plan for every subcommand and flag; four HTTP tests on a recording 127.0.0.1 listener (search sends no me/player request, list --devices fetches only the devices, --toggle fetches the playback twice and --next once, the status line sends no me/tracks request); the --uri parser.

Live smoke test on Windows against my Spotify account (default build): playback (status, -t, -n, -pp, --seek, --shuffle, -v, --share-track), list -d, list -p, list --liked, search -t, play -n and play -u spotify:track:... all work; play -u with qobuz:track:1, spotify:episode:1 and an https://open.spotify.com link exits 2 with the messages above.

Not run: Linux, macOS; live --like, --dislike, --repeat, --share-album, --transfer and the saved-device retry.

Additional notes

The CLI still drives Spotify only. When another spotatui process plays Local Files, Subsonic, YouTube, Qobuz or Radio, spotatui playback acts on the Spotify player, not on what you hear. Fixing that needs the CLI to ask the running spotatui, which is follow-up work.


💬 Questions or want to chat with other contributors? Join the spotatui Discord.

Summary by CodeRabbit

  • Improvements
    • CLI commands make fewer unnecessary Spotify requests: playback and device information are fetched only when needed, which can reduce delays.
    • Status updates no longer download the full Liked Songs list.
    • play --uri validates Spotify URIs before running and reports clearer errors for unsupported types, including sources that can only be played in the running app.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2c9016d5-334a-424e-9e56-335490362c78

📥 Commits

Reviewing files that changed from the base of the PR and between 80840c6 and e37773c.


📒 Files selected for processing (1)
  • CHANGELOG.md

🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.



📝 Walkthrough

Walkthrough

The CLI selects device and playback requests based on the command and flags. Status retrieval no longer requests all saved tracks. The play --uri argument parser accepts five Spotify URI prefixes and rejects unsupported inputs.

Changes

CLI behavior

Layer / File(s) Summary
Conditional Spotify state requests
src/cli/handle.rs, src/cli/cli_app.rs, src/infra/network/requests.rs, CHANGELOG.md
The CLI selects device and playback probes based on the command and playback flags. Status retrieval no longer requests all saved tracks. Tests verify request selection and use a test-only switch to bypass API pacing. The changelog records the request changes and URI validation.
Spotify URI validation
src/cli/clap.rs
The play --uri parser accepts five Spotify URI prefixes and returns errors for unsupported inputs. Help text and tests cover accepted and rejected inputs.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to e3777

The reviewed status change has no identified regression; the PR is mergeable after normal checks.

Pre-merge checks | Passed 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title uses the allowed conventional-commit prefix fix(cli):, clearly describes the main CLI change, and remains concise.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

✨ Simplify code
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LargeModGames
LargeModGames merged commit 8c5fb10 into main Oct 10, 2026
35 checks passed
@LargeModGames
LargeModGames deleted the fix/cli-probe-per-subcommand branch October 10, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant