mirror of
https://github.com/msitarzewski/agency-agents.git
synced 2026-10-13 01:30:05 +00:00
fix(openclaw): detect existing agents and report registration failures
This commit is contained in:
@@ -28,3 +28,4 @@ jobs:
|
||||
run: |
|
||||
chmod +x scripts/test-install.sh scripts/install.sh
|
||||
./scripts/test-install.sh
|
||||
bash scripts/test-install-openclaw-registration.sh
|
||||
|
||||
+13
-2
@@ -936,7 +936,15 @@ install_openclaw() {
|
||||
[[ -d "$src" ]] || { err "integrations/openclaw missing. Run convert.sh first."; return 1; }
|
||||
mkdir -p "$dest"
|
||||
if command -v openclaw >/dev/null 2>&1; then
|
||||
existing_agents=$'\n'"$(openclaw agents list --json 2>/dev/null | sed -n 's/^[[:space:]]*\"id\": \"\\([^\"]*\\)\".*/\\1/p')"$'\n'
|
||||
local agents_json
|
||||
if ! agents_json="$(openclaw agents list --json 2>/dev/null)"; then
|
||||
err "OpenClaw: could not list registered agents; refusing to guess which workspaces need registration."
|
||||
return 1
|
||||
fi
|
||||
# IDs may appear in compact or pretty JSON, and several may share a line.
|
||||
# Agent IDs are slugs, so quoted id tokens need no JSON parser dependency.
|
||||
existing_agents=$'\n'"$(printf '%s' "$agents_json" | grep -oE '"id"[[:space:]]*:[[:space:]]*"[^"]*"' \
|
||||
| sed -E 's/^"id"[[:space:]]*:[[:space:]]*"([^"]*)"$/\1/' || true)"$'\n'
|
||||
fi
|
||||
local d
|
||||
while IFS= read -r -d '' d; do
|
||||
@@ -949,7 +957,10 @@ install_openclaw() {
|
||||
install_file "$d/IDENTITY.md" "$dest/$name/IDENTITY.md"
|
||||
if command -v openclaw >/dev/null 2>&1; then
|
||||
if [[ "$existing_agents" != *$'\n'"$name"$'\n'* ]]; then
|
||||
openclaw agents add "$name" --workspace "$dest/$name" --non-interactive || true
|
||||
if ! openclaw agents add "$name" --workspace "$dest/$name" --non-interactive; then
|
||||
err "OpenClaw: failed to register '$name'; the copied workspace is not active."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
(( count++ )) || true
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
# Existing agents must not be registered again, and failed registration must
|
||||
# not be reported as a successful OpenClaw install.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
scratch="$(mktemp -d)"
|
||||
trap 'rm -rf "$scratch"' EXIT
|
||||
mkdir -p "$scratch/repo/scripts" "$scratch/repo/engineering" \
|
||||
"$scratch/repo/integrations/openclaw/example-agent" "$scratch/bin"
|
||||
cp "$SCRIPT_DIR/install.sh" "$SCRIPT_DIR/lib.sh" "$scratch/repo/scripts/"
|
||||
cp "$SCRIPT_DIR/../divisions.json" "$scratch/repo/"
|
||||
cat > "$scratch/repo/engineering/example.md" <<'EOF'
|
||||
---
|
||||
name: Example Agent
|
||||
description: Example
|
||||
color: blue
|
||||
---
|
||||
# Example Agent
|
||||
EOF
|
||||
for f in SOUL.md AGENTS.md IDENTITY.md; do
|
||||
printf '# Example Agent\n' > "$scratch/repo/integrations/openclaw/example-agent/$f"
|
||||
done
|
||||
cat > "$scratch/bin/openclaw" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
if [[ "$1 $2 $3" == 'agents list --json' ]]; then
|
||||
if [[ "$OPENCLAW_TEST_MODE" == list-fail ]]; then
|
||||
exit 48
|
||||
elif [[ "$OPENCLAW_TEST_MODE" == existing ]]; then
|
||||
printf '[{"id":"example-agent"}]\n'
|
||||
else
|
||||
printf '[]\n'
|
||||
fi
|
||||
elif [[ "$1 $2" == 'agents add' ]]; then
|
||||
printf 'add called\n' >> "$OPENCLAW_TEST_LOG"
|
||||
exit 47
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
EOF
|
||||
chmod +x "$scratch/bin/openclaw"
|
||||
|
||||
export OPENCLAW_TEST_LOG="$scratch/add.log"
|
||||
export PATH="$scratch/bin:$PATH"
|
||||
export HOME="$scratch/home"
|
||||
export OPENCLAW_TEST_MODE=existing
|
||||
bash "$scratch/repo/scripts/install.sh" --tool openclaw --agent example-agent \
|
||||
--no-convert --path "$scratch/destination" > "$scratch/existing.log" 2>&1
|
||||
[[ ! -e "$OPENCLAW_TEST_LOG" ]] || {
|
||||
echo 'FAIL: compact JSON existing agent was registered again' >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
export OPENCLAW_TEST_MODE=missing
|
||||
if bash "$scratch/repo/scripts/install.sh" --tool openclaw --agent example-agent \
|
||||
--no-convert --path "$scratch/destination" > "$scratch/missing.log" 2>&1; then
|
||||
echo 'FAIL: failed OpenClaw registration was reported as successful' >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q 'failed to register' "$scratch/missing.log"
|
||||
|
||||
rm -f "$OPENCLAW_TEST_LOG"
|
||||
export OPENCLAW_TEST_MODE=list-fail
|
||||
if bash "$scratch/repo/scripts/install.sh" --tool openclaw --agent example-agent \
|
||||
--no-convert --path "$scratch/destination" > "$scratch/list-fail.log" 2>&1; then
|
||||
echo 'FAIL: failed OpenClaw roster query was reported as successful' >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q 'could not list registered agents' "$scratch/list-fail.log"
|
||||
[[ ! -e "$OPENCLAW_TEST_LOG" ]]
|
||||
echo 'PASS: OpenClaw existing-agent detection and registration failure reporting'
|
||||
Reference in New Issue
Block a user