feat(sync): include history in snapshots
This commit is contained in:
@@ -98,6 +98,7 @@ fn sync_snapshot_imports_remote_bookmarks_into_active_scope() -> Result<(), Box<
|
||||
source.set_bookmark_collection_name(&bookmark_id, "Research")?;
|
||||
source.set_bookmark_tags(&bookmark_id, vec!["rust".to_string(), "gpui".to_string()])?;
|
||||
source.set_bookmark_note(&bookmark_id, "Read later")?;
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -129,6 +130,7 @@ fn sync_snapshot_imports_remote_tabs_into_active_scope() -> Result<(), Box<dyn E
|
||||
source.toggle_active_tab_pinned()?;
|
||||
source.toggle_active_tab_favorite()?;
|
||||
source.set_active_tab_zoom_percent(125)?;
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -166,6 +168,7 @@ fn sync_snapshot_imports_remote_spaces_before_tabs() -> Result<(), Box<dyn Error
|
||||
let research_home_tab_id = source.snapshot()?.active_tab_id;
|
||||
source.set_tab_sync_enabled(&research_home_tab_id, false)?;
|
||||
source.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -203,6 +206,7 @@ fn sync_snapshot_updates_existing_tab_metadata() -> Result<(), Box<dyn Error>> {
|
||||
let source_tab_id = source.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
source.set_tab_title(&source_tab_id, "Research Brief")?;
|
||||
source.set_tab_favicon_key(&source_tab_id, "https://example.com/favicon.ico")?;
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -226,6 +230,7 @@ fn sync_snapshot_omits_paused_tabs() -> Result<(), Box<dyn Error>> {
|
||||
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);
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -250,6 +255,7 @@ fn sync_snapshot_updates_existing_bookmark_metadata() -> Result<(), Box<dyn Erro
|
||||
source.set_bookmark_collection_name(&source_bookmark_id, "Research")?;
|
||||
source.set_bookmark_tags(&source_bookmark_id, vec!["servo".to_string()])?;
|
||||
source.set_bookmark_note(&source_bookmark_id, "Canonical")?;
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -279,6 +285,7 @@ fn sync_snapshot_omits_paused_bookmarks() -> Result<(), Box<dyn Error>> {
|
||||
source.set_tab_sync_enabled(&source_tab_id, false)?;
|
||||
source.bookmark_active_tab()?;
|
||||
source.set_sync_object_policy(SyncObjectKind::Bookmarks, SyncObjectPolicy::Paused);
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -301,6 +308,7 @@ fn sync_snapshot_imports_remote_url_notes_into_active_scope() -> Result<(), Box<
|
||||
source.set_tab_sync_enabled(&source_tab_id, false)?;
|
||||
source.set_tab_title(&source_tab_id, "Research Brief")?;
|
||||
source.save_active_url_note(" # Finding\r\n- one ")?;
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -332,6 +340,7 @@ fn sync_snapshot_imports_remote_tab_notes_after_tabs() -> Result<(), Box<dyn Err
|
||||
let source_tab_id = source.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
source.set_tab_title(&source_tab_id, "Research Brief")?;
|
||||
source.save_active_tab_note("pinned tab context")?;
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -365,6 +374,7 @@ fn sync_snapshot_updates_existing_note_body() -> Result<(), Box<dyn Error>> {
|
||||
source.set_tab_sync_enabled(&source_tab_id, false)?;
|
||||
source.set_tab_title(&source_tab_id, "Research Brief")?;
|
||||
source.save_active_url_note("canonical note")?;
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -395,6 +405,7 @@ fn sync_snapshot_omits_paused_notes() -> Result<(), Box<dyn Error>> {
|
||||
source.set_tab_sync_enabled(&source_tab_id, false)?;
|
||||
source.save_active_url_note("local only")?;
|
||||
source.set_sync_object_policy(SyncObjectKind::Notes, SyncObjectPolicy::Paused);
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -420,3 +431,7 @@ fn sync_snapshot_rejects_unknown_schema_rev() -> Result<(), Box<dyn Error>> {
|
||||
assert!(error.to_string().contains("unsupported schema_rev 999"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pause_history_sync(core: &mut BrowserCore) {
|
||||
core.set_sync_object_policy(SyncObjectKind::History, SyncObjectPolicy::Paused);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
use std::error::Error;
|
||||
|
||||
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||
use ely_domain::{SyncObjectKind, SyncObjectPolicy, UrlText};
|
||||
|
||||
#[test]
|
||||
fn sync_snapshot_imports_remote_history_into_active_scope() -> Result<(), Box<dyn Error>> {
|
||||
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.set_tab_title(&source_tab_id, "Research Brief")?;
|
||||
source.set_tab_favicon_key(&source_tab_id, "favicons/example.ico")?;
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let target_profile_id = target.snapshot()?.active_profile_id;
|
||||
let target_space_id = target.snapshot()?.active_space_id;
|
||||
let summary = target.apply_sync_snapshot_bytes(&bytes)?;
|
||||
let snapshot = target.snapshot()?;
|
||||
let [entry] = snapshot.history_entries.as_slice() else {
|
||||
return Err(
|
||||
format!("expected 1 history entry, got {}", snapshot.history_entries.len()).into()
|
||||
);
|
||||
};
|
||||
|
||||
assert_eq!(summary.imported(), 1);
|
||||
assert_eq!(summary.updated(), 0);
|
||||
assert_eq!(summary.skipped(), 0);
|
||||
assert_eq!(entry.profile_id(), &target_profile_id);
|
||||
assert_eq!(entry.space_id(), &target_space_id);
|
||||
assert_eq!(entry.source_tab_id(), &source_tab_id);
|
||||
assert_eq!(entry.title(), "Research Brief");
|
||||
assert_eq!(entry.url().as_str(), "https://example.com/research");
|
||||
assert_eq!(entry.favicon_key(), Some("favicons/example.ico"));
|
||||
assert_eq!(entry.visit_count(), 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_snapshot_updates_existing_history_entry() -> Result<(), Box<dyn Error>> {
|
||||
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 first_source_tab_id = source.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
source.set_tab_sync_enabled(&first_source_tab_id, false)?;
|
||||
let latest_source_tab_id = source.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
source.set_tab_sync_enabled(&latest_source_tab_id, false)?;
|
||||
source.set_tab_title(&latest_source_tab_id, "Canonical Research")?;
|
||||
source.set_tab_favicon_key(&latest_source_tab_id, "favicons/canonical.ico")?;
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let target_tab_id = target.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
target.set_tab_title(&target_tab_id, "Old Research")?;
|
||||
target.set_tab_favicon_key(&target_tab_id, "favicons/old.ico")?;
|
||||
let summary = target.apply_sync_snapshot_bytes(&bytes)?;
|
||||
let snapshot = target.snapshot()?;
|
||||
let [entry] = snapshot.history_entries.as_slice() else {
|
||||
return Err(
|
||||
format!("expected 1 history entry, got {}", snapshot.history_entries.len()).into()
|
||||
);
|
||||
};
|
||||
|
||||
assert_eq!(summary.imported(), 0);
|
||||
assert_eq!(summary.updated(), 1);
|
||||
assert_eq!(summary.skipped(), 0);
|
||||
assert_eq!(entry.source_tab_id(), &target_tab_id);
|
||||
assert_eq!(entry.title(), "Canonical Research");
|
||||
assert_eq!(entry.favicon_key(), Some("favicons/canonical.ico"));
|
||||
assert_eq!(entry.visit_count(), 2);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_snapshot_omits_paused_history() -> Result<(), Box<dyn Error>> {
|
||||
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.set_sync_object_policy(SyncObjectKind::History, 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.history_entries.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
@@ -94,6 +94,13 @@ fn paused_profile_data_is_omitted_from_sync_snapshots() -> Result<(), Box<dyn Er
|
||||
assert_eq!(summary.updated(), 0);
|
||||
assert_eq!(summary.skipped(), 0);
|
||||
assert!(snapshot.profiles.iter().any(|profile| profile.name() == "Research"));
|
||||
let imported_profile_id = snapshot
|
||||
.profiles
|
||||
.iter()
|
||||
.find(|profile| profile.name() == "Research")
|
||||
.ok_or("missing imported profile")?
|
||||
.id()
|
||||
.clone();
|
||||
assert!(
|
||||
snapshot.tabs.iter().all(|tab| tab.url().as_str() != "https://example.com/paused-profile")
|
||||
);
|
||||
@@ -101,5 +108,7 @@ fn paused_profile_data_is_omitted_from_sync_snapshots() -> Result<(), Box<dyn Er
|
||||
assert!(snapshot.notes.is_empty());
|
||||
assert!(snapshot.reading_list.is_empty());
|
||||
assert!(snapshot.site_permissions.is_empty());
|
||||
target.select_profile(&imported_profile_id)?;
|
||||
assert!(target.snapshot()?.history_entries.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ fn sync_snapshot_imports_remote_reading_list_into_active_scope() -> Result<(), B
|
||||
&entry_id,
|
||||
ReadingProgress::InProgress(ReadingProgressPercent::new(42)?),
|
||||
)?;
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -52,6 +53,7 @@ fn sync_snapshot_updates_existing_reading_list_entry() -> Result<(), Box<dyn Err
|
||||
source.set_tab_title(&source_tab_id, "Canonical Long Read")?;
|
||||
let source_entry_id = source.save_active_tab_to_reading_list()?;
|
||||
source.set_reading_list_progress(&source_entry_id, ReadingProgress::Finished)?;
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -84,6 +86,7 @@ fn sync_snapshot_omits_paused_reading_list() -> Result<(), Box<dyn Error>> {
|
||||
source.set_tab_sync_enabled(&source_tab_id, false)?;
|
||||
source.save_active_tab_to_reading_list()?;
|
||||
source.set_sync_object_policy(SyncObjectKind::ReadingList, SyncObjectPolicy::Paused);
|
||||
pause_history_sync(&mut source);
|
||||
let bytes = source.build_sync_snapshot_bytes()?;
|
||||
|
||||
let mut target = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
@@ -96,3 +99,7 @@ fn sync_snapshot_omits_paused_reading_list() -> Result<(), Box<dyn Error>> {
|
||||
assert!(snapshot.reading_list.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pause_history_sync(core: &mut BrowserCore) {
|
||||
core.set_sync_object_policy(SyncObjectKind::History, SyncObjectPolicy::Paused);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user