e49d12a72b
First automated coverage. 38 tests, run against the built image (which has the app deps); tests/ and requirements-dev.txt are not baked into the runtime image. - tests/test_dedup_gating.py: the safety-critical one. Drives dedup-library.sh's process_group with --apply + --only-paths and asserts ONLY the confirmed path is deleted and the higher-ranked FLAC is kept. - tests/test_pipeline_runner.py: lock skip, use_lock=False bypass, lock release, success/failure/timeout recording. - tests/test_db.py: schema version + idempotent migrations, FK-safe job-run pruning, stale-run reconciliation. - tests/test_credential_service.py: conf-field substitution incl. newline- injection safety, secret/non-secret classification, cookie-expiry parsing. - tests/test_playlist_service.py: cron round-trips, name validation, render. - tests/test_diagnostics.py: /health + /setup checks. - conftest.py points every path setting at throwaway temp dirs and a temp DB, so tests never touch a real library, /config, or the network. See tests/README.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1.8 KiB
1.8 KiB
Tests
Unit and safety tests for the control-plane app and the dedup file-deleter.
They run against throwaway temp dirs and a temp SQLite database (set up in
conftest.py); they never touch a real library, your /config, or the network.
Running them
The runtime image doesn't ship pytest, so install it into a throwaway run of
the built image (which already has the app's own dependencies). Run as root so
pip can write into the image's venv, and keep pytest's cache off so it doesn't
create files in your working tree:
docker run --rm --user root -v "$PWD":/src -w /src -e PYTHONPATH=/src \
--entrypoint bash alembic:latest \
-c "pip install -q pytest && pytest -q -p no:cacheprovider"
Tests set their own temp ALEMBIC_CONFIG_DIR, MUSIC_DATA_DIR, and encryption
key (see conftest.py), so nothing here touches a real library or config.
Or, if you have a matching Python environment locally:
pip install -r requirements-dev.txt
PYTHONPATH=. pytest -q
What's covered
- Dedup safety (
test_dedup_gating.py):dedup-library.shdeletes only the paths confirmed via--only-paths, and keeps the higher-ranked (FLAC) copy. This is the most important test: the script deletes files. - Runner (
test_pipeline_runner.py): lock skip,use_lock=Falsebypass, success/failure/timeout recording, lock release. - Migrations (
test_db.py): schema version, idempotent re-run, FK-safe job-run pruning, stale-run reconciliation. - Credential rendering (
test_credential_service.py): config field substitution (including newline-injection safety), secret vs non-secret classification, cookie-expiry parsing. - Playlists (
test_playlist_service.py): cron round-trips, name validation, config render/delete. - Diagnostics (
test_diagnostics.py): the/healthand/setupchecks.