Files
drharness/tests/test_tool_shell_ctrlc.sh
hal9000 bbc4f5acf0 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.
2026-08-05 23:49:07 +00:00

31 lines
1.0 KiB
Bash
Executable File

#!/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"