54 lines
1.9 KiB
Bash
Executable File
54 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# test_tool_shell.sh - Fully validates the run_shell tool
|
|
|
|
# Mock response: ask for run_dangerous_shell
|
|
tool_call run_dangerous_shell '{"command":"echo Hello from shell","timeout_seconds":5}' >> mock_responses.txt
|
|
be_done 'Shell done' >> mock_responses.txt
|
|
|
|
OUTPUT=$("${DRHARNESS}" -F chat.json -n -m "Run shell command" -t run_dangerous_shell -d < "mock_responses.txt" 2>/dev/null)
|
|
|
|
if [ "${OUTPUT}" != "Shell done" ]; then
|
|
echo "FAIL: run_dangerous_shell tool - expected 'Shell done', got '${OUTPUT}'"
|
|
exit 1
|
|
fi
|
|
|
|
RESULT=$(dr_result chat.json 2)
|
|
if ! echo "$RESULT" | grep -q '^Hello from shell$' ; then
|
|
echo "FAIL: run_dangerous_shell tool - expected 'Hello from shell' in output"
|
|
echo "Got: $RESULT"
|
|
exit 1
|
|
fi
|
|
|
|
# Test error: invalid command (exit code != 0)
|
|
rm -f chat.json
|
|
tool_call run_dangerous_shell '{"command":"exit 42"}' >> mock_responses2.txt
|
|
be_done 'Error handled' >> mock_responses2.txt
|
|
|
|
"${DRHARNESS}" -F chat.json -n -m "Run invalid shell" -t run_dangerous_shell -d < "mock_responses2.txt" >/dev/null 2>&1
|
|
TOOL_RESULT=$(dr_result chat.json 2)
|
|
|
|
if ! echo "${TOOL_RESULT}" | grep -q "\[exit 42\]"; then
|
|
echo "FAIL: run_dangerous_shell tool - expected exit code in output"
|
|
echo "Got: ${TOOL_RESULT}"
|
|
exit 1
|
|
fi
|
|
|
|
tool_call run_dangerous_shell '{"command":"cat /dev/urandom > /dev/null","timeout_seconds":1}' >> mock_responses3.txt
|
|
be_done 'done' >> mock_responses3.txt
|
|
|
|
# If we hit the timeout of the timeout utility then we fail
|
|
timeout 5s "${DRHARNESS}" -F chat3.json -n -m "This is a test" -t run_dangerous_shell -d < "mock_responses3.txt"
|
|
|
|
echo "PASS: tool_shell"
|
|
|
|
|
|
seq 1 1044 > long_file
|
|
tool_call run_dangerous_shell '{"command":"cat long_file"}' >> mock_responses4.txt
|
|
be_done 'done' >> mock_responses4.txt
|
|
"${DRHARNESS}" -F chat4.json -n -m "This is a test" -t run_dangerous_shell -d < "mock_responses4.txt"
|
|
dr_result chat4.json 2 > long_file_from_harness
|
|
echo "" >> long_file
|
|
|
|
diff -u long_file long_file_from_harness
|
|
|