update
Some checks failed
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v5) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v6) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v7) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to GHCR (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Has been cancelled
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
POEditor import / update-translations (push) Has been cancelled

This commit is contained in:
2025-12-08 16:16:23 +01:00
commit c251f174ed
1349 changed files with 194301 additions and 0 deletions

1
plugins/testdata/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.wasm

10
plugins/testdata/Makefile vendored Normal file
View File

@@ -0,0 +1,10 @@
# Fake sample plugins used for testing
PLUGINS := fake_album_agent fake_artist_agent fake_scrobbler multi_plugin fake_init_service unauthorized_plugin
all: $(PLUGINS:%=%/plugin.wasm)
clean:
rm -f $(PLUGINS:%=%/plugin.wasm)
%/plugin.wasm: %/plugin.go
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o $@ ./$*

17
plugins/testdata/README.md vendored Normal file
View File

@@ -0,0 +1,17 @@
# Plugin Test Data
This directory contains test data and mock implementations used for testing the Navidrome plugin system.
## Contents
Each of these directories contains the source code for a simple Go plugin that implements a specific agent interface
(or multiple interfaces in the case of `multi_plugin`). These are compiled into WASM modules using the
`Makefile` and used in integration tests for the plugin adapters (e.g., `adapter_media_agent_test.go`).
Running `make` within this directory will build all test plugins.
## Usage
The primary use of this directory is during the development and testing phase. The `Makefile` is used to build the
necessary WASM plugin binaries. The tests within the `plugins` package (and potentially other packages that interact
with plugins) then utilize these compiled plugins and other test fixtures found here.

View File

@@ -0,0 +1,9 @@
{
"name": "fake_album_agent",
"author": "Navidrome Test",
"version": "1.0.0",
"description": "Test data for album agent",
"website": "https://test.navidrome.org/fake-album-agent",
"capabilities": ["MetadataAgent"],
"permissions": {}
}

View File

@@ -0,0 +1,70 @@
//go:build wasip1
package main
import (
"context"
"github.com/navidrome/navidrome/plugins/api"
)
type FakeAlbumAgent struct{}
var ErrNotFound = api.ErrNotFound
func (FakeAlbumAgent) GetAlbumInfo(ctx context.Context, req *api.AlbumInfoRequest) (*api.AlbumInfoResponse, error) {
if req.Name != "" && req.Artist != "" {
return &api.AlbumInfoResponse{
Info: &api.AlbumInfo{
Name: req.Name,
Mbid: "album-mbid-123",
Description: "This is a test album description",
Url: "https://example.com/album",
},
}, nil
}
return nil, ErrNotFound
}
func (FakeAlbumAgent) GetAlbumImages(ctx context.Context, req *api.AlbumImagesRequest) (*api.AlbumImagesResponse, error) {
if req.Name != "" && req.Artist != "" {
return &api.AlbumImagesResponse{
Images: []*api.ExternalImage{
{Url: "https://example.com/album1.jpg", Size: 300},
{Url: "https://example.com/album2.jpg", Size: 400},
},
}, nil
}
return nil, ErrNotFound
}
func (FakeAlbumAgent) GetArtistMBID(ctx context.Context, req *api.ArtistMBIDRequest) (*api.ArtistMBIDResponse, error) {
return nil, api.ErrNotImplemented
}
func (FakeAlbumAgent) GetArtistURL(ctx context.Context, req *api.ArtistURLRequest) (*api.ArtistURLResponse, error) {
return nil, api.ErrNotImplemented
}
func (FakeAlbumAgent) GetArtistBiography(ctx context.Context, req *api.ArtistBiographyRequest) (*api.ArtistBiographyResponse, error) {
return nil, api.ErrNotImplemented
}
func (FakeAlbumAgent) GetSimilarArtists(ctx context.Context, req *api.ArtistSimilarRequest) (*api.ArtistSimilarResponse, error) {
return nil, api.ErrNotImplemented
}
func (FakeAlbumAgent) GetArtistImages(ctx context.Context, req *api.ArtistImageRequest) (*api.ArtistImageResponse, error) {
return nil, api.ErrNotImplemented
}
func (FakeAlbumAgent) GetArtistTopSongs(ctx context.Context, req *api.ArtistTopSongsRequest) (*api.ArtistTopSongsResponse, error) {
return nil, api.ErrNotImplemented
}
func main() {}
// Register the plugin implementation
func init() {
api.RegisterMetadataAgent(FakeAlbumAgent{})
}

View File

@@ -0,0 +1,9 @@
{
"name": "fake_artist_agent",
"author": "Navidrome Test",
"version": "1.0.0",
"description": "Test data for artist agent",
"website": "https://test.navidrome.org/fake-artist-agent",
"capabilities": ["MetadataAgent"],
"permissions": {}
}

View File

@@ -0,0 +1,82 @@
//go:build wasip1
package main
import (
"context"
"github.com/navidrome/navidrome/plugins/api"
)
type FakeArtistAgent struct{}
var ErrNotFound = api.ErrNotFound
func (FakeArtistAgent) GetArtistMBID(ctx context.Context, req *api.ArtistMBIDRequest) (*api.ArtistMBIDResponse, error) {
if req.Name != "" {
return &api.ArtistMBIDResponse{Mbid: "1234567890"}, nil
}
return nil, ErrNotFound
}
func (FakeArtistAgent) GetArtistURL(ctx context.Context, req *api.ArtistURLRequest) (*api.ArtistURLResponse, error) {
if req.Name != "" {
return &api.ArtistURLResponse{Url: "https://example.com"}, nil
}
return nil, ErrNotFound
}
func (FakeArtistAgent) GetArtistBiography(ctx context.Context, req *api.ArtistBiographyRequest) (*api.ArtistBiographyResponse, error) {
if req.Name != "" {
return &api.ArtistBiographyResponse{Biography: "This is a test biography"}, nil
}
return nil, ErrNotFound
}
func (FakeArtistAgent) GetSimilarArtists(ctx context.Context, req *api.ArtistSimilarRequest) (*api.ArtistSimilarResponse, error) {
if req.Name != "" {
return &api.ArtistSimilarResponse{
Artists: []*api.Artist{
{Name: "Similar Artist 1", Mbid: "mbid1"},
{Name: "Similar Artist 2", Mbid: "mbid2"},
},
}, nil
}
return nil, ErrNotFound
}
func (FakeArtistAgent) GetArtistImages(ctx context.Context, req *api.ArtistImageRequest) (*api.ArtistImageResponse, error) {
if req.Name != "" {
return &api.ArtistImageResponse{
Images: []*api.ExternalImage{
{Url: "https://example.com/image1.jpg", Size: 100},
{Url: "https://example.com/image2.jpg", Size: 200},
},
}, nil
}
return nil, ErrNotFound
}
func (FakeArtistAgent) GetArtistTopSongs(ctx context.Context, req *api.ArtistTopSongsRequest) (*api.ArtistTopSongsResponse, error) {
if req.ArtistName != "" {
return &api.ArtistTopSongsResponse{
Songs: []*api.Song{
{Name: "Song 1", Mbid: "mbid1"},
{Name: "Song 2", Mbid: "mbid2"},
},
}, nil
}
return nil, ErrNotFound
}
// Add empty implementations for the album methods to satisfy the MetadataAgent interface
func (FakeArtistAgent) GetAlbumInfo(ctx context.Context, req *api.AlbumInfoRequest) (*api.AlbumInfoResponse, error) {
return nil, api.ErrNotImplemented
}
func (FakeArtistAgent) GetAlbumImages(ctx context.Context, req *api.AlbumImagesRequest) (*api.AlbumImagesResponse, error) {
return nil, api.ErrNotImplemented
}
// main is required by Go WASI build
func main() {}
// init is used by go-plugin to register the implementation
func init() {
api.RegisterMetadataAgent(FakeArtistAgent{})
}

View File

@@ -0,0 +1,9 @@
{
"name": "fake_init_service",
"version": "1.0.0",
"capabilities": ["LifecycleManagement"],
"author": "Test Author",
"description": "Test LifecycleManagement Callback",
"website": "https://test.navidrome.org/fake-init-service",
"permissions": {}
}

View File

@@ -0,0 +1,42 @@
//go:build wasip1
package main
import (
"context"
"errors"
"log"
"github.com/navidrome/navidrome/plugins/api"
)
type initServicePlugin struct{}
func (p *initServicePlugin) OnInit(ctx context.Context, req *api.InitRequest) (*api.InitResponse, error) {
log.Printf("OnInit called with %v", req)
// Check for specific error conditions in the config
if req.Config != nil {
if errorType, exists := req.Config["returnError"]; exists {
switch errorType {
case "go_error":
return nil, errors.New("initialization failed with Go error")
case "response_error":
return &api.InitResponse{
Error: "initialization failed with response error",
}, nil
}
}
}
// Default: successful initialization
return &api.InitResponse{}, nil
}
// Required by Go WASI build
func main() {}
// Register the LifecycleManagement implementation
func init() {
api.RegisterLifecycleManagement(&initServicePlugin{})
}

View File

@@ -0,0 +1,9 @@
{
"name": "fake_scrobbler",
"author": "Navidrome Test",
"version": "1.0.0",
"description": "Test data for scrobbler",
"website": "https://test.navidrome.org/fake-scrobbler",
"capabilities": ["Scrobbler"],
"permissions": {}
}

View File

@@ -0,0 +1,33 @@
//go:build wasip1
package main
import (
"context"
"log"
"github.com/navidrome/navidrome/plugins/api"
)
type FakeScrobbler struct{}
func (FakeScrobbler) IsAuthorized(ctx context.Context, req *api.ScrobblerIsAuthorizedRequest) (*api.ScrobblerIsAuthorizedResponse, error) {
log.Printf("[FakeScrobbler] IsAuthorized called for user: %s (%s)", req.Username, req.UserId)
return &api.ScrobblerIsAuthorizedResponse{Authorized: true}, nil
}
func (FakeScrobbler) NowPlaying(ctx context.Context, req *api.ScrobblerNowPlayingRequest) (*api.ScrobblerNowPlayingResponse, error) {
log.Printf("[FakeScrobbler] NowPlaying called for user: %s (%s), track: %s", req.Username, req.UserId, req.Track.Name)
return &api.ScrobblerNowPlayingResponse{}, nil
}
func (FakeScrobbler) Scrobble(ctx context.Context, req *api.ScrobblerScrobbleRequest) (*api.ScrobblerScrobbleResponse, error) {
log.Printf("[FakeScrobbler] Scrobble called for user: %s (%s), track: %s, timestamp: %d", req.Username, req.UserId, req.Track.Name, req.Timestamp)
return &api.ScrobblerScrobbleResponse{}, nil
}
func main() {}
func init() {
api.RegisterScrobbler(FakeScrobbler{})
}

View File

@@ -0,0 +1,13 @@
{
"name": "multi_plugin",
"author": "Navidrome Test",
"version": "1.0.0",
"description": "Test data for multiple services",
"website": "https://test.navidrome.org/multi-plugin",
"capabilities": ["MetadataAgent", "SchedulerCallback", "LifecycleManagement"],
"permissions": {
"scheduler": {
"reason": "For testing scheduled callback functionality"
}
}
}

124
plugins/testdata/multi_plugin/plugin.go vendored Normal file
View File

@@ -0,0 +1,124 @@
//go:build wasip1
package main
import (
"context"
"log"
"strings"
"github.com/navidrome/navidrome/plugins/api"
"github.com/navidrome/navidrome/plugins/host/scheduler"
)
// MultiPlugin implements the MetadataAgent interface for testing
type MultiPlugin struct{}
var ErrNotFound = api.ErrNotFound
var sched = scheduler.NewSchedulerService()
// Artist-related methods
func (MultiPlugin) GetArtistMBID(ctx context.Context, req *api.ArtistMBIDRequest) (*api.ArtistMBIDResponse, error) {
if req.Name != "" {
return &api.ArtistMBIDResponse{Mbid: "multi-artist-mbid"}, nil
}
return nil, ErrNotFound
}
func (MultiPlugin) GetArtistURL(ctx context.Context, req *api.ArtistURLRequest) (*api.ArtistURLResponse, error) {
log.Printf("GetArtistURL received: %v", req)
// Use an ID that could potentially clash with other plugins
// The host will ensure this doesn't conflict by prefixing with plugin name
customId := "artist:" + req.Name
log.Printf("Registering scheduler with custom ID: %s", customId)
// Use the scheduler service for one-time scheduling
resp, err := sched.ScheduleOneTime(ctx, &scheduler.ScheduleOneTimeRequest{
ScheduleId: customId,
DelaySeconds: 6,
Payload: []byte("test-payload"),
})
if err != nil {
log.Printf("Error scheduling one-time job: %v", err)
} else {
log.Printf("One-time schedule registered with ID: %s", resp.ScheduleId)
}
return &api.ArtistURLResponse{Url: "https://multi.example.com/artist"}, nil
}
func (MultiPlugin) GetArtistBiography(ctx context.Context, req *api.ArtistBiographyRequest) (*api.ArtistBiographyResponse, error) {
return &api.ArtistBiographyResponse{Biography: "Multi agent artist bio"}, nil
}
func (MultiPlugin) GetSimilarArtists(ctx context.Context, req *api.ArtistSimilarRequest) (*api.ArtistSimilarResponse, error) {
return &api.ArtistSimilarResponse{}, nil
}
func (MultiPlugin) GetArtistImages(ctx context.Context, req *api.ArtistImageRequest) (*api.ArtistImageResponse, error) {
return &api.ArtistImageResponse{}, nil
}
func (MultiPlugin) GetArtistTopSongs(ctx context.Context, req *api.ArtistTopSongsRequest) (*api.ArtistTopSongsResponse, error) {
return &api.ArtistTopSongsResponse{}, nil
}
// Album-related methods
func (MultiPlugin) GetAlbumInfo(ctx context.Context, req *api.AlbumInfoRequest) (*api.AlbumInfoResponse, error) {
if req.Name != "" && req.Artist != "" {
return &api.AlbumInfoResponse{
Info: &api.AlbumInfo{
Name: req.Name,
Mbid: "multi-album-mbid",
Description: "Multi agent album description",
Url: "https://multi.example.com/album",
},
}, nil
}
return nil, ErrNotFound
}
func (MultiPlugin) GetAlbumImages(ctx context.Context, req *api.AlbumImagesRequest) (*api.AlbumImagesResponse, error) {
return &api.AlbumImagesResponse{}, nil
}
// Scheduler callback
func (MultiPlugin) OnSchedulerCallback(ctx context.Context, req *api.SchedulerCallbackRequest) (*api.SchedulerCallbackResponse, error) {
log.Printf("Scheduler callback received with ID: %s, payload: '%s', isRecurring: %v",
req.ScheduleId, string(req.Payload), req.IsRecurring)
// Demonstrate how to parse the custom ID format
if strings.HasPrefix(req.ScheduleId, "artist:") {
parts := strings.Split(req.ScheduleId, ":")
if len(parts) == 2 {
artistName := parts[1]
log.Printf("This schedule was for artist: %s", artistName)
}
}
return &api.SchedulerCallbackResponse{}, nil
}
func (MultiPlugin) OnInit(ctx context.Context, req *api.InitRequest) (*api.InitResponse, error) {
log.Printf("OnInit called with %v", req)
// Schedule a recurring every 5 seconds
_, _ = sched.ScheduleRecurring(ctx, &scheduler.ScheduleRecurringRequest{
CronExpression: "@every 5s",
Payload: []byte("every 5 seconds"),
})
return &api.InitResponse{}, nil
}
// Required by Go WASI build
func main() {}
// Register the service implementations
func init() {
api.RegisterLifecycleManagement(MultiPlugin{})
api.RegisterMetadataAgent(MultiPlugin{})
api.RegisterSchedulerCallback(MultiPlugin{})
}

View File

@@ -0,0 +1,9 @@
{
"name": "unauthorized_plugin",
"author": "Navidrome Test",
"version": "1.0.0",
"description": "Test plugin that tries to access unauthorized services",
"website": "https://test.navidrome.org/unauthorized-plugin",
"capabilities": ["MetadataAgent"],
"permissions": {}
}

View File

@@ -0,0 +1,78 @@
//go:build wasip1
package main
import (
"context"
"github.com/navidrome/navidrome/plugins/api"
"github.com/navidrome/navidrome/plugins/host/http"
)
type UnauthorizedPlugin struct{}
var ErrNotFound = api.ErrNotFound
func (UnauthorizedPlugin) GetAlbumInfo(ctx context.Context, req *api.AlbumInfoRequest) (*api.AlbumInfoResponse, error) {
// This plugin attempts to make an HTTP call without having HTTP permission
// This should fail since the plugin has no permissions in its manifest
httpClient := http.NewHttpService()
request := &http.HttpRequest{
Url: "https://example.com/test",
Headers: map[string]string{
"Accept": "application/json",
},
TimeoutMs: 5000,
}
_, err := httpClient.Get(ctx, request)
if err != nil {
// Expected to fail due to missing permission
return nil, err
}
return &api.AlbumInfoResponse{
Info: &api.AlbumInfo{
Name: req.Name,
Mbid: "unauthorized-test",
Description: "This should not work",
Url: "https://example.com/unauthorized",
},
}, nil
}
func (UnauthorizedPlugin) GetAlbumImages(ctx context.Context, req *api.AlbumImagesRequest) (*api.AlbumImagesResponse, error) {
return nil, api.ErrNotImplemented
}
func (UnauthorizedPlugin) GetArtistMBID(ctx context.Context, req *api.ArtistMBIDRequest) (*api.ArtistMBIDResponse, error) {
return nil, api.ErrNotImplemented
}
func (UnauthorizedPlugin) GetArtistURL(ctx context.Context, req *api.ArtistURLRequest) (*api.ArtistURLResponse, error) {
return nil, api.ErrNotImplemented
}
func (UnauthorizedPlugin) GetArtistBiography(ctx context.Context, req *api.ArtistBiographyRequest) (*api.ArtistBiographyResponse, error) {
return nil, api.ErrNotImplemented
}
func (UnauthorizedPlugin) GetSimilarArtists(ctx context.Context, req *api.ArtistSimilarRequest) (*api.ArtistSimilarResponse, error) {
return nil, api.ErrNotImplemented
}
func (UnauthorizedPlugin) GetArtistImages(ctx context.Context, req *api.ArtistImageRequest) (*api.ArtistImageResponse, error) {
return nil, api.ErrNotImplemented
}
func (UnauthorizedPlugin) GetArtistTopSongs(ctx context.Context, req *api.ArtistTopSongsRequest) (*api.ArtistTopSongsResponse, error) {
return nil, api.ErrNotImplemented
}
func main() {}
// Register the plugin implementation
func init() {
api.RegisterMetadataAgent(UnauthorizedPlugin{})
}