Skip to content

Commit 4041070

Browse files
authored
ci: add runtime smoke test for live agent startup (#153)
1 parent f2f69fb commit 4041070

3 files changed

Lines changed: 155 additions & 0 deletions

File tree

bin/ci/setup-arch.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ echo " ✓ bootstrap + install verification passed"
6767
echo "=== Running CLI smoke checks ==="
6868
bash /home/baudbot_admin/baudbot/bin/ci/smoke-cli.sh
6969

70+
echo "=== Running runtime smoke checks ==="
71+
bash /home/baudbot_admin/baudbot/bin/ci/smoke-agent-runtime.sh
72+
7073
echo "=== Installing test dependencies ==="
7174
export PATH="/home/baudbot_agent/opt/node/bin:$PATH"
7275
cd /home/baudbot_admin/baudbot

bin/ci/setup-ubuntu.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ echo " ✓ bootstrap + install verification passed"
105105
echo "=== Running CLI smoke checks ==="
106106
bash /home/baudbot_admin/baudbot/bin/ci/smoke-cli.sh
107107

108+
echo "=== Running runtime smoke checks ==="
109+
bash /home/baudbot_admin/baudbot/bin/ci/smoke-agent-runtime.sh
110+
108111
echo "=== Installing test dependencies ==="
109112
export PATH="/home/baudbot_agent/opt/node/bin:$PATH"
110113
cd /home/baudbot_admin/baudbot

bin/ci/smoke-agent-runtime.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env bash
2+
# Runtime smoke-test for baudbot agent lifecycle in CI droplets.
3+
#
4+
# Verifies that:
5+
# - baudbot starts successfully
6+
# - control-agent session socket is created and reachable
7+
# - session-control RPC responds successfully
8+
# - bridge supervisor status artifact exists
9+
# - process remains healthy for a short stabilization window
10+
# - baudbot stops cleanly
11+
12+
set -Eeuo pipefail
13+
14+
readonly AGENT_USER="baudbot_agent"
15+
readonly AGENT_HOME="/home/${AGENT_USER}"
16+
readonly CONTROL_DIR="${AGENT_HOME}/.pi/session-control"
17+
readonly CONTROL_ALIAS="${CONTROL_DIR}/control-agent.alias"
18+
readonly BRIDGE_STATUS_FILE="${AGENT_HOME}/.pi/agent/slack-bridge-supervisor.json"
19+
readonly START_TIMEOUT_SECONDS=60
20+
readonly STABILIZE_SECONDS=20
21+
22+
started=0
23+
24+
log() {
25+
printf '[runtime-smoke] %s\n' "$*"
26+
}
27+
28+
require_cmd() {
29+
local cmd="$1"
30+
command -v "$cmd" >/dev/null 2>&1 || {
31+
log "missing required command: ${cmd}"
32+
exit 2
33+
}
34+
}
35+
36+
cleanup() {
37+
local exit_code=$?
38+
if [[ $started -eq 1 ]]; then
39+
log "cleanup: attempting to stop baudbot"
40+
sudo baudbot stop >/dev/null 2>&1 || true
41+
fi
42+
exit "$exit_code"
43+
}
44+
trap cleanup EXIT
45+
46+
wait_for_control_socket() {
47+
local deadline=$((SECONDS + START_TIMEOUT_SECONDS))
48+
local target=""
49+
50+
while (( SECONDS < deadline )); do
51+
if [[ -L "$CONTROL_ALIAS" ]]; then
52+
target="$(readlink -- "$CONTROL_ALIAS" 2>/dev/null || true)"
53+
if [[ -n "$target" ]]; then
54+
if [[ "$target" != /* ]]; then
55+
target="${CONTROL_DIR}/${target}"
56+
fi
57+
if [[ -S "$target" ]]; then
58+
printf '%s\n' "$target"
59+
return 0
60+
fi
61+
fi
62+
fi
63+
sleep 1
64+
done
65+
66+
return 1
67+
}
68+
69+
probe_rpc_get_message() {
70+
local socket_path="$1"
71+
sudo -u "$AGENT_USER" python3 - "$socket_path" <<'PY'
72+
import json
73+
import socket
74+
import sys
75+
76+
sock_path = sys.argv[1]
77+
request = {"type": "get_message", "id": "ci-runtime-smoke"}
78+
79+
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
80+
try:
81+
client.settimeout(4)
82+
client.connect(sock_path)
83+
client.sendall((json.dumps(request) + "\n").encode("utf-8"))
84+
85+
buf = b""
86+
while b"\n" not in buf:
87+
chunk = client.recv(4096)
88+
if not chunk:
89+
break
90+
buf += chunk
91+
92+
if not buf:
93+
print("empty rpc response", file=sys.stderr)
94+
sys.exit(1)
95+
96+
line = buf.split(b"\n", 1)[0].decode("utf-8", errors="replace")
97+
response = json.loads(line)
98+
if not response.get("success", False):
99+
print(f"rpc reported failure: {response}", file=sys.stderr)
100+
sys.exit(1)
101+
102+
print("rpc-ok")
103+
finally:
104+
client.close()
105+
PY
106+
}
107+
108+
main() {
109+
require_cmd sudo
110+
require_cmd baudbot
111+
require_cmd python3
112+
113+
log "starting baudbot"
114+
sudo baudbot start
115+
started=1
116+
117+
log "waiting for control-agent socket"
118+
local socket_path=""
119+
if ! socket_path="$(wait_for_control_socket)"; then
120+
log "control-agent socket did not become ready within ${START_TIMEOUT_SECONDS}s"
121+
sudo baudbot status || true
122+
exit 1
123+
fi
124+
log "control socket ready: ${socket_path}"
125+
126+
log "probing session-control RPC"
127+
probe_rpc_get_message "$socket_path"
128+
129+
log "checking bridge supervisor status file"
130+
if [[ ! -f "$BRIDGE_STATUS_FILE" ]]; then
131+
log "missing bridge supervisor status file: ${BRIDGE_STATUS_FILE}"
132+
sudo baudbot status || true
133+
exit 1
134+
fi
135+
136+
log "stabilization window (${STABILIZE_SECONDS}s)"
137+
sleep "$STABILIZE_SECONDS"
138+
139+
log "verifying runtime health via baudbot status"
140+
sudo baudbot status >/dev/null
141+
142+
log "stopping baudbot"
143+
sudo baudbot stop
144+
started=0
145+
146+
log "runtime smoke passed"
147+
}
148+
149+
main "$@"

0 commit comments

Comments
 (0)