restore_tests.rs (5132B)
1 use super::*; 2 use radroots_storage::backup::{BackupFormatVersion, BackupSecretPolicy}; 3 #[cfg(feature = "memory")] 4 use radroots_storage::backup::{BackupMember, BackupMemberKind, MemberDigest}; 5 6 #[cfg(feature = "memory")] 7 #[tokio::test] 8 async fn restore_metadata_is_not_a_successful_restore_capability() { 9 let client = crate::ClientBuilder::memory_default().build().unwrap(); 10 let operations = client.storage_operations().unwrap(); 11 let manifest = BackupManifest::new( 12 BackupFormatVersion::V1, 13 BackupId::new([6; 16]).unwrap(), 14 100, 15 BackupSecretPolicy::ExcludeProtectedStorage, 16 vec![ 17 BackupMember::new( 18 "runtime/events.bin", 19 BackupMemberKind::Runtime, 20 1, 21 MemberDigest::new([8; 32]), 22 ) 23 .unwrap(), 24 ], 25 ) 26 .unwrap(); 27 let restore = 28 RestorePlan::new(manifest, BackupSecretPolicy::ExcludeProtectedStorage, 200).unwrap(); 29 operations.begin_restore(restore.clone()).await.unwrap(); 30 assert_eq!( 31 operations.stage_restore(restore.clone()).await, 32 Err(RestoreCapabilityError::Unsupported) 33 ); 34 assert_eq!( 35 operations.finalize_restore(restore).await, 36 Err(RestoreCapabilityError::Unsupported) 37 ); 38 client.close().await.unwrap(); 39 } 40 41 #[cfg(feature = "sqlite")] 42 #[tokio::test] 43 async fn sdk_restore_retains_historical_ids_and_requires_an_explicit_reopen() { 44 use radroots_storage::{ 45 authored_draft::{AuthoredDraft, AuthoredDraftId, AuthoredDraftStage}, 46 event::SourceGeneration, 47 status::ShutdownState, 48 }; 49 let root = tempfile::tempdir().unwrap(); 50 let backup = tempfile::tempdir().unwrap(); 51 let paths = SqlitePaths::from_directory(root.path()).unwrap(); 52 let client = crate::ClientBuilder::sqlite( 53 SqliteOptions::new(paths.clone(), SqliteOpenMode::Create) 54 .with_source_generation(SourceGeneration::new([9; 32]).unwrap(), 100) 55 .unwrap() 56 .with_backup_root(backup.path()) 57 .unwrap(), 58 ) 59 .await 60 .unwrap() 61 .build() 62 .unwrap(); 63 let draft = AuthoredDraft::initial( 64 AuthoredDraftId::new([7; 16]).unwrap(), 65 [3; 32], 66 "fixture.restore.v1", 67 b"historical identity".to_vec(), 68 AuthoredDraftStage::Draft, 69 None, 70 100, 71 ) 72 .unwrap(); 73 let later = AuthoredDraft::initial( 74 AuthoredDraftId::new([8; 16]).unwrap(), 75 [3; 32], 76 "fixture.restore.v1", 77 b"later live state".to_vec(), 78 AuthoredDraftStage::Draft, 79 None, 80 200, 81 ) 82 .unwrap(); 83 client 84 .storage() 85 .unwrap() 86 .append_authored_draft(draft.clone(), None) 87 .await 88 .unwrap(); 89 let operations = client.storage_operations().unwrap(); 90 let plan = BackupPlan::new( 91 BackupId::new([6; 16]).unwrap(), 92 BackupFormatVersion::V1, 93 BackupSecretPolicy::IncludeProtectedStorage, 94 100, 95 ) 96 .unwrap(); 97 let manifest = operations.capture_backup(plan.clone()).await.unwrap(); 98 operations 99 .finalize_backup(plan, manifest.clone()) 100 .await 101 .unwrap(); 102 client 103 .storage() 104 .unwrap() 105 .append_authored_draft(later.clone(), None) 106 .await 107 .unwrap(); 108 let restore = 109 RestorePlan::new(manifest, BackupSecretPolicy::IncludeProtectedStorage, 200).unwrap(); 110 drop(operations.stage_restore(restore.clone())); 111 drop(operations.finalize_restore(restore.clone())); 112 assert_eq!( 113 operations.status().await.unwrap().shutdown(), 114 ShutdownState::Open 115 ); 116 assert_eq!( 117 operations 118 .stage_restore(restore.clone()) 119 .await 120 .unwrap() 121 .len(), 122 2 123 ); 124 assert_eq!( 125 client 126 .storage() 127 .unwrap() 128 .authored_draft_head(later.draft_id()) 129 .await 130 .unwrap(), 131 Some(later.clone()) 132 ); 133 operations.finalize_restore(restore.clone()).await.unwrap(); 134 assert_eq!( 135 operations.status().await.unwrap().shutdown(), 136 ShutdownState::Closed 137 ); 138 assert_eq!( 139 operations.stage_restore(restore.clone()).await, 140 Err(RestoreCapabilityError::Unavailable) 141 ); 142 assert_eq!( 143 operations.finalize_restore(restore).await, 144 Err(RestoreCapabilityError::Unavailable) 145 ); 146 client.close().await.unwrap(); 147 let reopened = 148 crate::ClientBuilder::sqlite(SqliteOptions::new(paths, SqliteOpenMode::ReadWriteExisting)) 149 .await 150 .unwrap() 151 .build() 152 .unwrap(); 153 assert_eq!( 154 reopened 155 .storage() 156 .unwrap() 157 .authored_draft_head(draft.draft_id()) 158 .await 159 .unwrap(), 160 Some(draft) 161 ); 162 assert_eq!( 163 reopened 164 .storage() 165 .unwrap() 166 .authored_draft_head(later.draft_id()) 167 .await 168 .unwrap(), 169 None 170 ); 171 reopened.close().await.unwrap(); 172 }