xiaohongshu
xiaohongshu
Pattern for automated testing with GitHub issue creation and Claude Code auto-fixing. Creates Test → Fail → Issue → Fix → Repeat cycle until tests pass.
Full skill instructions
This skill provides a generalized pattern for continuous automated testing and fixing using Claude Code. The system creates a feedback loop: Test → Fail → Issue → Fix → Test that runs until all tests pass.
Use this pattern when you want:
Test Runner (run-tests.sh)
├─> Runs test suite with timeout
├─> Captures output and environment context
└─> On failure: Creates GitHub issue
↓
GitHub Issues (with full context)
↓
Issue Fixer (fix-issue.sh)
├─> Fetches issue from GitHub
├─> Invokes Claude Code with detailed prompt
└─> Claude investigates, fixes, tests, closes issue
↓
Auto-Fix Loop (auto-fix-loop.sh)
└─> Orchestrates: Test → Fix → Repeat until green
#!/bin/bash
set -euo pipefail
# Configuration
TIMEOUT_SECONDS=10
OUTPUT_FILE="/tmp/test-output.txt"
COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
DATE=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
OS_INFO=$(uname -a)
# Run tests with timeout
timeout $TIMEOUT_SECONDS <YOUR_TEST_COMMAND> 2>&1 | tee "$OUTPUT_FILE"
EXIT_CODE=${PIPESTATUS[0]}
# Annotate timeout
if [ $EXIT_CODE -eq 124 ]; then
EXIT_CODE="124 (timeout after ${TIMEOUT_SECONDS}s)"
fi
# On failure: Create GitHub issue
if [ $EXIT_CODE -ne 0 ]; then
# Strip ANSI color codes
CLEAN_OUTPUT=$(sed 's/\x1b\[[0-9;]*m//g' "$OUTPUT_FILE")
# Create issue
gh issue create \
--title "Test Failure: <TEST_NAME>" \
--body "$(cat <<EOF
## Test Failure Report
**Exit Code:** $EXIT_CODE
**Date:** $DATE
**Commit:** $COMMIT
**Branch:** $BRANCH
**OS:** $OS_INFO
### Test Output
\`\`\`
$CLEAN_OUTPUT
\`\`\`
### Diagnostic Information
<Add service status, connectivity checks, etc.>
### Files Involved
- Test: <path/to/test>
- Implementation: <path/to/impl>
### Expected Behavior
<What should happen>
### Actual Behavior
<What actually happened>
EOF
)"
exit 1
fi
echo "All tests passed!"
exit 0
Key Customization Points:
<YOUR_TEST_COMMAND>: Language-specific test runner
pytest tests/npm testcargo testgo test ./...TIMEOUT_SECONDS: Appropriate for your test suite#!/bin/bash
set -euo pipefail
# Parse arguments
ISSUE_NUM="$1"
MODEL="${2:-haiku}"
PERMISSION_MODE="interactive"
# Parse options
while [[ $# -gt 0 ]]; do
case $1 in
--model)
MODEL="$2"
shift 2
;;
--auto-edit)
PERMISSION_MODE="acceptEdits"
shift
;;
--no-prompts)
PERMISSION_MODE="dangerouslySkip"
shift
;;
*)
shift
;;
esac
done
# Fetch issue
ISSUE_TITLE=$(gh issue view "$ISSUE_NUM" --json title --jq '.title')
ISSUE_BODY=$(gh issue view "$ISSUE_NUM" --json body --jq '.body')
# Create prompt with guidance
PROMPT=$(cat <<EOF
GitHub Issue #$ISSUE_NUM: $ISSUE_TITLE
$ISSUE_BODY
IMPORTANT: Project-Specific Guidance
- <What code to modify vs what code to leave alone>
- <Where to look for the bug>
- <Common pitfalls to avoid>
Steps:
1. Read the test output carefully
2. Examine the source code
3. Identify the root cause
4. Implement a fix
5. Test with: ./run-tests.sh
6. If tests pass, close the issue with: gh issue close $ISSUE_NUM
You MUST verify the fix by running tests before closing the issue.
EOF
)
# Build Claude Code command
CLAUDE_OPTS=(--model "$MODEL")
if [ "$PERMISSION_MODE" = "dangerouslySkip" ]; then
CLAUDE_OPTS+=(--dangerously-skip-permissions)
elif [ "$PERMISSION_MODE" != "interactive" ]; then
CLAUDE_OPTS+=(--permission-mode "$PERMISSION_MODE")
fi
# Invoke Claude Code
claude "${CLAUDE_OPTS[@]}" "$PROMPT"
Model Selection:
haiku: Simple bugs, syntax errors (fast, cheap)sonnet: Most issues (balanced)opus: Complex architectural problems (slow, expensive)Permission Modes:
interactive (default): User approves each actionacceptEdits: Auto-accept file edits, prompt for bashdangerouslySkip: No prompts (sandboxed environments only!)#!/bin/bash
set -euo pipefail
MAX_ITERATIONS=${1:-10}
MODEL=${2:-haiku}
TEST_MODE=${3:-}
echo "Starting auto-fix loop (max $MAX_ITERATIONS iterations, model: $MODEL)"
iteration=0
while [ $iteration -lt $MAX_ITERATIONS ]; do
echo "========================================="
echo "Iteration $((iteration + 1))/$MAX_ITERATIONS"
echo "========================================="
# Run tests
if ./run-tests.sh $TEST_MODE; then
echo "SUCCESS! All tests passed!"
exit 0
fi
# Wait for GitHub API
sleep 2
# Find open issues
OPEN_ISSUES=$(gh issue list --state open --search "Test Failure" --json number --jq '.[].number')
if [ -z "$OPEN_ISSUES" ]; then
echo "No open test failure issues found"
sleep 2
continue
fi
# Fix the first issue
ISSUE_NUM=$(echo "$OPEN_ISSUES" | head -1)
echo "Fixing issue #$ISSUE_NUM..."
./fix-issue.sh --model "$MODEL" --no-prompts "$ISSUE_NUM"
iteration=$((iteration + 1))
done
echo "Max iterations reached without success"
exit 1
Using --dangerously-skip-permissions requires sandboxing because Claude Code can:
Only use --dangerously-skip-permissions in isolated environments!
# Start VM
qemu-system-x86_64 \
-m 2048 \
-hda debian-vm.qcow2 \
-netdev user,id=net0,hostfwd=tcp::2224-:22 \
-enable-kvm -cpu host \
-display none -daemonize
# Copy project
rsync -avz --exclude='target/' --exclude='.git/' \
./ user@localhost:~/project/ -e "ssh -p 2224"
# Run in VM
ssh -p 2224 user@localhost 'cd ~/project && ./auto-fix-loop.sh'
Pros: Full isolation, easy reset, works offline Cons: Requires local resources, disk space limits
# Copy to remote with lots of space
rsync -avz ./ user@remote:/path/to/testing/
# Start VM on remote
ssh user@remote 'qemu-system-x86_64 ... -daemonize'
# Forward VM SSH port
ssh -L 2230:localhost:3260 user@remote
# Access remote VM as if local
ssh -p 2230 user@localhost 'cd ~/project && ./auto-fix-loop.sh'
Pros: Unlimited disk space, doesn't consume local resources, can run overnight Cons: Requires network, more complex setup
FROM <base-image>
RUN apt-get update && apt-get install -y gh <build-tools>
COPY . /project
WORKDIR /project
CMD ["./auto-fix-loop.sh"]
docker build -t auto-tester .
docker run --rm auto-tester
Pros: Lightweight, fast startup Cons: Less isolation than VM
# 1. Write tests for new feature (they fail)
./run-tests.sh
# 2. Run auto-fix loop (interactive)
./auto-fix-loop.sh 20 sonnet
# 3. Review changes
git diff
# 4. Commit if satisfied
git commit -am "Implement feature X"
# After making changes
./run-tests.sh
# If issues created
./fix-issue.sh --auto-edit 15
# Verify
./run-tests.sh
# In sandboxed VM
nohup ./auto-fix-loop.sh 100 haiku > overnight.log 2>&1 &
# Next morning
tail overnight.log
gh issue list --state closed
Include in issues:
Bad issue: "Tests failed. Output: Error"
Too short = false positives. Too long = wasted time on hangs.
Critical: Add to fix-issue.sh prompt:
IMPORTANT: The tests in tests/ are CORRECT and must NOT be modified.
Fix the implementation code in src/, not the test code.
Claude Code may try to "fix" tests to make them pass. Explicitly forbid this.
Set based on:
Typical: 10-20 iterations
# run-tests.sh
pytest tests/ --junit-xml=results.xml || EXIT_CODE=$?
# run-tests.sh
npm test 2>&1 | tee test-output.txt || EXIT_CODE=$?
# run-tests.sh
cargo test --all 2>&1 | tee test-output.txt || EXIT_CODE=$?
# run-tests.sh
go test ./... -v -timeout 30s || EXIT_CODE=$?
Problem: Modifies test files to make tests pass
Solution: Add explicit guidance in fix-issue.sh:
IMPORTANT: Tests are CORRECT. Fix implementation code only.
Problem: Fix doesn't solve the problem
Solution:
Problem: Different environment
Solution:
gh CLI: sudo apt-get install ghgh auth loginrun-tests.sh with your test commandfix-issue.sh with project guidanceauto-fix-loop.sh for orchestration./run-tests.sh (should create issue)./fix-issue.sh 1 (check it works)./auto-fix-loop.sh 5 haiku--no-prompts modexiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience