Skip to content

refactor(output): shared table/ID renderers and generic field selection - #42

Merged
rianjs merged 3 commits into
mainfrom
refactor/32-output-dedup
Jul 25, 2026
Merged

rianjs merged 3 commits into
mainfrom
refactor/32-output-dedup

Conversation

@rianjs

@rianjs rianjs commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • share generic table and ID render loops across track, album, artist, saved-item, and playlist output
  • share generic field selection and field-name formatting across track, album, artist, and playlist output
  • remove saved-only cases from base cell renderers and temporary saved-item ID slices

LOC delta: +114/-322 (net -208)

Playlist scope

  • playlist tables, playlist IDs, and playlist field selection use the shared helpers
  • playlist-item rendering remains separate because cells depend on row offset/position, and its ID output intentionally skips missing IDs

Verification

  • go build ./...
  • go vet ./...
  • make test
  • golangci-lint run

Closes #32

@rianjs

rianjs commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

TDD assessment

Verdict: insufficient.

The observable rendering paths are otherwise well pinned:

  • Table shape is covered for track, album, artist, and playlist with exact byte strings, including headers, | delimiters, trailing newlines, and header-only empty pages. The album/artist empty cases are exercised through search command tests; track and playlist also have direct output tests.
  • Saved-track and saved-album tests pin both the ADDED_AT header and a rendered timestamp value.
  • Removing the TrackAddedAt and AlbumAddedAt cases from trackCell/albumCell is observationally neutral: each deleted case returned -, exactly as the unchanged default branch does. Saved values still route through savedTrackCell/savedAlbumCell and are covered.
  • Saved IDs are pinned: the track library --id test exercises RenderSavedTrackIDs; saved albums are covered both directly and through library --id. The allocation removal therefore has output coverage.

The gap is the four family-specific unknown-field messages. Existing tests only use strings.Contains on the valid fields: suffix, so all would pass if the shared helper supplied the wrong noun. In particular, playlist does not pin unknown playlist field.

Cheapest fix: strengthen the existing assertions in internal/output/track_test.go (TestTrackProjectionRejectsUnknownAndIDsHaveNoHeader), internal/output/catalog_test.go (TestRenderAlbumsShapes and TestRenderArtistsShapes), and internal/output/playlist_test.go (TestPlaylistFieldsAndRendering) to compare the full errors:

  • unknown track field "nope"; valid fields: ID, TRACK, ARTIST_IDS, ARTISTS, ALBUM_ID, ALBUM, DURATION, URI, URL, DISC_NUMBER, TRACK_NUMBER, EXPLICIT, RESTRICTION, ARTWORK
  • unknown album field "nope"; valid fields: ID, ALBUM, ARTIST_IDS, ARTISTS, RELEASE_DATE, TOTAL_TRACKS, URI, URL, ALBUM_TYPE, RELEASE_DATE_PRECISION, RESTRICTION, ARTWORK
  • unknown artist field "nope"; valid fields: ID, ARTIST, URI, URL, ARTWORK
  • unknown playlist field "nope"; valid fields: ID, PLAYLIST, OWNER_ID, OWNER, ITEM_COUNT, PUBLIC, COLLABORATIVE, URI, URL, SNAPSHOT_ID, DESCRIPTION, ARTWORK

No new test functions or helper-level tests are needed. Current suite passes: 472 tests across 22 packages.

@rianjs
rianjs merged commit 5b8f73f into main Jul 25, 2026
9 checks passed
@rianjs
rianjs deleted the refactor/32-output-dedup branch July 25, 2026 16:12
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.

refactor(output): shared table/ID renderers and generic field selection

1 participant