fix(release): outside services see the build's real version in Minstrel's User-Agent (#8129)
release / web (push) Successful in 1m37s
release / go (push) Successful in 2m1s
release / govulncheck (push) Successful in 19s
release / integration (push) Failing after 4m20s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 3m47s
release / android (push) Canceled after 4m27s

MusicBrainz, the Cover Art Archive and AcoustID ask a client to name
itself with a version and a contact. Minstrel sent three different
strings: Minstrel/1.0 to MusicBrainz, Minstrel/dev to the Cover Art
Archive and no version at all to AcoustID, whatever the build. All three
now come from buildinfo.UserAgent, which carries buildinfo.Version and
the operator's contact address when one is configured, else the project
URL. ProjectURL is that one place to repoint when the project moves
(#7897).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 12:00:41 -05:00
co-authored by Claude Opus 5.5
parent e2172e925e
commit 4587b0a038
6 changed files with 47 additions and 16 deletions
+1 -5
View File
@@ -210,15 +210,11 @@ func run() error {
acoustIDLookup := library.NewAcoustIDLookupWorker(pool, logger.With("component", "acoustid_lookup"),
acoustIDSettings, acoustIDClient)
contact := cfg.Library.ContactEmail
if contact == "" {
contact = "https://git.fabledsword.com/bvandeusen/minstrel"
}
// Swap in the production User-Agent + MinPeriod on the registered
// MBCAA provider. init() registered it with default config; this
// updates the running instance.
coverart.NewMBCAAProviderFromConfig(coverart.FetcherConfig{
UserAgent: fmt.Sprintf("Minstrel/dev (%s)", contact),
UserAgent: buildinfo.UserAgent(cfg.Library.ContactEmail),
MinPeriod: time.Second,
})
+3 -2
View File
@@ -30,6 +30,8 @@ import (
"strconv"
"sync"
"time"
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
)
// DefaultBaseURL is the lookup endpoint.
@@ -45,7 +47,6 @@ const (
// bodyLimit caps the response read. A lookup with meta=recordings for a
// popular song runs to tens of kilobytes.
bodyLimit = 2 << 20
userAgent = "Minstrel ( https://git.fabledsword.com/bvandeusen/minstrel )"
)
// The server's error codes that the worker treats differently.
@@ -127,7 +128,7 @@ func (c *Client) Lookup(ctx context.Context, apiKey, fingerprint string, duratio
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Content-Encoding", "gzip")
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("User-Agent", buildinfo.UserAgent(""))
resp, err := c.http.Do(req)
if err != nil {
+16
View File
@@ -29,3 +29,19 @@ var Channel = "local"
// Started is when this process started, for the admin Overview's uptime.
var Started = time.Now()
// ProjectURL is where Minstrel's source lives. Outside services that ask a
// client to say how to reach its maker are pointed here.
const ProjectURL = "https://git.fabledsword.com/bvandeusen/minstrel"
// UserAgent is how Minstrel names itself to outside services (MusicBrainz,
// the Cover Art Archive, AcoustID), which ask for the app's name, its
// version and a contact, so a release can be told from a dev build in
// their logs. contact is the operator's address when one is configured;
// without one the project's URL stands in.
func UserAgent(contact string) string {
if contact == "" {
contact = ProjectURL
}
return "Minstrel/" + Version + " ( " + contact + " )"
}
+19
View File
@@ -0,0 +1,19 @@
package buildinfo
import "testing"
// The User-Agent carries the build's own version, so MusicBrainz and the
// others can tell a release from a dev build, and a contact: the operator's
// when set, the project's otherwise.
func TestUserAgent_NamesTheVersionAndAContact(t *testing.T) {
was := Version
t.Cleanup(func() { Version = was })
Version = "2026.11.28.1700"
if got, want := UserAgent("admin@example.com"), "Minstrel/2026.11.28.1700 ( admin@example.com )"; got != want {
t.Errorf("with a contact: %q, want %q", got, want)
}
if got, want := UserAgent(""), "Minstrel/2026.11.28.1700 ( "+ProjectURL+" )"; got != want {
t.Errorf("without one: %q, want %q", got, want)
}
}
+4 -5
View File
@@ -10,15 +10,13 @@ import (
"net/url"
"strings"
"time"
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
)
// DefaultBaseURL is the public MusicBrainz web service.
const DefaultBaseURL = "https://musicbrainz.org/ws/2"
// UserAgent identifies Minstrel. MusicBrainz refuses requests without a
// descriptive one.
const UserAgent = "Minstrel/1.0 ( https://git.fabledsword.com/bvandeusen/minstrel )"
// DefaultTimeout bounds one request. A browse page with track
// lists is the slowest thing asked for.
const DefaultTimeout = 20 * time.Second
@@ -130,7 +128,8 @@ func (c *Client) once(ctx context.Context, full string, out any) (retry bool, er
return false, fmt.Errorf("musicbrainz: build request: %w", err)
}
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", UserAgent)
// MusicBrainz refuses requests without a descriptive User-Agent.
req.Header.Set("User-Agent", buildinfo.UserAgent(""))
resp, err := c.httpClient().Do(req)
if err != nil {
+4 -4
View File
@@ -8,6 +8,7 @@ import (
"sync/atomic"
"time"
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
"git.fabledsword.com/bvandeusen/minstrel/internal/musicbrainz"
"git.fabledsword.com/bvandeusen/minstrel/internal/providers"
)
@@ -16,8 +17,6 @@ import (
var mbBaseURL = "https://musicbrainz.org/ws/2"
const (
// mbUserAgent identifies the app — MusicBrainz rejects requests without one.
mbUserAgent = musicbrainz.UserAgent
// artistTagWeightFactor down-weights artist-level fallback tags relative
// to recording-specific tags — the artist's overall character is a coarser
// signal than a tag on the exact recording.
@@ -38,8 +37,9 @@ type musicbrainzProvider struct {
func init() {
Register(&musicbrainzProvider{
client: providers.NewHTTPClient(providers.HTTPOptions{
Name: "musicbrainz",
UserAgent: mbUserAgent,
Name: "musicbrainz",
// MusicBrainz rejects requests without one.
UserAgent: buildinfo.UserAgent(""),
HTTPClient: &http.Client{Timeout: 30 * time.Second},
// MusicBrainz's 1 request/second is per address: share it with
// the release catalogue.