From 0cfd6b0504629bc211bb865654b7fd4547885c06 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 1 Jun 2026 23:45:30 +0200 Subject: [PATCH] fix(e2e): clean timed-out docker harness containers --- scripts/lib/docker-e2e-package.sh | 22 +++++++++++++++- test/scripts/docker-build-helper.test.ts | 32 ++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/scripts/lib/docker-e2e-package.sh b/scripts/lib/docker-e2e-package.sh index 428c990f4576..4c231317f0de 100644 --- a/scripts/lib/docker-e2e-package.sh +++ b/scripts/lib/docker-e2e-package.sh @@ -132,6 +132,19 @@ docker_e2e_cleanup_package_mount_args() { done } +docker_e2e_cleanup_container_cidfile() { + local cidfile="${1:-}" + [ -n "$cidfile" ] || return 0 + if [ -f "$cidfile" ]; then + local container_id + container_id="$(head -n 1 "$cidfile" 2>/dev/null || true)" + if [ -n "$container_id" ]; then + docker_e2e_docker_cmd rm -f "$container_id" >/dev/null 2>&1 || true + fi + rm -f "$cidfile" + fi +} + docker_e2e_harness_mount_args() { DOCKER_E2E_HARNESS_ARGS=( -v "$ROOT_DIR/scripts/e2e:/app/scripts/e2e:ro" @@ -143,7 +156,14 @@ docker_e2e_harness_mount_args() { docker_e2e_run_with_harness() { docker_e2e_harness_mount_args local run_status=0 - docker_e2e_docker_run_cmd run --rm "${DOCKER_E2E_HARNESS_ARGS[@]}" "$@" || run_status="$?" + local cid_dir + local cidfile + cid_dir="$(mktemp -d "${TMPDIR:-/tmp}/openclaw-docker-e2e-container.XXXXXX")" + cidfile="$cid_dir/container.cid" + docker_e2e_docker_run_cmd run --rm --cidfile "$cidfile" "${DOCKER_E2E_HARNESS_ARGS[@]}" "$@" || + run_status="$?" + docker_e2e_cleanup_container_cidfile "$cidfile" + rmdir "$cid_dir" 2>/dev/null || true docker_e2e_cleanup_package_mount_args return "$run_status" } diff --git a/test/scripts/docker-build-helper.test.ts b/test/scripts/docker-build-helper.test.ts index f51a716c42ca..2312cbe6bc5c 100644 --- a/test/scripts/docker-build-helper.test.ts +++ b/test/scripts/docker-build-helper.test.ts @@ -936,14 +936,17 @@ case "$1" in exit 0 ;; --kill-after=30s) - printf "%s %s\\n" "$1" "$2" >"$TMPDIR/docker-timeout-seen" + timeout_args="$1 $2" shift 2 ;; *) - printf "%s\\n" "$1" >"$TMPDIR/docker-timeout-seen" + timeout_args="$1" shift ;; esac +if [[ "\${1:-}" == "docker" && "\${2:-}" == "run" ]]; then + printf "%s\\n" "$timeout_args" >"$TMPDIR/docker-timeout-seen" +fi "$@" SH chmod +x "$TMPDIR/bin/timeout" @@ -984,20 +987,42 @@ export -f node source "$ROOT_DIR/scripts/lib/docker-e2e-package.sh" docker() { + if [[ "$1" == "rm" ]]; then + shift + test "$1" = "-f" + shift + printf "%s\\n" "$1" >>"$TMPDIR/docker-rm-seen" + return 0 + fi + + local cidfile="" local mount_path="" local expect_volume_path=0 + local expect_cidfile=0 local arg for arg in "$@"; do + if [[ "$expect_cidfile" == "1" ]]; then + cidfile="$arg" + expect_cidfile=0 + continue + fi if [[ "$expect_volume_path" == "1" ]]; then mount_path="\${arg%%:*}" expect_volume_path=0 continue fi + if [[ "$arg" == "--cidfile" ]]; then + expect_cidfile=1 + continue + fi if [[ "$arg" == "-v" ]]; then expect_volume_path=1 fi done + test -n "$cidfile" + test ! -e "$cidfile" + printf "container-%s\\n" "\${DOCKER_STUB_STATUS:-}" >"$cidfile" test -n "$mount_path" test -f "$mount_path" printf "%s\\n" "$mount_path" >"$TMPDIR/package-mount-seen" @@ -1011,8 +1036,10 @@ docker_e2e_package_mount_args "$package_tgz" DOCKER_STUB_STATUS=7 docker_e2e_run_with_harness image-name bash -lc true || run_status="$?" test "\${run_status:-0}" = "7" test "$(cat "$TMPDIR/docker-timeout-seen")" = "--kill-after=30s 3s" +grep -qx "container-7" "$TMPDIR/docker-rm-seen" test -f "$TMPDIR/package-mount-seen" test ! -e "$pack_dir" +test -z "$(find "$TMPDIR" -maxdepth 1 -name 'openclaw-docker-e2e-container.*' -print)" external_dir="$TMPDIR/external-package" mkdir -p "$external_dir" @@ -1022,6 +1049,7 @@ unset DOCKER_COMMAND_TIMEOUT rm -f "$TMPDIR/docker-timeout-seen" docker_e2e_run_with_harness image-name bash -lc true test "$(cat "$TMPDIR/docker-timeout-seen")" = "--kill-after=30s 3600s" +grep -qx "container-" "$TMPDIR/docker-rm-seen" test -f "$external_dir/openclaw-current.tgz" `;