Skip to content

feat: add and remove playlist items by position #24

Description

@rianjs

Goal

Ship the first reversible playlist mutation slice: insert tracks while preserving order and remove one exact playlist position, with live provider-contract checks and automatic fixture restoration.

Depends on #23.

Surface

  • sptfy playlists items add <playlist-reference> <track-reference>... [--position <n>]
  • sptfy playlists items remove <playlist-reference> <zero-based-position>

Constraints

  • Request the sorted public/private playlist modification scopes only when these mutations ship; stale credentials fail before mutation with the established sptfy init --overwrite hint.
  • Add accepts validated track IDs, typed track URIs, and canonical track URLs. It validates the complete batch before I/O, preserves input order and intentional duplicates, inserts at the zero-based position, and appends when --position is omitted.
  • Use Spotify's current POST /playlists/{id}/items and DELETE /playlists/{id}/items endpoints, not deprecated /tracks endpoints.
  • Chunk adds at Spotify's 100-item boundary without changing requested order or insertion position.
  • Remove identifies the current track at the requested position, uses the current snapshot, and removes it only when that source URI occurs once. If it occurs more than once, fail before mutation rather than letting Spotify remove every occurrence.
  • Reject non-track, local, unavailable, out-of-range, and stale-position cases without guessing.
  • Mutations remain unprompted because their successful output retains enough identity/position information for the inverse command. Emit compact success data only after every required request succeeds.
  • The live harness must restore the exact original playlist order on success, failure, interrupt, and cleanup failure paths.

Empirical acceptance criteria

  • A live provider-contract check demonstrates Spotify's actual URI-removal behavior for duplicate occurrences before the CLI relies on the uniqueness guard.
  • Provider tests prove exact methods/paths/bodies, snapshot propagation, append and positioned insert behavior, and 100/101 add chunking.
  • Command tests prove add-at-start/middle/end, append, duplicate preservation, exact unique-position removal, and inverse-command output.
  • Duplicate-source removal, stale/out-of-range positions, invalid references, missing scopes, and complete-batch validation failures make no unintended mutation request.
  • The opt-in live smoke inserts a known track at a known position, verifies the exact resulting order, removes that exact position, and verifies byte-for-byte restoration of the original ordered IDs.
  • Static live-smoke tests prove cleanup runs and restoration failures fail the smoke.
  • make check, make snapshot, and the opt-in add/remove round trip pass with the fixture restored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions