Files
cdnutterandClaude Opus 5.5 5b088bb4a6 Rename host library to master throughout
The two libraries are now "master" and "slave" everywhere: UI text, API
JSON fields (master_root, rel_master, master_size, ...), Go identifiers,
database columns, quality verdicts, quarantine subfolders and docs.

Existing databases are upgraded by a new migration that renames the
columns in place and rewrites stored "host" values, so pairs, history,
cached verdicts and restorable quarantine entries carry over. Network
"host" usages (SplitHostPort, the Origin/Host check) are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-22 16:50:55 -07:00

58 lines
1.9 KiB
Go

package probe
import (
"context"
"os/exec"
"path/filepath"
"testing"
)
func TestScoreOrdering(t *testing.T) {
flac24 := Info{Codec: "flac", Lossless: true, BitDepth: 24, SampleRate: 96000}
flac16 := Info{Codec: "flac", Lossless: true, BitDepth: 16, SampleRate: 44100}
opus160 := Info{Codec: "opus", Bitrate: 160_000}
mp3320 := Info{Codec: "mp3", Bitrate: 320_000}
mp3128 := Info{Codec: "mp3", Bitrate: 128_000}
order := []Info{flac24, flac16, mp3320, opus160, mp3128}
for i := 1; i < len(order); i++ {
if Score(order[i-1]) <= Score(order[i]) {
t.Errorf("%v should outrank %v", order[i-1], order[i])
}
}
if v := Compare(mp3128, flac16); v.Better != "slave" {
t.Errorf("lossless slave should win, got %s", v.Better)
}
if v := Compare(mp3320, Info{Codec: "mp3", Bitrate: 310_000}); v.Better != "equal" {
t.Errorf("within 5%% should be equal, got %s", v.Better)
}
}
func TestProbeRealFiles(t *testing.T) {
ffmpeg, err1 := exec.LookPath("ffmpeg")
ffprobe, err2 := exec.LookPath("ffprobe")
if err1 != nil || err2 != nil {
t.Skip("ffmpeg/ffprobe not installed")
}
dir := t.TempDir()
flac, mp3 := filepath.Join(dir, "a.flac"), filepath.Join(dir, "a.mp3")
for _, args := range [][]string{
{"-f", "lavfi", "-i", "sine=f=440:d=2", "-sample_fmt", "s16", flac},
{"-f", "lavfi", "-i", "sine=f=440:d=2", "-b:a", "128k", mp3},
} {
if out, err := exec.Command(ffmpeg, append([]string{"-v", "error", "-y"}, args...)...).CombinedOutput(); err != nil {
t.Fatalf("ffmpeg: %v %s", err, out)
}
}
p := Prober{Bin: ffprobe}
fi, mi := p.Probe(context.Background(), flac), p.Probe(context.Background(), mp3)
if fi.Error != "" || mi.Error != "" {
t.Fatalf("probe errors: %q %q", fi.Error, mi.Error)
}
if !fi.Lossless || fi.BitDepth != 16 || mi.Lossless || mi.Codec != "mp3" {
t.Fatalf("unexpected probe results %+v / %+v", fi, mi)
}
if v := Compare(mi, fi); v.Better != "slave" {
t.Fatalf("flac slave should beat mp3 master, got %+v", v)
}
}