Files
furumi-web/docs/development.md
T
sanapachandClaude Opus 5.5 4d6a1513d9 Publish matched import entries into private playlists over Device Sync
Each source playlist gets an ordinary private playlist, created with its
PlaylistCreated operation in one transaction even when nothing matched.
Matched entries follow in source order, at most 200 per transaction: the
playlist row, the item register, the existing PlaylistTrackAdded operation
and a receipt are written together, so fed_sync_ops serves as the outbox
and an interrupted batch leaves nothing behind. Locks are taken in a fixed
order (per-user advisory lock, import lease, playlist, fed-device identity,
registers). Registers are only inserted; an item the playlist has or had,
a removal committed to the journal but not yet applied, a repeat or a
receipt keep the publisher from adding it again. A deleted target pauses
publication until POST .../playlists/{pid}/recreate; POST .../resync
retries unmatched entries and appends new matches at the end.

Before each batch the outgoing Device Sync line is measured by serializing
the same parts the exchange sends. Tracks and new playlists are published
while the music snapshot stays within library_import_sync_budget (2 MiB)
and the whole line within 7 MiB; the rest waits as deferred_sync_limit.

Device Sync gets local helpers only: create_owned_playlist_tx is extracted
from the playlist handler, append_in_transaction takes an explicit
position, the two operations have in-transaction variants on
append_local_op, and applying a playlist item writes its register under an
atomic last-writer-wins condition and its playlist row in the same
transaction, so concurrent operations cannot make them diverge. The
protocol and its formats are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 17:46:47 +02:00

9.6 KiB

Development

Project overview · Installation · Admin UI conventions

Architecture

Furumusic is written in Rust on the Cot 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 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:

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:

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:

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:

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

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

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

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

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, 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 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.