diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-19 18:59:43 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-19 18:59:43 +0300 |
| commit | 46a2b259a71828e7fcdeab1f67ef675304e2ca14 (patch) | |
| tree | 0b8aa654d8977ff24ecb25763e961d4a6fa78615 /tests/cli_wrapper.rs | |
| parent | 26c5f97a908c1ebe4228302d1b9e8c5423b2ab75 (diff) | |
fix: defer api worktree operations
refs #686
refs #657
refs #662
refs https://github.com/ogulcancelik/herdr/discussions/687
Diffstat (limited to 'tests/cli_wrapper.rs')
| -rw-r--r-- | tests/cli_wrapper.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/cli_wrapper.rs b/tests/cli_wrapper.rs index 53d91c43..1870f670 100644 --- a/tests/cli_wrapper.rs +++ b/tests/cli_wrapper.rs @@ -2008,6 +2008,76 @@ fn worktree_management_commands_work() { } #[test] +fn forced_worktree_remove_terminates_processes_inside_checkout() { + let base = unique_test_dir(); + let config_home = base.join("config"); + let runtime_dir = base.join("runtime"); + let socket_path = runtime_dir.join("herdr.sock"); + let repo = base.join("repo"); + let checkout = base.join("checkout-with-process"); + create_committed_repo(&repo); + + let herdr = spawn_herdr(&config_home, &runtime_dir, &socket_path); + wait_for_socket(&socket_path, Duration::from_secs(5)); + + let created = run_cli_json( + &socket_path, + &[ + "worktree", + "create", + "--cwd", + repo.to_str().unwrap(), + "--branch", + "worktree/force-process", + "--path", + checkout.to_str().unwrap(), + "--json", + ], + ); + let child_workspace_id = created["result"]["workspace"]["workspace_id"] + .as_str() + .unwrap() + .to_string(); + let pane_id = created["result"]["root_pane"]["pane_id"] + .as_str() + .unwrap() + .to_string(); + + let pid_file = base.join("worktree-remove-force.pid"); + let command = format!( + "python3 -c 'import os,time,pathlib; pathlib.Path(r\"{}\").write_text(str(os.getpid())); time.sleep(1000)'", + pid_file.display() + ); + let ran = run_cli(&socket_path, &["pane", "run", &pane_id, &command]); + assert!( + ran.status.success(), + "stderr: {}", + String::from_utf8_lossy(&ran.stderr) + ); + let pid = wait_for_pid_file(&pid_file, Duration::from_secs(5)).unwrap_or_else(|err| { + panic!("failed to read pane child pid: {err}"); + }); + assert!(process_exists(pid), "child process was not running"); + + let removed = run_cli_json( + &socket_path, + &[ + "worktree", + "remove", + "--workspace", + &child_workspace_id, + "--force", + "--json", + ], + ); + assert_eq!(removed["result"]["type"], "worktree_removed"); + assert!(wait_for_pid_exit(pid, Duration::from_secs(3))); + assert!(!checkout.exists()); + + cleanup_spawned_herdr(herdr, base); +} + +#[test] fn worktree_open_existing_checkout_by_path_and_branch() { let base = unique_test_dir(); let config_home = base.join("config"); |
