forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-databricks-3-classes.sh
More file actions
executable file
·138 lines (125 loc) · 4.69 KB
/
test-databricks-3-classes.sh
File metadata and controls
executable file
·138 lines (125 loc) · 4.69 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
# E2E test: run opencode itself against Databricks Model Serving for one
# representative of each major foundation-model class (Claude / GPT / Gemini)
# using the profile in opencode.json. Tests basic response + tool use.
set -u
BASE_URL="http://localhost:4096"
PROVIDER="databricks"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
MODELS=(
"databricks-claude-sonnet-4-6"
"databricks-gpt-5-5"
"databricks-gemini-2-5-pro"
)
PASSED=0
FAILED=0
ERRORS=()
SERVER_PID=""
start_server() {
echo -n " Starting dev server... "
pkill -f "bun.*serve" 2>/dev/null
sleep 1
cd "$SCRIPT_DIR" && bun dev serve > /tmp/opencode-test-server.log 2>&1 &
SERVER_PID=$!
for i in $(seq 1 30); do
if curl -s "$BASE_URL/session" | jq -e . > /dev/null 2>&1; then
echo "OK (pid: $SERVER_PID)"
return 0
fi
sleep 1
done
echo "FAIL (timeout)"
return 1
}
stop_server() {
pkill -f "bun.*serve" 2>/dev/null
}
test_model() {
local model="$1"
echo ""
echo "============================================"
echo "Testing: $model"
echo "============================================"
echo -n " Creating session... "
local sess
sess=$(curl -s -X POST "$BASE_URL/session" -H "Content-Type: application/json" -d '{"title":"test-'"$model"'"}')
local sid
sid=$(echo "$sess" | jq -r '.id // empty')
if [ -z "$sid" ]; then
echo "FAIL"
FAILED=$((FAILED + 1)); ERRORS+=("$model: session creation failed"); return 1
fi
echo "$sid"
echo -n " Basic response... "
local resp
resp=$(curl -s --max-time 120 -X POST "$BASE_URL/session/$sid/message" \
-H "Content-Type: application/json" \
-d '{"model":{"providerID":"'"$PROVIDER"'","modelID":"'"$model"'"},"parts":[{"type":"text","text":"What is 2+2? Answer with just the number."}]}')
local err
err=$(echo "$resp" | jq -r '.info.error.name // empty')
if [ -n "$err" ]; then
local msg
msg=$(echo "$resp" | jq -r '.info.error.data.message // empty' | head -c 200)
echo "FAIL ($err: $msg)"
FAILED=$((FAILED + 1)); ERRORS+=("$model: basic - $err - $msg"); return 1
fi
local txt
txt=$(echo "$resp" | jq -r '[.parts[] | select(.type=="text") | .text] | join(" ")')
if [ -z "$txt" ] || [ "$txt" = "null" ]; then
echo "FAIL (no text)"
FAILED=$((FAILED + 1)); ERRORS+=("$model: no text in basic response"); return 1
fi
local in_t out_t
in_t=$(echo "$resp" | jq '.info.tokens.input // 0')
out_t=$(echo "$resp" | jq '.info.tokens.output // 0')
echo "OK (\"${txt:0:50}\") [${in_t}/${out_t} tokens]"
echo -n " Tool call... "
local tool_resp
tool_resp=$(curl -s --max-time 300 -X POST "$BASE_URL/session/$sid/message" \
-H "Content-Type: application/json" \
-d '{"model":{"providerID":"'"$PROVIDER"'","modelID":"'"$model"'"},"parts":[{"type":"text","text":"Use the read tool to read the file at /Users/david.okeeffe/Repos/opencode/opencode.json and tell me the value of provider.databricks.options.profile."}]}')
local terr
terr=$(echo "$tool_resp" | jq -r '.info.error.name // empty')
if [ -n "$terr" ]; then
local tmsg
tmsg=$(echo "$tool_resp" | jq -r '.info.error.data.message // empty' | head -c 200)
echo "FAIL ($terr: $tmsg)"
FAILED=$((FAILED + 1)); ERRORS+=("$model: tool - $terr - $tmsg"); return 1
fi
local hist
hist=$(curl -s "$BASE_URL/session/$sid/message")
local n_tools
n_tools=$(echo "$hist" | jq '[.[] | .parts[] | select(.type=="tool")] | length')
local final_text
final_text=$(echo "$tool_resp" | jq -r '[.parts[] | select(.type=="text") | .text] | join(" ")' | head -c 200)
if [ "$n_tools" -gt 0 ]; then
local names
names=$(echo "$hist" | jq -r '[.[] | .parts[] | select(.type=="tool") | .tool] | unique | join(", ")')
echo "OK (tools: $names) text: \"${final_text:0:80}\""
PASSED=$((PASSED + 1))
else
echo "FAIL (no tool call) text: \"${final_text:0:80}\""
FAILED=$((FAILED + 1)); ERRORS+=("$model: no tool call in tool test")
fi
}
echo "====================================================="
echo " Databricks 3-class opencode E2E"
echo "====================================================="
echo " Profile: $(jq -r '.provider.databricks.options.profile' opencode.json)"
echo " Models: ${#MODELS[@]}"
echo "====================================================="
if ! curl -s "$BASE_URL/session" | jq -e . > /dev/null 2>&1; then
start_server || exit 1
else
echo " Server already running"
fi
for m in "${MODELS[@]}"; do test_model "$m"; done
echo ""
echo "====================================================="
echo " RESULTS: $PASSED / ${#MODELS[@]} passed"
echo "====================================================="
if [ ${#ERRORS[@]} -gt 0 ]; then
echo " Failures:"
for e in "${ERRORS[@]}"; do echo " - $e"; done
fi
exit $FAILED