From a2ee1880a692f79105fee9295d7e7bf2227fed2d Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 16 Jul 2026 23:38:14 +0000 Subject: [PATCH] fix(hooks): treat Gradle distribution download failure as infra skip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pre-push spotless gate already skips itself (warn + exit 0) when `./gradlew spotlessApply` fails for infra reasons, so a restricted sandbox can't strand a push over formatting. But its detection regex only covered dependency-resolution/network errors, not the case where the Gradle wrapper can't download the pinned distribution itself — e.g. an egress-proxy 40x on `gradle--bin.zip`. That surfaced as a hard BLOCK on an XML-only change even though CI's spotlessCheck would pass. Add the distribution-bootstrap markers (the `gradle--bin.zip` URL, the Java `Server returned HTTP response code` download exception, and "could not install gradle") to the infra-skip regex. These strings only appear when gradlew failed before running any task, so they can't mask a real formatting/compile failure (verified: a spotlessKotlinCheck violation still blocks). Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_0157AWJNEzybTuegstbWiQ6B --- .claude/hooks/pre-push-spotless.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.claude/hooks/pre-push-spotless.sh b/.claude/hooks/pre-push-spotless.sh index ff989f68a6..782d769d18 100755 --- a/.claude/hooks/pre-push-spotless.sh +++ b/.claude/hooks/pre-push-spotless.sh @@ -64,9 +64,13 @@ before="$(git diff HEAD -- '*.kt' '*.kts' 2>/dev/null | sha1sum)" log="$(mktemp /tmp/spotless-gate.XXXXXX.log)" if ! ./gradlew spotlessApply >"$log" 2>&1; then # Distinguish a formatting failure (block) from Gradle being unable to RUN — - # e.g. deps can't resolve in a restricted sandbox. An infra failure must not - # strand the agent; warn and let CI's spotlessCheck be the backstop. - if grep -qiE "could not resolve|could not (get|download)|handshake|connect timed out|no address|unable to (find|resolve) host|read timed out" "$log"; then + # e.g. deps can't resolve, or the wrapper can't even download the Gradle + # distribution, in a restricted sandbox. An infra failure must not strand the + # agent; warn and let CI's spotlessCheck be the backstop. The distribution + # patterns (the `gradle--bin.zip` URL, the Java download exception, and a + # proxy 40x on that fetch) only appear when `./gradlew` failed *before* running + # any task, so they can't mask a real formatting/compile error. + if grep -qiE "could not resolve|could not (get|download)|handshake|connect timed out|no address|unable to (find|resolve) host|read timed out|server returned http response code|gradle-[0-9][0-9.]*-(bin|all)\.zip|could not install gradle" "$log"; then echo "WARN: could not run spotlessApply (Gradle infra/network failure), skipping the formatting gate." >&2 echo " CI's spotlessCheck still enforces formatting on the PR." >&2 rm -f "$log"