Remove the /rest compatibility layer and the playlist model. Moods are now first-class private collections, and playback is driven by short-lived radio sessions whose queues are generated by the server. - Bearer device tokens (hashed) with revocable sessions. - Library snapshot/delta sync with tombstones and per-folder scoping. - Mood CRUD, seeds, preview and recommendations. - Radio batches weighted by seeds, genres, artists, text and playback affinity. - Playback events (started/completed/skipped) and explicit add-to-mood. - Stream, download and cover endpoints with query-token support for browsers. - V5 migration drops playlists and migrates existing moods; scanner writes tombstones and song update timestamps. - Built-in UI rebuilt on the native API with a radio player. - Native API integration tests and a rewritten smoke test (49 checks). - Chart bumped to 0.2.0. BREAKING CHANGE: the OpenSubsonic API and static playlists are gone.
274 lines
11 KiB
Bash
Executable File
274 lines
11 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# End-to-end smoke test for the native 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.
|
|
#
|
|
# Requirements: ffmpeg, sqlite3, curl, python3, java.
|
|
# 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")}"
|
|
PORT="${SMOKE_PORT:-18099}"
|
|
USER="smoke"
|
|
PASS="smoke-pass"
|
|
BASE="http://127.0.0.1:${PORT}"
|
|
TOKEN=""
|
|
HTTP_STATUS=""
|
|
HTTP_BODY=""
|
|
|
|
PASSED=0
|
|
FAILED=0
|
|
|
|
log() { printf '%s\n' "$*"; }
|
|
pass() { PASSED=$((PASSED + 1)); log "PASS $1"; }
|
|
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"
|
|
|
|
log "Generated test library in $WORK"
|
|
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"
|
|
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"
|
|
|
|
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
|
|
|
|
cat > "$WORK/users.yaml" <<EOF
|
|
users:
|
|
- name: $USER
|
|
password: "$PASS"
|
|
admin: true
|
|
folders: [1]
|
|
EOF
|
|
|
|
log "Building fat JAR..."
|
|
(cd "$ROOT" && "$GRADLE" -q shadowJar)
|
|
|
|
JAR="$(find "$ROOT/build/libs" -name 'musicmanager-*-all.jar' | head -1)"
|
|
if [[ -z "$JAR" ]]; then
|
|
log "Could not find the fat JAR under build/libs"
|
|
exit 1
|
|
fi
|
|
|
|
DATA_DIR="$WORK/data" LIBRARY_CONFIG="$WORK/library.yaml" 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..."
|
|
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
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
if [[ "${SONGS:-0}" -lt 3 ]]; then
|
|
log "Server did not scan the test library; 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"
|
|
|
|
# api <method> <path> [json-body] [token-override]
|
|
api() {
|
|
local method="$1" path="$2" body="${3:-}" auth="${4:-$TOKEN}"
|
|
local args=(-s -w '\n%{http_code}' -X "$method" "$BASE/api/v1$path")
|
|
[[ -n "$auth" ]] && args+=(-H "Authorization: Bearer $auth")
|
|
if [[ -n "$body" ]]; then
|
|
args+=(-H 'Content-Type: application/json' -d "$body")
|
|
fi
|
|
local out
|
|
out="$(curl "${args[@]}")"
|
|
HTTP_STATUS="$(printf '%s' "$out" | tail -1)"
|
|
HTTP_BODY="$(printf '%s' "$out" | sed '$d')"
|
|
}
|
|
|
|
expect() {
|
|
local name="$1" expected="$2" method="$3" path="$4" body="${5:-}"
|
|
api "$method" "$path" "$body"
|
|
if [[ "$HTTP_STATUS" == "$expected" ]]; then
|
|
pass "$name"
|
|
else
|
|
fail "$name" "HTTP $HTTP_STATUS (expected $expected): ${HTTP_BODY:0:240}"
|
|
fi
|
|
}
|
|
|
|
expect_eq() {
|
|
local name="$1" expected="$2" actual="$3"
|
|
if [[ "$actual" == "$expected" ]]; then
|
|
pass "$name"
|
|
else
|
|
fail "$name" "expected '$expected', got '$actual'"
|
|
fi
|
|
}
|
|
|
|
log ""
|
|
log "Authentication"
|
|
LOGIN_STATUS="$(curl -s -o "$WORK/login.json" -w '%{http_code}' -X POST \
|
|
-H 'Content-Type: application/json' \
|
|
-d "{\"username\":\"$USER\",\"password\":\"$PASS\",\"deviceName\":\"smoke\",\"platform\":\"cli\"}" \
|
|
"$BASE/api/v1/auth/login")"
|
|
expect_eq "login status" "200" "$LOGIN_STATUS"
|
|
TOKEN="$(json_field '["token"]' < "$WORK/login.json" 2>/dev/null || true)"
|
|
if [[ -n "$TOKEN" ]]; then pass "login token"; else fail "login token" "$(head -c 200 "$WORK/login.json")"; fi
|
|
expect_eq "login user" "$USER" "$(json_field '["user"]["name"]' < "$WORK/login.json" 2>/dev/null || true)"
|
|
|
|
BAD_STATUS="$(curl -s -o /dev/null -w '%{http_code}' -X POST \
|
|
-H 'Content-Type: application/json' -d '{"username":"smoke","password":"wrong"}' \
|
|
"$BASE/api/v1/auth/login")"
|
|
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 ""
|
|
log "Moods"
|
|
expect "create mood" "201" "POST" "/moods" \
|
|
"{\"name\":\"Smoke Mood\",\"genres\":[\"Rock\"],\"targetSize\":10,\"seedSongIds\":[\"$SONG_ID\"]}"
|
|
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 "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"]')"
|
|
|
|
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 "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}]}"
|
|
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")"
|
|
if [[ "$STREAM_STATUS" == "200" && -s "$WORK/stream.mp3" ]]; then
|
|
pass "stream with query token"
|
|
else
|
|
fail "stream with query token" "HTTP $STREAM_STATUS"
|
|
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")"
|
|
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")"
|
|
if [[ "$TRANSCODE_STATUS" == "200" && -s "$WORK/transcoded.mp3" ]] \
|
|
&& grep -qi '^content-type: audio/mpeg' "$WORK/transcode.headers"; then
|
|
pass "stream transcode"
|
|
else
|
|
fail "stream transcode" "HTTP $TRANSCODE_STATUS"
|
|
fi
|
|
|
|
DOWNLOAD_STATUS="$(curl -s -o "$WORK/download.mp3" -w '%{http_code}' \
|
|
"$BASE/api/v1/songs/$SONG_ID/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
|
|
pass "cover art"
|
|
else
|
|
fail "cover art" "HTTP $COVER_STATUS"
|
|
fi
|
|
|
|
expect "scan status" "200" "GET" "/scan"
|
|
expect "start scan" "202" "POST" "/scan"
|
|
|
|
log ""
|
|
log "Cleanup"
|
|
expect "delete mood" "204" "DELETE" "/moods/$MOOD_ID"
|
|
expect "logout" "204" "POST" "/auth/logout"
|
|
api "GET" "/me" "" "$TOKEN"
|
|
expect_eq "token revoked after logout" "401" "$HTTP_STATUS"
|
|
|
|
log ""
|
|
log "Smoke test finished: $PASSED passed, $FAILED failed"
|
|
log "Server log: $WORK/server.log"
|
|
|
|
if [[ "$FAILED" -gt 0 ]]; then
|
|
exit 1
|
|
fi
|