use cotton_client::data_dir::{prepare_locked_data_dir, LockedDataDirError, PrepareOps};use cotton_core::flavor::Flavor;use cotton_store::process_lock::{Holder, ProcessLock, LOCK_FILE};fn holder() -> Holder {Holder { pid: std::process::id(), bundle_path: "/synthetic/Recovery.app".into(), started_at: "2026-10-18T01:00:00Z".into(), }}/// RULE: Write and hold the folder lock before adoption opens any store; 75 and 151 opened one Mac's copy together for three minutes on 18 Oct 2026.#[test]fn adoption_has_the_lock_before_its_first_store_open() {let home = tempfile::tempdir().unwrap();let legacy = cotton_client::data_dir::legacy_data_dir(home.path()); std::fs::create_dir_all(&legacy).unwrap(); std::fs::write(legacy.join("registry.db"), b"synthetic marker").unwrap();let ops = PrepareOps::system() .with_read_attribute(|_| None) .with_relocate(|_, current| {let on_disk: Holder = serde_json::from_slice(&std::fs::read(current.join(LOCK_FILE)).unwrap()).unwrap(); assert_eq!(on_disk.bundle_path, "/synthetic/Recovery.app"); assert!(ProcessLock::acquire(current, holder()).is_err());Ok(Vec::new()) });let (path, _lease) = prepare_locked_data_dir(Flavor::Real, home.path(), None, &ops, holder()).unwrap(); assert_eq!(path, home.path().join("CottonDB")); assert!(!legacy.exists());}/// RULE: An existing app's live lease prevents even the legacy rename, so a second 75/151 process cannot move or open its folder (18 Oct 2026).#[test]fn a_held_legacy_folder_is_not_moved() {let home = tempfile::tempdir().unwrap();let legacy = cotton_client::data_dir::legacy_data_dir(home.path()); std::fs::create_dir_all(&legacy).unwrap(); std::fs::write(legacy.join("registry.db"), b"synthetic marker").unwrap();let _first = ProcessLock::acquire(&legacy, holder()).unwrap();let ops = PrepareOps::system() .with_read_attribute(|_| None) .with_relocate(|_, _| panic!("must not open a store"));let error = prepare_locked_data_dir(Flavor::Real, home.path(), None, &ops, holder()).unwrap_err(); assert!(matches!(error, LockedDataDirError::Lock(_))); assert!(legacy.join("registry.db").exists()); assert!(!home.path().join("CottonDB").exists());}