mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-08 02:17:25 +02: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.
164 lines
5.1 KiB
Go
164 lines
5.1 KiB
Go
package plugins
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("LyricsPlugin", Ordered, func() {
|
|
var (
|
|
lyricsManager *Manager
|
|
provider *LyricsPlugin
|
|
)
|
|
|
|
BeforeAll(func() {
|
|
lyricsManager, _ = createTestManagerWithPlugins(nil,
|
|
"test-lyrics"+PackageExtension,
|
|
"test-metadata-agent"+PackageExtension,
|
|
)
|
|
|
|
p, ok := lyricsManager.LoadLyricsProvider("test-lyrics")
|
|
Expect(ok).To(BeTrue())
|
|
provider = p.(*LyricsPlugin)
|
|
})
|
|
|
|
Describe("LoadLyricsProvider", func() {
|
|
It("returns a lyrics provider for a plugin with Lyrics capability", func() {
|
|
Expect(provider).ToNot(BeNil())
|
|
})
|
|
|
|
It("returns false for a plugin without Lyrics capability", func() {
|
|
_, ok := lyricsManager.LoadLyricsProvider("test-metadata-agent")
|
|
Expect(ok).To(BeFalse())
|
|
})
|
|
|
|
It("returns false for non-existent plugin", func() {
|
|
_, ok := lyricsManager.LoadLyricsProvider("non-existent")
|
|
Expect(ok).To(BeFalse())
|
|
})
|
|
})
|
|
|
|
Describe("GetLyrics", func() {
|
|
It("successfully returns lyrics from the plugin", func() {
|
|
track := &model.MediaFile{
|
|
ID: "track-1",
|
|
Title: "Test Song",
|
|
Artist: "Test Artist",
|
|
}
|
|
|
|
result, err := provider.GetLyrics(GinkgoT().Context(), track)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(result).To(HaveLen(1))
|
|
Expect(result[0].Line).ToNot(BeEmpty())
|
|
Expect(result[0].Line[0].Value).To(ContainSubstring("Test Song"))
|
|
})
|
|
|
|
It("defaults language to 'xxx' when plugin does not provide one", func() {
|
|
manager, _ := createTestManagerWithPlugins(map[string]map[string]string{
|
|
"test-lyrics": {"no_lang": "true"},
|
|
}, "test-lyrics"+PackageExtension)
|
|
|
|
p, ok := manager.LoadLyricsProvider("test-lyrics")
|
|
Expect(ok).To(BeTrue())
|
|
|
|
track := &model.MediaFile{ID: "track-1", Title: "Test Song", Artist: "Test Artist"}
|
|
result, err := p.GetLyrics(GinkgoT().Context(), track)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(result).To(HaveLen(1))
|
|
Expect(result[0].Lang).To(Equal("xxx"))
|
|
})
|
|
|
|
It("blocks new calls while the per-plugin concurrency cap is saturated", func() {
|
|
sem := provider.plugin.lyricsSem
|
|
for range cap(sem) {
|
|
sem <- struct{}{}
|
|
}
|
|
|
|
ctx := GinkgoT().Context()
|
|
track := &model.MediaFile{ID: "track-1", Title: "Test Song", Artist: "Test Artist"}
|
|
done := make(chan error, 1)
|
|
go func() {
|
|
_, err := provider.GetLyrics(ctx, track)
|
|
done <- err
|
|
}()
|
|
|
|
Consistently(done, "500ms").ShouldNot(Receive())
|
|
<-sem // free one slot; the pending call should now proceed
|
|
Eventually(done).Should(Receive(BeNil()))
|
|
for range cap(sem) - 1 {
|
|
<-sem
|
|
}
|
|
})
|
|
|
|
It("gives up waiting for a slot when the context is cancelled", func() {
|
|
sem := provider.plugin.lyricsSem
|
|
for range cap(sem) {
|
|
sem <- struct{}{}
|
|
}
|
|
defer func() {
|
|
for range cap(sem) {
|
|
<-sem
|
|
}
|
|
}()
|
|
|
|
ctx, cancel := context.WithCancel(GinkgoT().Context())
|
|
cancel()
|
|
_, err := provider.GetLyrics(ctx, &model.MediaFile{ID: "track-1"})
|
|
Expect(err).To(MatchError(context.Canceled))
|
|
})
|
|
|
|
It("returns error when plugin returns error", func() {
|
|
manager, _ := createTestManagerWithPlugins(map[string]map[string]string{
|
|
"test-lyrics": {"error": "service unavailable"},
|
|
}, "test-lyrics"+PackageExtension)
|
|
|
|
p, ok := manager.LoadLyricsProvider("test-lyrics")
|
|
Expect(ok).To(BeTrue())
|
|
|
|
track := &model.MediaFile{ID: "track-1", Title: "Test Song"}
|
|
_, err := p.GetLyrics(GinkgoT().Context(), track)
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
// Each DescribeTable entry proves that the adapter's content-sniffing routes
|
|
// the plugin's rich payload to the right parser rather than mangling it as plain text.
|
|
DescribeTable("content-sniffs plugin responses across all supported formats",
|
|
func(format string, wantSynced bool, wantLine string) {
|
|
manager, _ := createTestManagerWithPlugins(map[string]map[string]string{
|
|
"test-lyrics": {"format": format},
|
|
}, "test-lyrics"+PackageExtension)
|
|
|
|
p, ok := manager.LoadLyricsProvider("test-lyrics")
|
|
Expect(ok).To(BeTrue())
|
|
|
|
track := &model.MediaFile{ID: "track-1", Title: "Test Song", Artist: "Test Artist"}
|
|
result, err := p.GetLyrics(GinkgoT().Context(), track)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(result).To(HaveLen(1))
|
|
Expect(result[0].Synced).To(Equal(wantSynced), "unexpected Synced value for format %s", format)
|
|
Expect(result[0].Line).To(HaveLen(1))
|
|
Expect(result[0].Line[0].Value).To(Equal(wantLine))
|
|
},
|
|
Entry("ttml", "ttml", true, "plugin ttml line"),
|
|
Entry("srt", "srt", true, "plugin srt line"),
|
|
Entry("yaml", "yaml", true, "plugin yaml line"),
|
|
Entry("lrc", "lrc", true, "plugin lrc line"),
|
|
Entry("plain", "plain", false, "plugin plain line"),
|
|
)
|
|
})
|
|
|
|
Describe("PluginNames", func() {
|
|
It("returns plugin names with Lyrics capability", func() {
|
|
names := lyricsManager.PluginNames("Lyrics")
|
|
Expect(names).To(ContainElement("test-lyrics"))
|
|
})
|
|
|
|
It("does not return metadata agent plugins for Lyrics capability", func() {
|
|
names := lyricsManager.PluginNames("Lyrics")
|
|
Expect(names).ToNot(ContainElement("test-metadata-agent"))
|
|
})
|
|
})
|
|
})
|