| 2373 | |
| 2374 | #[tracing::instrument(name = "verify", skip_all)] |
| 2375 | fn verify() -> CliResult<ShimSnapshot> { |
| 2376 | let root = find_repository_root()?; |
| 2377 | // CB-13A R2: diagnosis is a read-only observation boundary. Opening for |
| 2378 | // operation inspection performs no migration, no deferred-tree alignment, |
| 2379 | // and no operation recovery, so an incomplete repository is *reported* |
| 2380 | // rather than silently repaired before any verdict is collected. |
| 2381 | let repo = Repository::open_readonly_for_operation_inspection(&root).map_err(CliError::from)?; |
| 2382 | let working_copy = repo.require_working_copy_id().map_err(CliError::from)?; |
| 2383 | let git = open_git(&root)?; |
| 2384 | let policy = conversion_policy(&git)?; |
| 2385 | let filter = GitAttributesFilter::for_repository(&root); |
| 2386 | |
| 2387 | // CB-11A: `atomic shim verify` proves all five layers, or reports |
| 2388 | // structured divergence. Every check is read-only. |
| 2389 | let mut verdicts: Vec<(&'static str, bool, String)> = Vec::new(); |
| 2390 | |
| 2391 | // Layer 0 — operations: the journal heads are complete and verified. |
| 2392 | // An incomplete or diverged head means the repository is mid-recovery; |
| 2393 | // diagnosis reports it instead of recovering before inspection. |
| 2394 | verdicts.push(operation_layer_verdict(&repo, working_copy)); |
| 2395 | |
| 2396 | // Layer 1 — durable: working-copy desired state equals the view head. |
| 2397 | let view_name = repo |
| 2398 | .desired_view_name(working_copy) |
| 2399 | .map_err(CliError::from)?; |
| 2400 | let record = repo |
| 2401 | .working_copy_record(working_copy) |
| 2402 | .map_err(CliError::from)?; |
| 2403 | let view_info = repo.get_view_info(&view_name).map_err(CliError::from)?; |
| 2404 | let durable_ok = view_info.state == record.desired_state; |
| 2405 | verdicts.push(( |
| 2406 | "durable", |
| 2407 | durable_ok, |
| 2408 | if durable_ok { |
| 2409 | format!( |
| 2410 | "working copy desired state {} matches view '{}' head", |
| 2411 | record.desired_state, view_name |
| 2412 | ) |
| 2413 | } else { |
| 2414 | format!( |
| 2415 | "working copy desired state {} diverges from view '{}' head {}", |
| 2416 | record.desired_state, view_name, view_info.state |
| 2417 | ) |
| 2418 | }, |
| 2419 | )); |
| 2420 | |
| 2421 | // Layer 2 — manifest: the durable projection builds and equals the Git |
| 2422 | // HEAD tree. |
| 2423 | let mut projected_tree: Option<atomic_core::operation::GitObjectId> = None; |
| 2424 | match repo.project_tree(&view_name, &policy) { |
| 2425 | Ok(project) => { |
| 2426 | let head_tree: Option<git2::Oid> = git |
| 2427 | .head() |
| 2428 | .ok() |
| 2429 | .and_then(|head| head.peel_to_commit().ok()) |
| 2430 | .and_then(|commit| commit.tree().ok()) |
| 2431 | .map(|tree| tree.id()); |
| 2432 | let projected = Some(project.git.root.clone()); |