mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 23:36:11 +00:00
fix(daemon): leave repos alone while grove add or clone is still building them
Add a .grove-busy marker held by migrate and clone/init, treat a repo as ready only with .bare/HEAD and no marker or .grove-stage, warn once on stale markers. Also re-watch recreated dirs by inode, watch shallow dirs before discovery, and retry failed watches with a rate-limited log. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3784e1533b
commit
e2abeed414
8 files changed
+335
-45
No files matched your search
@@ -656,3 +656,91 @@ fn not_migrated_list_follows_clones_added_and_removed() {
|
||||
});
|
||||
d.shutdown();
|
||||
}
|
||||
|
||||
fn events(sock: &Path, kind: &str) -> Vec<serde_json::Value> {
|
||||
let log = ipc::request(sock, &json!({"v":1,"cmd":"log","limit":500})).unwrap();
|
||||
log["data"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|e| e["kind"] == kind)
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repo_with_busy_marker_is_ignored_until_the_marker_is_removed() {
|
||||
let w = world("rd-busy", &["pca"]);
|
||||
let root = w.base.join("pca");
|
||||
let (d, sock) = start_event_only(&w, "pca");
|
||||
wait_until("initial repo listed", 10, || repo_paths(&sock).len() == 1);
|
||||
|
||||
let new = root.join("g/halfway");
|
||||
fs::create_dir_all(&new).unwrap();
|
||||
fs::write(
|
||||
new.join(".grove-busy"),
|
||||
format!("{} 1\n", std::process::id()),
|
||||
)
|
||||
.unwrap();
|
||||
bare_layout(&new, &w.remote);
|
||||
std::thread::sleep(Duration::from_millis(1500));
|
||||
assert_eq!(repo_paths(&sock).len(), 1, "busy repo must not be managed");
|
||||
assert!(git(&w.remote, &["for-each-ref", "refs/sync/"]).is_empty());
|
||||
|
||||
fs::remove_file(new.join(".grove-busy")).unwrap();
|
||||
wait_until("repo managed once the marker is gone", 10, || {
|
||||
repo_paths(&sock).contains(&new.display().to_string())
|
||||
});
|
||||
d.shutdown();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stale_busy_marker_keeps_the_repo_out_and_warns_once() {
|
||||
let w = world("rd-stale", &["pca"]);
|
||||
let root = w.base.join("pca");
|
||||
let stale = root.join("g/crashed");
|
||||
fs::create_dir_all(&stale).unwrap();
|
||||
bare_layout(&stale, &w.remote);
|
||||
fs::write(stale.join(".grove-busy"), "999999999 1\n").unwrap();
|
||||
let (d, sock) = start_event_only(&w, "pca");
|
||||
wait_until("warning logged", 10, || {
|
||||
!events(&sock, "repo_stalled").is_empty()
|
||||
});
|
||||
// Another rescan must not repeat the warning, and the marker is never deleted.
|
||||
fs::create_dir_all(root.join("g/other")).unwrap();
|
||||
std::thread::sleep(Duration::from_millis(1500));
|
||||
assert_eq!(events(&sock, "repo_stalled").len(), 1);
|
||||
assert_eq!(repo_paths(&sock).len(), 1);
|
||||
assert!(stale.join(".grove-busy").exists());
|
||||
d.shutdown();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clone_appears_only_when_complete() {
|
||||
let w = world("rd-clonecomplete", &["pca"]);
|
||||
let root = w.base.join("pca");
|
||||
let (d, sock) = start_event_only(&w, "pca");
|
||||
wait_until("initial repo listed", 10, || repo_paths(&sock).len() == 1);
|
||||
|
||||
let new = root.join("g/cloned");
|
||||
let url = w.remote.display().to_string();
|
||||
let target = new.clone();
|
||||
let h = std::thread::spawn(move || {
|
||||
grove_core::registry::clone_bare_layout(&url, &target, &[]).unwrap()
|
||||
});
|
||||
let mut seen = false;
|
||||
let end = Instant::now() + Duration::from_secs(30);
|
||||
while Instant::now() < end && !seen {
|
||||
if repo_paths(&sock).contains(&new.display().to_string()) {
|
||||
// Listed: the clone must be finished, never in the middle.
|
||||
assert!(!new.join(".grove-busy").exists());
|
||||
assert!(new.join(".bare/HEAD").exists());
|
||||
assert!(new.join("main").is_dir());
|
||||
seen = true;
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
}
|
||||
h.join().unwrap();
|
||||
assert!(seen, "cloned repo never managed");
|
||||
d.shutdown();
|
||||
}
|
||||
Reference in new issue
Block a user