api tests hash passwords at bcrypt's lowest cost; one genre splitter (#8330, #8331)
release / web (push) Successful in 1m30s
release / go (push) Successful in 1m55s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 2m43s
release / android (push) Successful in 4m31s
release / Build signed APK (push) Successful in 5m0s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 13s
release / Verify release artifacts (tag releases only) (push) Skipped

#8330: every password the api handlers store goes through hashPassword at
bcrypt.DefaultCost, most of a second per hash under -race, so the password
tests took about 1.4s each, roughly 15s of the package. The cost is now a
package variable the tests' TestMain lowers to MinCost, after refusing a
production default below bcrypt.DefaultCost.

#8331: recommendation and taste each had a splitGenres and subsonic's
hasGenre split inline, the same rule three times. internal/genretag.Split
is the one copy, a stdlib-only leaf, and the two TestSplitGenres tables
are one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 14:05:33 -05:00
co-authored by Claude Opus 5.5
parent 10b10b8179
commit 6ef96be290
10 changed files with 90 additions and 112 deletions
+3 -23
View File
@@ -1,11 +1,10 @@
package recommendation
import (
"strings"
"github.com/jackc/pgx/v5/pgtype"
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
"github.com/Fabled-Sword/minstrel/internal/genretag"
)
type SessionVector struct {
@@ -34,10 +33,8 @@ func BuildSessionVector(priorTracks []dbq.Track) SessionVector {
seen[artistID] = true
v.Artists = append(v.Artists, artistID)
}
if t.Genre != nil && *t.Genre != "" {
for _, g := range splitGenres(*t.Genre) {
v.Tags[g]++
}
for _, g := range genretag.Split(t.Genre) {
v.Tags[g]++
}
v.RecentTrackIDs = append(v.RecentTrackIDs, uuidString(t.ID))
}
@@ -50,20 +47,3 @@ func uuidString(u pgtype.UUID) string {
}
return u.String()
}
// splitGenres splits a track's denormalized genre string on the common
// multi-genre delimiters (`;`, `,`) used by various tag editors. Trims
// whitespace; drops empty fragments. Strings with no delimiter come back
// as a single-element slice.
func splitGenres(s string) []string {
parts := strings.FieldsFunc(s, func(r rune) bool {
return r == ';' || r == ','
})
out := make([]string, 0, len(parts))
for _, p := range parts {
if p = strings.TrimSpace(p); p != "" {
out = append(out, p)
}
}
return out
}
@@ -135,40 +135,6 @@ func TestBuildSessionVector_NoSeparatorStaysOpaque(t *testing.T) {
}
}
func TestSplitGenres(t *testing.T) {
cases := []struct {
in string
want []string
}{
{"", nil},
{"Pop", []string{"Pop"}},
{"Pop; Rock", []string{"Pop", "Rock"}},
{"Pop, Rock", []string{"Pop", "Rock"}},
{"Pop; Rock, Jazz", []string{"Pop", "Rock", "Jazz"}},
{" Pop ; Rock ", []string{"Pop", "Rock"}},
{";; Pop ;;", []string{"Pop"}},
{"ElectronicComplextroGlitch Hop", []string{"ElectronicComplextroGlitch Hop"}},
}
for _, c := range cases {
got := splitGenres(c.in)
if c.want == nil {
if len(got) != 0 {
t.Errorf("splitGenres(%q) = %v, want empty", c.in, got)
}
continue
}
if len(got) != len(c.want) {
t.Errorf("splitGenres(%q) = %v, want %v", c.in, got, c.want)
continue
}
for i := range got {
if got[i] != c.want[i] {
t.Errorf("splitGenres(%q)[%d] = %q, want %q", c.in, i, got[i], c.want[i])
}
}
}
}
func TestBuildSessionVector_JSONRoundTrip(t *testing.T) {
a1 := uuid("11111111-1111-1111-1111-111111111111")
v := BuildSessionVector([]dbq.Track{
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"github.com/jackc/pgx/v5/pgtype"
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
"github.com/Fabled-Sword/minstrel/internal/genretag"
)
// Taste-match tuning. The taste profile (written by internal/taste) holds
@@ -105,7 +106,7 @@ func (p TasteProfile) Match(
var tg float64
if genre != nil {
tags := splitGenres(*genre)
tags := genretag.Split(genre)
if len(tags) > 0 {
var sum float64
for _, t := range tags {