MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / verify_convergence

Method verify_convergence

atomic-cli/src/commands/clone/command.rs:500–543  ·  view source on GitHub ↗

Verify convergence with the order-invariant `SetId`: each applied view's local **effective** set-id must equal the remote's, taken from the server view inventory (`GET /refs/views`), which the server folds over each view's effective (own ∪ ancestors) change set. Comparing against the server-computed value — an independent source — catches a dropped or corrupt change that counts/merkle-order alone

(
        &self,
        repo: &Repository,
        remote: &HttpRemote,
        views: &HashSet<String>,
    )

Source from the content-addressed store, hash-verified

498 /// corrupt change that counts/merkle-order alone would miss, and is correct
499 /// for drafts (whose effective set differs from their own set).
500 async fn verify_convergence(
501 &self,
502 repo: &Repository,
503 remote: &HttpRemote,
504 views: &HashSet<String>,
505 ) {
506 let inventory = match remote.list_view_refs().await {
507 Ok(inv) => inv,
508 // Inventory unavailable — skip verification rather than fail the clone.
509 Err(_) => return,
510 };
511 let remote_set: HashMap<String, String> = inventory
512 .into_iter()
513 .filter_map(|v| v.set_id.map(|s| (v.name, s)))
514 .collect();
515
516 let mut verified = 0usize;
517 let mut mismatched = 0usize;
518 for view in views {
519 let Some(expected) = remote_set.get(view) else {
520 continue; // remote reported no set-id for this view
521 };
522 match repo.view_set_id(view) {
523 Ok(local) if &local.to_base32() == expected => verified += 1,
524 Ok(local) => {
525 mismatched += 1;
526 print_warning(&format!(
527 "Set-id mismatch for view '{}': local {} != remote {}. \
528 The clone may be incomplete or divergent.",
529 view,
530 local.to_base32(),
531 expected
532 ));
533 }
534 Err(e) => print_warning(&format!(
535 "Could not compute local set-id for view '{}': {}",
536 view, e
537 )),
538 }
539 }
540 if mismatched == 0 && verified > 0 {
541 print_success("Verified: cloned view set-ids match the remote (convergent)");
542 }
543 }
544
545 /// Index a pack's change objects into `base32 hash → bytes` for local save.
546 fn change_objects_from_pack(pack: &SyncPack) -> HashMap<String, Vec<u8>> {

Callers 1

run_asyncMethod · 0.80

Calls 8

print_warningFunction · 0.85
print_successFunction · 0.85
list_view_refsMethod · 0.80
view_set_idMethod · 0.80
getMethod · 0.65
collectMethod · 0.45
into_iterMethod · 0.45
to_base32Method · 0.45

Tested by

no test coverage detected