Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions crates/dim-agent-capabilities/tests/hooks_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}}}}'",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: this prints the async context after the marker is published, so wait_file(&late) at 1703 returns before the print, before the handler exits, and before the runtime reads its stdout. The final count check at 1705 can therefore pass with async context written later: locally, an instrumented append of a second post-tool block containing async context 50 ms after the point returned Ok and the test still passed, while the same append at 0 ms failed 1701 with left 2. The count also misses the merged case, since post_tools joins every run into one block (runner.rs:1871-1887). Today the result is discarded (runner.rs:188-206), so this is coverage only, but the check cannot catch the regression. Please publish the marker after the print (or wait for a completion marker plus the run's settle) and assert the block text lacks async context, or drop the print.

gate.display(),
late.display(),
late.display(),
late.display(),
),
})),
command(serde_json::json!({
"type": "command",
Expand All @@ -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(&note, "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;
Expand Down