forked from rainchen/MacOS-Agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
106 lines (95 loc) · 3.92 KB
/
test.sh
File metadata and controls
106 lines (95 loc) · 3.92 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# set -x
# Function to print in green
print_green() {
printf "\e[32m%s\e[0m\n" "$1"
}
# Function to print in red
print_red() {
printf "\e[31m%s\e[0m\n" "$1"
}
# Parse command-line options
while [[ $# -gt 0 ]]; do
case "$1" in
--api)
api_url="$2"
shift 2
;;
--apikey)
api_key="$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Check if both API URL and API key are provided
if [ -z "$api_url" ] || [ -z "$api_key" ]; then
echo "Both API URL and API key are required. Use --api http://localhost:8088 --apikey a-secret-key"
exit 1
fi
# Test case 1
echo "point=ping"
response=$(curl -s -X POST $api_url -H "Content-Type: application/json" -H "Authorization: Bearer $api_key" -d '{"point": "ping"}')
expected='{"result": "pong"}'
if [ "$response" == "$expected" ]; then
print_green "Test passed: $response"
else
print_red "Test failed: expected '$expected', got '$response'"
fi
# Test case 2
echo "point=get_llm_system_prompt"
response=$(curl -s -X POST $api_url -H "Content-Type: application/json" -H "Authorization: Bearer $api_key" -d '{"point": "get_llm_system_prompt"}')
expected='## Environment Information'
if [[ "$response" == *"$expected"* ]]; then
print_green "Test passed: $response"
else
print_red "Test failed: expected to contain '$expected', got '$response'"
fi
# Test case 3
echo "point=execute_script, llm_output is having code block"
response=$(curl -s -X POST $api_url -H "Content-Type: application/json" -H "Authorization: Bearer $api_key" -d '{"point": "execute_script", "params": {"inputs": {"llm_output": "```applescript\ntell application \"System Settings\" to activate```"}}}' | tr -d '\n')
expected="<script>tell application \"System Settings\" to activate</script><returncode>0</returncode><stdout></stdout><stderr></stderr>"
if [[ "$response" == *"$expected"* ]]; then
print_green "Test passed: $response"
else
print_red "Test failed: expected '$expected', got '$response'"
fi
# Test case 4
echo "point=execute_script, llm_output is not having code block"
response=$(curl -s -X POST $api_url -H "Content-Type: application/json" -H "Authorization: Bearer $api_key" -d '{"point": "execute_script", "params": {"inputs": {"llm_output": "open system settings"}}}' | tr -d '\n')
expected=""
if [ "$response" == "$expected" ]; then
print_green "Test passed: $response"
else
print_red "Test failed: expected '$expected', got '$response'"
fi
# Test case 5
echo "point=execute_script, llm_output is empty"
response=$(curl -s -X POST $api_url -H "Content-Type: application/json" -H "Authorization: Bearer $api_key" -d '{"point": "execute_script", "params": {"inputs": {"llm_output": ""}}}' | tr -d '\n')
expected=""
if [ "$response" == "$expected" ]; then
print_green "Test passed: $response"
else
print_red "Test failed: expected '$expected', got '$response'"
fi
# Test case 6
echo "point=execute_script, run top command with timeout limit"
response=$(curl -s -X POST $api_url -H "Content-Type: application/json" -H "Authorization: Bearer $api_key" -d '{"point": "execute_script", "params": {"inputs": {"llm_output": "```applescript\ndo shell script \"top\"```", "script_timeout": 3}}}' | tr -d '\n')
expected="Script execution timed out"
if [[ "$response" == *"$expected"* ]]; then
print_green "Test passed: $response"
else
print_red "Test failed: expected to contain '$expected', got '$response'"
fi
# Test case 7: llm_output having <user_goal>a user goal</user_goal>
echo "point=execute_script, llm_output having <user_goal>a user goal</user_goal>"
response=$(curl -s -X POST $api_url -H "Content-Type: application/json" -H "Authorization: Bearer $api_key" -d '{"point": "execute_script", "params": {"inputs": {"llm_output": "<user_goal>a user goal</user_goal>"}}}' | tr -d '\n')
expected="" # it should be print in server log with --debug flag
if [[ "$response" == *"$expected"* ]]; then
print_green "Test passed: $response"
else
print_red "Test failed: expected to contain '$expected', got '$response'"
fi