mirror of
https://github.com/navidrome/navidrome.git
synced 2026-09-23 03:35:27 -04:00
* test(plugins): build test plugins in Go instead of shelling out to make The plugins suite built its .ndp test packages by running `make -C plugins/testdata`, which needs make and zip on the PATH. That is the reason the 26 WASM-dependent spec files are tagged //go:build !windows. buildTestPlugins now does the same work in Go: the same mtime check make performed, `GOOS=wasip1 GOARCH=wasm go build` per plugin, and archive/zip for the package. TinyGo was already optional and unused in CI, so nothing is lost there. The first plugin builds on its own so the shared wasip1 stdlib and PDK objects land in the build cache before the rest fan out: on a cold cache that is 2.2s against 3.4s for the sequential make and 7.3s for an unrestrained fan-out. Packaging moved into a writeNdp helper shared with createTestPackage, which was already writing the same two-entry archive. Entries are written in a fixed order, so the .ndp bytes are now reproducible; the loader hashes those bytes, and `zip` also stored file mtimes, so the previous packages differed on every rebuild. The Makefile is unchanged and still works for building the plugins by hand. Removing the !windows tags is a separate step, once CI is green here. * test(plugins): run the WASM plugin specs on Windows With the test plugins now built in Go, nothing in the suite needs a Unix toolchain, so the //go:build !windows tags come off all 25 spec files. The Windows CI job runs `go test ./...`, so it picks the suite up with no workflow change. plugins_suite_windows_test.go existed only to bootstrap the handful of specs that compiled on Windows; plugins_suite_test.go now serves both. * test(plugins): skip the planted-symlink spec where symlinks need privileges os.Symlink needs an elevated token or Developer Mode on Windows, so the unconditional Expect(...).To(Succeed()) would fail for contributors running the suite on an ordinary Windows box. The elevated GitHub runner hides this. The equivalent spec in sandbox_fs_internal_test.go already attempts the symlink and skips on error; this does the same, keeping the pin live everywhere it can run, including Windows CI. * fix(ci): stop the Windows ndpgen test failing silently The ndpgen suite builds its helper binary to %TEMP%\ndpgen-test, and Windows will not exec a file without an executable extension, so the "supports verbose mode" spec has been failing there. Nobody noticed because the Test ndpgen step ran under pwsh, which carries on after a non-zero exit and takes the step's status from the last command, so the job stayed green with a FAIL line in its log. Add the .exe suffix, and run the step under bash like the Linux job does, so a failure in any of its three commands fails the job.
197 lines
5.6 KiB
Go
197 lines
5.6 KiB
Go
package plugins
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"sync"
|
|
|
|
"github.com/navidrome/navidrome/core/agents"
|
|
"github.com/navidrome/navidrome/server/events"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Manager", Ordered, func() {
|
|
var ctx context.Context
|
|
|
|
BeforeAll(func() {
|
|
ctx = GinkgoT().Context()
|
|
})
|
|
|
|
Describe("Plugin Loading", func() {
|
|
It("loads enabled plugins from DB on Start", func() {
|
|
// Plugin is already loaded by testManager.Start() via loadEnabledPlugins
|
|
names := testManager.PluginNames(string(CapabilityMetadataAgent))
|
|
Expect(names).To(ContainElement("test-metadata-agent"))
|
|
})
|
|
})
|
|
|
|
Describe("unloadPlugin", func() {
|
|
It("removes a loaded plugin", func() {
|
|
// Plugin is already loaded from Start
|
|
err := testManager.unloadPlugin("test-metadata-agent")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
names := testManager.PluginNames(string(CapabilityMetadataAgent))
|
|
Expect(names).ToNot(ContainElement("test-metadata-agent"))
|
|
})
|
|
|
|
It("returns error when plugin not found", func() {
|
|
err := testManager.unloadPlugin("nonexistent")
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("not found"))
|
|
})
|
|
})
|
|
|
|
Describe("EnablePlugin", func() {
|
|
It("enables and loads a disabled plugin", func() {
|
|
// First disable the plugin (which also unloads it)
|
|
err := testManager.DisablePlugin(ctx, "test-metadata-agent")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(testManager.PluginNames(string(CapabilityMetadataAgent))).ToNot(ContainElement("test-metadata-agent"))
|
|
|
|
// Enable it
|
|
err = testManager.EnablePlugin(ctx, "test-metadata-agent")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
names := testManager.PluginNames(string(CapabilityMetadataAgent))
|
|
Expect(names).To(ContainElement("test-metadata-agent"))
|
|
})
|
|
})
|
|
|
|
Describe("DisablePlugin", func() {
|
|
It("disables and unloads an enabled plugin", func() {
|
|
// Ensure the plugin is loaded first
|
|
_ = testManager.EnablePlugin(ctx, "test-metadata-agent")
|
|
|
|
err := testManager.DisablePlugin(ctx, "test-metadata-agent")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
names := testManager.PluginNames(string(CapabilityMetadataAgent))
|
|
Expect(names).ToNot(ContainElement("test-metadata-agent"))
|
|
})
|
|
})
|
|
|
|
Describe("GetPluginInfo", func() {
|
|
BeforeEach(func() {
|
|
// Ensure plugin is loaded for this test
|
|
_ = testManager.EnablePlugin(ctx, "test-metadata-agent")
|
|
})
|
|
|
|
It("returns information about all loaded plugins", func() {
|
|
info := testManager.GetPluginInfo()
|
|
Expect(info).To(HaveKey("test-metadata-agent"))
|
|
Expect(info["test-metadata-agent"].Name).To(Equal("Test Plugin"))
|
|
Expect(info["test-metadata-agent"].Version).To(Equal("1.0.0"))
|
|
})
|
|
})
|
|
|
|
It("can call the plugin concurrently", func() {
|
|
// Ensure plugin is loaded
|
|
_ = testManager.EnablePlugin(ctx, "test-metadata-agent")
|
|
|
|
const concurrency = 30
|
|
errs := make(chan error, concurrency)
|
|
bios := make(chan string, concurrency)
|
|
|
|
g := sync.WaitGroup{}
|
|
g.Add(concurrency)
|
|
for i := range concurrency {
|
|
go func(i int) {
|
|
defer g.Done()
|
|
a, ok := testManager.LoadMediaAgent("test-metadata-agent")
|
|
Expect(ok).To(BeTrue())
|
|
agent := a.(agents.ArtistBiographyRetriever)
|
|
bio, err := agent.GetArtistBiography(ctx, fmt.Sprintf("artist-%d", i), fmt.Sprintf("Artist %d", i), "")
|
|
if err != nil {
|
|
errs <- err
|
|
return
|
|
}
|
|
bios <- bio
|
|
}(i)
|
|
}
|
|
g.Wait()
|
|
|
|
// Collect results
|
|
for range concurrency {
|
|
select {
|
|
case err := <-errs:
|
|
Expect(err).ToNot(HaveOccurred())
|
|
case bio := <-bios:
|
|
Expect(bio).To(ContainSubstring("Biography for Artist"))
|
|
}
|
|
}
|
|
})
|
|
|
|
Describe("sendPluginRefreshEvent", func() {
|
|
var broker *testBroker
|
|
var manager *Manager
|
|
|
|
BeforeEach(func() {
|
|
broker = &testBroker{}
|
|
manager = &Manager{
|
|
broker: broker,
|
|
}
|
|
})
|
|
|
|
It("sends refresh event with single plugin ID", func() {
|
|
manager.sendPluginRefreshEvent(ctx, "test-plugin")
|
|
|
|
Expect(broker.broadcastCalled).To(BeTrue())
|
|
Expect(broker.lastEvent).ToNot(BeNil())
|
|
Expect(broker.lastEventCtx).To(Equal(ctx))
|
|
|
|
refreshEvent, ok := broker.lastEvent.(*events.RefreshResource)
|
|
Expect(ok).To(BeTrue(), "event should be a RefreshResource")
|
|
Expect(refreshEvent.Data(refreshEvent)).To(Equal(`{"plugin":["test-plugin"]}`))
|
|
})
|
|
|
|
It("sends refresh event with multiple plugin IDs", func() {
|
|
manager.sendPluginRefreshEvent(ctx, "plugin-1", "plugin-2", "plugin-3")
|
|
|
|
Expect(broker.broadcastCalled).To(BeTrue())
|
|
refreshEvent, ok := broker.lastEvent.(*events.RefreshResource)
|
|
Expect(ok).To(BeTrue())
|
|
Expect(refreshEvent.Data(refreshEvent)).To(Equal(`{"plugin":["plugin-1","plugin-2","plugin-3"]}`))
|
|
})
|
|
|
|
It("sends refresh event with wildcard when using events.Any", func() {
|
|
manager.sendPluginRefreshEvent(ctx, events.Any)
|
|
|
|
Expect(broker.broadcastCalled).To(BeTrue())
|
|
refreshEvent, ok := broker.lastEvent.(*events.RefreshResource)
|
|
Expect(ok).To(BeTrue())
|
|
Expect(refreshEvent.Data(refreshEvent)).To(Equal(`{"plugin":["*"]}`))
|
|
})
|
|
|
|
It("does not panic when broker is nil", func() {
|
|
manager.broker = nil
|
|
Expect(func() {
|
|
manager.sendPluginRefreshEvent(ctx, "test-plugin")
|
|
}).ToNot(Panic())
|
|
})
|
|
})
|
|
})
|
|
|
|
// testBroker is a simple mock implementation of events.Broker for testing
|
|
type testBroker struct {
|
|
lastEvent events.Event
|
|
lastEventCtx context.Context
|
|
broadcastCalled bool
|
|
}
|
|
|
|
func (m *testBroker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
// Not used in tests
|
|
}
|
|
|
|
func (m *testBroker) SendMessage(ctx context.Context, event events.Event) {
|
|
// Not used in tests
|
|
}
|
|
|
|
func (m *testBroker) SendBroadcastMessage(ctx context.Context, event events.Event) {
|
|
m.lastEvent = event
|
|
m.lastEventCtx = ctx
|
|
m.broadcastCalled = true
|
|
}
|