From 81abd35c859feff0476b849b017823329d671ec4 Mon Sep 17 00:00:00 2001 From: Darcy Liu Date: Sat, 25 Apr 2026 23:50:59 +0000 Subject: [PATCH] refactor(tests): streamline Claude Code request execution in Docker test script Introduce a new function, run_claude_request, to encapsulate the logic for executing Claude Code requests within a Docker container. This refactor simplifies the test script by reducing redundancy and improving readability, while maintaining the same functionality for back-to-back requests. Made-with: Cursor --- .../run_claude_code_docker_test.sh | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/proxy_e2e_anthropic_messages_tests/claude_code/run_claude_code_docker_test.sh b/tests/proxy_e2e_anthropic_messages_tests/claude_code/run_claude_code_docker_test.sh index 9ac0a01f124..d647b14e349 100755 --- a/tests/proxy_e2e_anthropic_messages_tests/claude_code/run_claude_code_docker_test.sh +++ b/tests/proxy_e2e_anthropic_messages_tests/claude_code/run_claude_code_docker_test.sh @@ -193,18 +193,38 @@ curl -fsS --connect-timeout 5 --max-time 20 \ -H "Authorization: Bearer ${LITELLM_MASTER_KEY}" "${PROXY_URL}/v1/models" | grep -q "\"${MODEL_NAME}\"" echo "[4/5] Running back-to-back Claude Code requests in an isolated non-root container..." +run_claude_request() { + local prompt="$1" + local output_file="$2" + local run_output + + if ! run_output="$( + docker compose -p "${COMPOSE_PROJECT_NAME}" -f "${COMPOSE_FILE}" run --rm -T \ + -e CLAUDE_CODE_PROMPT="${prompt}" \ + -e CLAUDE_CODE_OUTPUT_FILE="${output_file}" \ + claude-code 2>&1 + )"; then + echo "Claude Code container run failed." + echo "---- claude-code container output ----" + printf '%s\n' "${run_output}" | sed -n '1,200p' + echo "---- litellm logs tail ----" + docker compose -p "${COMPOSE_PROJECT_NAME}" -f "${COMPOSE_FILE}" logs --tail=200 litellm || true + return 1 + fi + + printf '%s\n' "${run_output}" +} + FIRST_RESPONSE="$( -docker compose -p "${COMPOSE_PROJECT_NAME}" -f "${COMPOSE_FILE}" run --rm \ - -e CLAUDE_CODE_PROMPT="Respond with exactly this text and nothing else: Hello from LiteLLM Claude Code request one." \ - -e CLAUDE_CODE_OUTPUT_FILE="/tmp/claude-output-1.txt" \ - claude-code + run_claude_request \ + "Respond with exactly this text and nothing else: Hello from LiteLLM Claude Code request one." \ + "/tmp/claude-output-1.txt" )" SECOND_RESPONSE="$( -docker compose -p "${COMPOSE_PROJECT_NAME}" -f "${COMPOSE_FILE}" run --rm \ - -e CLAUDE_CODE_PROMPT="Respond with exactly this text and nothing else: Hello from LiteLLM Claude Code request two." \ - -e CLAUDE_CODE_OUTPUT_FILE="/tmp/claude-output-2.txt" \ - claude-code + run_claude_request \ + "Respond with exactly this text and nothing else: Hello from LiteLLM Claude Code request two." \ + "/tmp/claude-output-2.txt" )" [[ -n "${FIRST_RESPONSE}" ]] || {