-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmoke.sh
More file actions
executable file
·130 lines (113 loc) · 4.94 KB
/
smoke.sh
File metadata and controls
executable file
·130 lines (113 loc) · 4.94 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
#!/usr/bin/env bash
# smoke.sh — end-to-end smoke test for @chio/opencode-plugin against the real
# chio daemon harness. Direct-plugin-invocation mode: loads the built plugin as
# an ES module, drives each chio_* tool's execute() against real chio
# subprocesses (trust plane + MCP edge). No mocks.
#
# Self-contained: spins up a dedicated copy of chio-test-harness on ports
# 8942/8933 so it doesn't collide with concurrent smoke agents (claude-code
# on 8931/8940, codex on 8935/8944).
#
# Exit codes:
# 0 every step passed
# 1 dependency missing
# 2 harness did not come up
# 3 a smoke assertion failed
set -euo pipefail
PLUGIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SMOKE_HARNESS_DIR="${CHIO_SMOKE_HARNESS_DIR:-/tmp/chio-smoke-opencode}"
SMOKE_HARNESS_SRC="${CHIO_SMOKE_HARNESS_SRC:-/Users/connor/Medica/backbay/standalone/chio-test-harness}"
# Wave 5.0.1: chio-policy re-landed velocity/human_in_loop first-class,
# so the `chio` binary once again accepts the canonical harness policy.
# Prefer `chio`; CHIO_BIN override still wins if explicitly set.
ARC_BIN="${CHIO_BIN:-/Users/connor/Medica/backbay/standalone/arc/target/release/chio}"
RESULTS_DIR="${PLUGIN_DIR}/smoke-results"
LOG_PATH="${RESULTS_DIR}/smoke-$(date +%Y%m%d-%H%M%S).log"
LATEST="${RESULTS_DIR}/latest.log"
mkdir -p "${RESULTS_DIR}"
: > "${LOG_PATH}"
log() {
printf '[%s] %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$*" | tee -a "${LOG_PATH}"
}
fail() {
# Usage: fail "message" [exit_code]
local msg="$1"
local rc="${2:-3}"
# If rc is not numeric, default to 3.
[[ "${rc}" =~ ^[0-9]+$ ]] || rc=3
log "FAIL: ${msg}"
log "--- last 40 lines of harness trust.log ---"
tail -40 "${SMOKE_HARNESS_DIR}/var/trust.log" 2>/dev/null | tee -a "${LOG_PATH}" || true
log "--- last 40 lines of harness mcp.log ---"
tail -40 "${SMOKE_HARNESS_DIR}/var/mcp.log" 2>/dev/null | tee -a "${LOG_PATH}" || true
cleanup || true
exit "${rc}"
}
cleanup() {
log "teardown: stopping harness"
if [[ -d "${SMOKE_HARNESS_DIR}" ]]; then
CHIO_BIN="${ARC_BIN}" bash "${SMOKE_HARNESS_DIR}/bin/stop.sh" 2>&1 | tee -a "${LOG_PATH}" || true
fi
# Kill any orphaned chio/node mcp procs we spawned.
pkill -f "chio mcp serve-http.*${SMOKE_HARNESS_DIR}" 2>/dev/null || true
pkill -f "chio trust serve.*--listen.*894" 2>/dev/null || true
}
trap 'cleanup' EXIT INT TERM
# ---------- 0. pre-flight ----------
log "step 0: pre-flight"
[[ -x "${ARC_BIN}" ]] || { log "chio binary missing at ${ARC_BIN}"; exit 1; }
command -v node >/dev/null || { log "node missing on PATH"; exit 1; }
command -v bun >/dev/null || { log "bun missing on PATH"; exit 1; }
command -v curl >/dev/null || { log "curl missing on PATH"; exit 1; }
# ---------- 0a. clone harness if missing ----------
if [[ ! -d "${SMOKE_HARNESS_DIR}" ]]; then
log "cloning harness from ${SMOKE_HARNESS_SRC} -> ${SMOKE_HARNESS_DIR}"
cp -r "${SMOKE_HARNESS_SRC}" "${SMOKE_HARNESS_DIR}"
# Rewrite ports: claude-code uses 8931/8940, codex 8935/8944, we use 8933/8942.
for f in "${SMOKE_HARNESS_DIR}/bin/start.sh" "${SMOKE_HARNESS_DIR}/bin/env.sh" "${SMOKE_HARNESS_DIR}/bin/wait-ready.sh"; do
sed -i.bak 's/8931/8933/g; s/8940/8942/g' "${f}"
rm -f "${f}.bak"
done
(cd "${SMOKE_HARNESS_DIR}/hello-mcp" && bun install 2>&1 | tee -a "${LOG_PATH}") || fail "hello-mcp install failed" 1
fi
# ---------- 0b. build plugin ----------
log "step 0b: build plugin"
(cd "${PLUGIN_DIR}" && bun install --no-save >> "${LOG_PATH}" 2>&1) || fail "bun install failed"
(cd "${PLUGIN_DIR}" && bun run build >> "${LOG_PATH}" 2>&1) || fail "bun run build failed"
[[ -f "${PLUGIN_DIR}/dist/index.js" ]] || fail "dist/index.js missing after build"
# ---------- 1. start harness (canonical policy) ----------
log "step 1: start harness with canonical.yaml on 8933/8942"
# Wipe var/ so receipts from prior runs don't bleed into chio_replay assertions.
rm -rf "${SMOKE_HARNESS_DIR}/var"
mkdir -p "${SMOKE_HARNESS_DIR}/var"
if ! CHIO_BIN="${ARC_BIN}" bash "${SMOKE_HARNESS_DIR}/bin/start.sh" 2>&1 | tee -a "${LOG_PATH}" | grep -q '^READY$'; then
fail "harness did not reach READY" 2
fi
# Source env.sh for CHIO_TOKEN and friends.
# shellcheck disable=SC1091
source "${SMOKE_HARNESS_DIR}/bin/env.sh"
# ---------- 2. prepare scratch workspace ----------
SMOKE_WS="${SMOKE_HARNESS_DIR}/ws"
rm -rf "${SMOKE_WS}"
mkdir -p "${SMOKE_WS}"
cat > "${SMOKE_WS}/opencode.json" <<EOF
{
"plugin": ["file:${PLUGIN_DIR}"]
}
EOF
# ---------- 3+ : drive the plugin ----------
log "step 2: running smoke driver (direct-plugin-invocation)"
export CHIO_WORKTREE="${SMOKE_WS}"
export CHIO_HARNESS_DIR="${SMOKE_HARNESS_DIR}"
export CHIO_SMOKE_LOG="${LOG_PATH}"
export CHIO_BIN="${ARC_BIN}"
# CHIO_TRUST_URL / CHIO_MCP_URL / CHIO_TOKEN / CHIO_POLICY already set by env.sh.
if ! node "${PLUGIN_DIR}/smoke/driver.mjs" 2>&1 | tee -a "${LOG_PATH}"; then
fail "smoke driver exited non-zero"
fi
# ---------- teardown ----------
cleanup
trap - EXIT INT TERM
cp "${LOG_PATH}" "${LATEST}"
log "SMOKE PASSED - log: ${LATEST}"
exit 0