feat: rebuild AudioManager around downloadable moods
CI / chart (push) Successful in 3s
CI / test (push) Successful in 2m2s
CI / chart-push (push) Successful in 4s
CI / image (push) Successful in 3m20s

- V8 wipe migration and the shared song store keyed by YouTube video id
- media store, indexer, downloader, recommendation top-up and refcounted GC
- mood songs plus the recommendation lifecycle and mixed radio pools
- new search, song and recommendation API; remove library/longform/seed routes
- chart PVC/media env, docs, Nix, README and an end-to-end smoke test
This commit is contained in:
TapTap committed 2026-11-15 21:37:39 +00:00
1 parent 50d8b6c580
commit 824eb36dd2
59 files changed
+3838 -5276

No files matched your search

+123 -82
View File
@@ -1,18 +1,19 @@
#!/usr/bin/env bash
#
# End-to-end smoke test for the native mood-first API.
# End-to-end smoke test for the mood-first API.
#
# Generates a tiny tagged MP3 library, starts the server against it, and
# exercises auth, sync, moods, radio sessions, add-to-mood and streaming.
# Seeds a tiny media store, starts the server with a fake `yt-dlp` on PATH, and
# exercises auth, search, moods, downloads, recommendations, radio sessions,
# streaming and covers.
#
# Requirements: ffmpeg, sqlite3, curl, python3, java.
# Requirements: ffmpeg, sqlite3, curl, python3, java, bash.
# Usage: scripts/smoke.sh [work-dir]
#
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
GRADLE="${GRADLE:-./gradlew}"
WORK="${1:-$(mktemp -d "${TMPDIR:-/tmp}/musicmanager-smoke.XXXXXX")}"
WORK="${1:-$(mktemp -d "${TMPDIR:-/tmp}/audiomanager-smoke.XXXXXX")}"
PORT="${SMOKE_PORT:-18099}"
USER="smoke"
PASS="smoke-pass"
@@ -30,51 +31,72 @@ fail() { FAILED=$((FAILED + 1)); log "FAIL $1: $2"; }
json_field() { python3 -c 'import json,sys;d=json.load(sys.stdin);print(eval("d"+sys.argv[1]))' "$1"; }
mkdir -p "$WORK/music/Smoke Artist/Smoke Album" "$WORK/music/Second Artist/Second Album" \
"$WORK/longform/Long Narrator/Long Book" "$WORK/data"
MEDIA="$WORK/data/media"
mkdir -p "$MEDIA/vid-seed-1" "$MEDIA/vid-seed-2" "$WORK/bin" "$WORK/data"
log "Generated test library in $WORK"
log "Seeding the media store in $MEDIA"
ffmpeg -hide_banner -loglevel error -y -f lavfi -i "color=c=red:s=64x64" -frames:v 1 "$WORK/cover.jpg"
ffmpeg -hide_banner -loglevel error -y \
-f lavfi -i "sine=frequency=440:duration=2" \
-metadata title="Smoke Song" -metadata artist="Smoke Artist" \
-metadata album="Smoke Album" -metadata album_artist="Smoke Artist" \
-metadata genre="Rock" -metadata track="1" -metadata date="2026" \
-b:a 192k "$WORK/music/Smoke Artist/Smoke Album/01 - Smoke Song.mp3"
-f lavfi -i "sine=frequency=440:duration=2" -i "$WORK/cover.jpg" \
-map 0:a -map 1:v -c:v copy -c:a libmp3lame -b:a 192k -id3v2_version 3 \
-metadata title="Seed One" -metadata artist="Seed Artist" -metadata album="Seed Album" \
-metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" \
"$MEDIA/vid-seed-1/Seed One.mp3"
ffmpeg -hide_banner -loglevel error -y \
-f lavfi -i "sine=frequency=550:duration=2" \
-metadata title="Second Song" -metadata artist="Second Artist" \
-metadata album="Second Album" -metadata album_artist="Second Artist" \
-metadata genre="Ambient" -metadata track="1" -metadata date="2026" \
-b:a 192k "$WORK/music/Second Artist/Second Album/01 - Second Song.mp3"
ffmpeg -hide_banner -loglevel error -y \
-f lavfi -i "sine=frequency=660:duration=2" \
-metadata title="Chapter One" -metadata artist="Long Narrator" \
-metadata album="Long Book" -metadata album_artist="Long Narrator" \
-metadata genre="Audiobook" -metadata track="1" -metadata date="2026" \
-b:a 128k "$WORK/longform/Long Narrator/Long Book/01 - Chapter One.mp3"
ffmpeg -hide_banner -loglevel error -y \
-f lavfi -i "color=c=red:s=64x64" -frames:v 1 \
"$WORK/music/Smoke Artist/Smoke Album/cover.jpg"
-c:a libmp3lame -b:a 192k -id3v2_version 3 \
-metadata title="Seed Two" -metadata artist="Second Artist" -metadata album="Second Album" \
"$MEDIA/vid-seed-2/Seed Two.mp3"
cat > "$WORK/library.yaml" <<EOF
library:
folders:
- id: 1
name: "Music"
type: music
path: $WORK/music
- id: 10
name: "Long-form"
type: longform
path: $WORK/longform
EOF
# Deterministic stand-in for yt-dlp: search, URL resolve and download.
cat > "$WORK/bin/yt-dlp" <<'FAKE'
#!/usr/bin/env bash
set -euo pipefail
out=""
prev=""
for arg in "$@"; do
if [[ "$prev" == "-o" ]]; then out="$arg"; fi
prev="$arg"
done
if [[ " $* " == *" --flat-playlist "* ]]; then
cat <<'JSON'
{"entries":[
{"id":"vid-seed-1","title":"Seed Artist - Seed One","duration":180,"channel":"Seed Artist"},
{"id":"vid-rec-a","title":"New Artist - Downloaded Track","duration":180,"channel":"New Artist","thumbnail":"https://example/a.jpg"},
{"id":"vid-rec-b","title":"Other Artist - Another Track","duration":200,"channel":"Other Artist"},
{"id":"vid-long","title":"Long Set","duration":900,"channel":"DJ"},
{"id":"vid-short","title":"Interlude","duration":10,"channel":"DJ"}
]}
JSON
exit 0
fi
if [[ " $* " == *" --dump-single-json "* ]]; then
url="${*: -1}"
id="${url##*=}"; id="${id##*/}"
printf '{"id":"%s","title":"URL Artist - URL Track","channel":"URL Artist","duration":200}' "$id"
exit 0
fi
url="${*: -1}"
id="${url##*=}"
dir="$(dirname "$out")"
mkdir -p "$dir"
ffmpeg -hide_banner -loglevel error -y \
-f lavfi -i "sine=frequency=700:duration=1" \
-c:a libmp3lame -b:a 128k -id3v2_version 3 \
-metadata title="Downloaded Track" -metadata artist="New Artist" \
"$dir/$id.mp3"
printf '%s\n' "$dir/$id.mp3"
FAKE
chmod +x "$WORK/bin/yt-dlp"
cat > "$WORK/users.yaml" <<EOF
users:
- name: $USER
password: "$PASS"
admin: true
folders: [1]
EOF
log "Building fat JAR..."
@@ -86,32 +108,30 @@ if [[ -z "$JAR" ]]; then
exit 1
fi
DATA_DIR="$WORK/data" LIBRARY_CONFIG="$WORK/library.yaml" USERS_FILE="$WORK/users.yaml" PORT="$PORT" \
PATH="$WORK/bin:$PATH" DATA_DIR="$WORK/data" USERS_FILE="$WORK/users.yaml" PORT="$PORT" \
java -jar "$JAR" > "$WORK/server.log" 2>&1 &
SERVER_PID=$!
trap 'kill $SERVER_PID 2>/dev/null || true' EXIT
log "Waiting for the server and initial scan..."
log "Waiting for the server and the startup scan..."
SONGS=0
for _ in $(seq 1 120); do
if curl -sf "$BASE/health" >/dev/null 2>&1; then
SONGS="$(sqlite3 "$WORK/data/musicmanager.db" 'select count(*) from songs' 2>/dev/null || echo 0)"
[[ "$SONGS" -ge 3 ]] && break
[[ "$SONGS" -ge 2 ]] && break
fi
sleep 1
done
if [[ "${SONGS:-0}" -lt 3 ]]; then
log "Server did not scan the test library; see $WORK/server.log"
if [[ "${SONGS:-0}" -lt 2 ]]; then
log "Server did not index the media store; see $WORK/server.log"
tail -20 "$WORK/server.log" || true
exit 1
fi
SONG_ID="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where title='Smoke Song'")"
SONG2_ID="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where title='Second Song'")"
LONG_ID="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where title='Chapter One'")"
ALBUM_ID="$(sqlite3 "$WORK/data/musicmanager.db" "select album_id from songs where id='$SONG_ID'")"
log "Scanned: song=$SONG_ID second=$SONG2_ID longform=$LONG_ID"
SEED_ONE="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where video_id='vid-seed-1'")"
SEED_TWO="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where video_id='vid-seed-2'")"
log "Indexed: seed1=$SEED_ONE seed2=$SEED_TWO"
# api <method> <path> [json-body] [token-override]
api() {
@@ -146,6 +166,21 @@ expect_eq() {
fi
}
# wait_for <seconds> <name> <python-condition> <path>
wait_for() {
local seconds="$1" name="$2" condition="$3" path="$4" body=""
for _ in $(seq 1 "$seconds"); do
api GET "$path"
if [[ "$HTTP_STATUS" == "200" ]] \
&& printf '%s' "$HTTP_BODY" | python3 -c "import json,sys;d=json.load(sys.stdin);sys.exit(0 if ($condition) else 1)" 2>/dev/null; then
pass "$name"
return 0
fi
sleep 1
done
fail "$name" "timed out; last body: ${HTTP_BODY:0:240}"
}
log ""
log "Authentication"
LOGIN_STATUS="$(curl -s -o "$WORK/login.json" -w '%{http_code}' -X POST \
@@ -163,62 +198,68 @@ BAD_STATUS="$(curl -s -o /dev/null -w '%{http_code}' -X POST \
expect_eq "login rejects bad password" "401" "$BAD_STATUS"
UNAUTH_STATUS="$(curl -s -o /dev/null -w '%{http_code}' "$BASE/api/v1/moods")"
expect_eq "unauthenticated request rejected" "401" "$UNAUTH_STATUS"
expect "me" "200" "GET" "/me"
expect_eq "me name" "$USER" "$(printf '%s' "$HTTP_BODY" | json_field '["name"]')"
log ""
log "Library sync"
expect "library snapshot (music)" "200" "GET" "/library/songs?scope=music"
MUSIC_COUNT="$(printf '%s' "$HTTP_BODY" | json_field '["songs"].__len__()' 2>/dev/null || echo 0)"
expect_eq "music snapshot has 2 songs" "2" "$MUSIC_COUNT"
expect_eq "snapshot contains smoke song" "1" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print(sum(1 for s in json.load(sys.stdin)["songs"] if s["id"]=="'"$SONG_ID"'"))')"
expect "library snapshot (longform)" "200" "GET" "/library/songs?scope=longform"
expect_eq "longform snapshot has 1 song" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["songs"].__len__()')"
expect "search" "200" "GET" "/library/search?q=smoke&scope=music"
expect_eq "search finds one song" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["songs"].__len__()')"
log "Search"
expect "youtube search" "200" "GET" "/search?q=anything"
expect_eq "search hides long and short tracks" "3" "$(printf '%s' "$HTTP_BODY" | json_field '["results"].__len__()')"
expect_eq "search marks the seeded video" "true" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print(str(any(r["videoId"]=="vid-seed-1" and r["downloaded"] for r in json.load(sys.stdin)["results"])).lower())')"
log ""
log "Moods"
expect "create mood" "201" "POST" "/moods" \
"{\"name\":\"Smoke Mood\",\"genres\":[\"Rock\"],\"targetSize\":10,\"seedSongIds\":[\"$SONG_ID\"]}"
'{"name":"Smoke Mood","genres":["Rock"],"collectionPercent":50,"recommendationCount":2}'
MOOD_ID="$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["id"]' 2>/dev/null || true)"
if [[ -n "$MOOD_ID" ]]; then pass "mood id"; else fail "mood id" "${HTTP_BODY:0:200}"; fi
expect_eq "mood seed count" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["seedCount"]')"
expect "empty mood cannot start a session" "400" "POST" "/moods/$MOOD_ID/sessions" '{"limit":5}'
expect_eq "empty mood error code" "empty_mood" "$(printf '%s' "$HTTP_BODY" | json_field '["error"]["code"]')"
expect "add an existing song" "200" "POST" "/moods/$MOOD_ID/songs" "{\"songId\":\"$SEED_ONE\"}"
expect_eq "song count" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["detail"]["mood"]["songCount"]')"
expect "add a second song" "200" "POST" "/moods/$MOOD_ID/songs" "{\"songId\":\"$SEED_TWO\"}"
expect_eq "song count after second add" "2" "$(printf '%s' "$HTTP_BODY" | json_field '["detail"]["mood"]["songCount"]')"
expect "add by URL" "202" "POST" "/moods/$MOOD_ID/songs" '{"url":"https://youtu.be/vid-url"}'
wait_for 60 "URL download attaches to the mood" 'd["mood"]["songCount"] >= 3' "/moods/$MOOD_ID"
expect "list moods" "200" "GET" "/moods"
expect_eq "list contains mood" "1" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print(sum(1 for m in json.load(sys.stdin)["moods"] if m["id"]=="'"$MOOD_ID"'"))')"
expect "get mood" "200" "GET" "/moods/$MOOD_ID"
expect "mood preview" "200" "GET" "/moods/$MOOD_ID/preview?limit=10"
expect_eq "preview is not empty" "yes" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print("yes" if json.load(sys.stdin)["songs"] else "no")')"
expect "add seed" "200" "POST" "/moods/$MOOD_ID/seeds" "{\"songId\":\"$SONG2_ID\"}"
expect_eq "seed count after add" "2" "$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["seedCount"]')"
expect "remove seed" "204" "DELETE" "/moods/$MOOD_ID/seeds/$SONG2_ID"
expect "get mood after seed removal" "200" "GET" "/moods/$MOOD_ID"
expect_eq "seed count after remove" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["seedCount"]')"
expect "remove a song" "204" "DELETE" "/moods/$MOOD_ID/songs/$SEED_TWO"
log ""
log "Recommendations"
expect "refresh recommendations" "200" "POST" "/moods/$MOOD_ID/recommendations/refresh"
REC_VIDEO="$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;r=json.load(sys.stdin)["recommendations"];print(r[0]["videoId"] if r else "")')"
wait_for 90 "recommendations download" 'd["mood"]["recommendationReady"] >= 1' "/moods/$MOOD_ID"
expect "add a recommendation" "200" "POST" "/moods/$MOOD_ID/recommendations/$REC_VIDEO/add"
SECOND_REC="$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;r=json.load(sys.stdin)["detail"]["recommendations"];print(r[0]["videoId"] if r else "")')"
if [[ -n "$SECOND_REC" ]]; then
expect "reject a recommendation" "200" "POST" "/moods/$MOOD_ID/recommendations/$SECOND_REC/reject"
expect_eq "rejected state" "rejected" "$(printf '%s' "$HTTP_BODY" | json_field '["recommendation"]["state"]')"
else
fail "reject a recommendation" "no second recommendation was available"
fi
log ""
log "Radio sessions"
expect "start session" "201" "POST" "/moods/$MOOD_ID/sessions" '{"limit":10}'
SESSION_ID="$(printf '%s' "$HTTP_BODY" | json_field '["id"]' 2>/dev/null || true)"
if [[ -n "$SESSION_ID" ]]; then pass "session id"; else fail "session id" "${HTTP_BODY:0:200}"; fi
expect_eq "queue contains seed" "yes" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print("yes" if any(s["id"]=="'"$SONG_ID"'" for s in json.load(sys.stdin)["queue"]) else "no")')"
expect_eq "queue excludes longform" "yes" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print("yes" if all(s["id"]!="'"$LONG_ID"'" for s in json.load(sys.stdin)["queue"]) else "no")')"
expect_eq "queue contains a collection song" "yes" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print("yes" if json.load(sys.stdin)["queue"] else "no")')"
expect "next tracks" "200" "POST" "/sessions/$SESSION_ID/next" '{"limit":10}'
expect "playback event" "200" "POST" "/sessions/$SESSION_ID/events" \
"{\"events\":[{\"songId\":\"$SONG_ID\",\"type\":\"completed\",\"positionSeconds\":2}]}"
"{\"events\":[{\"songId\":\"$SEED_ONE\",\"type\":\"completed\",\"positionSeconds\":2}]}"
expect_eq "accepted events" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["accepted"]')"
expect "add playing track to current mood" "200" "POST" "/sessions/$SESSION_ID/add-to-mood" \
"{\"songId\":\"$SONG2_ID\"}"
expect_eq "seed count after add-to-mood" "2" "$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["seedCount"]')"
expect "resume session" "200" "GET" "/sessions/$SESSION_ID"
expect_eq "session mood" "$MOOD_ID" "$(printf '%s' "$HTTP_BODY" | json_field '["moodId"]')"
expect "close session" "204" "DELETE" "/sessions/$SESSION_ID"
log ""
log "Media"
STREAM_STATUS="$(curl -s -o "$WORK/stream.mp3" -w '%{http_code}' \
"$BASE/api/v1/songs/$SONG_ID/stream?token=$TOKEN")"
"$BASE/api/v1/songs/$SEED_ONE/stream?token=$TOKEN")"
if [[ "$STREAM_STATUS" == "200" && -s "$WORK/stream.mp3" ]]; then
pass "stream with query token"
else
@@ -226,11 +267,11 @@ else
fi
RANGE_STATUS="$(curl -s -o /dev/null -w '%{http_code}' -H 'Range: bytes=0-9' \
"$BASE/api/v1/songs/$SONG_ID/stream?token=$TOKEN")"
"$BASE/api/v1/songs/$SEED_ONE/stream?token=$TOKEN")"
expect_eq "stream range" "206" "$RANGE_STATUS"
TRANSCODE_STATUS="$(curl -s -D "$WORK/transcode.headers" -o "$WORK/transcoded.mp3" -w '%{http_code}' \
"$BASE/api/v1/songs/$SONG_ID/stream?token=$TOKEN&maxBitRate=64")"
"$BASE/api/v1/songs/$SEED_ONE/stream?token=$TOKEN&maxBitRate=64")"
if [[ "$TRANSCODE_STATUS" == "200" && -s "$WORK/transcoded.mp3" ]] \
&& grep -qi '^content-type: audio/mpeg' "$WORK/transcode.headers"; then
pass "stream transcode"
@@ -239,16 +280,16 @@ else
fi
DOWNLOAD_STATUS="$(curl -s -o "$WORK/download.mp3" -w '%{http_code}' \
"$BASE/api/v1/songs/$SONG_ID/stream?token=$TOKEN&download=true")"
"$BASE/api/v1/songs/$SEED_ONE/stream?token=$TOKEN&download=true")"
if [[ "$DOWNLOAD_STATUS" == "200" && -s "$WORK/download.mp3" ]]; then
pass "download original"
else
fail "download original" "HTTP $DOWNLOAD_STATUS"
fi
COVER_STATUS="$(curl -s -o "$WORK/cover.jpg" -w '%{http_code}' \
"$BASE/api/v1/covers/$ALBUM_ID?size=32&token=$TOKEN")"
if [[ "$COVER_STATUS" == "200" && -s "$WORK/cover.jpg" ]]; then
COVER_STATUS="$(curl -s -o "$WORK/cover-out.jpg" -w '%{http_code}' \
"$BASE/api/v1/songs/$SEED_ONE/cover?size=32&token=$TOKEN")"
if [[ "$COVER_STATUS" == "200" && -s "$WORK/cover-out.jpg" ]]; then
pass "cover art"
else
fail "cover art" "HTTP $COVER_STATUS"