Skip to content

Commit 3dc1c78

Browse files
fix: eliminate test isolation violation in test-record-review-crossval.sh (merge worktree-20260319-094922)
2 parents 5dea069 + 964374a commit 3dc1c78

File tree

3 files changed

+19
-38
lines changed

3 files changed

+19
-38
lines changed

plugins/dso/hooks/compute-diff-hash.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@ if [[ -n "${CFG_UNIT_SNAPSHOT_PATH:-}" ]]; then
165165
NON_REVIEWABLE_PATTERN="${NON_REVIEWABLE_PATTERN}|^${_USP_ESCAPED}.*\\.html$"
166166
fi
167167

168-
# Exclude test sentinel files that leak when test runners are killed by tool timeout.
169-
# These must remain visible to git (not gitignored) because the crossval test's
170-
# overlap check requires them, but they must not affect the diff hash.
171-
NON_REVIEWABLE_PATTERN="${NON_REVIEWABLE_PATTERN}|^\\.crossval-test-sentinel-"
172-
173168
# Build the untracked file list from live git query
174169
_get_untracked_files() {
175170
git ls-files --others --exclude-standard 2>/dev/null | { grep -v -E "$NON_REVIEWABLE_PATTERN" || true; }

plugins/dso/hooks/record-review.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,19 @@ if [[ -n "$CFG_UNIT_SNAPSHOT_PATH" ]]; then
257257
_RR_GREP_PATTERN="${_RR_GREP_PATTERN}|^${_USP_ESC}.*\\.html$"
258258
fi
259259

260-
CHANGED_FILES=$(
261-
{
262-
git diff --name-only HEAD -- "${_RR_EXCLUDE[@]}" 2>/dev/null || true
263-
git diff --cached --name-only HEAD -- "${_RR_EXCLUDE[@]}" 2>/dev/null || true
264-
git ls-files --others --exclude-standard 2>/dev/null | { grep -v -E "$_RR_GREP_PATTERN" || true; }
265-
} | sort -u | { grep -v '^$' || true; }
266-
)
260+
# Allow tests to inject changed files without writing to the repo.
261+
# isolation-ok: test-only override for overlap check
262+
if [[ -n "${RECORD_REVIEW_CHANGED_FILES:-}" ]]; then
263+
CHANGED_FILES="$RECORD_REVIEW_CHANGED_FILES"
264+
else
265+
CHANGED_FILES=$(
266+
{
267+
git diff --name-only HEAD -- "${_RR_EXCLUDE[@]}" 2>/dev/null || true
268+
git diff --cached --name-only HEAD -- "${_RR_EXCLUDE[@]}" 2>/dev/null || true
269+
git ls-files --others --exclude-standard 2>/dev/null | { grep -v -E "$_RR_GREP_PATTERN" || true; }
270+
} | sort -u | { grep -v '^$' || true; }
271+
)
272+
fi
267273

268274
if [[ -n "$CHANGED_FILES" ]] && [[ -n "$FILES_FROM_FINDINGS" ]]; then
269275
OVERLAP_FOUND=""

tests/hooks/test-record-review-crossval.sh

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ source "$DSO_PLUGIN_DIR/hooks/lib/deps.sh"
2828
# delete the production reviewer-findings.json — the root cause of the
2929
# "reviewer-findings.json not found" bug that blocked the commit workflow.
3030
ARTIFACTS_DIR=$(mktemp -d "${TMPDIR:-/tmp}/test-record-review-crossval-XXXXXX")
31-
export WORKFLOW_PLUGIN_ARTIFACTS_DIR="$ARTIFACTS_DIR"
31+
export WORKFLOW_PLUGIN_ARTIFACTS_DIR="$ARTIFACTS_DIR" # isolation-ok: test overrides hook artifact dir
3232
FINDINGS_FILE="$ARTIFACTS_DIR/reviewer-findings.json"
3333

3434
PASS=0
@@ -40,38 +40,18 @@ RED='\033[0;31m'
4040
GREEN='\033[0;32m'
4141
NC='\033[0m' # No Color
4242

43-
# Create a temp untracked file in the repo so findings files always overlap with
44-
# the git diff regardless of the worktree's current state. The file is cleaned up on exit.
45-
# NOTE: Do NOT use a .tmp extension — *.tmp is gitignored and won't appear in
46-
# git ls-files --others, breaking the overlap check in record-review.sh.
47-
#
48-
# Clean up any stale sentinels from previous killed runs (e.g., timeout exit 144 where
49-
# the EXIT trap did not fire). This prevents accumulation of untracked files that
50-
# cause diff hash instability in the review gate.
51-
# Only remove sentinels whose owner PID is no longer running — do NOT use a blind glob,
52-
# which would remove other *concurrent* instances' sentinels and break their overlap checks.
53-
for _stale in "$REPO_ROOT"/.crossval-test-sentinel-*.marker; do
54-
[[ -f "$_stale" ]] || continue
55-
_stale_pid="${_stale%.marker}"
56-
_stale_pid="${_stale_pid##*-}"
57-
if ! kill -0 "$_stale_pid" 2>/dev/null; then
58-
rm -f "$_stale"
59-
fi
60-
done
61-
SENTINEL_FILE="$REPO_ROOT/.crossval-test-sentinel-$$.marker"
62-
touch "$SENTINEL_FILE"
63-
SENTINEL_BASENAME=$(basename "$SENTINEL_FILE")
43+
# Use a synthetic filename for the overlap check instead of writing to the repo.
44+
# record-review.sh accepts RECORD_REVIEW_CHANGED_FILES to inject changed files
45+
# without creating untracked files in the working tree.
46+
SENTINEL_BASENAME="test-overlap-target.sh"
47+
export RECORD_REVIEW_CHANGED_FILES="$SENTINEL_BASENAME" # isolation-ok: test injects overlap target without writing to repo
6448

6549
cleanup() {
6650
rm -f "$FINDINGS_FILE"
67-
# Re-create sentinel after cleanup so it stays present for overlap checks.
68-
# The EXIT trap (cleanup_all) removes it finally at script exit.
69-
touch "$SENTINEL_FILE"
7051
}
7152

7253
cleanup_all() {
7354
rm -rf "$ARTIFACTS_DIR"
74-
rm -f "$SENTINEL_FILE"
7555
}
7656
trap cleanup_all EXIT
7757

0 commit comments

Comments
 (0)