From e1b426c4a732e0d11650a250b0d5cdb5ccf2d37f Mon Sep 17 00:00:00 2001 From: Drew Ritter Date: Wed, 25 Nov 2026 00:37:26 -0800 Subject: fix(systematic-debugging): return find-polluter.sh, its test and its section to dev's text where no issue requires a change This branch deleted skills/systematic-debugging/find-polluter.sh, its test tests/systematic-debugging/test-find-polluter.sh, and the "Finding Which Test Causes Pollution" section of root-cause-tracing.md that runs the script. Jesse fixed the script and added its test in v6.2.0 (01461735), and no issue this PR cites asks for their removal: #2460 proposes fixes to the script in place, and those fixes are not part of this PR. The script, its test and the section return to dev's text, so this branch no longer changes them. The script keeps its executable bit. Co-Authored-By: Claude Opus 5.5 --- tests/systematic-debugging/test-find-polluter.sh | 90 ++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 tests/systematic-debugging/test-find-polluter.sh (limited to 'tests/systematic-debugging') diff --git a/tests/systematic-debugging/test-find-polluter.sh b/tests/systematic-debugging/test-find-polluter.sh new file mode 100755 index 0000000..0902e7d --- /dev/null +++ b/tests/systematic-debugging/test-find-polluter.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +SCRIPT_UNDER_TEST="$REPO_ROOT/skills/systematic-debugging/find-polluter.sh" + +FAILURES=0 +TEST_ROOT="$(mktemp -d)" + +cleanup() { + rm -rf "$TEST_ROOT" +} +trap cleanup EXIT + +pass() { + echo " [PASS] $1" +} + +fail() { + echo " [FAIL] $1" + FAILURES=$((FAILURES + 1)) +} + +assert_contains() { + local haystack="$1" + local needle="$2" + local description="$3" + + if printf '%s' "$haystack" | grep -Fq -- "$needle"; then + pass "$description" + else + fail "$description (expected output to contain: $needle)" + fi +} + +# Toy project: one top-level test, one nested test. A stubbed `npm` on PATH +# creates the pollution marker whenever any test runs, so the first test file +# executed is always identified as the polluter. +setup_project() { + PROJECT="$TEST_ROOT/project" + rm -rf "$PROJECT" + mkdir -p "$PROJECT/src/feature" "$PROJECT/bin" + echo "test('top')" > "$PROJECT/src/top.test.ts" + echo "test('nested')" > "$PROJECT/src/feature/nested.test.ts" + cat > "$PROJECT/bin/npm" <<'EOF' +#!/usr/bin/env bash +touch pollution.marker +EOF + chmod +x "$PROJECT/bin/npm" +} + +# run_polluter — runs the script in the toy project with the stub +# npm first on PATH; captures combined output, never aborts on exit code. +run_polluter() { + local pattern="$1" + rm -f "$PROJECT/pollution.marker" + ( + cd "$PROJECT" + PATH="$PROJECT/bin:$PATH" "$SCRIPT_UNDER_TEST" 'pollution.marker' "$pattern" 2>&1 + ) || true +} + +echo "Test: documented pattern finds nested test files (issue #2008)" +setup_project +OUTPUT="$(run_polluter 'src/**/*.test.ts')" +assert_contains "$OUTPUT" "FOUND POLLUTER" "documented pattern runs tests and detects pollution" + +echo "Test: documented pattern also finds top-level test files" +setup_project +OUTPUT="$(run_polluter 'src/**/*.test.ts')" +assert_contains "$OUTPUT" "Found 2 test files" "src/**/*.test.ts matches src/top.test.ts and src/feature/nested.test.ts" + +echo "Test: ./-prefixed pattern matches the same files" +setup_project +OUTPUT="$(run_polluter './src/**/*.test.ts')" +assert_contains "$OUTPUT" "Found 2 test files" "leading ./ on the pattern is accepted" + +echo "Test: non-matching pattern reports an honest zero" +setup_project +OUTPUT="$(run_polluter 'nomatch/**/*.test.ts')" +assert_contains "$OUTPUT" "Found 0 test files" "empty result counts as 0, not 1" +assert_contains "$OUTPUT" "No polluter found" "empty result exits via the clean path" + +echo "" +if [ "$FAILURES" -gt 0 ]; then + echo "$FAILURES test(s) failed" + exit 1 +fi +echo "All tests passed" -- cgit