Files
drharness/tests/test_tool_edit.sh
2026-05-09 12:26:08 -05:00

55 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# test_tool_edit.sh - Fully validates the edit tool
# Create a file with known content
cat > "input.txt" << 'INNER_EOF'
Line one
oldString to replace
Line three
INNER_EOF
# Mock: ask for edit
tool_call edit '{"filePath":"input.txt","oldString":"oldString to replace","newString":"NEW REPLACED STRING"}' >> mock_responses.txt
# Mock: finish
be_done 'Edit complete' >> mock_responses.txt
OUTPUT=$("${DRHARNESS}" -F chat.json -n -m "Edit the file" -t edit -d < "mock_responses.txt" 2>/dev/null)
if [ "${OUTPUT}" != "Edit complete" ]; then
echo "FAIL: edit tool - expected 'Edit complete', got '${OUTPUT}'"
exit 1
fi
# Verify the file was actually edited
EXPECTED="Line one
NEW REPLACED STRING
Line three"
if [ "$(cat input.txt)" != "$EXPECTED" ]; then
echo "FAIL: edit tool - file content mismatch"
echo "Expected:"
echo "$EXPECTED"
echo "Got:"
cat input.txt
exit 1
fi
# Test edit tool error handling: oldString not found
cat > "input2.txt" << 'INNER_EOF'
Some content here
INNER_EOF
# Mock: ask for edit with non-matching string
tool_call edit '{"filePath":"input2.txt","oldString":"NONEXISTENT","newString":"something"}' >> mock_responses2.txt
# Mock: finish
be_done 'Finished' >> mock_responses2.txt
OUTPUT=$("${DRHARNESS}" -F chat2.json -n -m "Try invalid edit" -t edit -d < "mock_responses2.txt" 2>/dev/null)
# Check the tool result in the json using helper
cat > expected_edit_error.txt << 'EOF'
Error: oldString not found in content
EOF
check_tool_call chat2.json 2 expected_edit_error.txt
echo "PASS: tool_edit"