The bitrate/codec quality ladder is hand-copied into four files, and the only unit test targets the copy with no caller

Đang mở
#896 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
csharp
Lĩnh vực
backend, testing

Hướng nghiên cứu

Read the four implementations in SearchResultScorer.cs, CompositeScorer.cs, SearchResultSortingService.cs, and QualityProfileService.cs, plus tests/Features/Application/Audiobooks/Quality/QualityScoringTests.cs. Start by tracing the three live callers and checking where QualityMatcher in listenarr.domain/Common/ can live without unwanted assembly dependencies. Done means one shared ladder serves the live callers, the unreachable copy is resolved, and the existing score assertions cover the surviving implementation.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

GetQualityScore maps a quality string to a number (FLAC 100, AAX 95, M4B 90, Opus 85, the V0/V1/V2 presets, then bitrates). It is written out by hand in four separate files. Three of those drive live behaviour, and the fourth has no caller at all, which is awkward because the fourth is the one the only direct unit test of the ladder reaches.

Checked on canary d25b3e11 (1.3.3).

The four copies

File Declared at Called from What it decides
listenarr.application/Search/Scoring/SearchResultScorer.cs :414 :280 accept/reject scoring, and the MinimumScore threshold
listenarr.application/Search/Scoring/CompositeScorer.cs :132 :35 the "Smart" sort shown in the UI
listenarr.application/Search/Scoring/SearchResultSortingService.cs :137 :97-98 the "Quality" column sort
listenarr.application/Audiobooks/Quality/QualityProfileService.cs :223 nothing nothing

Each carries its own private ContainsVbrPreset and ContainsAnyBitrate helpers alongside it, so the duplication is the whole heuristic rather than one method.

git grep -n "GetQualityScore" -- '*.cs'

Ten lines: four declarations, four call sites spread across three of them, and two lines in QualityScoringTests. QualityProfileService is not partial and the method is private, so the absence of a call inside its own file is the whole story for that copy.

Why the test does not cover any of this

tests/Features/Application/Audiobooks/Quality/QualityScoringTests.cs:28-58 is the only test that exercises the ladder directly. It reaches QualityProfileService.GetQualityScore at :37 through BindingFlags.NonPublic | BindingFlags.Instance and puts nine tokens through it.

Those assertions are correct. They are just against the one copy that cannot affect anything. Nothing asserts that the three live copies return the same numbers, and because all four are private, nothing can assert it without reflection either.

They have already drifted once

SearchResultSortingService.cs:142 lowercases with ToLowerInvariant(). The other three use ToLower(), which follows the server's culture.

I want to be accurate about what that is worth. I could not make it change a score. None of the tokens the ladder matches on (flac, aax, m4b, opus, v0, aac, m4a, mp3, vbr, cbr, and the bitrates) contain an i, and the dotted and dotless I is the only place ToLower and ToLowerInvariant disagree for these inputs. I ran the four copies over a token corpus under en-US, de-DE, tr-TR and az-Latn-AZ and they agreed everywhere.

So this is not a live bug. It is one line of unintended difference that got in without anything noticing, in logic where the next such difference would change a ranking silently.

Suggested fix

Extract one implementation and have the three live call sites use it, the same direction as #869 for the naming-variable table. QualityMatcher in listenarr.domain/Common/ already looks like where codec and bitrate knowledge lives, so that may be the natural home, though I have not checked whether moving it there would pull anything unwanted into the domain assembly.

Deciding what happens to the QualityProfileService copy is part of it. If it is genuinely unreachable it can go, but then QualityScoringTests needs repointing at whatever survives rather than deleting, since its assertions are the only recorded statement of what the ladder is supposed to return.

Offer

I have a test that pins the four copies to each other, in case it is wanted ahead of any refactor. It reflects into all four, runs them over a corpus covering every rung plus the casing and separator variants, and asserts they agree, under each of the four cultures above.

It passes on canary as it stands, so it is a regression guard and not a reproduction. It fails the moment someone edits one copy and not the others, and it names the copy that moved. Dropping 85 to 84 in CompositeScorer alone fails it with

"OPUS": SearchResultScorer (accept/reject scoring) = 85, CompositeScorer (Smart sort) = 84,
SearchResultSortingService (Quality column sort) = 85, QualityProfileService (no production caller) = 85

Full suite with it added: 3,042 passed, 0 failed, 127 skipped, against a 3,039 baseline on d25b3e11.

It needs reflection to reach all four, which is awkward, and I would rather that were an argument for making them one method than for keeping the test. Happy to open it as a PR, or to leave it if you would rather go straight to the extraction.

Related

#582 and #549 are also about quality logic, but neither is this. #582 is the import-time comparison of candidate against existing, and #549 is DeriveQualityLabel producing labels that do not match profile keys. This is the search-side scoring ladder and it is duplicated independently of both.

Ngôn ngữ chính
C#
Star
901
Fork
70
Merge trung bình
16 giờ 27 phút
Pull request đã merge (30 ngày)
60

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Listenarrs/Listenarr

Tất cả issue của Listenarrs/Listenarr

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.