Commit 1d4c64a0c99 for woocommerce

commit 1d4c64a0c9953c9213ede68b11236ea8df06d70d
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date:   Sat Sep 12 23:53:17 2026 +0300

    [tests] Let the wp-env start retry recover from root-owned mount points (#68666)

    ci: Let the wp-env start retry recover from root-owned mount points

    The retry loop around `wp-env start` was written for transient network
    failures, where re-running the start is enough. It cannot recover from
    a failure that happened after containers were already running.

    `.wp-env.e2e.json` maps `test-data/images/` into the container, and the
    container writes there as root. `wp-env start` removes a mapping's
    directory before re-creating it, so once an attempt has run containers,
    every later attempt dies with "EACCES: permission denied, rmdir" on
    that directory, whatever the original failure was. All three attempts
    are then spent, and the reported error names the permission failure
    rather than what actually went wrong.

    Blocks e2e hits this through its seed: the first attempt fails the
    `products.sh` guard "the sample-data image import did not complete",
    which is a re-runnable step the retry exists to re-run, and then cannot
    reach it because the mount point is no longer removable.

    Reclaim ownership of the wp-env home before each retry, and classify
    both the seed guard and the permission failure so the existing
    `reason=` markers name them instead of reporting `unknown`. Only a
    retry runs the chown; a green first attempt never reaches it.

    Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d83ae35d266..fc199a439a4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -373,6 +373,8 @@ jobs:
             if grep -qF 'curl error 28' "$log"; then reason=packagist
             elif grep -qE 'registry-1\.docker\.io|context deadline exceeded|failed to receive status: rpc error|connection reset by peer' "$log"; then reason=dockerhub
             elif grep -qE 'ETIMEDOUT|socket hang up|ECONNRESET' "$log"; then reason=wordpress
+            elif grep -qF 'the sample-data image import did not complete' "$log"; then reason=blocks-seed
+            elif grep -qE 'EACCES: permission denied, rmdir' "$log"; then reason=stale-mount
             else reason=unknown
             fi
             if [ "$attempt" -ge "$max_attempts" ]; then
@@ -385,6 +387,14 @@ jobs:
             # a repeat failure then records every connect attempt with its address and errno.
             # Healthy first attempts stay untraced, so this costs nothing on a green job.
             export NODE_DEBUG=net
+            # An attempt that got as far as running containers leaves wp-env's mapped
+            # directories owned by root, because the container writes into them as root.
+            # `wp-env start` removes a mapping's directory before re-creating it, so those
+            # leftovers make every later attempt fail with "EACCES: permission denied,
+            # rmdir" no matter what the original failure was -- the retry can never
+            # recover. Hand the tree back to the runner user first. Only retries pay this
+            # cost; a green first attempt never reaches it.
+            sudo chown -R "$(id -u):$(id -g)" "${WP_ENV_HOME:-$HOME/wp-env}" 2>/dev/null || true
             sleep "$((attempt * 15))"
             attempt=$((attempt + 1))
           done