Retry indexer search with stripped parenthetical suffixes when initial query returns no results
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/claude-agent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1131,3 +1131,78 @@ func TestRecoverOrphaned_FindsActiveDownloads(t *testing.T) {
|
||||
assert.Equal(t, "orphan-hash", active[0].QbitHash)
|
||||
assert.Equal(t, "downloading", active[0].State)
|
||||
}
|
||||
|
||||
func TestMonitorAlbum_SearchRetryAllExhausted(t *testing.T) {
|
||||
suite := setupSuite(t)
|
||||
cleanTables(t, suite.pool)
|
||||
|
||||
suite.mocks.metadata.GetAlbumFunc = func(ctx context.Context, in *metadataPb.GetAlbumRequest, opts ...grpc.CallOption) (*metadataPb.GetAlbumResponse, error) {
|
||||
return &metadataPb.GetAlbumResponse{
|
||||
Album: newMetadataAlbum("test-album-ext-id", "Ain't My Bitch (remastered)", "artist-ext-id", "Metallica"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
var queryCount int
|
||||
suite.mocks.indexer.SearchFunc = func(query string, limit int32, idx string) (*indexer.SearchResponse, error) {
|
||||
queryCount++
|
||||
return newSearchResponse(), nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
resp, err := suite.client.MonitorAlbum(ctx, &pb.MonitorAlbumRequest{
|
||||
AlbumId: "test-album-ext-id",
|
||||
Quality: pb.QualityType_QUALITY_LOSSLESS,
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp.Album)
|
||||
assert.Nil(t, resp.Release)
|
||||
assert.Equal(t, 2, queryCount)
|
||||
}
|
||||
|
||||
func TestMonitorAlbum_SearchRetryWithStrippedTitle(t *testing.T) {
|
||||
suite := setupSuite(t)
|
||||
cleanTables(t, suite.pool)
|
||||
|
||||
suite.mocks.metadata.GetAlbumFunc = func(ctx context.Context, in *metadataPb.GetAlbumRequest, opts ...grpc.CallOption) (*metadataPb.GetAlbumResponse, error) {
|
||||
return &metadataPb.GetAlbumResponse{
|
||||
Album: newMetadataAlbum("test-album-ext-id", "Ain't My Bitch (remastered)", "artist-ext-id", "Metallica"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
var queries []string
|
||||
suite.mocks.indexer.SearchFunc = func(query string, limit int32, idx string) (*indexer.SearchResponse, error) {
|
||||
queries = append(queries, query)
|
||||
if len(queries) == 1 {
|
||||
return newSearchResponse(), nil
|
||||
}
|
||||
return newSearchResponse(
|
||||
newSearchItem("Metallica - Load [FLAC]", 50, "magnet:?xt=urn:btih:abc123"),
|
||||
), nil
|
||||
}
|
||||
|
||||
suite.mocks.magnet.ResolveFunc = func(magnetURI string) ([]byte, error) {
|
||||
return newTorrentData(), nil
|
||||
}
|
||||
|
||||
suite.mocks.torrent.FindFunc = func(opts torrent.FindOptions) ([]torrent.TorrentInfo, error) {
|
||||
return []torrent.TorrentInfo{}, nil
|
||||
}
|
||||
|
||||
suite.mocks.torrent.AddMagnetFunc = func(magnetURI string, savePath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
resp, err := suite.client.MonitorAlbum(ctx, &pb.MonitorAlbumRequest{
|
||||
AlbumId: "test-album-ext-id",
|
||||
Quality: pb.QualityType_QUALITY_LOSSLESS,
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp.Release)
|
||||
|
||||
require.Len(t, queries, 2)
|
||||
assert.Equal(t, "Metallica Ain't My Bitch (remastered)", queries[0])
|
||||
assert.Equal(t, "Metallica Ain't My Bitch", queries[1])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user