66 lines
2.2 KiB
Bash
Executable File
66 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# test_tool_list_files.sh - Fully validates the list_files tool
|
|
|
|
# Create test directory structure
|
|
mkdir -p test_dir/subdir
|
|
echo "file1" > test_dir/file1.txt
|
|
echo "file2" > test_dir/subdir/file2.txt
|
|
|
|
# Mock response: ask for list_files (non-recursive)
|
|
tool_call list_files '{"path":"test_dir","recursive":false}' >> mock_responses.txt
|
|
be_done 'List complete' >> mock_responses.txt
|
|
|
|
OUTPUT=$("${DRHARNESS}" -F chat.json -n -m "List files" -t list_files -d < "mock_responses.txt" 2>/dev/null)
|
|
|
|
if [ "${OUTPUT}" != "List complete" ]; then
|
|
echo "FAIL: list_files tool - expected 'List complete', got '${OUTPUT}'"
|
|
exit 1
|
|
fi
|
|
|
|
# Verify tool result in chat.json contains directory listing
|
|
# Using dr_result helper to get the content
|
|
# Note: check_tool_call expects a file, so we use it with a dummy file or direct dr_result check
|
|
TOOL_RESULT=$(dr_result chat.json 2)
|
|
if ! echo "${TOOL_RESULT}" | grep -q "file1.txt"; then
|
|
echo "FAIL: list_files tool - expected 'file1.txt' in output"
|
|
echo "Got: ${TOOL_RESULT}"
|
|
exit 1
|
|
fi
|
|
|
|
if ! echo "${TOOL_RESULT}" | grep -q "subdir/"; then
|
|
echo "FAIL: list_files tool - expected 'subdir/' in output"
|
|
echo "Got: ${TOOL_RESULT}"
|
|
exit 1
|
|
fi
|
|
|
|
# Test recursive listing
|
|
rm -f chat.json
|
|
tool_call list_files '{"path":"test_dir","recursive":true}' >> mock_responses2.txt
|
|
be_done 'Recursive complete' >> mock_responses2.txt
|
|
|
|
OUTPUT=$("${DRHARNESS}" -F chat.json -n -m "List recursively" -t list_files -d < "mock_responses2.txt" 2>/dev/null)
|
|
|
|
TOOL_RESULT=$(dr_result chat.json 2)
|
|
|
|
if ! echo "${TOOL_RESULT}" | grep -q "subdir/file2.txt"; then
|
|
echo "FAIL: list_files tool (recursive) - expected 'subdir/file2.txt' in output"
|
|
echo "Got: ${TOOL_RESULT}"
|
|
exit 1
|
|
fi
|
|
|
|
# Test error: path does not exist
|
|
rm -f chat.json
|
|
tool_call list_files '{"path":"nonexistent_dir"}' >> mock_responses3.txt
|
|
be_done 'Error complete' >> mock_responses3.txt
|
|
|
|
"${DRHARNESS}" -F chat.json -n -m "List nonexistent" -t list_files -d < "mock_responses3.txt" > /dev/null 2>&1
|
|
TOOL_RESULT=$(dr_result chat.json 2)
|
|
|
|
if ! echo "${TOOL_RESULT}" | grep -q "Error: path does not exist"; then
|
|
echo "FAIL: list_files tool - expected error for nonexistent path"
|
|
echo "Got: ${TOOL_RESULT}"
|
|
exit 1
|
|
fi
|
|
|
|
echo "PASS: tool_list_files"
|