init
This commit is contained in:
63
.opencode/skills/ck-debug/scripts/find-polluter.sh
Normal file
63
.opencode/skills/ck-debug/scripts/find-polluter.sh
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/bin/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
|
||||
TEST_FILES=$(find . -path "$TEST_PATTERN" | sort)
|
||||
TOTAL=$(echo "$TEST_FILES" | wc -l | tr -d ' ')
|
||||
|
||||
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
|
||||
102
.opencode/skills/ck-debug/scripts/find-polluter.test.md
Normal file
102
.opencode/skills/ck-debug/scripts/find-polluter.test.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# find-polluter.sh Test Documentation
|
||||
|
||||
## Purpose
|
||||
Bisection script to find which test creates unwanted files or state pollution.
|
||||
|
||||
## Manual Test Procedure
|
||||
|
||||
### Setup Test Scenario
|
||||
```bash
|
||||
# Create test directory
|
||||
mkdir -p /tmp/polluter-test && cd /tmp/polluter-test
|
||||
|
||||
# Create clean test
|
||||
cat > test1.test.js << 'EOF'
|
||||
console.log('Test 1: clean');
|
||||
EOF
|
||||
|
||||
# Create polluter test
|
||||
cat > test2.test.js << 'EOF'
|
||||
const fs = require('fs');
|
||||
fs.mkdirSync('.git', { recursive: true });
|
||||
console.log('Test 2: creates pollution');
|
||||
EOF
|
||||
|
||||
# Create another clean test
|
||||
cat > test3.test.js << 'EOF'
|
||||
console.log('Test 3: clean');
|
||||
EOF
|
||||
```
|
||||
|
||||
### Run Script
|
||||
```bash
|
||||
# For projects with npm test
|
||||
/path/to/find-polluter.sh '.git' 'src/**/*.test.ts'
|
||||
|
||||
# For node-only tests (modify script to use 'node' instead of 'npm test')
|
||||
./find-polluter.sh '.git' '*.test.js'
|
||||
```
|
||||
|
||||
### Expected Output
|
||||
```
|
||||
🔍 Searching for test that creates: .git
|
||||
Test pattern: *.test.js
|
||||
|
||||
Found 3 test files
|
||||
|
||||
[1/3] Testing: ./test1.test.js
|
||||
[2/3] Testing: ./test2.test.js
|
||||
|
||||
🎯 FOUND POLLUTER!
|
||||
Test: ./test2.test.js
|
||||
Created: .git
|
||||
```
|
||||
|
||||
### Cleanup
|
||||
```bash
|
||||
rm -rf /tmp/polluter-test
|
||||
```
|
||||
|
||||
## Test Results
|
||||
|
||||
✅ Script logic verified (2025-11-11)
|
||||
- Correctly iterates through test files
|
||||
- Detects pollution creation
|
||||
- Reports the polluting test file
|
||||
- Exits early when polluter found
|
||||
|
||||
## Usage Notes
|
||||
|
||||
**Prerequisites:**
|
||||
- Test runner (npm test) must be configured in project
|
||||
- Test pattern must match actual test files
|
||||
- Pollution path must be accurate
|
||||
|
||||
**Customization:**
|
||||
If your project doesn't use `npm test`, modify line 42:
|
||||
```bash
|
||||
# Replace
|
||||
npm test "$TEST_FILE" > /dev/null 2>&1 || true
|
||||
|
||||
# With your test command
|
||||
node "$TEST_FILE" > /dev/null 2>&1 || true
|
||||
# Or
|
||||
jest "$TEST_FILE" > /dev/null 2>&1 || true
|
||||
```
|
||||
|
||||
## Common Use Cases
|
||||
|
||||
1. **Find test creating .git directory:**
|
||||
```bash
|
||||
./find-polluter.sh '.git' 'src/**/*.test.ts'
|
||||
```
|
||||
|
||||
2. **Find test creating node_modules:**
|
||||
```bash
|
||||
./find-polluter.sh 'node_modules' 'test/**/*.spec.js'
|
||||
```
|
||||
|
||||
3. **Find test creating specific file:**
|
||||
```bash
|
||||
./find-polluter.sh 'unwanted-file.txt' '**/*.test.js'
|
||||
```
|
||||
Reference in New Issue
Block a user