diff --git a/crates/dim-agent-capabilities/tests/hooks_flow.rs b/crates/dim-agent-capabilities/tests/hooks_flow.rs index 77e88cfdf4..67015e9e46 100644 --- a/crates/dim-agent-capabilities/tests/hooks_flow.rs +++ b/crates/dim-agent-capabilities/tests/hooks_flow.rs @@ -1663,11 +1663,18 @@ async fn an_async_handler_does_not_delay_the_turn_or_the_next_point() { let late = env.path("late"); let now = env.path("now"); let done = env.path("now.done"); + let gate = env.path("gate"); env.sources.set(document(serde_json::json!({ "PostToolUse": [ command(serde_json::json!({ "type": "command", "async": true, - "command": format!("{}; printf 'late' > {}", sleep(1500), late.display()), + "command": format!( + "while [ ! -f {} ]; do sleep 0.01; done; printf 'late' > {}.tmp && mv {}.tmp {}; printf '{{\"hookSpecificOutput\":{{\"additionalContext\":\"async context\"}}}}'", + gate.display(), + late.display(), + late.display(), + late.display(), + ), })), command(serde_json::json!({ "type": "command", @@ -1682,28 +1689,18 @@ async fn an_async_handler_does_not_delay_the_turn_or_the_next_point() { let session = env.session().await; let note = env.path("work/note.txt"); std::fs::write(¬e, "note\n").unwrap(); - let started = std::time::Instant::now(); turn( &session, &format!("tool:read {{\"path\":{:?}}}", note.to_str().unwrap()), ) .await; - assert!(started.elapsed() < Duration::from_millis(1200)); - for _ in 0..100 { - if done.exists() { - break; - } - tokio::time::sleep(Duration::from_millis(10)).await; - } - assert!( - done.exists(), - "the PostToolUse hook did not write its marker" - ); + wait_file(&done, "the PostToolUse hook did not write its marker").await; assert_eq!(std::fs::read_to_string(&now).unwrap(), "now"); assert!(!late.exists(), "the async handler is still running"); let blocks = wait_blocks(&session, "post-tool", 1).await; assert_eq!(blocks.len(), 1, "the async handler writes no context"); - tokio::time::sleep(Duration::from_millis(2000)).await; + std::fs::write(&gate, "").unwrap(); + wait_file(&late, "the async handler did not finish").await; assert_eq!(std::fs::read_to_string(&late).unwrap(), "late"); assert_eq!(hook_blocks(&session, "post-tool").await.len(), 1); env.close().await;