fix(library): drop out-of-range years instead of failing the album
Tag-supplied years were being passed straight to Postgres' date column without validation. Files with corrupt or 5+ digit years (seen in the wild on a couple of dozen albums) tripped SQLSTATE 22008 and the entire album upsert failed, dropping every track on those albums from the library. Validate the year is within 1..9999 before constructing the date. If it's outside that window, log a warning naming the album and year, and insert the album with no release_date — a soft field shouldn't take down the whole row. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,31 @@ import (
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
)
|
||||
|
||||
func TestReleaseDateFromYear(t *testing.T) {
|
||||
cases := []struct {
|
||||
in int
|
||||
ok bool
|
||||
label string
|
||||
}{
|
||||
{0, false, "missing tag"},
|
||||
{-1, false, "negative"},
|
||||
{1, true, "lower bound"},
|
||||
{1999, true, "ordinary"},
|
||||
{9999, true, "upper bound"},
|
||||
{10000, false, "five digits"},
|
||||
{99999999, false, "tag corruption"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got, ok := releaseDateFromYear(c.in)
|
||||
if ok != c.ok {
|
||||
t.Errorf("%s: ok = %v, want %v", c.label, ok, c.ok)
|
||||
}
|
||||
if ok && (!got.Valid || got.Time.Year() != c.in) {
|
||||
t.Errorf("%s: date = %+v, want year=%d", c.label, got, c.in)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestScanner_Integration exercises walk → tag-parse → upsert → incremental
|
||||
// skip against a real Postgres. Gated on MINSTREL_TEST_DATABASE_URL.
|
||||
func TestScanner_Integration(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user