feat: add client compatibility endpoints and a smoke test script
- getMusicDirectory for folder/album browsing - server-side play queues with savePlayQueue/getPlayQueue and index variants - jukebox status and internet radio compatibility responses - scripts/smoke.sh generates a tagged MP3 library, runs the server and verifies all endpoints clients use, including Range, download and covers
This commit is contained in:
1 parent
46266d8071
commit
4d313a2846
9 files changed
+474
No files matched your search
Executable
+200
@@ -0,0 +1,200 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# End-to-end smoke test: generates a tiny tagged MP3 library, starts the server
|
||||
# against it, and exercises the endpoints a Subsonic client uses.
|
||||
#
|
||||
# Requirements: ffmpeg, sqlite3, curl, md5sum, java (or use nix-shell).
|
||||
# Usage: scripts/smoke.sh [work-dir]
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
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}"
|
||||
SALT="smoke-salt"
|
||||
TOKEN="$(printf '%s%s' "$PASS" "$SALT" | md5sum | cut -d' ' -f1)"
|
||||
AUTH="u=${USER}&t=${TOKEN}&s=${SALT}&v=1.16.1&c=smoke&f=json"
|
||||
|
||||
PASSED=0
|
||||
FAILED=0
|
||||
|
||||
log() { printf '%s\n' "$*"; }
|
||||
pass() { PASSED=$((PASSED + 1)); log "PASS $1"; }
|
||||
fail() { FAILED=$((FAILED + 1)); log "FAIL $1: $2"; }
|
||||
|
||||
mkdir -p "$WORK/music/Smoke Artist/Smoke Album" "$WORK/longform" "$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" \
|
||||
-q:a 9 "$WORK/music/Smoke Artist/Smoke Album/01 - Smoke Song.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" && ./gradlew -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..."
|
||||
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" -gt 0 ]] && break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [[ "${SONGS:-0}" -eq 0 ]]; then
|
||||
log "Server did not scan the test library; see $WORK/server.log"
|
||||
tail -20 "$WORK/server.log" || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ALBUM_ID="$(sqlite3 "$WORK/data/musicmanager.db" 'select id from albums limit 1')"
|
||||
ARTIST_ID="$(sqlite3 "$WORK/data/musicmanager.db" 'select id from artists limit 1')"
|
||||
SONG_ID="$(sqlite3 "$WORK/data/musicmanager.db" 'select id from songs limit 1')"
|
||||
log "Scanned: artist=$ARTIST_ID album=$ALBUM_ID song=$SONG_ID"
|
||||
|
||||
# check <name> <path-with-query> [expected-status]
|
||||
check() {
|
||||
local name="$1" path="$2" expected="${3:-200}" body status
|
||||
body="$(curl -s -w '\n%{http_code}' "$BASE$path")"
|
||||
status="$(printf '%s' "$body" | tail -1)"
|
||||
body="$(printf '%s' "$body" | sed '$d')"
|
||||
|
||||
if [[ "$status" != "$expected" ]]; then
|
||||
fail "$name" "HTTP $status (expected $expected): $(printf '%s' "$body" | head -c 200)"
|
||||
return
|
||||
fi
|
||||
if [[ "$expected" == "200" ]] && ! printf '%s' "$body" | grep -q '"status":"ok"'; then
|
||||
fail "$name" "$(printf '%s' "$body" | head -c 200)"
|
||||
return
|
||||
fi
|
||||
pass "$name"
|
||||
}
|
||||
|
||||
check "ping" "/rest/ping.view?$AUTH"
|
||||
check "getLicense" "/rest/getLicense.view?$AUTH"
|
||||
check "getOpenSubsonicExtensions" "/rest/getOpenSubsonicExtensions.view?$AUTH"
|
||||
check "getMusicFolders" "/rest/getMusicFolders.view?$AUTH"
|
||||
check "getIndexes" "/rest/getIndexes.view?$AUTH"
|
||||
check "getArtists" "/rest/getArtists.view?$AUTH"
|
||||
check "getArtist" "/rest/getArtist.view?$AUTH&id=$ARTIST_ID"
|
||||
check "getAlbum" "/rest/getAlbum.view?$AUTH&id=$ALBUM_ID"
|
||||
check "getSong" "/rest/getSong.view?$AUTH&id=$SONG_ID"
|
||||
check "search3" "/rest/search3.view?$AUTH&query=smoke"
|
||||
check "getAlbumList2" "/rest/getAlbumList2.view?$AUTH&type=alphabeticalByName&size=10"
|
||||
check "getAlbumList" "/rest/getAlbumList.view?$AUTH&type=newest&size=10"
|
||||
check "getRandomSongs" "/rest/getRandomSongs.view?$AUTH&size=10"
|
||||
check "getGenres" "/rest/getGenres.view?$AUTH"
|
||||
check "getSongsByGenre" "/rest/getSongsByGenre.view?$AUTH&genre=Rock"
|
||||
check "getMusicDirectory (folder)" "/rest/getMusicDirectory.view?$AUTH&id=1"
|
||||
check "getMusicDirectory (album)" "/rest/getMusicDirectory.view?$AUTH&id=$ALBUM_ID"
|
||||
check "getUser" "/rest/getUser.view?$AUTH&username=$USER"
|
||||
check "getUsers" "/rest/getUsers.view?$AUTH"
|
||||
check "getScanStatus" "/rest/getScanStatus.view?$AUTH"
|
||||
check "getStarred2" "/rest/getStarred2.view?$AUTH"
|
||||
check "getLyricsBySongId" "/rest/getLyricsBySongId.view?$AUTH&id=$SONG_ID"
|
||||
check "getArtistInfo2" "/rest/getArtistInfo2.view?$AUTH&id=$ARTIST_ID"
|
||||
check "getAlbumInfo2" "/rest/getAlbumInfo2.view?$AUTH&id=$ALBUM_ID"
|
||||
check "getSimilarSongs2" "/rest/getSimilarSongs2.view?$AUTH&id=$ARTIST_ID"
|
||||
check "getTopSongs" "/rest/getTopSongs.view?$AUTH&artist=Smoke%20Artist"
|
||||
check "getInternetRadioStations" "/rest/getInternetRadioStations.view?$AUTH"
|
||||
check "jukeboxControl" "/rest/jukeboxControl.view?$AUTH&action=status"
|
||||
|
||||
check "scrobble" "/rest/scrobble.view?$AUTH&id=$SONG_ID"
|
||||
check "star" "/rest/star.view?$AUTH&id=$SONG_ID&albumId=$ALBUM_ID&artistId=$ARTIST_ID"
|
||||
check "getStarred2 after star" "/rest/getStarred2.view?$AUTH"
|
||||
check "setRating" "/rest/setRating.view?$AUTH&id=$SONG_ID&rating=4"
|
||||
check "unstar" "/rest/unstar.view?$AUTH&id=$SONG_ID&albumId=$ALBUM_ID&artistId=$ARTIST_ID"
|
||||
check "createBookmark" "/rest/createBookmark.view?$AUTH&id=$SONG_ID&position=1000"
|
||||
check "getBookmarks" "/rest/getBookmarks.view?$AUTH"
|
||||
check "deleteBookmark" "/rest/deleteBookmark.view?$AUTH&id=$SONG_ID"
|
||||
|
||||
PLAYLIST_JSON="$(curl -s "$BASE/rest/createPlaylist.view?$AUTH&name=Smoke%20List&songId=$SONG_ID")"
|
||||
PLAYLIST_ID="$(printf '%s' "$PLAYLIST_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin)["subsonic-response"]["playlist"]["id"])' 2>/dev/null || true)"
|
||||
if [[ -z "$PLAYLIST_ID" ]]; then
|
||||
fail "createPlaylist" "$(printf '%s' "$PLAYLIST_JSON" | head -c 300)"
|
||||
else
|
||||
pass "createPlaylist"
|
||||
check "getPlaylists" "/rest/getPlaylists.view?$AUTH"
|
||||
check "getPlaylist" "/rest/getPlaylist.view?$AUTH&id=$PLAYLIST_ID"
|
||||
check "updatePlaylist" "/rest/updatePlaylist.view?$AUTH&playlistId=$PLAYLIST_ID&songIndexToRemove=0"
|
||||
check "deletePlaylist" "/rest/deletePlaylist.view?$AUTH&id=$PLAYLIST_ID"
|
||||
fi
|
||||
|
||||
check "savePlayQueue" "/rest/savePlayQueue.view?$AUTH&id=$SONG_ID&position=0"
|
||||
check "getPlayQueue" "/rest/getPlayQueue.view?$AUTH"
|
||||
check "savePlayQueueByIndex" "/rest/savePlayQueueByIndex.view?$AUTH&id=$SONG_ID¤tIndex=0&position=0"
|
||||
check "getPlayQueueByIndex" "/rest/getPlayQueueByIndex.view?$AUTH"
|
||||
|
||||
STREAM_STATUS="$(curl -s -o "$WORK/stream.mp3" -w '%{http_code}' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID")"
|
||||
if [[ "$STREAM_STATUS" == "200" && -s "$WORK/stream.mp3" ]]; then
|
||||
pass "stream"
|
||||
else
|
||||
fail "stream" "HTTP $STREAM_STATUS, $(wc -c < "$WORK/stream.mp3" 2>/dev/null || echo 0) bytes"
|
||||
fi
|
||||
|
||||
RANGE_STATUS="$(curl -s -o /dev/null -w '%{http_code}' -H 'Range: bytes=0-9' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID")"
|
||||
if [[ "$RANGE_STATUS" == "206" ]]; then pass "stream range"; else fail "stream range" "HTTP $RANGE_STATUS"; fi
|
||||
|
||||
DOWNLOAD_STATUS="$(curl -s -o /dev/null -w '%{http_code}' "$BASE/rest/download.view?$AUTH&id=$SONG_ID")"
|
||||
if [[ "$DOWNLOAD_STATUS" == "200" ]]; then pass "download"; else fail "download" "HTTP $DOWNLOAD_STATUS"; fi
|
||||
|
||||
COVER_STATUS="$(curl -s -o "$WORK/cover.jpg" -w '%{http_code}' "$BASE/rest/getCoverArt.view?$AUTH&id=$ALBUM_ID&size=32")"
|
||||
if [[ "$COVER_STATUS" == "200" && -s "$WORK/cover.jpg" ]]; then
|
||||
pass "getCoverArt"
|
||||
else
|
||||
fail "getCoverArt" "HTTP $COVER_STATUS"
|
||||
fi
|
||||
|
||||
log ""
|
||||
log "Smoke test finished: $PASSED passed, $FAILED failed"
|
||||
log "Server log: $WORK/server.log"
|
||||
|
||||
if [[ "$FAILED" -gt 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user