@sjawhar/claude-envoy 1.18.0 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,178 +0,0 @@
1
- #!/usr/bin/env bash
2
- # smoke-channel.sh — real Claude Code channel delivery smoke.
3
- # See README.md for prerequisites, configuration, and why this is not CI.
4
- set -euo pipefail
5
-
6
- readonly envoy_url="${ENVOY_URL:-http://127.0.0.1:9020}"
7
- readonly nats_url="${ENVOY_NATS_URL:?set ENVOY_NATS_URL to the live Envoy NATS listener}"
8
- readonly claude_bin="${CLAUDE_BIN:-claude}"
9
- readonly channel_entry="${CLAUDE_CHANNEL_ENTRY:?set CLAUDE_CHANNEL_ENTRY, e.g. plugin:claude-envoy@<marketplace>}"
10
- # `--channels` only works for an entry managed settings allowlist (`allowedChannelPlugins`);
11
- # here that is the `legion-plugins` marketplace. Everything else (a dev marketplace, a
12
- # bare `server:` entry) needs the development bypass. Always overridable.
13
- if [[ -n "${CLAUDE_CHANNEL_FLAG:-}" ]]; then
14
- readonly channel_flag="$CLAUDE_CHANNEL_FLAG"
15
- elif [[ "$channel_entry" == *"@legion-plugins" ]]; then
16
- readonly channel_flag="--channels"
17
- else
18
- readonly channel_flag="--dangerously-load-development-channels"
19
- fi
20
- readonly plugin_dir="${CLAUDE_PLUGIN_DIR:-}"
21
- readonly mcp_config="${CLAUDE_MCP_CONFIG:-}"
22
- readonly startup_timeout=60
23
- readonly session_timeout=45
24
- readonly delivery_timeout=90
25
- readonly teardown_timeout=15
26
-
27
- fail() {
28
- printf 'FAIL: %s\n' "$*" >&2
29
- [[ -n "${tmux_session:-}" ]] && tmux capture-pane -pt "$tmux_session" >&2 || true
30
- if [[ -n "${claude_output:-}" && -f "$claude_output" ]]; then
31
- printf -- '--- claude pane output (%s) ---\n' "$claude_output" >&2
32
- cat "$claude_output" >&2 || true
33
- fi
34
- exit 1
35
- }
36
-
37
- command -v "$claude_bin" >/dev/null 2>&1 || fail "$claude_bin is not on PATH"
38
- command -v tmux >/dev/null 2>&1 || fail "tmux is required"
39
- command -v curl >/dev/null 2>&1 || fail "curl is required"
40
- command -v jq >/dev/null 2>&1 || fail "jq is required"
41
-
42
- readonly nonce="$(od -An -N4 -tx1 /dev/urandom | tr -d ' \n')"
43
- readonly target_session="claude-channel-smoke-${nonce}"
44
- readonly message="channel-smoke-payload-${nonce}"
45
- workdir="$(mktemp -d "/tmp/${target_session}.XXXXXX")"
46
- readonly workdir
47
- # The smoke runs its own tmux server on a socket in its scratch directory, so its cleanup can end
48
- # only the session it started: `tmux kill-session` on the shared default server could end anyone's.
49
- readonly tmux_socket="${workdir}/tmux.sock"
50
- tmux() { command tmux -S "$tmux_socket" "$@"; }
51
- readonly received_file="${workdir}/received.txt"
52
- readonly claude_output="${workdir}/claude-output.txt"
53
- readonly delivery_instruction="Envoy channel smoke: use Bash to write exactly ${message}, with no trailing newline, to ${received_file}; then reply CHANNEL_SMOKE_DONE."
54
- tmux_session=""
55
-
56
- cleanup() {
57
- [[ -n "$tmux_session" ]] && tmux kill-session -t "$tmux_session" 2>/dev/null || true
58
- rm -rf "$workdir"
59
- }
60
- trap cleanup EXIT INT TERM
61
-
62
- # Claude Code shows up to three dialogs before its prompt, in an order that
63
- # depends on what this machine has already consented to: folder trust, the
64
- # development-channel warning, and first-use MCP server consent. Poll the pane
65
- # and answer whichever is showing until the prompt appears.
66
- answer_startup_dialogs() {
67
- local deadline=$((SECONDS + startup_timeout)) pane
68
- while (( SECONDS < deadline )); do
69
- pane="$(tmux capture-pane -pt "$tmux_session" 2>/dev/null || true)"
70
- if [[ "$pane" == *"Yes, I trust this folder"* ]]; then
71
- tmux send-keys -t "$tmux_session" Down Enter
72
- elif [[ "$pane" == *"I am using this for local development"* ]]; then
73
- tmux send-keys -t "$tmux_session" Enter
74
- elif [[ "$pane" == *"New MCP server found"* ]]; then
75
- tmux send-keys -t "$tmux_session" Enter
76
- elif [[ "$pane" == *"shift+tab to cycle"* || "$pane" == *"? for shortcuts"* ]]; then
77
- # The permission-mode status line is drawn only once the prompt is live.
78
- return 0
79
- fi
80
- sleep 1
81
- done
82
- return 1
83
- }
84
-
85
- wait_for_session() {
86
- local deadline=$((SECONDS + session_timeout)) response
87
- while (( SECONDS < deadline )); do
88
- response="$(curl --connect-timeout 2 --max-time 5 -fsS "${envoy_url}/v1/sessions?dir=${workdir}" 2>/dev/null || true)"
89
- if jq -e --arg id "$target_session" '.[] | select(.session_id == $id)' <<<"$response" >/dev/null 2>&1; then
90
- session_row="$(jq -c --arg id "$target_session" '.[] | select(.session_id == $id) | {session_id, dir, capabilities}' <<<"$response")"
91
- return 0
92
- fi
93
- sleep 1
94
- done
95
- return 1
96
- }
97
-
98
- wait_for_delivery() {
99
- local deadline=$((SECONDS + delivery_timeout))
100
- while (( SECONDS < deadline )); do
101
- if [[ -f "$received_file" ]] && [[ "$(cat "$received_file")" == "$message" ]]; then
102
- return 0
103
- fi
104
- sleep 1
105
- done
106
- return 1
107
- }
108
-
109
- # wait_for_teardown returns 0 once a read of the session list leaves the session out, 1 when the
110
- # last list it read still held the session at the deadline, and 2 when it never read the list. A
111
- # read that fails (no answer, a non-200 such as the listener's refilling 503, a body that is not a
112
- # list) says nothing about the session, so it is retried, never taken for its absence;
113
- # teardown_read_error keeps the last such failure for the message.
114
- teardown_read_error=""
115
- wait_for_teardown() {
116
- local deadline=$((SECONDS + teardown_timeout)) response listed=0 rc
117
- local curl_error="${workdir}/teardown-curl.err"
118
- while (( SECONDS < deadline )); do
119
- if response="$(curl --connect-timeout 2 --max-time 5 -fsS "${envoy_url}/v1/sessions?dir=${workdir}" 2>"$curl_error")"; then
120
- rc=0
121
- jq -e --arg id "$target_session" 'any(.[]; .session_id == $id)' <<<"$response" >/dev/null 2>&1 || rc=$?
122
- case "$rc" in
123
- 0) listed=1 ;;
124
- 1) return 0 ;;
125
- *) teardown_read_error="GET /v1/sessions answered a body that is not a session list: ${response:0:200}" ;;
126
- esac
127
- else
128
- teardown_read_error="$(tr '\n' ' ' <"$curl_error")"
129
- fi
130
- sleep 1
131
- done
132
- (( listed )) && return 1
133
- return 2
134
- }
135
-
136
- # The channel server gets a known direct Envoy route through the QA override.
137
- # The smoke starts an interactive Claude Code session: channel notifications are
138
- # meant to wake an already-open session, while -p has no interactive consent or
139
- # plan-approval surfaces.
140
- tmux_session="${target_session}"
141
- session_row=""
142
- claude_command=("$claude_bin")
143
- [[ -z "$plugin_dir" ]] || claude_command+=(--plugin-dir "$plugin_dir")
144
- [[ -z "$mcp_config" ]] || claude_command+=(--mcp-config "$mcp_config")
145
- tmux new-session -d -s "$tmux_session" -x 220 -y 50 -c "$workdir" \
146
- env ENVOY_NATS_URL="$nats_url" ENVOY_URL="$envoy_url" ENVOY_SESSION_ID="$target_session" \
147
- CLAUDE_PROJECT_DIR="$workdir" CLAUDE_PLUGIN_DATA="${workdir}/plugin-data" \
148
- "${claude_command[@]}" "$channel_flag" "$channel_entry"
149
- tmux set-option -t "$tmux_session" remain-on-exit on
150
- # Everything Claude prints, dialogs included, lands in a file the failure path dumps.
151
- tmux pipe-pane -t "$tmux_session" -o "cat >> '${claude_output}'"
152
- answer_startup_dialogs || fail "Claude did not reach its prompt within ${startup_timeout}s"
153
-
154
- printf 'starting interactive Claude channel smoke %s with %s %s; watch it with: tmux -S %s attach -t %s\n' \
155
- "$target_session" "$channel_flag" "$channel_entry" "$tmux_socket" "$tmux_session"
156
- wait_for_session || fail "channel session did not register with Envoy within ${session_timeout}s"
157
- printf 'registered Envoy channel session %s\n' "$session_row"
158
-
159
- response_file="$(mktemp)"
160
- trap 'rm -f "$response_file"; cleanup' EXIT INT TERM
161
- status="$(curl --connect-timeout 2 --max-time 5 -sS -o "$response_file" -w '%{http_code}' \
162
- -X POST -H 'Content-Type: application/json' "${envoy_url}/v1/messages/send" \
163
- --data "$(jq -nc --arg target "$target_session" --arg body "$delivery_instruction" '{source:"human", target_session:$target, message:$body, idempotency_key:("channel-smoke-" + $target)}')" 2>/dev/null || true)"
164
- [[ "$status" == "200" ]] || fail "Envoy direct send returned ${status}: $(cat "$response_file")"
165
- printf 'sent direct Envoy event; waiting up to %ss for Claude to consume the channel notification\n' "$delivery_timeout"
166
- wait_for_delivery || fail "Claude did not write the exact channel payload within ${delivery_timeout}s"
167
-
168
- printf 'delivery observed; terminating Claude session and checking deregistration\n'
169
- tmux kill-session -t "$tmux_session" || fail "tmux kill-session failed"
170
- tmux_session=""
171
- teardown_rc=0
172
- wait_for_teardown || teardown_rc=$?
173
- case "$teardown_rc" in
174
- 0) ;;
175
- 1) fail "Envoy session remained registered after ${teardown_timeout}s" ;;
176
- *) fail "could not read Envoy's session list within ${teardown_timeout}s of the teardown, so deregistration is unproven: ${teardown_read_error:-no read finished}" ;;
177
- esac
178
- printf 'PASS: Envoy event arrived through Claude Code channel notifications and the session deregistered — %s\n' "$session_row"