@@ -38,7 +38,7 @@ use crate::{
3838 MonoApiServiceState , oauth:: api_store:: BrowserSessionStore ,
3939 router:: snapshot_router:: routers,
4040 } ,
41- callisto:: { mega_refs, mst2_verified_object} ,
41+ callisto:: { mega_refs, mst2_verified_object, sea_orm_active_enums :: PushQueueKindEnum } ,
4242 ceres:: {
4343 api_service:: { ApiHandler , cache:: GitObjectCache , mono_api_service:: MonoApiService } ,
4444 snapshot:: {
@@ -48,15 +48,22 @@ use crate::{
4848 } ,
4949 } ,
5050 common:: utils:: MEGA_BRANCH_NAME ,
51- config:: testing:: isolated_config,
51+ config:: { model :: PushPolicy , testing:: isolated_config} ,
5252 jupiter:: {
53- service:: git_service:: GitService ,
53+ service:: {
54+ git_service:: GitService ,
55+ push_queue_service:: {
56+ EnqueueRequest , ExecuteOutcome , ExecuteRequest , PushExecContext , PushPayload ,
57+ push_operation_id,
58+ } ,
59+ } ,
5460 storage:: {
5561 base_storage:: StorageConnector ,
5662 mono_storage:: MST2_VERIFICATION_VERSION ,
5763 object_storage:: { MegaObjectStorageWrapper , build_object_storage} ,
64+ push_queue_storage:: { ClaimOutcome , EnqueueOutcome } ,
5865 } ,
59- tests:: { test_redis_manager, test_storage_with_config} ,
66+ tests:: { test_redis_manager, test_storage_with_config, with_test_vault } ,
6067 } ,
6168 orbit_api:: {
6269 error:: OrbitResult ,
@@ -221,10 +228,82 @@ fn digest(bytes: &[u8]) -> [u8; 32] {
221228 Sha256 :: digest ( bytes) . into ( )
222229}
223230
231+ async fn publish_native_push (
232+ storage : & crate :: jupiter:: storage:: Storage ,
233+ path : & str ,
234+ old : ObjectHash ,
235+ new : & Commit ,
236+ ) {
237+ let old_id = old. to_string ( ) ;
238+ let new_id = new. id . to_string ( ) ;
239+ let payload = PushPayload {
240+ commits : vec ! [ new_id. clone( ) ] ,
241+ fork_base : Some ( old_id. clone ( ) ) ,
242+ n : 1 ,
243+ } ;
244+ let outcome = storage
245+ . push_queue_service
246+ . enqueue ( EnqueueRequest {
247+ kind : PushQueueKindEnum :: Push ,
248+ operation_id : push_operation_id ( & old_id, & new_id) ,
249+ path : path. to_string ( ) ,
250+ old_id,
251+ new_id,
252+ requester : None ,
253+ payload : payload. to_json ( ) ,
254+ ref_name : Some ( MEGA_BRANCH_NAME . to_string ( ) ) ,
255+ is_delete : false ,
256+ } )
257+ . await
258+ . unwrap ( ) ;
259+ let EnqueueOutcome :: Inserted { id } = outcome else {
260+ panic ! ( "fresh fixture push must insert: {outcome:?}" ) ;
261+ } ;
262+ assert_eq ! (
263+ storage
264+ . push_queue_service
265+ . storage( )
266+ . claim_for_execution( id)
267+ . await
268+ . unwrap( ) ,
269+ ClaimOutcome :: Claimed
270+ ) ;
271+ let context = PushExecContext {
272+ storage : storage. clone ( ) ,
273+ git_object_cache : Arc :: new ( GitObjectCache {
274+ connection : test_redis_manager ( ) . await ,
275+ prefix : String :: new ( ) ,
276+ } ) ,
277+ pre_apply_enter_barrier : None ,
278+ pre_apply_release_barrier : None ,
279+ } ;
280+ let outcome = storage
281+ . push_queue_service
282+ . execute_b3 (
283+ ExecuteRequest {
284+ id,
285+ ..Default :: default ( )
286+ } ,
287+ None ,
288+ None ,
289+ Some ( & context) ,
290+ )
291+ . await
292+ . unwrap ( ) ;
293+ assert ! ( matches!(
294+ outcome,
295+ ExecuteOutcome :: Done {
296+ root_cas_writes: 1 ,
297+ ..
298+ }
299+ ) ) ;
300+ }
301+
224302impl Fixture {
225303 async fn new ( ) -> Self {
226304 let temp = tempfile:: tempdir ( ) . unwrap ( ) ;
227305 let mut config = isolated_config ( temp. path ( ) . join ( "config" ) ) ;
306+ config. monorepo . push_policy = PushPolicy :: Trunk ;
228307 config. mst2 . enabled = true ;
229308 config. mst2 . publication_enabled = true ;
230309 config. mst2 . instance_uuid = Some ( uuid:: Uuid :: new_v4 ( ) . to_string ( ) ) ;
@@ -238,6 +317,7 @@ impl Fixture {
238317 counts : counts. clone ( ) ,
239318 } ) ) ,
240319 } ;
320+ let storage = with_test_vault ( storage, temp. path ( ) ) . await ;
241321 // Unique bytes prevent another test's process-wide digest cache from
242322 // turning a required cold read into a hit. These bytes also look like
243323 // a Git object header, and contain NUL and non-UTF-8 content.
@@ -273,6 +353,20 @@ impl Fixture {
273353 item( TreeItemMode :: Link , link_oid, "link" ) ,
274354 item( TreeItemMode :: Tree , nested. id, "nested" ) ,
275355 ] ) ;
356+ let old_tip = Commit :: from_tree_id_with_kind (
357+ HashKind :: Sha1 ,
358+ project. id ,
359+ vec ! [ ] ,
360+ "fixed content initial path tip" ,
361+ )
362+ . unwrap ( ) ;
363+ let new_tip = Commit :: from_tree_id_with_kind (
364+ HashKind :: Sha1 ,
365+ project. id ,
366+ vec ! [ old_tip. id] ,
367+ "fixed content published path tip" ,
368+ )
369+ . unwrap ( ) ;
276370 let root = tree ( vec ! [
277371 item( TreeItemMode :: Blob , blob_oid, "outside" ) ,
278372 item( TreeItemMode :: Tree , project. id, "project" ) ,
@@ -292,7 +386,7 @@ impl Fixture {
292386 )
293387 . await
294388 . unwrap ( ) ;
295- mono. save_mega_commits ( vec ! [ commit. clone( ) ] , None )
389+ mono. save_mega_commits ( vec ! [ commit. clone( ) , old_tip . clone ( ) , new_tip . clone ( ) ] , None )
296390 . await
297391 . unwrap ( ) ;
298392 mono. save_refs (
@@ -307,9 +401,30 @@ impl Fixture {
307401 )
308402 . await
309403 . unwrap ( ) ;
404+ mono. save_refs (
405+ mega_refs:: Model :: new (
406+ "/project" . to_string ( ) ,
407+ MEGA_BRANCH_NAME . to_string ( ) ,
408+ old_tip. id . to_string ( ) ,
409+ old_tip. tree_id . to_string ( ) ,
410+ false ,
411+ ) ,
412+ None ,
413+ )
414+ . await
415+ . unwrap ( ) ;
310416 mono. initialize_native_publication ( storage. config ( ) . mst2 . instance_uuid . as_deref ( ) . unwrap ( ) )
311417 . await
312418 . unwrap ( ) ;
419+ publish_native_push ( & storage, "/project" , old_tip. id , & new_tip) . await ;
420+ let head = mono
421+ . read_native_publication_head ( storage. config ( ) . mst2 . instance_uuid . as_deref ( ) . unwrap ( ) )
422+ . await
423+ . unwrap ( ) ;
424+ assert_eq ! ( head. token. sequence, 1 ) ;
425+ assert ! ( head. token. certificate. is_some( ) ) ;
426+ assert_eq ! ( head. root. commit, commit. id. to_string( ) ) ;
427+ assert_eq ! ( head. root. tree, root. id. to_string( ) ) ;
313428 let state = MonoApiServiceState {
314429 entity_store : storage. entity_store . clone ( ) ,
315430 storage,
@@ -1018,25 +1133,49 @@ async fn mst2_fixed_warm_map_still_checks_map_indices_batches_and_http_lease() {
10181133async fn mst2_fixed_old_snapshot_reads_its_original_oid_after_real_ref_advances ( ) {
10191134 let fixture = Fixture :: new ( ) . await ;
10201135 let mono = fixture. state . storage . mono_storage ( ) ;
1021- let mut main = mono. get_main_ref ( "/" ) . await . unwrap ( ) . unwrap ( ) ;
1022- let old_commit = ObjectHash :: from_hex_for_kind ( HashKind :: Sha1 , & main. ref_commit_hash ) . unwrap ( ) ;
1023- let new_root = tree ( vec ! [ ] ) ;
1136+ let main = mono. get_main_ref ( "/" ) . await . unwrap ( ) . unwrap ( ) ;
1137+ let project = mono. get_main_ref ( "/project" ) . await . unwrap ( ) . unwrap ( ) ;
1138+ let old_commit =
1139+ ObjectHash :: from_hex_for_kind ( HashKind :: Sha1 , & project. ref_commit_hash ) . unwrap ( ) ;
1140+ let blob_oid = ObjectHash :: from_hex_for_kind ( HashKind :: Sha1 , & fixture. oid ) . unwrap ( ) ;
1141+ let new_tree = tree ( vec ! [ item( TreeItemMode :: Blob , blob_oid, "new-only" ) ] ) ;
10241142 let new_commit = Commit :: from_tree_id_with_kind (
10251143 HashKind :: Sha1 ,
1026- new_root . id ,
1144+ new_tree . id ,
10271145 vec ! [ old_commit] ,
1028- "advanced empty ref " ,
1146+ "advanced project without old paths " ,
10291147 )
10301148 . unwrap ( ) ;
1031- mono. save_mega_trees ( vec ! [ new_root . clone( ) ] , new_commit. id , None )
1149+ mono. save_mega_trees ( vec ! [ new_tree . clone( ) ] , new_commit. id , None )
10321150 . await
10331151 . unwrap ( ) ;
10341152 mono. save_mega_commits ( vec ! [ new_commit. clone( ) ] , None )
10351153 . await
10361154 . unwrap ( ) ;
1037- main. ref_commit_hash = new_commit. id . to_string ( ) ;
1038- main. ref_tree_hash = new_root. id . to_string ( ) ;
1039- mono. update_ref ( main, None ) . await . unwrap ( ) ;
1155+ publish_native_push ( & fixture. state . storage , "/project" , old_commit, & new_commit) . await ;
1156+ let head = mono
1157+ . read_native_publication_head (
1158+ fixture
1159+ . state
1160+ . storage
1161+ . config ( )
1162+ . mst2
1163+ . instance_uuid
1164+ . as_deref ( )
1165+ . unwrap ( ) ,
1166+ )
1167+ . await
1168+ . unwrap ( ) ;
1169+ assert_eq ! ( head. token. sequence, 2 ) ;
1170+ assert ! ( head. token. certificate. is_some( ) ) ;
1171+ assert_ne ! ( head. root. commit, main. ref_commit_hash) ;
1172+ assert_ne ! ( head. root. tree, main. ref_tree_hash) ;
1173+ let published = mono. get_main_ref ( "/" ) . await . unwrap ( ) . unwrap ( ) ;
1174+ assert_eq ! ( head. root. commit, published. ref_commit_hash) ;
1175+ assert_eq ! ( head. root. tree, published. ref_tree_hash) ;
1176+ let published_project = mono. get_main_ref ( "/project" ) . await . unwrap ( ) . unwrap ( ) ;
1177+ assert_eq ! ( published_project. ref_commit_hash, new_commit. id. to_string( ) ) ;
1178+ assert_eq ! ( published_project. ref_tree_hash, new_tree. id. to_string( ) ) ;
10401179 let response = fixture. send ( "HEAD" , "blob?path=/file" , Body :: empty ( ) ) . await ;
10411180 assert_eq ! ( response. status( ) , 200 ) ;
10421181 assert_eq ! (
0 commit comments