| 2417 | |
| 2418 | #[tracing::instrument(name = "verify", skip_all)] |
| 2419 | fn verify() -> CliResult<ShimSnapshot> { |
| 2420 | let root = find_repository_root()?; |
| 2421 | // CB-13A R2: diagnosis is a read-only observation boundary. Opening for |
| 2422 | // operation inspection performs no migration, no deferred-tree alignment, |
| 2423 | // and no operation recovery, so an incomplete repository is *reported* |
| 2424 | // rather than silently repaired before any verdict is collected. |
| 2425 | let repo = Repository::open_readonly_for_operation_inspection(&root).map_err(CliError::from)?; |
| 2426 | let working_copy = repo.require_working_copy_id().map_err(CliError::from)?; |
| 2427 | let git = open_git(&root)?; |
| 2428 | let policy = conversion_policy(&git)?; |
| 2429 | let filter = GitAttributesFilter::for_repository(&root); |
| 2430 | |
| 2431 | // CB-11A: `atomic shim verify` proves all five layers, or reports |
| 2432 | // structured divergence. Every check is read-only. |
| 2433 | let mut verdicts: Vec<(&'static str, bool, String)> = Vec::new(); |
| 2434 | |
| 2435 | // Layer 0 — operations: the journal heads are complete and verified. |
| 2436 | // An incomplete or diverged head means the repository is mid-recovery; |
| 2437 | // diagnosis reports it instead of recovering before inspection. |
| 2438 | verdicts.push(operation_layer_verdict(&repo, working_copy)); |
| 2439 | |
| 2440 | // Layer 1 — durable: working-copy desired state equals the view head. |
| 2441 | let view_name = repo |
| 2442 | .desired_view_name(working_copy) |
| 2443 | .map_err(CliError::from)?; |
| 2444 | let record = repo |
| 2445 | .working_copy_record(working_copy) |
| 2446 | .map_err(CliError::from)?; |
| 2447 | let view_info = repo.get_view_info(&view_name).map_err(CliError::from)?; |
| 2448 | let durable_ok = view_info.state == record.desired_state; |
| 2449 | verdicts.push(( |
| 2450 | "durable", |
| 2451 | durable_ok, |
| 2452 | if durable_ok { |
| 2453 | format!( |
| 2454 | "working copy desired state {} matches view '{}' head", |
| 2455 | record.desired_state, view_name |
| 2456 | ) |
| 2457 | } else { |
| 2458 | format!( |
| 2459 | "working copy desired state {} diverges from view '{}' head {}", |
| 2460 | record.desired_state, view_name, view_info.state |
| 2461 | ) |
| 2462 | }, |
| 2463 | )); |
| 2464 | |
| 2465 | // Layer 2 — manifest: the durable projection builds and equals the Git |
| 2466 | // HEAD tree. |
| 2467 | let mut projected_tree: Option<atomic_core::operation::GitObjectId> = None; |
| 2468 | match repo.project_tree(&view_name, &policy) { |
| 2469 | Ok(project) => { |
| 2470 | let head_tree: Option<git2::Oid> = git |
| 2471 | .head() |
| 2472 | .ok() |
| 2473 | .and_then(|head| head.peel_to_commit().ok()) |
| 2474 | .and_then(|commit| commit.tree().ok()) |
| 2475 | .map(|tree| tree.id()); |
| 2476 | let projected = Some(project.git.root.clone()); |