Add unit test for ctrlc feature on shell tool (issue 193)

Test verifies that when SIGINT (Ctrl+C) is sent to drharness during
shell command execution, the tool returns the expected
'[user requested halt of program]' message.
This commit is contained in:
2026-08-05 23:49:07 +00:00
parent d2451f3484
commit bbc4f5acf0
2 changed files with 31 additions and 0 deletions
+1
View File
@@ -19,6 +19,7 @@ add_dr_test(test_tool_read_file)
add_dr_test(test_tool_list_files)
add_dr_test(test_tool_grep)
add_dr_test(test_tool_shell)
add_dr_test(test_tool_shell_ctrlc)
add_dr_test(test_tool_read_multi_modal)
# Add feature validation tests
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
# test_tool_shell_ctrlc.sh - Test ctrlc (SIGINT) handling in the shell tool
# Test 1: Verify that SIGINT during shell execution results in "[user requested halt of program]" message
tool_call run_dangerous_shell '{"command":"sleep 100","timeout_seconds":300}' >> mock_ctrlc.txt
be_done 'Done after interrupt' >> mock_ctrlc.txt
# Run drharness in background, then send SIGINT after a short delay
"${DRHARNESS}" -F chat_ctrlc.json -n -m "Run shell with ctrlc" -t run_dangerous_shell -d < "mock_ctrlc.txt" > /dev/null 2>&1 &
DRHARNESS_PID=$!
# Wait a moment for the shell command to start
sleep 1
# Send SIGINT (Ctrl+C) to the drharness process
kill -SIGINT $DRHARNESS_PID
# Wait for drharness to complete
wait $DRHARNESS_PID
# Check that the tool result contains the ctrlc message
TOOL_RESULT=$(dr_result chat_ctrlc.json 2)
if ! echo "${TOOL_RESULT}" | grep -q "\[user requested halt of program\]"; then
echo "FAIL: Expected '[user requested halt of program]' in tool output"
echo "Got: ${TOOL_RESULT}"
exit 1
fi
echo "PASS: tool_shell_ctrlc"