43 lines
1.2 KiB
Bash
Executable File
43 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# test_tool_read_file.sh - Fully validates the read_file tool
|
|
|
|
# Create a test file
|
|
cat > read_test.txt << 'INNER_EOF'
|
|
Line 1 of test
|
|
Line 2 of test
|
|
INNER_EOF
|
|
|
|
# Mock response: ask for read_file
|
|
tool_call read_file '{"path":"read_test.txt"}' >> mock_responses.txt
|
|
be_done 'Read complete' >> mock_responses.txt
|
|
|
|
OUTPUT=$("${DRHARNESS}" -F chat.json -n -m "Read file" -t read_file -d < "mock_responses.txt" 2>/dev/null)
|
|
|
|
if [ "${OUTPUT}" != "Read complete" ]; then
|
|
echo "FAIL: read_file tool - expected 'Read complete', got '${OUTPUT}'"
|
|
exit 1
|
|
fi
|
|
|
|
RESULT=$(dr_result chat.json 2)
|
|
if [ "$RESULT" != "Line 1 of test
|
|
Line 2 of test" ]; then
|
|
echo "FAIL: read_file tool - content mismatch"
|
|
echo "Got: $RESULT"
|
|
exit 1
|
|
fi
|
|
|
|
# Test error: file does not exist
|
|
rm -f chat.json
|
|
tool_call read_file '{"path":"nonexistent.txt"}' >> mock_responses2.txt
|
|
be_done 'File error done' >> mock_responses2.txt
|
|
|
|
"${DRHARNESS}" -F chat.json -n -m "Read nonexistent" -t read_file -d < "mock_responses2.txt" >/dev/null 2>&1
|
|
RESULT=$(dr_result chat.json 2)
|
|
if ! echo "$RESULT" | grep -q "Error: file does not exist"; then
|
|
echo "FAIL: read_file tool - expected error for nonexistent file"
|
|
echo "Got: $RESULT"
|
|
exit 1
|
|
fi
|
|
|
|
echo "PASS: tool_read_file"
|