-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·57 lines (45 loc) · 1.5 KB
/
test.sh
File metadata and controls
executable file
·57 lines (45 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Configuration
FOLDER="./tests"
BASE_URL="http://localhost:8040" # Serve PDFs from 8040
ENDPOINT="http://localhost:8000/api/v1/hackrx/run"
AUTH_TOKEN="febc0daceda23ebce03d324301d34ad3768494f0b52a39ffb4adaf083d8f9c5c"
MINISERVE_PORT=8040
# Start miniserve in the background
echo "Starting miniserve on port $MINISERVE_PORT..."
miniserve "$FOLDER" --port $MINISERVE_PORT &
MINISERVE_PID=$!
# Wait for miniserve to be ready
sleep 1
# Batch test loop
for pdf in "$FOLDER"/*.pdf; do
base=$(basename "$pdf" .pdf)
txt="$FOLDER/$base.txt"
echo "Found $base pdf and $txt text"
if [ ! -f "$txt" ]; then
echo "Warning: Missing $base.txt, skipping..."
continue
fi
questions=$(jq -Rs '[split("\n")[] | select(length > 0)]' < "$txt")
payload=$(jq -n \
--arg pdf_path "$BASE_URL/$base.pdf" \
--argjson questions "$questions" \
'{documents: $pdf_path, questions: $questions}'
)
response=$(curl -s -X POST "$ENDPOINT" \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "$payload")
echo "$response"
if echo "$response" | grep -q ""answers""; then
echo "--- $base processed successfully ---"
else
echo "Warning: $base may not have been processed successfully. Aborting process"
kill $MINISERVE_PID
exit 1
fi
done
# Kill miniserve
echo "Tests completed. Killing miniserve (PID $MINISERVE_PID)..."
kill $MINISERVE_PID