mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-18 07:30:29 +00:00
* refactor(persistence): adopt generic deluan/rest repository API Pin deluan/rest to the refactor branch. REST-facing repository methods take a context and return typed values. Drop DataStore.Resource and ResourceRepository; the native API names typed repositories directly through a per-request adapter that later commits remove. * refactor(persistence): base repository helpers take a context * refactor(persistence): LibraryRepository takes a context per call * refactor(persistence): PropertyRepository takes a context per call * refactor(persistence): UserPropsRepository takes a context per call * refactor(persistence): TranscodingRepository takes a context per call * refactor(persistence): ShareRepository takes a context per call * refactor(persistence): PlayerRepository takes a context per call * refactor(persistence): RadioRepository takes a context per call * refactor(persistence): PlayQueueRepository takes a context per call * refactor(persistence): Tag and Genre repositories take a context per call * refactor(persistence): PluginRepository takes a context per call * refactor(persistence): Scrobble repositories take a context per call * refactor(persistence): FolderRepository takes a context per call * refactor(persistence): Artwork repositories take a context per call * refactor(persistence): UserRepository takes a context per call * refactor(persistence): ArtistRepository takes a context per call ReadAll no longer rewrites the shared sort mappings for the role filter; it works on a per-call copy. * test(persistence): assert artist role sort sanitization in ReadAll * refactor(persistence): AlbumRepository takes a context per call * test(persistence): pass the test context to album repository helpers * refactor(persistence): MediaFileRepository takes a context per call * refactor(persistence): Playlist repositories take a context per call * refactor(persistence): build all repositories once per store * refactor(core): REST repository wrappers are built once * refactor(persistence): repositories are stateless Remove the context field from the base repository and the per-request REST adapter. Enable the containedctx linter so no repository can hold a request context again. * chore(lint): skip containedctx in test files * refactor: share simplifications from the stateless repositories sweep Add deleteOwnedAll on sqlRepository and use it in player/share Delete to remove the duplicated bulk-delete loop; have Share.Repository() return model.ShareRepository so subsonic sharing.go drops its repeated type assertions. * chore(core): assert REST wrappers implement Persistable * chore: reformat imports * perf(persistence): build repositories on first use Each transaction store used to construct all 21 repositories up front, paying for filter and sort mapping setup the block never touched. Fields are now sync.OnceValue thunks, so a store only builds what it uses. * fix(persistence): clean plugin references per deleted user A bulk user delete that fails on a later id had already removed the earlier rows but skipped their plugin cleanup. Cleanup now runs right after each successful delete. * fix(core): unload disabled plugins even when a user delete fails A bulk delete can fail on a later id after earlier users were removed and their plugins auto-disabled. The wrapper returned before unloading, leaving those plugins running until the next successful delete or a restart. * chore(deps): pin deluan/rest to v1.0.1 Replaces the pseudo-version of the refactor branch with the tagged release. REST error messages now name the bare type (Artist, not model.Artist). * test: use the spec context instead of context.Background() Replace the context.Background()/context.TODO() calls this branch added to tests with the spec's ctx, GinkgoT().Context(), or t/b.Context(), so repository calls are bound to the running spec's lifetime. * test: declare the spec context once per Describe Set ctx from GinkgoT().Context() first in each top-level BeforeEach and reuse it, building user contexts on top of it instead of repeating inline calls.
292 lines
12 KiB
Go
292 lines
12 KiB
Go
package e2e
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing/fstest"
|
|
|
|
"github.com/Masterminds/squirrel"
|
|
"github.com/navidrome/navidrome/conf"
|
|
"github.com/navidrome/navidrome/consts"
|
|
"github.com/navidrome/navidrome/core/artwork"
|
|
"github.com/navidrome/navidrome/model"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
// Doc reference:
|
|
// https://www.navidrome.org/docs/usage/library/artwork/#artists
|
|
// Default ArtistArtPriority is "artist.*, album/artist.*, external".
|
|
// Library-folder images are file-backed (asserted on the worker state row); uploaded and
|
|
// image-folder images are real files on disk (asserted byte-for-byte).
|
|
var _ = Describe("Artist artwork resolution", func() {
|
|
BeforeEach(func() {
|
|
setupResolutionHarness()
|
|
})
|
|
|
|
When("the artist folder contains an artist.jpg", func() {
|
|
// Artist/
|
|
// ├── artist.jpg ← matched by artist.*
|
|
// └── Album/
|
|
// └── 01 - Track.mp3
|
|
It("returns the artist.* image from the artist folder", func() {
|
|
conf.Server.ArtistArtPriority = "artist.*, album/artist.*, external"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album/01 - Track.mp3": trackFile(1, "Track", map[string]any{"albumartist": "Artist"}),
|
|
"Artist/artist.jpg": smallPNG("artist-folder"),
|
|
})
|
|
scan()
|
|
expectArtistFolder(soleArtist(), "Artist/artist.jpg")
|
|
})
|
|
})
|
|
|
|
When("artist.* only exists inside an album folder", func() {
|
|
// Artist/
|
|
// └── Album/
|
|
// ├── 01 - Track.mp3
|
|
// └── artist.jpg ← matched by album/artist.*
|
|
It("falls through to album/artist.* and returns that image", func() {
|
|
conf.Server.ArtistArtPriority = "artist.*, album/artist.*, external"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album/01 - Track.mp3": trackFile(1, "Track", map[string]any{"albumartist": "Artist"}),
|
|
"Artist/Album/artist.jpg": smallPNG("album-artist"),
|
|
})
|
|
scan()
|
|
expectArtistFolder(soleArtist(), "Artist/Album/artist.jpg")
|
|
})
|
|
})
|
|
|
|
When("both the artist folder and an album folder have an artist.* image", func() {
|
|
// Artist/
|
|
// ├── artist.jpg ← wins (artist.* before album/artist.*)
|
|
// └── Album/
|
|
// ├── 01 - Track.mp3
|
|
// └── artist.jpg
|
|
It("prefers the artist-folder image (artist.* comes before album/artist.*)", func() {
|
|
conf.Server.ArtistArtPriority = "artist.*, album/artist.*, external"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album/01 - Track.mp3": trackFile(1, "Track", map[string]any{"albumartist": "Artist"}),
|
|
"Artist/artist.jpg": smallPNG("artist-folder"),
|
|
"Artist/Album/artist.jpg": smallPNG("album-artist"),
|
|
})
|
|
scan()
|
|
expectArtistFolder(soleArtist(), "Artist/artist.jpg")
|
|
})
|
|
})
|
|
|
|
When("ArtistArtPriority has no album/ fallback", func() {
|
|
// Artist/
|
|
// ├── artist.jpg ← must resolve via the artist folder itself
|
|
// └── Album/
|
|
// └── 01 - Track.mp3
|
|
It("still resolves the artist folder and returns artist.*", func() {
|
|
conf.Server.ArtistArtPriority = "artist.*"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album/01 - Track.mp3": trackFile(1, "Track", map[string]any{"albumartist": "Artist"}),
|
|
"Artist/artist.jpg": smallPNG("artist-folder"),
|
|
})
|
|
scan()
|
|
expectArtistFolder(soleArtist(), "Artist/artist.jpg")
|
|
})
|
|
})
|
|
|
|
When("the artist's only album folder has no images of its own", func() {
|
|
// Artist/
|
|
// ├── backdrop1.jpg
|
|
// ├── folder.jpg ← matched by folder.*
|
|
// ├── logo.png
|
|
// └── Album/
|
|
// ├── 01 - Track.mp3
|
|
// └── 02 - Track.mp3
|
|
It("resolves the artist folder, not the library root", func() {
|
|
conf.Server.ArtistArtPriority = "folder.*, artist.*, album/artist.*"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album/01 - Track.mp3": trackFile(1, "Track 1", map[string]any{"albumartist": "Artist", "album": "Album"}),
|
|
"Artist/Album/02 - Track.mp3": trackFile(2, "Track 2", map[string]any{"albumartist": "Artist", "album": "Album"}),
|
|
"Artist/backdrop1.jpg": smallPNG("backdrop"),
|
|
"Artist/folder.jpg": smallPNG("artist-folder"),
|
|
"Artist/logo.png": smallPNG("logo"),
|
|
})
|
|
scan()
|
|
expectArtistFolder(soleArtist(), "Artist/folder.jpg")
|
|
})
|
|
})
|
|
|
|
When("the artist's only album has its tracks in disc subfolders", func() {
|
|
// Artist/
|
|
// ├── artist.jpg ← wins (artist.* before album/artist.*)
|
|
// └── Album/
|
|
// ├── artist.jpg
|
|
// ├── CD1/01 - Track.mp3
|
|
// └── CD2/02 - Track.mp3
|
|
It("prefers the artist-folder image over the album-folder one", func() {
|
|
conf.Server.ArtistArtPriority = "artist.*, album/artist.*, external"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album/CD1/01 - Track.mp3": trackFile(1, "Track 1", map[string]any{"albumartist": "Artist", "album": "Album"}),
|
|
"Artist/Album/CD2/02 - Track.mp3": trackFile(2, "Track 2", map[string]any{"albumartist": "Artist", "album": "Album"}),
|
|
"Artist/artist.jpg": smallPNG("artist-folder"),
|
|
"Artist/Album/artist.jpg": smallPNG("album-artist"),
|
|
})
|
|
scan()
|
|
expectArtistFolder(soleArtist(), "Artist/artist.jpg")
|
|
})
|
|
})
|
|
|
|
When("one album has disc subfolders and another sits at artist level", func() {
|
|
// Artist/
|
|
// ├── artist.jpg ← wins
|
|
// ├── Album1/
|
|
// │ ├── artist.jpg
|
|
// │ ├── CD1/01 - Track.mp3
|
|
// │ └── CD2/02 - Track.mp3
|
|
// └── Album2/03 - Track.mp3
|
|
It("prefers the artist-folder image over the album-folder one", func() {
|
|
conf.Server.ArtistArtPriority = "artist.*, album/artist.*, external"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album1/CD1/01 - Track.mp3": trackFile(1, "Track 1", map[string]any{"albumartist": "Artist", "album": "Album1"}),
|
|
"Artist/Album1/CD2/02 - Track.mp3": trackFile(2, "Track 2", map[string]any{"albumartist": "Artist", "album": "Album1"}),
|
|
"Artist/Album2/03 - Track.mp3": trackFile(3, "Track 3", map[string]any{"albumartist": "Artist", "album": "Album2"}),
|
|
"Artist/artist.jpg": smallPNG("artist-folder"),
|
|
"Artist/Album1/artist.jpg": smallPNG("album-artist"),
|
|
})
|
|
scan()
|
|
expectArtistFolder(soleArtist(), "Artist/artist.jpg")
|
|
})
|
|
})
|
|
|
|
When("every album of the artist has its tracks in disc subfolders", func() {
|
|
// Artist/
|
|
// ├── artist.jpg ← wins
|
|
// ├── Album1/
|
|
// │ ├── artist.jpg
|
|
// │ ├── CD1/01 - Track.mp3
|
|
// │ └── CD2/02 - Track.mp3
|
|
// └── Album2/
|
|
// ├── CD1/03 - Track.mp3
|
|
// └── CD2/04 - Track.mp3
|
|
It("prefers the artist-folder image over the album-folder one", func() {
|
|
conf.Server.ArtistArtPriority = "artist.*, album/artist.*, external"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album1/CD1/01 - Track.mp3": trackFile(1, "Track 1", map[string]any{"albumartist": "Artist", "album": "Album1"}),
|
|
"Artist/Album1/CD2/02 - Track.mp3": trackFile(2, "Track 2", map[string]any{"albumartist": "Artist", "album": "Album1"}),
|
|
"Artist/Album2/CD1/03 - Track.mp3": trackFile(3, "Track 3", map[string]any{"albumartist": "Artist", "album": "Album2"}),
|
|
"Artist/Album2/CD2/04 - Track.mp3": trackFile(4, "Track 4", map[string]any{"albumartist": "Artist", "album": "Album2"}),
|
|
"Artist/artist.jpg": smallPNG("artist-folder"),
|
|
"Artist/Album1/artist.jpg": smallPNG("album-artist"),
|
|
})
|
|
scan()
|
|
expectArtistFolder(soleArtist(), "Artist/artist.jpg")
|
|
})
|
|
})
|
|
|
|
When("an artist has an uploaded image and a matching artist.* file", func() {
|
|
// <DataFolder>/
|
|
// └── artwork/
|
|
// └── artist/
|
|
// └── <id>_upload.jpg ← wins (uploaded image beats the priority chain)
|
|
// Library:
|
|
// Artist/
|
|
// ├── artist.jpg (ignored — uploaded image comes first)
|
|
// └── Album/
|
|
// └── 01 - Track.mp3
|
|
It("prefers the uploaded image over any priority-chain match", func() {
|
|
conf.Server.ArtistArtPriority = "artist.*, album/artist.*, external"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album/01 - Track.mp3": trackFile(1, "Track", map[string]any{"albumartist": "Artist"}),
|
|
"Artist/artist.jpg": smallPNG("artist-folder"),
|
|
})
|
|
scan()
|
|
ar := soleArtist()
|
|
|
|
uploaded := ar.ID + "_upload.jpg"
|
|
writeUploadedImage(consts.EntityArtist, uploaded, pngBytes("artist-uploaded"))
|
|
ar.UploadedImage = uploaded
|
|
Expect(rds.Artist().Put(rctx, &ar)).To(Succeed())
|
|
|
|
ia := acquire(model.KindArtistArtwork, ar.ID)
|
|
Expect(ia.Source).To(Equal("upload"))
|
|
Expect(serveBytes(model.NewArtworkID(model.KindArtistArtwork, ar.ID, nil))).To(Equal(pngBytes("artist-uploaded")))
|
|
})
|
|
})
|
|
|
|
When("ArtistArtPriority uses album/<arbitrary pattern> (not just album/artist.*)", func() {
|
|
// Artist/
|
|
// └── Album/
|
|
// ├── 01 - Track.mp3
|
|
// └── artist.jpg ← matched by album/artist.*
|
|
It("resolves the pattern against the artist's album image files", func() {
|
|
conf.Server.ArtistArtPriority = "album/artist.*, external"
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album/01 - Track.mp3": trackFile(1, "Track", map[string]any{"albumartist": "Artist"}),
|
|
"Artist/Album/artist.jpg": smallPNG("album-artist"),
|
|
})
|
|
scan()
|
|
expectArtistFolder(soleArtist(), "Artist/Album/artist.jpg")
|
|
})
|
|
})
|
|
|
|
// resolveArtist only samples albums where this artist is the SOLE album artist, so a
|
|
// collaboration or compilation never donates its images as the artist's own.
|
|
When("the artist's only album is credited to two album artists", func() {
|
|
// Artist/
|
|
// └── Collab Album/ (album artists: "Artist" + a collaborator)
|
|
// ├── 01 - Track.mp3
|
|
// └── artist.jpg ← must NOT become the artist image
|
|
It("ignores the album's images and settles absent", func() {
|
|
conf.Server.ArtistArtPriority = "album/artist.*"
|
|
// " / " is a default artists split separator, so this single tag yields two album artists.
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Collab Album/01 - Track.mp3": trackFile(1, "Track", map[string]any{"albumartist": "Artist / Collaborator"}),
|
|
"Artist/Collab Album/artist.jpg": smallPNG("collab-artist"),
|
|
})
|
|
scan()
|
|
Expect(firstAlbum().Participants[model.RoleAlbumArtist]).To(HaveLen(2),
|
|
"sanity check: the album must be credited to two album artists")
|
|
|
|
ar := soleArtist()
|
|
ia := acquire(model.KindArtistArtwork, ar.ID)
|
|
Expect(ia.Hash).To(BeEmpty())
|
|
Expect(serveErr(model.NewArtworkID(model.KindArtistArtwork, ar.ID, nil))).
|
|
To(MatchError(artwork.ErrUnavailable))
|
|
})
|
|
})
|
|
|
|
When("ArtistArtPriority starts with image-folder and ArtistImageFolder has a name-matching image", func() {
|
|
// <ArtistImageFolder>/
|
|
// └── Artist.jpg ← matched by artist name (image-folder source)
|
|
// Library:
|
|
// Artist/
|
|
// └── Album/
|
|
// └── 01 - Track.mp3 (no artist.* present in library)
|
|
It("returns the image from the configured artist image folder", func() {
|
|
imgFolder := GinkgoT().TempDir()
|
|
Expect(os.WriteFile(filepath.Join(imgFolder, "Artist.jpg"), pngBytes("image-folder"), 0o600)).To(Succeed())
|
|
conf.Server.ArtistImageFolder = imgFolder
|
|
conf.Server.ArtistArtPriority = "image-folder, artist.*, album/artist.*"
|
|
|
|
setLayout(fstest.MapFS{
|
|
"Artist/Album/01 - Track.mp3": trackFile(1, "Track", map[string]any{"albumartist": "Artist"}),
|
|
})
|
|
scan()
|
|
|
|
ar := soleArtist()
|
|
ia := acquire(model.KindArtistArtwork, ar.ID)
|
|
Expect(ia.Source).To(Equal("folder"))
|
|
Expect(serveBytes(model.NewArtworkID(model.KindArtistArtwork, ar.ID, nil))).To(Equal(pngBytes("image-folder")))
|
|
})
|
|
})
|
|
})
|
|
|
|
func soleArtist() model.Artist {
|
|
GinkgoHelper()
|
|
artists, err := rds.Artist().GetAll(rctx, model.QueryOptions{
|
|
Filters: squirrel.Eq{"artist.name": "Artist"},
|
|
})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
if len(artists) == 0 {
|
|
Fail("sole artist not found")
|
|
return model.Artist{}
|
|
}
|
|
return artists[0]
|
|
}
|