Repository navigation
Expand file tree
/
Copy pathrun-integ-tests.sh
More file actions
executable file
·175 lines (159 loc) · 5.04 KB
/
Copy pathrun-integ-tests.sh
File metadata and controls
executable file
·175 lines (159 loc) · 5.04 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
# Copyright (c) 2022-2026 Super Durable, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
keep_running=false
# --agent-harnesses runs only the agent-harnesses tests and passes the other arguments to them.
only_agent_harnesses=false
test_args=()
for arg in "$@"; do
case "$arg" in
--keep-running)
keep_running=true
;;
--agent-harnesses)
only_agent_harnesses=true
;;
*)
test_args+=("$arg")
;;
esac
done
export DEX_INTEG_ENGINE="${DEX_INTEG_ENGINE:-zd}"
if [[ "$DEX_INTEG_ENGINE" != zd ]]; then
echo "DEX_INTEG_ENGINE must be zd" >&2
exit 2
fi
if [[ -n "${DEX_SERVER_ZD_BINARY:-}" && "$DEX_SERVER_ZD_BINARY" == */* ]]; then
DEX_SERVER_ZD_BINARY="$(cd "$(dirname "$DEX_SERVER_ZD_BINARY")" && pwd)/$(basename "$DEX_SERVER_ZD_BINARY")"
fi
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
repo_root=$(cd "$script_dir/../.." && pwd)
entity_store_dir="$repo_root/examples/entity-store"
compose_project="dex-python-examples-$$"
dex_port="${DEX_EXAMPLES_DEX_PORT:-19802}"
web_port="${DEX_EXAMPLES_WEB_PORT:-19902}"
dex_address="127.0.0.1:${dex_port}"
log_file="/tmp/test-python-examples-integ-services.log"
test_dir=$(mktemp -d)
binary_dir=$(mktemp -d)
dexcli_pid=""
entity_store_started=false
: >"$log_file"
cleanup() {
status=$?
if $keep_running; then
if [[ "$status" -ne 0 ]]; then
cat "$log_file" >&2
fi
return
fi
if [[ -n "$dexcli_pid" ]] && kill -0 "$dexcli_pid" 2>/dev/null; then
kill -TERM "$dexcli_pid"
wait "$dexcli_pid" || true
fi
if $entity_store_started; then
if ! docker compose -p "$compose_project" \
-f "$entity_store_dir/docker-compose.yml" down --volumes >>"$log_file" 2>&1; then
echo "failed to stop the Python examples entity store" >&2
fi
fi
if [[ "$status" -ne 0 ]]; then
cat "$log_file" >&2
fi
rm -r "$test_dir" "$binary_dir"
}
trap cleanup EXIT
if [[ ! -f "$repo_root/web/assets/dist/index.html" ]]; then
(
cd "$repo_root/web"
npm ci
npm run build
)
fi
(
cd "$repo_root/cli"
GOWORK=off go build -trimpath -o "$binary_dir/dexcli" ./cmd/dexcli
)
docker compose -p "$compose_project" \
-f "$entity_store_dir/docker-compose.yml" up --detach --wait
entity_store_started=true
if [[ -z "${DEX_SERVER_ZD_BINARY:-}" ]]; then
(cd "$repo_root" && cargo build --release --locked --manifest-path server-zd/Cargo.toml -p dexzd-server --bin dex-server-zd)
DEX_SERVER_ZD_BINARY="$repo_root/server-zd/target/release/dex-server-zd"
fi
# A config file, unlike a flag, also works with an older DEX_SERVER_ZD_BINARY.
printf 'dev:\n durabilityMode: processCrashSafe\n' >"$test_dir/zd-overrides.yaml"
dev_args=(-engine zd -zd-binary "$DEX_SERVER_ZD_BINARY" -zd-data-dir "$test_dir/zd" -zd-config "$test_dir/zd-overrides.yaml")
dev_args+=(-attribute-store-config "$entity_store_dir/attribute-store.yaml")
"$binary_dir/dexcli" dev \
"${dev_args[@]}" \
-bind-address 127.0.0.1 \
-dex-port "$dex_port" \
-web-port "$web_port" \
-open=false \
>>"$log_file" 2>&1 &
dexcli_pid=$!
dex_ready=false
for _ in {1..240}; do
if grep -q "Dex development environment is ready" "$log_file"; then
dex_ready=true
break
fi
if ! kill -0 "$dexcli_pid" 2>/dev/null; then
echo "dexcli exited before Dex became ready" >&2
exit 1
fi
sleep 0.25
done
if ! $dex_ready; then
echo "Dex did not become ready" >&2
exit 1
fi
cd "$script_dir"
export DEXCLI_PATH="$binary_dir/dexcli"
if ! $only_agent_harnesses; then
pytest_args=(pytest -vv tests/)
if ((${#test_args[@]})); then
pytest_args+=("${test_args[@]}")
fi
DEX_FLOW_SERVICE_ADDRESS="$dex_address" \
uv run --frozen "${pytest_args[@]}"
sync_pytest_args=(pytest -vv sync-python/sync_tests/integ)
if ((${#test_args[@]})); then
sync_pytest_args+=("${test_args[@]}")
fi
DEX_FLOW_SERVICE_ADDRESS="$dex_address" \
uv run --frozen "${sync_pytest_args[@]}"
fi
# The agent harness examples have their own project: the OpenAI Agents SDK conflicts with LiteLLM.
# Arguments for the main suites would not match its tests, so they run with no arguments or alone.
if $only_agent_harnesses || ((${#test_args[@]} == 0)); then
harness_pytest_args=(pytest -vv tests/)
if ((${#test_args[@]})); then
harness_pytest_args+=("${test_args[@]}")
fi
(
cd "$script_dir/agent-harnesses"
DEX_FLOW_SERVICE_ADDRESS="$dex_address" \
uv run --frozen "${harness_pytest_args[@]}"
)
fi
if $keep_running; then
echo ""
echo "Dex Web: http://127.0.0.1:${web_port}"
echo "dexcli: --server ${dex_address}"
echo "Press Ctrl+C to stop dexcli dev"
wait "$dexcli_pid"
fi