Converted all external tool calling to async
This commit is contained in:
@@ -25,11 +25,9 @@ impl AgentPool {
|
||||
/// continuing to run after the server exits. Collects each agent's worktree
|
||||
/// path, then SIGKILLs every process running inside that path and verifies
|
||||
/// termination before returning.
|
||||
pub fn kill_all_children(&self) {
|
||||
pub async fn kill_all_children(&self) {
|
||||
let worktree_paths: Vec<(String, std::path::PathBuf)> = {
|
||||
let Ok(agents) = self.agents.lock() else {
|
||||
return;
|
||||
};
|
||||
let agents = self.agents.lock().await;
|
||||
agents
|
||||
.iter()
|
||||
.filter_map(|(key, agent)| {
|
||||
@@ -69,11 +67,9 @@ impl AgentPool {
|
||||
/// Fallback used by `stop_agent` when no worktree path is recorded for the
|
||||
/// agent. Also the primary kill path for any caller that has only a composite
|
||||
/// key and not a worktree path directly.
|
||||
pub(super) fn kill_child_for_key(&self, key: &str) {
|
||||
pub(super) async fn kill_child_for_key(&self, key: &str) {
|
||||
let worktree_path = {
|
||||
let Ok(agents) = self.agents.lock() else {
|
||||
return;
|
||||
};
|
||||
let agents = self.agents.lock().await;
|
||||
agents
|
||||
.get(key)
|
||||
.and_then(|a| a.worktree_info.as_ref().map(|wt| wt.path.clone()))
|
||||
@@ -124,18 +120,18 @@ mod tests {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kill_all_children_is_safe_on_empty_pool() {
|
||||
#[tokio::test]
|
||||
async fn kill_all_children_is_safe_on_empty_pool() {
|
||||
let pool = AgentPool::new_test(3001);
|
||||
pool.kill_all_children(); // must not panic
|
||||
pool.kill_all_children().await; // must not panic
|
||||
}
|
||||
|
||||
/// AC 4 — `kill_child_for_key` SIGKILLs the single agent's process and
|
||||
/// verifies it is gone within 2 s. The sleeper has the worktree path in
|
||||
/// its argv[0] so `pgrep -f` can locate it, mirroring how claude-code is
|
||||
/// launched with `--directory <worktree>` in production.
|
||||
#[test]
|
||||
fn kill_child_for_key_kills_real_process() {
|
||||
#[tokio::test]
|
||||
async fn kill_child_for_key_kills_real_process() {
|
||||
use std::os::unix::process::CommandExt;
|
||||
|
||||
let pool = AgentPool::new_test(3002);
|
||||
@@ -165,7 +161,7 @@ mod tests {
|
||||
"sleeper pid {pid} should be running before kill_child_for_key"
|
||||
);
|
||||
|
||||
pool.kill_child_for_key("story-1090-kill:coder");
|
||||
pool.kill_child_for_key("story-1090-kill:coder").await;
|
||||
let _ = child.wait(); // reap zombie so ps -p returns false
|
||||
|
||||
assert!(
|
||||
@@ -176,8 +172,8 @@ mod tests {
|
||||
|
||||
/// AC 5 — `kill_all_children` SIGKILLs all agents' processes. Two agents
|
||||
/// with distinct worktree paths are injected; both must be gone after the call.
|
||||
#[test]
|
||||
fn kill_all_children_kills_multiple_real_processes() {
|
||||
#[tokio::test]
|
||||
async fn kill_all_children_kills_multiple_real_processes() {
|
||||
use std::os::unix::process::CommandExt;
|
||||
|
||||
let pool = AgentPool::new_test(3003);
|
||||
@@ -213,7 +209,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
pool.kill_all_children();
|
||||
pool.kill_all_children().await;
|
||||
|
||||
for (pid, child, _tmp) in &mut sleepers {
|
||||
let _ = child.wait(); // reap zombie
|
||||
|
||||
Reference in New Issue
Block a user