Files
AudioManager/scripts/smoke.sh
T
TapTap 28bfdd9d00
CI / chart (push) Successful in 2s
CI / chart-push (push) Successful in 2s
CI / test (push) Successful in 1m41s
CI / image (push) Successful in 3m11s
feat: add per-user moods as generated playlists
Add private server-managed playlist moods with curated seeds and related
library fill. Moods are created or promoted from existing playlists in the
web UI, refresh lazily after their TTL, and are marked stale after a scan.

Symfonium stars pin the active mood: opening a mood restores its context,
and a starred song becomes a permanent seed. Without an active session the
song is pinned to every mood that already contains it.

Includes the V4 migration, custom mood endpoints, management UI, tests and
smoke coverage. Bump the chart to 0.1.4.
2026-11-14 12:52:25 +00:00

266 lines
11 KiB
Bash
Executable File

#!/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)"
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}"
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" \
-b:a 192k "$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" && "$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..."
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_post <name> <path> <extra-form-data>
check_post() {
local name="$1" path="$2" extra="${3:-}" body status
body="$(curl -s -w '\n%{http_code}' -X POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data "${AUTH}${extra}" "$BASE$path")"
status="$(printf '%s' "$body" | tail -1)"
body="$(printf '%s' "$body" | sed '$d')"
if [[ "$status" != "200" ]]; then
fail "$name (POST)" "HTTP $status: $(printf '%s' "$body" | head -c 200)"
return
fi
if ! printf '%s' "$body" | grep -q '"status":"ok"'; then
fail "$name (POST)" "$(printf '%s' "$body" | head -c 200)"
return
fi
pass "$name (POST)"
}
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"
# The formPost extension means clients may use POST for every endpoint.
check_post "ping" "/rest/ping.view"
check_post "getAlbumList2" "/rest/getAlbumList2.view" "&type=alphabeticalByName&size=10"
check_post "getGenres" "/rest/getGenres.view"
check_post "getPlaylists" "/rest/getPlaylists.view"
check_post "getUser" "/rest/getUser.view" "&username=$USER"
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
MOOD_JSON="$(curl -s "$BASE/rest/createMood.view?$AUTH&name=Smoke%20Mood&songId=$SONG_ID&targetSize=5")"
MOOD_ID="$(printf '%s' "$MOOD_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin)["subsonic-response"]["mood"]["id"])' 2>/dev/null || true)"
if [[ -z "$MOOD_ID" ]]; then
fail "createMood" "$(printf '%s' "$MOOD_JSON" | head -c 300)"
else
pass "createMood"
check "getMoods" "/rest/getMoods.view?$AUTH"
check "getMood" "/rest/getMood.view?$AUTH&id=$MOOD_ID"
check "getPlaylist (mood)" "/rest/getPlaylist.view?$AUTH&id=$MOOD_ID"
check "refreshMood" "/rest/refreshMood.view?$AUTH&id=$MOOD_ID"
check "deleteMood" "/rest/deleteMood.view?$AUTH&id=$MOOD_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&currentIndex=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
TRANSCODE_STATUS="$(curl -s -D "$WORK/transcode.headers" -o "$WORK/transcoded.mp3" -w '%{http_code}' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID&maxBitRate=64")"
if [[ "$TRANSCODE_STATUS" == "200" && -s "$WORK/transcoded.mp3" ]] \
&& grep -qi '^content-type: audio/mpeg' "$WORK/transcode.headers" \
&& [[ $(wc -c < "$WORK/transcoded.mp3") -lt $(wc -c < "$WORK/stream.mp3") ]]; then
pass "stream transcode (maxBitRate)"
else
fail "stream transcode (maxBitRate)" "HTTP $TRANSCODE_STATUS, $(wc -c < "$WORK/transcoded.mp3" 2>/dev/null || echo 0) bytes"
fi
OFFSET_STATUS="$(curl -s -o "$WORK/offset.mp3" -w '%{http_code}' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID&timeOffset=1")"
if [[ "$OFFSET_STATUS" == "200" && -s "$WORK/offset.mp3" ]] \
&& [[ $(wc -c < "$WORK/offset.mp3") -lt $(wc -c < "$WORK/stream.mp3") ]]; then
pass "stream transcode (timeOffset)"
else
fail "stream transcode (timeOffset)" "HTTP $OFFSET_STATUS"
fi
FORMAT_STATUS="$(curl -s -o "$WORK/format.mp3" -w '%{http_code}' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID&format=flac")"
if [[ "$FORMAT_STATUS" == "200" && -s "$WORK/format.mp3" ]]; then
pass "stream transcode (format fallback)"
else
fail "stream transcode (format fallback)" "HTTP $FORMAT_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