The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
#!/bin/sh
set -eu
if [ "$(uname -s)" != "Darwin" ]; then
echo "Beacon endpoint smoke test is macOS-only; skipping on $(uname -s)."
exit 0
fi
ROOT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)"
TMP_DIR="$(mktemp -d)"
ORIGINAL_HOOKS="$TMP_DIR/hooks.bin.original"
HOOKS_BIN="$ROOT_DIR/cli/beacon/internal/embedded/hooks.bin"
cleanup() {
if [ -f "$ORIGINAL_HOOKS" ]; then
cp "$ORIGINAL_HOOKS" "$HOOKS_BIN"
chmod 644 "$HOOKS_BIN"
fi
rm -rf "$TMP_DIR"
}
trap cleanup EXIT INT TERM
cp "$HOOKS_BIN" "$ORIGINAL_HOOKS"
BIN_DIR="$TMP_DIR/bin"
HOME_DIR="$TMP_DIR/home"
LOG_PATH="$TMP_DIR/runtime.jsonl"
COLLECTOR_BIN="$BIN_DIR/beacon-otelcol"
BEACON_BIN="$BIN_DIR/beacon"
mkdir -p "$BIN_DIR" "$HOME_DIR" "$HOME_DIR/Library/LaunchAgents"
cat >"$COLLECTOR_BIN" <<'EOF'
#!/bin/sh
echo "fake beacon-otelcol for smoke test"
EOF
chmod +x "$COLLECTOR_BIN"
echo "Building temporary beacon-hooks..."
(
cd "$ROOT_DIR/cli/beacon-hooks"
go build -o "$HOOKS_BIN" .
)
echo "Building temporary beacon..."
(
cd "$ROOT_DIR/cli/beacon"
go build -o "$BEACON_BIN" .
)
# stdin comes from /dev/null so this behaves the same whether a developer runs it from
# a terminal or CI runs it headless. `endpoint install --user` is the one command here
# that would otherwise prompt for onboarding on a tty and hang the smoke test.
run_beacon() {
HOME="$HOME_DIR" "$BEACON_BIN" "$@" </dev/null
}
echo "Installing endpoint config in temporary HOME..."
INSTALL_OUTPUT="$TMP_DIR/install-output.txt"
run_beacon endpoint install \
--user \
--no-start \
--collector "$COLLECTOR_BIN" \
--log-path "$LOG_PATH" \
--harness claude,codex \
--session-sync \
--otlp-grpc-port 55317 \
--otlp-http-port 55318 >"$INSTALL_OUTPUT" 2>&1
cat "$INSTALL_OUTPUT"
test -f "$HOME_DIR/.beacon/endpoint/config.json"
test -f "$HOME_DIR/.beacon/endpoint/otelcol.yaml"
test -f "$HOME_DIR/Library/LaunchAgents/com.beacon.endpoint.collector.user.plist"
# The scheduled inventory job is written by install in user mode too (and, with --no-start, left
# unloaded), pointing the job at this install's runtime log.
INVENTORY_PLIST="$HOME_DIR/Library/LaunchAgents/com.beacon.endpoint.inventory.plist"
test -f "$INVENTORY_PLIST"
if ! grep -q -- "--scheduled" "$INVENTORY_PLIST" || ! grep -q -- "$LOG_PATH" "$INVENTORY_PLIST"; then
echo "scheduled inventory job must invoke the heartbeat with --scheduled and this install's log path" >&2
exit 1
fi
# --session-sync writes the opt-in session sync job the same way. Unlike inventory it does not run
# at load, so the install backfill is the only sweep at install time.
SESSION_SYNC_PLIST="$HOME_DIR/Library/LaunchAgents/com.beacon.endpoint.session-sync.plist"
test -f "$SESSION_SYNC_PLIST"
if ! grep -q -- "<string>--scheduled</string>" "$SESSION_SYNC_PLIST" || ! grep -q -- "$LOG_PATH" "$SESSION_SYNC_PLIST"; then
echo "scheduled session sync job must run the sync with --scheduled and this install's log path" >&2
exit 1
fi
if ! tr -d ' \n' <"$SESSION_SYNC_PLIST" | grep -q '<key>RunAtLoad</key><false/>'; then
echo "scheduled session sync job must not run at load" >&2
exit 1
fi
test -f "$LOG_PATH"
# A non-interactive install must never ask for an email or record an onboarding
# answer. Package postinstall scripts, MDM deployments, and CI all reach `endpoint
# install` without a terminal, so a prompt here is a broken fleet rollout.
# -E because the prompt strings are matched as alternates, and the second branch is
# the current email prompt ("Email › "), not the old "Email:".
if grep -qiE 'How are you using Beacon|Email .|free and open source' "$INSTALL_OUTPUT"; then
echo "non-interactive endpoint install must not prompt for onboarding" >&2
cat "$INSTALL_OUTPUT" >&2
exit 1
fi
if [ -e "$HOME_DIR/.beacon/profile.json" ]; then
echo "non-interactive endpoint install must not write an onboarding profile" >&2
exit 1
fi
echo "Checking endpoint status..."
STATUS_OUTPUT="$TMP_DIR/status.txt"
run_beacon endpoint status --user --log-path "$LOG_PATH" >"$STATUS_OUTPUT"
if ! grep -q '^Inventory heartbeat: scheduled every' "$STATUS_OUTPUT"; then
echo "endpoint status must report the scheduled inventory job" >&2
cat "$STATUS_OUTPUT" >&2
exit 1
fi
if ! grep -q '^Session sync: every 15m0s' "$STATUS_OUTPUT"; then
echo "endpoint status must report the scheduled session sync job" >&2
cat "$STATUS_OUTPUT" >&2
exit 1
fi
echo "Writing Wazuh validation event..."
run_beacon endpoint wazuh validate --user --log-path "$LOG_PATH" >/dev/null
echo "Checking Elastic Filebeat config generation..."
run_beacon endpoint elastic print-config --user --log-path "$LOG_PATH" >/dev/null
if ! grep -q '"action":"telemetry.enabled"' "$LOG_PATH"; then
echo "expected telemetry.enabled event in runtime log" >&2
exit 1
fi
if ! grep -q '"category":"validation"' "$LOG_PATH"; then
echo "expected validation event in runtime log" >&2
exit 1
fi
echo "Installing Cursor hooks in temporary HOME..."
run_beacon endpoint hooks install --harness cursor --user --log-path "$LOG_PATH" >/dev/null
run_beacon endpoint hooks status --harness cursor --user --log-path "$LOG_PATH" >/dev/null
test -f "$HOME_DIR/.cursor/hooks.json"
# The installed command passes its settings as flags rather than as an inline BEACON_ENDPOINT_MODE=1
# prefix, so that prefix is no longer what identifies a Beacon hook. Asserting the log flag and the
# platform instead: the flag is what makes it an endpoint hook, and the platform is what scopes it to
# this runtime.
if ! grep -q -- "--log " "$HOME_DIR/.cursor/hooks.json"; then
echo "expected Beacon hook command with --log in Cursor hooks.json" >&2
exit 1
fi
if ! grep -q -- "--platform cursor" "$HOME_DIR/.cursor/hooks.json"; then
echo "expected Beacon hook command scoped to cursor in Cursor hooks.json" >&2
exit 1
fi
echo "Installing and exercising OpenCode plugin in temporary HOME..."
run_beacon endpoint hooks install --harness opencode --user --log-path "$LOG_PATH" >/dev/null
run_beacon endpoint hooks status --harness opencode --user --log-path "$LOG_PATH" >/dev/null
OPENCODE_PLUGIN="$HOME_DIR/.config/opencode/plugins/beacon.ts"
OPENCODE_HOOK="$HOME_DIR/.beacon/endpoint/hooks/beacon-hooks"
test -f "$OPENCODE_PLUGIN"
test -x "$OPENCODE_HOOK"
if grep -q '__BEACON_' "$OPENCODE_PLUGIN"; then
echo "OpenCode plugin contains unresolved Beacon placeholders" >&2
exit 1
fi
emit_opencode() {
printf '%s\n' "$1" | \
HOME="$HOME_DIR" BEACON_ENDPOINT_MODE=1 BEACON_ENDPOINT_LOG="$LOG_PATH" \
"$OPENCODE_HOOK" --platform opencode opencode-event >/dev/null
}
emit_opencode '{"type":"chat.message","session_id":"ses_smoke","directory":"/tmp/project","model":"test/model","output":{"parts":[{"type":"text","text":"summarize"}]}}'
emit_opencode '{"type":"tool.execute.after","session_id":"ses_smoke","directory":"/tmp/project","tool_name":"bash","call_id":"call_bash","duration_ms":5,"tool_input":{"command":"git status --short"},"tool_response":{"output":"","metadata":{"exitCode":0}}}'
emit_opencode '{"type":"tool.execute.after","session_id":"ses_smoke","directory":"/tmp/project","tool_name":"write","call_id":"call_write","tool_input":{"filePath":"/tmp/project/smoke.txt","content":"value"},"tool_response":{"output":"ok","metadata":{}}}'
emit_opencode '{"type":"permission.replied","session_id":"ses_smoke","properties":{"sessionID":"ses_smoke","requestID":"per_smoke","reply":"reject"}}'
emit_opencode '{"type":"session.diff","session_id":"ses_smoke","properties":{"sessionID":"ses_smoke","diff":[]}}'
for action in prompt.submitted command.executed file.modified approval.denied; do
if ! grep -q "\"action\":\"$action\"" "$LOG_PATH"; then
echo "expected OpenCode $action event in runtime log" >&2
exit 1
fi
done
if grep '"session":{"id":"ses_smoke"' "$LOG_PATH" | grep -q 'opencode session diff observed'; then
echo "empty OpenCode session diff produced a file event" >&2
exit 1
fi
run_beacon endpoint hooks uninstall --harness opencode --user --log-path "$LOG_PATH" >/dev/null
test ! -f "$OPENCODE_PLUGIN"
echo "Uninstalling endpoint config..."
PLIST="$HOME_DIR/Library/LaunchAgents/com.beacon.endpoint.collector.user.plist"
run_beacon endpoint uninstall --user --log-path "$LOG_PATH" --keep-logs >/dev/null
if [ -f "$HOME_DIR/.beacon/endpoint/config.json" ]; then
echo "endpoint config was not removed by uninstall" >&2
exit 1
fi
# The macOS counterpart of the Linux test's "unit file survived uninstall". A service definition left
# behind is how a collector comes back at the next login after the operator was told it was removed --
# the failure this whole assertion exists for, and the one that shipped once on Windows.
if [ -f "$PLIST" ]; then
echo "launchd plist survived uninstall: $PLIST" >&2
exit 1
fi
echo "ok: the launchd plist was removed"
if [ -f "$INVENTORY_PLIST" ]; then
echo "scheduled inventory job plist survived uninstall: $INVENTORY_PLIST" >&2
exit 1
fi
echo "ok: the scheduled inventory job plist was removed"
if [ -f "$SESSION_SYNC_PLIST" ]; then
echo "scheduled session sync job plist survived uninstall: $SESSION_SYNC_PLIST" >&2
exit 1
fi
echo "ok: the scheduled session sync job plist was removed"
# Deliberately not asked of launchd. This install passes --no-start into a temporary HOME, so no job is
# ever bootstrapped -- which means any answer launchctl gave would be about some *other* install of the
# same label: a real one on the machine running this script. Asserting on that would fail for a
# developer who has Beacon installed and pass for one who does not, neither for a reason this test
# caused.
#
# So the file is the honest subject. This install wrote that exact plist and the uninstall must take it
# away. Whether launchd deregisters a job it had actually loaded is a real question that this test does
# not answer; it needs a genuine login session, which no CI runner provides.
test -f "$LOG_PATH"
echo "Beacon endpoint smoke test passed."