Sync podcast state through the store instead of the relay

Received podcast operations and snapshot sections are applied to the
podcast store, this device's snapshots are filled from it, and an
unknown episode position resumes from its progress register. The
relay module is removed; operations, gating and snapshot bounds on the
wire are unchanged. The device-sync Postgres tests now migrate their
database themselves and cover locally emitted podcast operations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sanapachandClaude Opus 5.5 committed 2026-11-20 15:12:38 +02:00
1 parent 7f07cb206a
commit 681ff7af89
4 files changed
+143 -609

No files matched your search

+102 -10
View File
@@ -1,7 +1,9 @@
//! Device-sync v4 storage paths against PostgreSQL.
//!
//! Requires a migrated disposable database (start the server once against
//! it); the test writes rows for a random user id and removes them again.
//! Requires a disposable database in `FURU_DEVICE_SYNC_TEST_DATABASE_URL`;
//! it is migrated with the production migrations on first use
//! (`crate::podcasts::postgres_tests::test_pool`). The tests write rows for
//! random user ids and remove them again.
use super::*;
use crate::player::queue_items::test_episode;
@@ -48,6 +50,14 @@ async fn cleanup(pool: &sqlx::PgPool, user_id: i64) {
"furumusic__fed_sync_ops",
"furumusic__fed_sync_vector",
"furumusic__playback_state",
"furumusic__podcast_fetch_state",
"furumusic__podcast_listen_session",
"furumusic__podcast_progress",
"furumusic__podcast_share",
"furumusic__podcast_subscription",
"furumusic__podcast_episode",
"furumusic__podcast_feed_alias",
"furumusic__podcast",
] {
sqlx::query(&format!("DELETE FROM {table} WHERE user_id = $1"))
.bind(user_id)
@@ -58,11 +68,9 @@ async fn cleanup(pool: &sqlx::PgPool, user_id: i64) {
}
#[tokio::test]
#[ignore = "requires a migrated disposable database in FURU_DEVICE_SYNC_TEST_DATABASE_URL"]
#[ignore = "requires a disposable database in FURU_DEVICE_SYNC_TEST_DATABASE_URL"]
async fn postgres_podcast_relay_gating_and_peer_versions() {
let pool = sqlx::PgPool::connect(&std::env::var("FURU_DEVICE_SYNC_TEST_DATABASE_URL").unwrap())
.await
.unwrap();
let pool = crate::podcasts::postgres_tests::test_pool().await;
let user_id = 8_000_000_000 + i64::from(rand_suffix());
cleanup(&pool, user_id).await;
let new = format!("tui_new_{user_id}");
@@ -320,11 +328,9 @@ async fn postgres_podcast_relay_gating_and_peer_versions() {
}
#[tokio::test]
#[ignore = "requires a migrated disposable database in FURU_DEVICE_SYNC_TEST_DATABASE_URL"]
#[ignore = "requires a disposable database in FURU_DEVICE_SYNC_TEST_DATABASE_URL"]
async fn postgres_unknown_episode_position_and_rollback_cleanup() {
let pool = sqlx::PgPool::connect(&std::env::var("FURU_DEVICE_SYNC_TEST_DATABASE_URL").unwrap())
.await
.unwrap();
let pool = crate::podcasts::postgres_tests::test_pool().await;
let user_id = 8_000_000_000 + i64::from(rand_suffix());
cleanup(&pool, user_id).await;
let tui = format!("tui_{user_id}");
@@ -469,6 +475,92 @@ async fn postgres_unknown_episode_position_and_rollback_cleanup() {
cleanup(&pool, user_id).await;
}
#[tokio::test]
#[ignore = "requires a disposable database in FURU_DEVICE_SYNC_TEST_DATABASE_URL"]
async fn postgres_local_podcast_actions_reach_v4_peers_only() {
let pool = crate::podcasts::postgres_tests::test_pool().await;
let user_id = 8_000_000_000 + i64::from(rand_suffix());
cleanup(&pool, user_id).await;
let identity = ensure_identity(&pool, user_id, "tester").await.unwrap();
let old = format!("tui_old_{user_id}");
let new = format!("tui_new_{user_id}");
for (device, version) in [(&old, 3), (&new, 4)] {
apply_device_profile(
&pool,
user_id,
&profile(device, version),
VersionReport::SelfReported(Some(version)),
true,
)
.await
.unwrap();
}
// A local action lands in the log with this device's stamp and in the
// store, in one transaction.
let store = crate::podcasts::PodcastStore::new(pool.clone());
let episode = test_episode();
let meta: PodcastMeta = serde_json::from_value(serde_json::json!({
"feed_url": episode.feed_url.as_str(), "title": episode.podcast_title,
}))
.unwrap();
let subscribed = store.subscribe(user_id, &meta).await.unwrap();
let played = store.mark_played(user_id, &episode).await.unwrap();
assert!(
subscribed
.ops
.iter()
.chain([&played.op])
.all(|op| op.origin_device_id == identity.device_id)
);
// A music operation recorded afterwards keeps the same clock and sequence.
record_local_op(
&pool,
user_id,
SyncOpPayload::TrackLikeSet {
content_id: format!("b3:{}", "5".repeat(64)),
liked: false,
fed: None,
},
)
.await
.unwrap();
let own: Vec<SyncOpWire> = ops_for_peer(&pool, user_id, &new, 4)
.await
.unwrap()
.into_iter()
.filter(|op| op.origin_device_id == identity.device_id)
.collect();
let kinds: Vec<_> = own.iter().map(|op| payload_kind(&op.payload)).collect();
assert!(kinds.ends_with(&[
"podcast_subscription_set",
"podcast_progress_set",
"track_like_set"
]));
assert!(
own.windows(2)
.all(|pair| pair[1].seq > pair[0].seq && pair[1].hlc_ms > pair[0].hlc_ms)
);
assert_eq!(own[own.len() - 3], subscribed.ops[0]);
assert_eq!(own[own.len() - 2], played.op);
// The v3 peer gets the music operation only.
let to_old = ops_for_peer(&pool, user_id, &old, 3).await.unwrap();
assert!(to_old.iter().all(|op| !op.payload.is_podcast()));
assert!(
to_old
.iter()
.any(|op| payload_kind(&op.payload) == "track_like_set")
);
// The snapshot carries the store's registers for v4 only.
let full = snapshot(&pool, user_id).await.unwrap();
assert_eq!(full.podcast_subscriptions.len(), 1);
assert_eq!(full.podcast_progress.len(), 1);
assert_eq!(full.podcast_progress[0].status, ProgressStatus::Completed);
assert!(!full.for_peer(3).has_podcast_state());
cleanup(&pool, user_id).await;
}
fn rand_suffix() -> u32 {
u32::from_le_bytes(
blake3::hash(random_hex(8).as_bytes()).as_bytes()[..4]