fix: address code review findings

- Fix notifications_sent PK: changed from (rgid, sent_at) to rgid-only PK
  to prevent duplicate RGID rows across seconds. Use INSERT OR REPLACE
  instead of INSERT OR IGNORE for true idempotency.
- Add foreign key constraints to DDL (artist_id references artist_settings,
  rgid references external_releases) per specification.
- Enable PRAGMA foreign_keys=ON and PRAGMA busy_timeout=5000 for concurrent
  access safety.
- Fix GetNotificationSentAt query: add ORDER BY sent_at DESC LIMIT 1 for
  deterministic results.
- Fix config test: change YAML key from 'chat' to 'chat_id' to match struct
  tag, add ChatID assertion.
- Fix migration tracking test: correct error message from "expected 4" to
  "expected 3".
- Remove dead code in TestLoadConfig_InvalidPort: eliminate unused YAML
  template and remove port 0 case (valid, not invalid).
- Remove unused path parameter from buildConfigWithPort helper.
- Remove pointless 100ms sleep in run() and unused time import.
- Remove tautological TestDefaultConfigPath test.
- Update README.md: Go version 1.21+ to 1.25+, placeholder passwords to
  CHANGE_ME.
- Update config.yaml.example: placeholder passwords to CHANGE_ME.
- Update all database tests to insert parent rows first for FK satisfaction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-20 11:07:28 +03:00
parent fb74b5fbba
commit 47d4ec4e32
11 changed files with 273 additions and 49 deletions

View File

@@ -30,7 +30,7 @@ musicbrainz:
telegram:
enabled: true
token: "abc123"
chat: "chat456"
chat_id: "chat456"
cron_schedule: "0 10 * * *"
scanner:
@@ -59,6 +59,9 @@ scanner:
if cfg.Navidrome.URL != "http://navidrome:4533" {
t.Errorf("expected navidrome url http://navidrome:4533, got %s", cfg.Navidrome.URL)
}
if cfg.Telegram.ChatID != "chat456" {
t.Errorf("expected telegram chat_id chat456, got %s", cfg.Telegram.ChatID)
}
if cfg.Navidrome.User != "service" {
t.Errorf("expected navidrome user service, got %s", cfg.Navidrome.User)
}
@@ -137,7 +140,6 @@ func TestLoadConfig_InvalidPort(t *testing.T) {
name string
port int
}{
{"port zero with explicit 0 and no default override", 0},
{"port too high", 70000},
{"port negative", -1},
}
@@ -147,32 +149,12 @@ func TestLoadConfig_InvalidPort(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.yaml")
yaml := `
navidrome:
url: "http://localhost:4533"
user: "u"
password: "p"
musicbrainz:
user_agent: "NaviWatcher/1.0 ( test@example.com )"
server:
port: ` + string(rune('0'+tt.port%10)) + `
`
// Use Sprintf for proper port formatting
yaml = buildConfigWithPort(path, tt.port)
yaml := buildConfigWithPort(tt.port)
if err := os.WriteFile(path, []byte(yaml), 0644); err != nil {
t.Fatalf("failed to write config: %v", err)
}
_, err := LoadConfig(path)
if tt.port == 0 {
// port 0 gets defaulted to 8080, which is valid
if err != nil {
t.Fatalf("port 0 should get default, got error: %v", err)
}
return
}
if err == nil {
t.Fatalf("expected error for port %d, got nil", tt.port)
}
@@ -180,7 +162,7 @@ server:
}
}
func buildConfigWithPort(path string, port int) string {
func buildConfigWithPort(port int) string {
return "navidrome:\n url: \"http://localhost:4533\"\n user: \"u\"\n password: \"p\"\n\nmusicbrainz:\n user_agent: \"NaviWatcher/1.0 ( test@example.com )\"\n\nserver:\n port: " + fmt.Sprintf("%d", port) + "\n"
}
@@ -349,7 +331,7 @@ func TestValidate_BoundaryPort(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.yaml")
yaml := buildConfigWithPort(path, tt.port)
yaml := buildConfigWithPort(tt.port)
if err := os.WriteFile(path, []byte(yaml), 0644); err != nil {
t.Fatalf("failed to write config: %v", err)
}