From 47eaea28a28d2579414fa34400e28482ea4d6f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Sat, 16 May 2026 03:53:42 -0400 Subject: [PATCH] fix(sync): honor paused object policies --- .../ely_browser_core/src/state/bookmarks.rs | 5 ++- crates/ely_browser_core/src/state/sync.rs | 3 ++ crates/ely_browser_core/tests/sync.rs | 40 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/crates/ely_browser_core/src/state/bookmarks.rs b/crates/ely_browser_core/src/state/bookmarks.rs index 22109b5..79caa77 100644 --- a/crates/ely_browser_core/src/state/bookmarks.rs +++ b/crates/ely_browser_core/src/state/bookmarks.rs @@ -1,6 +1,6 @@ use std::{collections::BTreeSet, time::SystemTime}; -use ely_domain::{BookmarkEntry, BookmarkId, SpaceId, UrlText}; +use ely_domain::{BookmarkEntry, BookmarkId, SpaceId, SyncObjectKind, SyncObjectPolicy, UrlText}; use serde::{Deserialize, Serialize}; use crate::CoreError; @@ -246,6 +246,9 @@ impl BrowserCore { /// used by the sync engine which mirrors the full state to the /// Cloudflare worker, not just the visible profile. pub fn visible_bookmarks_for_sync(&self) -> Vec<&BookmarkEntry> { + if self.sync_object_policy(SyncObjectKind::Bookmarks) == SyncObjectPolicy::Paused { + return Vec::new(); + } self.bookmarks.iter().collect() } diff --git a/crates/ely_browser_core/src/state/sync.rs b/crates/ely_browser_core/src/state/sync.rs index d22bc9e..382ec2f 100644 --- a/crates/ely_browser_core/src/state/sync.rs +++ b/crates/ely_browser_core/src/state/sync.rs @@ -178,6 +178,9 @@ impl BrowserCore { } pub(crate) fn visible_tabs_for_sync(&self) -> Vec<&BrowserTab> { + if self.sync_object_policy(SyncObjectKind::Tabs) == SyncObjectPolicy::Paused { + return Vec::new(); + } self.tabs .iter() .filter(|tab| { diff --git a/crates/ely_browser_core/tests/sync.rs b/crates/ely_browser_core/tests/sync.rs index cbb2496..a876271 100644 --- a/crates/ely_browser_core/tests/sync.rs +++ b/crates/ely_browser_core/tests/sync.rs @@ -181,6 +181,24 @@ fn sync_snapshot_updates_existing_tab_metadata() -> Result<(), Box> { Ok(()) } +#[test] +fn sync_snapshot_omits_paused_tabs() -> Result<(), Box> { + let mut source = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; + source.open_tab(UrlText::parse("https://example.com/research")?); + source.set_sync_object_policy(SyncObjectKind::Tabs, SyncObjectPolicy::Paused); + let bytes = source.build_sync_snapshot_bytes()?; + + let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; + let summary = target.apply_sync_snapshot_bytes(&bytes)?; + let snapshot = target.snapshot()?; + + assert_eq!(summary.imported(), 0); + assert_eq!(summary.updated(), 0); + assert_eq!(summary.skipped(), 0); + assert!(snapshot.tabs.iter().all(|tab| tab.url().as_str() != "https://example.com/research")); + Ok(()) +} + #[test] fn sync_snapshot_updates_existing_bookmark_metadata() -> Result<(), Box> { let mut source = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; @@ -212,6 +230,28 @@ fn sync_snapshot_updates_existing_bookmark_metadata() -> Result<(), Box Result<(), Box> { + let mut source = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; + let source_home_tab_id = source.snapshot()?.active_tab_id; + source.set_tab_sync_enabled(&source_home_tab_id, false)?; + let source_tab_id = source.open_tab(UrlText::parse("https://example.com/research")?); + source.set_tab_sync_enabled(&source_tab_id, false)?; + source.bookmark_active_tab()?; + source.set_sync_object_policy(SyncObjectKind::Bookmarks, SyncObjectPolicy::Paused); + let bytes = source.build_sync_snapshot_bytes()?; + + let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; + let summary = target.apply_sync_snapshot_bytes(&bytes)?; + let snapshot = target.snapshot()?; + + assert_eq!(summary.imported(), 0); + assert_eq!(summary.updated(), 0); + assert_eq!(summary.skipped(), 0); + assert!(snapshot.bookmarks.is_empty()); + Ok(()) +} + #[test] fn sync_snapshot_rejects_unknown_schema_rev() -> Result<(), Box> { let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;