Foundation: config, schema/migrations, auth, stable IDs, metadata probing

This commit is contained in:
2026-08-22 23:29:16 -05:00
commit d4ea7a4ca9
40 changed files with 3874 additions and 0 deletions
@@ -0,0 +1,75 @@
package metadata
import (
"context"
"os/exec"
"path/filepath"
"testing"
"time"
)
func TestProbeRealFile(t *testing.T) {
ffmpegPath, err := exec.LookPath("ffmpeg")
if err != nil {
t.Skip("ffmpeg not installed, skipping integration test")
}
if _, err := exec.LookPath("ffprobe"); err != nil {
t.Skip("ffprobe not installed, skipping integration test")
}
dir := t.TempDir()
out := filepath.Join(dir, "test.mp3")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, ffmpegPath,
"-f", "lavfi", "-i", "sine=frequency=440:duration=1",
"-metadata", "title=Integration Title",
"-metadata", "artist=Integration Artist",
"-metadata", "album=Integration Album",
"-metadata", "track=5/10",
"-codec:a", "libmp3lame", "-b:a", "64k",
out,
)
if combined, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("ffmpeg failed: %v\n%s", err, combined)
}
p := &Prober{}
tags, err := p.Probe(ctx, out)
if err != nil {
t.Fatalf("Probe: %v", err)
}
if tags.Title != "Integration Title" {
t.Errorf("Title = %q, want %q", tags.Title, "Integration Title")
}
if len(tags.Artists) != 1 || tags.Artists[0] != "Integration Artist" {
t.Errorf("Artists = %v", tags.Artists)
}
if tags.Album != "Integration Album" {
t.Errorf("Album = %q", tags.Album)
}
if tags.TrackNumber != 5 || tags.TrackTotal != 10 {
t.Errorf("Track = %d/%d, want 5/10", tags.TrackNumber, tags.TrackTotal)
}
if tags.DurationSeconds < 0.9 || tags.DurationSeconds > 1.5 {
t.Errorf("DurationSeconds = %v, want ~1", tags.DurationSeconds)
}
if tags.SampleRateHz == 0 {
t.Error("SampleRateHz = 0, want > 0")
}
if tags.Kind != "song" {
t.Errorf("Kind = %q, want song", tags.Kind)
}
}
func TestProbeRejectsMissingFile(t *testing.T) {
if _, err := exec.LookPath("ffprobe"); err != nil {
t.Skip("ffprobe not installed, skipping integration test")
}
p := &Prober{}
if _, err := p.Probe(context.Background(), "/nonexistent/path/does-not-exist.mp3"); err == nil {
t.Fatal("expected error probing a nonexistent file")
}
}