From 9a3f72b6966be0c2a6293b66775e547cafa7009e Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sun, 9 Aug 2026 17:28:07 +0000 Subject: [PATCH] test(lint): stop the release-gate suite inheriting the caller's PRE_COMMIT refs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit run_check set PRE_COMMIT_REMOTE_BRANCH and, when asked, PRE_COMMIT_TO_REF, but never cleared what was already in the environment. Standalone that is invisible — nothing sets those vars. Under the pre-push hook this suite exists to guard, pre-commit exports PRE_COMMIT_TO_REF and PRE_COMMIT_FROM_REF as shas of the real repo; the fixtures inherited them, the script resolved a rev that does not exist in the fixture, and 13 of 20 cases failed. The suite passed in every context except the only one that matters. The variables are now cleared in both branches, so a standalone run and a pre-push run are the same test. Verified 20/20 with the vars unset and with them set to real shas of this repo. Found by the pre-push hook rejecting the push, not by any test — the same shape as the --config regression: the local invocation exercised a different thing than the shipped one, and the two were indistinguishable by reading the file. Refs: #85 --- tests/test-check-release-needed.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test-check-release-needed.sh b/tests/test-check-release-needed.sh index 75d15e2..440960b 100755 --- a/tests/test-check-release-needed.sh +++ b/tests/test-check-release-needed.sh @@ -76,12 +76,21 @@ EOF # $3 is optional: pre-commit's PRE_COMMIT_TO_REF, the local sha being pushed. # Left off entirely, the variable stays unset and the script falls back to HEAD, # exactly as a plain `git push ` behaves. +# The fixture repo is the subject under test, so every PRE_COMMIT_* input must +# come from this function and nowhere else. Any such variable already in the +# environment belongs to the *caller's* repo: run under the pre-push hook this +# suite guards, PRE_COMMIT_TO_REF holds a sha of the real repo, which does not +# exist in the fixture, and the script resolves against the wrong rev. Clearing +# them is what makes a standalone run and a pre-push run the same test — this +# suite passed everywhere except under the hook it exists to protect. run_check() { local dir="$1" branch="$2" if [[ $# -ge 3 ]]; then - (cd "$dir" && PRE_COMMIT_REMOTE_BRANCH="$branch" PRE_COMMIT_TO_REF="$3" bash "$SCRIPT" 2>&1) + (cd "$dir" && unset PRE_COMMIT_FROM_REF \ + && PRE_COMMIT_REMOTE_BRANCH="$branch" PRE_COMMIT_TO_REF="$3" bash "$SCRIPT" 2>&1) else - (cd "$dir" && PRE_COMMIT_REMOTE_BRANCH="$branch" bash "$SCRIPT" 2>&1) + (cd "$dir" && unset PRE_COMMIT_FROM_REF PRE_COMMIT_TO_REF \ + && PRE_COMMIT_REMOTE_BRANCH="$branch" bash "$SCRIPT" 2>&1) fi }