From 9a2a3efd8eff3067ca49939ea01425f5a36f3336 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 13 Nov 2026 15:30:33 +0000 Subject: [PATCH] fix(tests): unset hook-exported git env before running suites Git exports GIT_DIR to the hooks it runs, so under the run-tests pre-push hook the validate-provenance-skill.bats fixtures' `git -C "$tmp"` calls resolved to this repo: 84 failures, core.bare=true and an emptied index on every push. run-tests.sh now unsets git's repo-locating variables before any suite runs. Reproduced with GIT_DIR pointed at a throwaway repo (61 failures) and verified clean after the fix (463/463). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012CqgnwEGtmfsjcoG9QwByN --- LESSONS.md | 4 ++++ tests/run-tests.sh | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/LESSONS.md b/LESSONS.md index 7f50d6f..fbe362a 100644 --- a/LESSONS.md +++ b/LESSONS.md @@ -141,3 +141,7 @@ The pre-push `run-tests` failed 2 of 3 full runs, on a different suite each time ## 2026-09-16 — A static guard covers exactly the spellings its regex models The guard added above (`tests/test-no-pipefail-early-exit-grep.sh`) reported the tree clean the day it landed, and the tree was not clean. Its pattern could not see a multi-stage pipeline (`echo x | filter | grep -q y`), a pipeline wrapped after a trailing `|`, or `set -o errexit -o pipefail` — the last a file-level miss that silently skipped every site in that file. Five live vulnerable sites sat in `tests/test-apm-current-hook.sh` while the suite reported green, and the fixtures carried 4 of the 12 vulnerable spellings that turned out to exist. A clean verdict from a static scanner is a claim about its regex, not about the tree. Fix: before trusting one, enumerate the spellings of the defect and measure the miss surface against them; and write the scanner's remit and its known false-positive shapes into the gate's own documentation, so the next reader knows what the green covers. + +## 2026-11-13 — Hook-exported GIT_DIR turned test fixtures loose on the real repo + +Under the `run-tests` pre-push hook, git exports `GIT_DIR` to the hook, so a bats fixture's `git -C "$tmp" init/commit/update-ref` hit this repo instead of its temp dir: 84 failures, `core.bare=true` and an emptied index on every push. The 2026-07-05 "repo root is a bare checkout" entry was likely this bug's symptom, not the repo's real shape. Fix: `tests/run-tests.sh` unsets git's repo-locating env vars before any suite runs. Rule: a test that builds its own repo must never inherit the caller's git environment. diff --git a/tests/run-tests.sh b/tests/run-tests.sh index bc86632..4abe2cc 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -33,6 +33,14 @@ # TEST_DIR — override root to search for test-*.sh (default: REPO_ROOT); used by tests. set -euo pipefail +# Git exports GIT_DIR (and can export GIT_WORK_TREE / GIT_INDEX_FILE) to the +# hooks it runs, so under the run-tests pre-push hook every `git -C "$tmp" ...` +# a fixture runs resolves to THIS repo, not the temp one -- the +# validate-provenance-skill.bats commit_as_base helper flipped core.bare=true and +# emptied the index here on every push. Suites build their own throwaway repos; +# none of them may inherit the caller's. +unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR + REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" BATS="$REPO_ROOT/tests/run-bats.sh" BATS_ONLY=false -- 2.43.0