Files
superpowers-zh/skills/systematic-debugging/find-polluter.sh
AI不止语 073a743ce7 fix: 同步上游两处纯代码修复(Windows hook 分发 + find-polluter 路径匹配)
对齐上游 v6.1.1 -> v6.2.0 时挑出的两处「无需翻译、无需 eval」的修复。
两个文件在我们这边都与上游 v6.1.1 字节一致(从未汉化改动),所以可直接取上游版。

1) hooks/hooks.json 加 "shell": "bash"(上游 5151e7a)

SessionStart hook 在 Windows 上原先不经 Git Bash 分发。我们的 hooks.json 与上游
除这一行外完全相同。这条直接改善 Windows 用户的 bootstrap 可靠性 —— 而 bootstrap
不加载 skill 就是死重。

冒烟测试:CLAUDE_PLUGIN_ROOT 指向仓库跑 run-hook.cmd session-start,
退出码 0,输出正确的 SessionStart JSON(含中文 using-superpowers 正文)。

2) skills/systematic-debugging/find-polluter.sh 取上游修复版(上游 6015d37、c8921b5)

修三个真 bug,已逐个实测新旧版对比:
- pattern 带 ./ 前缀时匹配不到(find . 输出 ./ 前缀路径):旧 1 个 -> 新 2 个
- -path 的 **/ 无法匹配零层目录,src/**/*.test.ts 漏掉 src/top.test.ts:
  旧 1 个 -> 新 2 个
- 完全无匹配时计数为 1 而非 0(echo 空串仍算一行):旧 1 -> 新 0

验证:audit.sh 153 pass / 0 fail、verify-release.sh 82 pass / 0 fail。

注:audit 的上游漂移 warn 从 2 条变 3 条(新增 using-git-worktrees),
且 executing-plans / finishing-a-development-branch 的上游 H 值有变化 ——
这是本次 git fetch upstream 把对比基准从旧快照更新到 v6.2.0 导致的,
不是本提交的改动引起。三个 SKILL.md 本提交都没碰。漂移详情见 #19。
2026-08-07 21:58:12 +08:00

73 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Bisection script to find which test creates unwanted files/state
# Usage: ./find-polluter.sh <file_or_dir_to_check> <test_pattern>
# Example: ./find-polluter.sh '.git' 'src/**/*.test.ts'
set -e
if [ $# -ne 2 ]; then
echo "Usage: $0 <file_to_check> <test_pattern>"
echo "Example: $0 '.git' 'src/**/*.test.ts'"
exit 1
fi
POLLUTION_CHECK="$1"
TEST_PATTERN="$2"
echo "🔍 Searching for test that creates: $POLLUTION_CHECK"
echo "Test pattern: $TEST_PATTERN"
echo ""
# Get list of test files (find . emits ./-prefixed paths, so accept the
# pattern written with or without a leading ./)
TEST_PATTERN="${TEST_PATTERN#./}"
# find -path can't match '**/' against zero directory levels, so a pattern
# like src/**/*.test.ts would skip src/top.test.ts; also try the pattern
# with '**/' collapsed to cover files directly under the base directory.
TEST_FILES=$(find . \( -path "./$TEST_PATTERN" -o -path "./${TEST_PATTERN//\*\*\//}" \) | sort -u)
if [ -z "$TEST_FILES" ]; then
TOTAL=0
else
TOTAL=$(printf '%s\n' "$TEST_FILES" | wc -l | tr -d ' ')
fi
echo "Found $TOTAL test files"
echo ""
COUNT=0
for TEST_FILE in $TEST_FILES; do
COUNT=$((COUNT + 1))
# Skip if pollution already exists
if [ -e "$POLLUTION_CHECK" ]; then
echo "⚠️ Pollution already exists before test $COUNT/$TOTAL"
echo " Skipping: $TEST_FILE"
continue
fi
echo "[$COUNT/$TOTAL] Testing: $TEST_FILE"
# Run the test
npm test "$TEST_FILE" > /dev/null 2>&1 || true
# Check if pollution appeared
if [ -e "$POLLUTION_CHECK" ]; then
echo ""
echo "🎯 FOUND POLLUTER!"
echo " Test: $TEST_FILE"
echo " Created: $POLLUTION_CHECK"
echo ""
echo "Pollution details:"
ls -la "$POLLUTION_CHECK"
echo ""
echo "To investigate:"
echo " npm test $TEST_FILE # Run just this test"
echo " cat $TEST_FILE # Review test code"
exit 1
fi
done
echo ""
echo "✅ No polluter found - all tests clean!"
exit 0