diff --git a/plugins/lyrics_adapter_test.go b/plugins/lyrics_adapter_test.go index 77b81099b..6e82dbfab 100644 --- a/plugins/lyrics_adapter_test.go +++ b/plugins/lyrics_adapter_test.go @@ -84,24 +84,31 @@ var _ = Describe("LyricsPlugin", Ordered, func() { Expect(err).To(HaveOccurred()) }) - It("content-sniffs TTML returned by the plugin", func() { - manager, _ := createTestManagerWithPlugins(map[string]map[string]string{ - "test-lyrics": {"format": "ttml"}, - }, "test-lyrics"+PackageExtension) + // 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()) + 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)) - // Verify the result is parsed as TTML (synced, with the exact cue text), - // not mangled as plain text with raw XML markup. - Expect(result[0].Synced).To(BeTrue()) - Expect(result[0].Line).To(HaveLen(1)) - Expect(result[0].Line[0].Value).To(Equal("plugin ttml line")) - }) + 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() { diff --git a/plugins/testdata/test-lyrics/main.go b/plugins/testdata/test-lyrics/main.go index c87fdf358..988490515 100644 --- a/plugins/testdata/test-lyrics/main.go +++ b/plugins/testdata/test-lyrics/main.go @@ -15,16 +15,21 @@ func init() { type testLyrics struct{} func (t *testLyrics) GetLyrics(input lyrics.GetLyricsRequest) (lyrics.GetLyricsResponse, error) { - // Check for configured error errMsg, hasErr := pdk.GetConfig("error") if hasErr && errMsg != "" { return lyrics.GetLyricsResponse{}, fmt.Errorf("%s", errMsg) } - // Return a minimal TTML document to exercise content-sniffing for rich formats. + // Config-selected formats let integration tests prove the adapter's content-sniffing + // detects each format; plain-text parsing would silently mangle the rich ones. format, hasFormat := pdk.GetConfig("format") - if hasFormat && format == "ttml" { - const ttml = ` + if hasFormat { + var text string + var lang string + switch format { + case "ttml": + lang = "eng" + text = `
@@ -32,11 +37,24 @@ func (t *testLyrics) GetLyrics(input lyrics.GetLyricsRequest) (lyrics.GetLyricsR
` - return lyrics.GetLyricsResponse{ - Lyrics: []lyrics.LyricsText{ - {Lang: "eng", Text: ttml}, - }, - }, nil + case "srt": + lang = "eng" + text = "1\n00:00:01,000 --> 00:00:02,000\nplugin srt line\n" + case "yaml": + lang = "eng" + text = "version: \"1.0\"\nmetadata:\n language: eng\nlines:\n - text: \"plugin yaml line\"\n start_ms: 1000\n" + case "lrc": + lang = "eng" + text = "[00:01.00]plugin lrc line" + case "plain": + lang = "eng" + text = "plugin plain line" + } + if text != "" { + return lyrics.GetLyricsResponse{ + Lyrics: []lyrics.LyricsText{{Lang: lang, Text: text}}, + }, nil + } } // Check if we should omit language (to test default language handling)