forked from Furumi/furumi-web
The browser scenario of the import page runs on isolated API fixtures, so nothing checked the page with the real handlers, the background worker and the publisher together. tests/browser-library-import-live.cjs seeds a few library tracks on a fresh disposable instance, uploads a Spotify export ZIP built in the test and checks that only the playlist files are sent, the statistics after the worker finishes, the private playlists in source order without repeats, the filters, a manual choice published by the next pass, the export flagged as already imported, Retry unmatched, history deletion that keeps the playlists and the page at phone width. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
251 lines
13 KiB
Markdown
251 lines
13 KiB
Markdown
# Development
|
|
|
|
[Project overview](../README.md) · [Installation](setup.md) · [Admin UI conventions](admin-ui.md)
|
|
|
|
## Architecture
|
|
|
|
Furumusic is written in Rust on the
|
|
[Cot](https://cot.rs) web framework. PostgreSQL stores the catalog, accounts,
|
|
playlists, configuration, and background-job state. Audio inspection uses
|
|
Symphonia, torrent downloads use librqbit, and the shared `music-dht`/Frid
|
|
protocol stack provides decentralized catalog search, media transfer, and
|
|
connected-device synchronization.
|
|
|
|
The browser interface and JSON API are served by the same application. Import,
|
|
artwork, metadata enrichment, similarity indexing, and maintenance run as
|
|
durable background jobs rather than blocking playback requests.
|
|
|
|
## Build profiles
|
|
|
|
Development and test builds use basic optimization (`opt-level = 1`) for
|
|
dependencies to keep macOS unwind tables below the compact-unwind size limit.
|
|
Application code stays unoptimized; debug symbols, assertions and panic
|
|
unwinding remain enabled. The first build compiles dependencies with these
|
|
settings, then reuses them from Cargo's cache. Dependency stepping in a debugger
|
|
can be less exact because of optimization. Release settings are independent.
|
|
|
|
See the [Cargo profile override documentation](https://doc.rust-lang.org/cargo/reference/profiles.html#overrides) for dependency-specific settings.
|
|
|
|
## Container builds and CI
|
|
|
|
CI uses Rust 1.97.0 and cargo-chef 0.1.74 to cache compiled dependencies separately
|
|
from application sources. Buildx imports and exports intermediate layers through
|
|
`ultradesu/furumusic:buildcache` (`mode=max`). After the first build, changes to
|
|
source code, templates or prompts reuse the dependency layer when its recipe and
|
|
toolchain are unchanged. Both dependency and application builds use `--locked`.
|
|
Update the pinned build tools in `Dockerfile`; changing them rebuilds the cache.
|
|
|
|
## Contributing
|
|
|
|
Bug reports, design discussions, and patches are welcome. Before submitting a
|
|
change, run:
|
|
|
|
```bash
|
|
cargo fmt --all -- --check
|
|
cargo clippy --all-targets -- -D warnings
|
|
cargo test --all-targets
|
|
```
|
|
|
|
Last.fm database tests use temporary tables on a disposable PostgreSQL database:
|
|
|
|
```bash
|
|
FURUMUSIC_LASTFM_TEST_DATABASE_URL=postgres://user:pass@localhost/test_db \
|
|
cargo test lastfm_popularity -- --include-ignored
|
|
```
|
|
|
|
## Access and sharing tests
|
|
|
|
Podcast regressions include browser-store tests in `tests/podcasts.test.cjs` and an
|
|
isolated PostgreSQL fixture for multiuser subscriptions, progress generations,
|
|
retention and administrator actions:
|
|
|
|
```bash
|
|
node --test tests/podcasts.test.cjs
|
|
FURU_PODCAST_RENDER_FIXTURE=1 cargo test renders_podcast_navigation_and_views
|
|
node tests/browser-podcast-ui.cjs
|
|
FURU_PODCAST_TEST_DATABASE_URL=postgresql://... cargo test podcasts -- --include-ignored
|
|
FURU_PODCAST_TEST_DATABASE_URL=postgresql://... cargo test admin_unicode_search -- --include-ignored
|
|
```
|
|
|
|
Use a disposable database. The PostgreSQL test creates and drops a unique schema;
|
|
its audio files use a unique temporary directory. Normal podcast tests need no network.
|
|
The podcast fixture includes real Frid v4 subscription operations, snapshot exchange,
|
|
offline unsubscribe replay, legacy-peer filtering, and private Unicode search. The
|
|
admin fixture exercises list counts, all three catalogue lists and the track picker
|
|
with Cyrillic and Greek searches. Use a PostgreSQL build with ICU support; running
|
|
these fixtures on a database created with locale `C` covers the locale regression.
|
|
The browser UI fixture checks direct list/detail hashes on first load and reload,
|
|
back navigation, RSS artwork and broken-image fallbacks, explicit subscriptions,
|
|
compact search cards and mobile layout. It uses isolated API fixtures with the
|
|
rendered application. Set `PLAYWRIGHT_MODULE` and `CHROME_PATH` as for the other
|
|
browser tests. Optional `ALPINE_FIXTURE` points to a local Alpine.js bundle for
|
|
offline browser runs; otherwise the page loads Alpine from its normal CDN.
|
|
|
|
The access regression suite uses a disposable migrated database and a local OIDC
|
|
provider with signed tokens and PKCE:
|
|
|
|
```bash
|
|
node --test tests/*.test.cjs
|
|
FURU_ACCESS_TEST_DATABASE_URL=postgresql://... cargo test postgres_approval_survives_sso_changes_without_implicit_grants -- --ignored
|
|
# Fresh disposable instance on :18048, media root /tmp/furumi-access-media,
|
|
# PostgreSQL container furumi-access-test-pg, database furumi_access_test:
|
|
node tests/browser-access-sharing.cjs
|
|
```
|
|
|
|
The browser test requires Playwright (`PLAYWRIGHT_MODULE`) and Chrome
|
|
(`CHROME_PATH`), and uses local port 18049 for its OIDC provider. It checks
|
|
approval, SSO precedence and group removal, guest playback and downloads,
|
|
unauthorized track substitution, and desktop/mobile player behavior.
|
|
|
|
## Statistics tests
|
|
|
|
```bash
|
|
node --test tests/*.test.cjs
|
|
cargo test admin:: -- --skip postgres_statistics_drilldown_and_pagination
|
|
# Use a disposable PostgreSQL; this test creates connection-local temporary tables.
|
|
FURU_STATISTICS_TEST_DATABASE_URL=postgresql://... cargo test postgres_statistics_drilldown_and_pagination -- --ignored
|
|
```
|
|
|
|
`tests/browser-statistics.cjs` additionally exercises a fresh disposable instance
|
|
at `FURU_TEST_URL` (default `http://127.0.0.1:3018`) and seeds the disposable Docker
|
|
container `furumi-statistics-test-pg`. It requires Playwright (or
|
|
`PLAYWRIGHT_MODULE`) and Chrome (or `CHROME_PATH`). Never point this test at a
|
|
live service.
|
|
|
|
## Metadata Repair tests
|
|
|
|
```bash
|
|
node --test tests/admin_metadata_repair.test.cjs
|
|
cargo test admin::metadata_fix::tests
|
|
```
|
|
|
|
`tests/browser-metadata-repair.cjs` checks the chat and plan updates, a four-release
|
|
merge, deletion and restoration of tracks and artist credits, playlists, playback
|
|
queues, and undo conflicts. Run it only against a disposable instance and a
|
|
PostgreSQL container named `furumi-repair-test-pg`, with database
|
|
`furumi_repair_test`. Set `FURU_TEST_URL`, `FURU_REPAIR_TEST_PG`, `CHROME_PATH`, and
|
|
`PLAYWRIGHT_MODULE` as needed. It seeds `tests/metadata_repair_fixture.sql` after
|
|
creating the test administrator. Set `FURU_REPAIR_SKIP_SEED=1` for a seeded database.
|
|
With `FURU_REPAIR_TEST_MODEL=1`, it additionally checks the reported release-only
|
|
selection and full ordered tracklist against the configured model, applies and
|
|
undoes that plan, and verifies individual track exclusions.
|
|
|
|
## Import destination tests
|
|
|
|
```bash
|
|
node --test tests/import_playlists.test.cjs
|
|
# Disposable PostgreSQL; both tests use temporary tables.
|
|
FURU_IMPORT_TEST_DATABASE_URL=postgresql://... cargo test import_destinations -- --ignored
|
|
FURU_IMPORT_TEST_DATABASE_URL=postgresql://... cargo test torrent_playlist -- --ignored
|
|
```
|
|
|
|
`tests/browser-import-playlists.cjs` checks the file upload flow, database
|
|
reconciliation and the torrent picker on desktop and mobile. It requires a fresh
|
|
migrated instance with the import agent disabled at `FURU_TEST_URL` (default
|
|
`http://127.0.0.1:3019`), the disposable PostgreSQL container
|
|
`furumi-import-playlist-test-pg` with database `furumi_import_test`, and Playwright
|
|
and Chrome configured as above. It uses a local torrent preview fixture and
|
|
simulated imported tracks, without downloading external torrents.
|
|
|
|
## Library import tests
|
|
|
|
```bash
|
|
cargo test library_import
|
|
# Disposable PostgreSQL with ICU support; each test creates and drops a unique schema.
|
|
FURU_LIBRARY_IMPORT_TEST_DATABASE_URL=postgresql://... cargo test library_import -- --include-ignored
|
|
```
|
|
|
|
The database tests cover per-user isolation, repeated and similar source playlists,
|
|
storing a 5000-entry export, exclusive claims, lease ownership, cancellation,
|
|
history deletion that keeps target playlists, resumption after a worker stops
|
|
without a server restart once its lease expires, continuing the same Spotify
|
|
API import after the user signs in again, and resolving a small library with
|
|
federation disabled: local matches get content ids from `agent_storage_dir`,
|
|
known federated tracks match without the network, and a federation stub that
|
|
panics proves no network access without consent. Peer catalogues come from a
|
|
fake catalogue source: the tests cover matches through the original, folded and
|
|
split artist names, repeated failed searches, lost catalogues, the budget of a
|
|
pass, a stopped node, manual choices with tampered candidates, and cancellation
|
|
that leaves no catalogue request running. The database needs the `pg_trgm`
|
|
extension; the tests install it into `public`.
|
|
|
|
The publisher tests (`src/library_import/tests/publisher.rs`) run against the
|
|
Device Sync tables of the same schema. They cover source order, repeats, empty
|
|
playlists, a second pass that adds nothing, Resync appending at the end, tracks
|
|
removed by the user or by a committed but not yet applied operation, a
|
|
federated track removed in the web player by its content id, deleted
|
|
target playlists and recreation, an entry failing after its operation was
|
|
recorded, registers written concurrently, deletions from the web and from
|
|
another device during a batch, older operations that arrive during a batch,
|
|
concurrent operations that must keep registers and playlist rows consistent,
|
|
two imports of one user publishing in turn, and the Device Sync budget for
|
|
tracks and playlists. `library_import_measures_the_outgoing_device_sync_line`
|
|
prints the measured line for 3,200 published tracks with `--nocapture`.
|
|
|
|
`cargo test federation::client` checks bounded artist catalogue lookups without a
|
|
database: at most 16 owners and the given number of parallel requests, timeouts,
|
|
errors, oversized catalogues, and that dropping a lookup stops its search and
|
|
requests.
|
|
|
|
The matcher's reference table (`src/library_import/matcher/tests.rs`) runs
|
|
without a database and documents the matching rules case by case.
|
|
|
|
The import page has browser-store tests and a browser scenario on the rendered
|
|
player with isolated API fixtures; neither needs a server or a database:
|
|
|
|
```bash
|
|
node --test tests/library_import.test.cjs
|
|
FURU_LIBRARY_IMPORT_RENDER_FIXTURE=1 cargo test library_import::tests::web
|
|
node tests/browser-library-import.cjs
|
|
```
|
|
|
|
The store tests unzip real archives with the vendored fflate and cover the
|
|
archive limits (size, entries, playlist files and declared sizes, checked
|
|
before decompression), the request limit, the selection of repeated, similar
|
|
and unavailable playlists, federated consent, polling, the Spotify sign-in
|
|
return and removing a federated track from a playlist. The browser scenario
|
|
checks the menu order on desktop and mobile, history polling, that only
|
|
`Playlist*.json` and `YourLibrary.json` from a ZIP with listening history reach
|
|
the server, the wizard, details, a manual choice, Retry unmatched, history
|
|
deletion, continuing a Spotify import after a new sign-in, federated track
|
|
removal in a playlist and reduced motion. Set `PLAYWRIGHT_MODULE` and
|
|
`CHROME_PATH` as for the other browser tests; `FURU_SCREENSHOT_DIR` chooses
|
|
where screenshots go (default `target/`).
|
|
|
|
`tests/browser-library-import-live.cjs` runs the same page against a real server
|
|
and its background worker:
|
|
|
|
```bash
|
|
# Fresh disposable instance; federation disabled, no Spotify client id.
|
|
FURU_DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:55432/furumi_libimport_live \
|
|
FURU_AGENT_STORAGE_DIR=/tmp/furumi-libimport-storage FURU_FEDERATION_ENABLED=false \
|
|
target/release/furumusic -l 127.0.0.1:3020
|
|
FURU_TEST_STORAGE_DIR=/tmp/furumi-libimport-storage node tests/browser-library-import-live.cjs
|
|
```
|
|
|
|
Start the instance a second time once the first start has applied the
|
|
migrations: on an empty database the scheduler starts before them, and import
|
|
workers run only after a restart. The test creates the administrator, seeds
|
|
library tracks over `psql` in the disposable container `FURU_TEST_PG_CONTAINER`
|
|
(default `furumi-libimport-test-pg`, database `FURU_TEST_DATABASE`, default
|
|
`furumi_libimport_live`) and writes their audio files into
|
|
`FURU_TEST_STORAGE_DIR`, which must be the instance's absolute
|
|
`FURU_AGENT_STORAGE_DIR`. `FURU_TEST_URL` defaults to `http://127.0.0.1:3020`.
|
|
It builds a Spotify export ZIP with listening history, checks that only the
|
|
playlist files are sent, and waits for the worker: statistics, private playlists
|
|
with the matched tracks in source order and without repeats (in the API, the
|
|
sidebar and the player), filters for unmatched and unsupported entries, a
|
|
manual choice for a remaster found only as the original and published by the
|
|
next pass, the same export flagged as already imported, Retry unmatched
|
|
appending a track added to the library meanwhile, history deletion that keeps
|
|
the playlists, and the page at phone width without horizontal scrolling. Run it
|
|
only against a fresh disposable instance and drop its database afterwards.
|
|
|
|
`src/player/vendor/fflate-0.8.2.min.js` is `umd/index.js` of the npm package
|
|
`fflate@0.8.2` (MIT, `src/player/vendor/fflate-LICENSE`), served unchanged at
|
|
`/vendor/fflate-0.8.2.js` and loaded only when a user picks an archive.
|
|
|
|
The Spotify export fixture in `src/library_import/adapters/fixtures/spotify_export/`
|
|
is synthetic. Add a fresh anonymized real export next to it before relying on the
|
|
parser for a new export format.
|