Repository navigation
Conversation
The player subcommands parsed their arguments as unrestricted integers, so negative seek positions and out-of-range volumes reached account setup and the Connect connection before Player.seek() or Player.volume() rejected them. Validate both at argparse level with small local type functions that report the accepted range and exit with status 2. The library-level checks remain as the safety boundary. Tests cover negative seek, volume below zero and above 100, and the 0/100 boundaries, and assert invalid input never opens a session.
Author
|
Closing this for now: CONTRIBUTING.md asks contributors to wait for the issue to be assigned before opening a PR, and #87 is still unassigned. The work is ready on the fork branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
spotapi player seekandspotapi player volumeaccepted any integer at the CLI layer, so negative seek positions and volumes outside 0–100 were only rejected after the CLI had readSPOTIFY_COOKIE, authorized an account, opened a Connect player, and reachedPlayer.seek()/Player.volume().Fixes #87
Root cause
The argparse entries for the two player subcommands used
type=int. The library validates both values, but that validation lives below account and session setup, so obviously invalid input paid the connection cost and surfaced the error at the wrong layer.Fix
Added two small local argparse type functions in
spotapi/cli.py:_seek_position: requires an integer >= 0, otherwise reportschoose a non-negative number of milliseconds._volume: requires an integer from 0 through 100, otherwise reportschoose a number from 0 to 100.Both raise
argparse.ArgumentTypeError, so argparse prints the usage line plus the range message and exits with status 2 beforemain()reaches_run. The existing validation insidePlayer.seek()andPlayer.volume()is unchanged as the library-level safety boundary.Testing
New offline tests:
test_cli_rejects_invalid_player_values_before_connectingcovers seek-1, volume-1and volume101; asserts exit status 2, the range message, and thatPrivate.from_cookiesis never called.test_cli_accepts_player_boundary_valuescovers seek0, volume0and volume100, asserting the value reaches the player method unchanged.Before the fix, the three rejection cases reached
_runand failed withSet SPOTIFY_COOKIE...; after the fix they exit during parsing.