test: cover claude and codex acp bind docker smoke

This commit is contained in:
Peter Steinberger
2026-04-07 06:06:13 +01:00
parent c2cd1aed5d
commit ce1d2c1004
4 changed files with 228 additions and 111 deletions

View File

@@ -305,12 +305,14 @@ Notes:
- `pnpm test:live src/gateway/gateway-acp-bind.live.test.ts`
- `OPENCLAW_LIVE_ACP_BIND=1`
- Defaults:
- ACP agent: `claude`
- ACP agents in Docker: `claude,codex`
- ACP agent for direct `pnpm test:live ...`: `claude`
- Synthetic channel: Slack DM-style conversation context
- ACP backend: `acpx`
- Overrides:
- `OPENCLAW_LIVE_ACP_BIND_AGENT=claude`
- `OPENCLAW_LIVE_ACP_BIND_AGENT=codex`
- `OPENCLAW_LIVE_ACP_BIND_AGENTS=claude,codex`
- `OPENCLAW_LIVE_ACP_BIND_AGENT_COMMAND='npx -y @agentclientprotocol/claude-agent-acp@<version>'`
- Notes:
- This lane uses the gateway `chat.send` surface with admin-only synthetic originating-route fields so tests can attach message-channel context without pretending to deliver externally.
@@ -330,9 +332,18 @@ Docker recipe:
pnpm test:docker:live-acp-bind
```
Single-agent Docker recipes:
```bash
pnpm test:docker:live-acp-bind:claude
pnpm test:docker:live-acp-bind:codex
```
Docker notes:
- The Docker runner lives at `scripts/test-live-acp-bind-docker.sh`.
- By default, it runs the ACP bind smoke against both supported live CLI agents in sequence: `claude`, then `codex`.
- Use `OPENCLAW_LIVE_ACP_BIND_AGENTS=claude` or `OPENCLAW_LIVE_ACP_BIND_AGENTS=codex` to narrow the matrix.
- It sources `~/.profile`, stages the matching CLI auth material into the container, installs `acpx` into a writable npm prefix, then installs the requested live CLI (`@anthropic-ai/claude-code` or `@openai/codex`) if missing.
- Inside Docker, the runner sets `OPENCLAW_LIVE_ACP_BIND_ACPX_COMMAND=$HOME/.npm-global/bin/acpx` so acpx keeps provider env vars from the sourced profile available to the child harness CLI.

View File

@@ -1169,6 +1169,8 @@
"test:docker:doctor-switch": "bash scripts/e2e/doctor-install-switch-docker.sh",
"test:docker:gateway-network": "bash scripts/e2e/gateway-network-docker.sh",
"test:docker:live-acp-bind": "bash scripts/test-live-acp-bind-docker.sh",
"test:docker:live-acp-bind:claude": "OPENCLAW_LIVE_ACP_BIND_AGENT=claude bash scripts/test-live-acp-bind-docker.sh",
"test:docker:live-acp-bind:codex": "OPENCLAW_LIVE_ACP_BIND_AGENT=codex bash scripts/test-live-acp-bind-docker.sh",
"test:docker:live-build": "bash scripts/test-live-build-docker.sh",
"test:docker:live-cli-backend": "bash scripts/test-live-cli-backend-docker.sh",
"test:docker:live-gateway": "bash scripts/test-live-gateway-models-docker.sh",

View File

@@ -9,24 +9,26 @@ CONFIG_DIR="${OPENCLAW_CONFIG_DIR:-$HOME/.openclaw}"
WORKSPACE_DIR="${OPENCLAW_WORKSPACE_DIR:-$HOME/.openclaw/workspace}"
PROFILE_FILE="${OPENCLAW_PROFILE_FILE:-$HOME/.profile}"
CLI_TOOLS_DIR="${OPENCLAW_DOCKER_CLI_TOOLS_DIR:-$HOME/.cache/openclaw/docker-cli-tools}"
ACP_AGENT="${OPENCLAW_LIVE_ACP_BIND_AGENT:-claude}"
ACP_AGENT_LIST_RAW="${OPENCLAW_LIVE_ACP_BIND_AGENTS:-${OPENCLAW_LIVE_ACP_BIND_AGENT:-claude,codex}}"
case "$ACP_AGENT" in
claude)
AUTH_PROVIDER="claude-cli"
CLI_PACKAGE="@anthropic-ai/claude-code"
CLI_BIN="claude"
;;
codex)
AUTH_PROVIDER="codex-cli"
CLI_PACKAGE="@openai/codex"
CLI_BIN="codex"
;;
*)
echo "Unsupported OPENCLAW_LIVE_ACP_BIND_AGENT: $ACP_AGENT (expected claude or codex)" >&2
exit 1
;;
esac
openclaw_live_acp_bind_resolve_auth_provider() {
case "${1:-}" in
claude) printf '%s\n' "claude-cli" ;;
codex) printf '%s\n' "codex-cli" ;;
*)
echo "Unsupported OPENCLAW_LIVE_ACP_BIND agent: ${1:-} (expected claude or codex)" >&2
return 1
;;
esac
}
openclaw_live_acp_bind_resolve_agent_command() {
case "${1:-}" in
claude) printf '%s' "${OPENCLAW_LIVE_ACP_BIND_AGENT_COMMAND_CLAUDE:-${OPENCLAW_LIVE_ACP_BIND_AGENT_COMMAND:-}}" ;;
codex) printf '%s' "${OPENCLAW_LIVE_ACP_BIND_AGENT_COMMAND_CODEX:-${OPENCLAW_LIVE_ACP_BIND_AGENT_COMMAND:-}}" ;;
*) return 1 ;;
esac
}
mkdir -p "$CLI_TOOLS_DIR"
@@ -35,54 +37,6 @@ if [[ -f "$PROFILE_FILE" ]]; then
PROFILE_MOUNT=(-v "$PROFILE_FILE":/home/node/.profile:ro)
fi
AUTH_DIRS=()
AUTH_FILES=()
if [[ -n "${OPENCLAW_DOCKER_AUTH_DIRS:-}" ]]; then
while IFS= read -r auth_dir; do
[[ -n "$auth_dir" ]] || continue
AUTH_DIRS+=("$auth_dir")
done < <(openclaw_live_collect_auth_dirs)
while IFS= read -r auth_file; do
[[ -n "$auth_file" ]] || continue
AUTH_FILES+=("$auth_file")
done < <(openclaw_live_collect_auth_files)
else
while IFS= read -r auth_dir; do
[[ -n "$auth_dir" ]] || continue
AUTH_DIRS+=("$auth_dir")
done < <(openclaw_live_collect_auth_dirs_from_csv "$AUTH_PROVIDER")
while IFS= read -r auth_file; do
[[ -n "$auth_file" ]] || continue
AUTH_FILES+=("$auth_file")
done < <(openclaw_live_collect_auth_files_from_csv "$AUTH_PROVIDER")
fi
AUTH_DIRS_CSV=""
if ((${#AUTH_DIRS[@]} > 0)); then
AUTH_DIRS_CSV="$(openclaw_live_join_csv "${AUTH_DIRS[@]}")"
fi
AUTH_FILES_CSV=""
if ((${#AUTH_FILES[@]} > 0)); then
AUTH_FILES_CSV="$(openclaw_live_join_csv "${AUTH_FILES[@]}")"
fi
EXTERNAL_AUTH_MOUNTS=()
if ((${#AUTH_DIRS[@]} > 0)); then
for auth_dir in "${AUTH_DIRS[@]}"; do
host_path="$HOME/$auth_dir"
if [[ -d "$host_path" ]]; then
EXTERNAL_AUTH_MOUNTS+=(-v "$host_path":/host-auth/"$auth_dir":ro)
fi
done
fi
if ((${#AUTH_FILES[@]} > 0)); then
for auth_file in "${AUTH_FILES[@]}"; do
host_path="$HOME/$auth_file"
if [[ -f "$host_path" ]]; then
EXTERNAL_AUTH_MOUNTS+=(-v "$host_path":/host-auth-files/"$auth_file":ro)
fi
done
fi
read -r -d '' LIVE_TEST_CMD <<'EOF' || true
set -euo pipefail
[ -f "$HOME/.profile" ] && source "$HOME/.profile" || true
@@ -152,6 +106,13 @@ cleanup() {
trap cleanup EXIT
source /src/scripts/lib/live-docker-stage.sh
openclaw_live_stage_source_tree "$tmp_dir"
# Use a writable node_modules overlay in the temp repo. Vite writes bundled
# config artifacts under the nearest node_modules/.vite-temp path, and the
# build-stage /app/node_modules tree is root-owned in this Docker lane.
mkdir -p "$tmp_dir/node_modules"
cp -aRs /app/node_modules/. "$tmp_dir/node_modules"
rm -rf "$tmp_dir/node_modules/.vite-temp"
mkdir -p "$tmp_dir/node_modules/.vite-temp"
openclaw_live_link_runtime_tree "$tmp_dir"
openclaw_live_stage_state_dir "$tmp_dir/.openclaw-state"
openclaw_live_prepare_staged_config
@@ -163,34 +124,102 @@ EOF
echo "==> Build live-test image: $LIVE_IMAGE_NAME (target=build)"
docker build --target build -t "$LIVE_IMAGE_NAME" -f "$ROOT_DIR/Dockerfile" "$ROOT_DIR"
echo "==> Run ACP bind live test in Docker"
echo "==> Agent: $ACP_AGENT"
echo "==> Auth dirs: ${AUTH_DIRS_CSV:-none}"
echo "==> Auth files: ${AUTH_FILES_CSV:-none}"
docker run --rm -t \
-u node \
--entrypoint bash \
-e ANTHROPIC_API_KEY \
-e ANTHROPIC_API_KEY_OLD \
-e OPENCLAW_LIVE_ACP_BIND_ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-}" \
-e OPENCLAW_LIVE_ACP_BIND_ANTHROPIC_API_KEY_OLD="${ANTHROPIC_API_KEY_OLD:-}" \
-e OPENAI_API_KEY \
-e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
-e HOME=/home/node \
-e NODE_OPTIONS=--disable-warning=ExperimentalWarning \
-e OPENCLAW_SKIP_CHANNELS=1 \
-e OPENCLAW_VITEST_FS_MODULE_CACHE=0 \
-e OPENCLAW_DOCKER_AUTH_DIRS_RESOLVED="$AUTH_DIRS_CSV" \
-e OPENCLAW_DOCKER_AUTH_FILES_RESOLVED="$AUTH_FILES_CSV" \
-e OPENCLAW_LIVE_TEST=1 \
-e OPENCLAW_LIVE_ACP_BIND=1 \
-e OPENCLAW_LIVE_ACP_BIND_AGENT="$ACP_AGENT" \
-e OPENCLAW_LIVE_ACP_BIND_AGENT_COMMAND="${OPENCLAW_LIVE_ACP_BIND_AGENT_COMMAND:-}" \
-v "$ROOT_DIR":/src:ro \
-v "$CONFIG_DIR":/home/node/.openclaw \
-v "$WORKSPACE_DIR":/home/node/.openclaw/workspace \
-v "$CLI_TOOLS_DIR":/home/node/.npm-global \
"${EXTERNAL_AUTH_MOUNTS[@]}" \
"${PROFILE_MOUNT[@]}" \
"$LIVE_IMAGE_NAME" \
-lc "$LIVE_TEST_CMD"
IFS=',' read -r -a ACP_AGENT_TOKENS <<<"$ACP_AGENT_LIST_RAW"
ACP_AGENTS=()
for token in "${ACP_AGENT_TOKENS[@]}"; do
agent="$(openclaw_live_trim "$token")"
[[ -n "$agent" ]] || continue
openclaw_live_acp_bind_resolve_auth_provider "$agent" >/dev/null
ACP_AGENTS+=("$agent")
done
if ((${#ACP_AGENTS[@]} == 0)); then
echo "No ACP bind agents selected. Use OPENCLAW_LIVE_ACP_BIND_AGENTS=claude,codex." >&2
exit 1
fi
for ACP_AGENT in "${ACP_AGENTS[@]}"; do
AUTH_PROVIDER="$(openclaw_live_acp_bind_resolve_auth_provider "$ACP_AGENT")"
AGENT_COMMAND="$(openclaw_live_acp_bind_resolve_agent_command "$ACP_AGENT")"
AUTH_DIRS=()
AUTH_FILES=()
if [[ -n "${OPENCLAW_DOCKER_AUTH_DIRS:-}" ]]; then
while IFS= read -r auth_dir; do
[[ -n "$auth_dir" ]] || continue
AUTH_DIRS+=("$auth_dir")
done < <(openclaw_live_collect_auth_dirs)
while IFS= read -r auth_file; do
[[ -n "$auth_file" ]] || continue
AUTH_FILES+=("$auth_file")
done < <(openclaw_live_collect_auth_files)
else
while IFS= read -r auth_dir; do
[[ -n "$auth_dir" ]] || continue
AUTH_DIRS+=("$auth_dir")
done < <(openclaw_live_collect_auth_dirs_from_csv "$AUTH_PROVIDER")
while IFS= read -r auth_file; do
[[ -n "$auth_file" ]] || continue
AUTH_FILES+=("$auth_file")
done < <(openclaw_live_collect_auth_files_from_csv "$AUTH_PROVIDER")
fi
AUTH_DIRS_CSV=""
if ((${#AUTH_DIRS[@]} > 0)); then
AUTH_DIRS_CSV="$(openclaw_live_join_csv "${AUTH_DIRS[@]}")"
fi
AUTH_FILES_CSV=""
if ((${#AUTH_FILES[@]} > 0)); then
AUTH_FILES_CSV="$(openclaw_live_join_csv "${AUTH_FILES[@]}")"
fi
EXTERNAL_AUTH_MOUNTS=()
if ((${#AUTH_DIRS[@]} > 0)); then
for auth_dir in "${AUTH_DIRS[@]}"; do
host_path="$HOME/$auth_dir"
if [[ -d "$host_path" ]]; then
EXTERNAL_AUTH_MOUNTS+=(-v "$host_path":/host-auth/"$auth_dir":ro)
fi
done
fi
if ((${#AUTH_FILES[@]} > 0)); then
for auth_file in "${AUTH_FILES[@]}"; do
host_path="$HOME/$auth_file"
if [[ -f "$host_path" ]]; then
EXTERNAL_AUTH_MOUNTS+=(-v "$host_path":/host-auth-files/"$auth_file":ro)
fi
done
fi
echo "==> Run ACP bind live test in Docker"
echo "==> Agent: $ACP_AGENT"
echo "==> Auth dirs: ${AUTH_DIRS_CSV:-none}"
echo "==> Auth files: ${AUTH_FILES_CSV:-none}"
docker run --rm -t \
-u node \
--entrypoint bash \
-e ANTHROPIC_API_KEY \
-e ANTHROPIC_API_KEY_OLD \
-e OPENCLAW_LIVE_ACP_BIND_ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-}" \
-e OPENCLAW_LIVE_ACP_BIND_ANTHROPIC_API_KEY_OLD="${ANTHROPIC_API_KEY_OLD:-}" \
-e OPENAI_API_KEY \
-e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
-e HOME=/home/node \
-e NODE_OPTIONS=--disable-warning=ExperimentalWarning \
-e OPENCLAW_SKIP_CHANNELS=1 \
-e OPENCLAW_VITEST_FS_MODULE_CACHE=0 \
-e OPENCLAW_DOCKER_AUTH_DIRS_RESOLVED="$AUTH_DIRS_CSV" \
-e OPENCLAW_DOCKER_AUTH_FILES_RESOLVED="$AUTH_FILES_CSV" \
-e OPENCLAW_LIVE_TEST=1 \
-e OPENCLAW_LIVE_ACP_BIND=1 \
-e OPENCLAW_LIVE_ACP_BIND_AGENT="$ACP_AGENT" \
-e OPENCLAW_LIVE_ACP_BIND_AGENT_COMMAND="$AGENT_COMMAND" \
-v "$ROOT_DIR":/src:ro \
-v "$CONFIG_DIR":/home/node/.openclaw \
-v "$WORKSPACE_DIR":/home/node/.openclaw/workspace \
-v "$CLI_TOOLS_DIR":/home/node/.npm-global \
"${EXTERNAL_AUTH_MOUNTS[@]}" \
"${PROFILE_MOUNT[@]}" \
"$LIVE_IMAGE_NAME" \
-lc "$LIVE_TEST_CMD"
done

View File

@@ -65,9 +65,19 @@ function extractAssistantTexts(messages: unknown[]): string[] {
.filter((value): value is string => typeof value === "string" && value.trim().length > 0);
}
function extractLastAssistantText(messages: unknown[]): string | null {
const texts = extractAssistantTexts(messages);
return texts.at(-1) ?? null;
function createAcpRecallPrompt(liveAgent: "claude" | "codex"): string {
if (liveAgent === "codex") {
return "Please include the exact token from your immediately previous assistant reply.";
}
return "Reply with exactly the token from your immediately previous assistant reply and nothing else.";
}
function createAcpMarkerPrompt(liveAgent: "claude" | "codex", memoryNonce: string): string {
const token = `ACP-BIND-MEMORY-${memoryNonce}`;
if (liveAgent === "codex") {
return `Please include the exact token ${token} in your reply.`;
}
return `Reply with exactly this token and nothing else: ${token}`;
}
function extractSpawnedAcpSessionKey(texts: string[]): string | null {
@@ -331,6 +341,44 @@ async function sendChatAndWait(params: {
await waitForAgentRunOk(params.client, started.runId);
}
async function waitForAssistantText(params: {
client: GatewayClient;
sessionKey: string;
contains: string;
minAssistantCount?: number;
timeoutMs?: number;
}): Promise<{ messages: unknown[]; lastAssistantText: string }> {
const timeoutMs = params.timeoutMs ?? 30_000;
const startedAt = Date.now();
while (Date.now() - startedAt < timeoutMs) {
const history = await params.client.request<{ messages?: unknown[] }>("chat.history", {
sessionKey: params.sessionKey,
limit: 16,
});
const messages = history.messages ?? [];
const assistantTexts = extractAssistantTexts(messages);
const lastAssistantText = assistantTexts.at(-1) ?? null;
if (
assistantTexts.length >= (params.minAssistantCount ?? 1) &&
lastAssistantText?.includes(params.contains)
) {
return { messages, lastAssistantText };
}
await sleep(500);
}
const finalHistory = await params.client.request<{ messages?: unknown[] }>("chat.history", {
sessionKey: params.sessionKey,
limit: 16,
});
throw new Error(
`timed out waiting for assistant text containing ${params.contains}: ${formatAssistantTextPreview(
extractAssistantTexts(finalHistory.messages ?? []),
)}`,
);
}
describeLive("gateway live (ACP bind)", () => {
it(
"binds a synthetic Slack DM conversation to a live ACP session and reroutes the next turn",
@@ -469,30 +517,57 @@ describeLive("gateway live (ACP bind)", () => {
});
logLiveStep("follow-up turn completed");
const firstBoundHistory = await waitForAssistantText({
client,
sessionKey: spawnedSessionKey,
contains: `ACP-BIND-${followupNonce}`,
});
const firstAssistantCount = extractAssistantTexts(firstBoundHistory.messages).length;
await sendChatAndWait({
client,
sessionKey: originalSessionKey,
idempotencyKey: `idem-memory-${randomUUID()}`,
message:
"Reply with exactly two uppercase tokens separated by a single space: " +
"first, the token from your immediately previous assistant reply; " +
`second, ACP-BIND-MEMORY-${memoryNonce}. No extra text.`,
message: createAcpRecallPrompt(liveAgent),
originatingChannel: "slack",
originatingTo: conversationId,
originatingAccountId: accountId,
});
logLiveStep("memory follow-up turn completed");
logLiveStep("memory recall turn completed");
const boundHistory = await client.request<{ messages?: unknown[] }>("chat.history", {
const recallHistory = await waitForAssistantText({
client,
sessionKey: spawnedSessionKey,
limit: 16,
contains: `ACP-BIND-${followupNonce}`,
minAssistantCount: firstAssistantCount + 1,
});
const assistantTexts = extractAssistantTexts(boundHistory.messages ?? []);
const lastAssistantText = extractLastAssistantText(boundHistory.messages ?? []);
const recallAssistantText = recallHistory.lastAssistantText;
expect(recallAssistantText).toContain(`ACP-BIND-${followupNonce}`);
logLiveStep("bound session transcript retained the previous token");
const recallAssistantCount = extractAssistantTexts(recallHistory.messages).length;
await sendChatAndWait({
client,
sessionKey: originalSessionKey,
idempotencyKey: `idem-marker-${randomUUID()}`,
message: createAcpMarkerPrompt(liveAgent, memoryNonce),
originatingChannel: "slack",
originatingTo: conversationId,
originatingAccountId: accountId,
});
logLiveStep("memory marker turn completed");
const boundHistory = await waitForAssistantText({
client,
sessionKey: spawnedSessionKey,
contains: `ACP-BIND-MEMORY-${memoryNonce}`,
minAssistantCount: recallAssistantCount + 1,
});
const assistantTexts = extractAssistantTexts(boundHistory.messages);
const lastAssistantText = boundHistory.lastAssistantText;
expect(assistantTexts.join("\n\n")).toContain(`ACP-BIND-${followupNonce}`);
expect(lastAssistantText).toContain(`ACP-BIND-${followupNonce}`);
expect(lastAssistantText).toContain(`ACP-BIND-MEMORY-${memoryNonce}`);
logLiveStep("bound session transcript contains follow-up token");
logLiveStep("bound session transcript contains the final marker token");
} finally {
releasePinnedPluginChannelRegistry(channelRegistry);
clearRuntimeConfigSnapshot();