Systematic bug fixing workflow with regression tests and PR creation. Use when the user asks to "fix a bug", "debug an issue", "resolve a problem", or provides error messages/failing tests to fix...
Systematic approach to fixing bugs with proper testing and documentation.
Run the provided command or test to observe the failure:
# For WAST tests
./wasmoon test <file>.wast
# For MoonBit tests
moon test -p <package> -f <file>.mbt
# For specific test by index
moon test -p <package> -f <file>.mbt -i <index>
Document:
Investigate the error systematically:
a) Examine error messages
b) Locate relevant code
**/*<keyword>*.mbtc) For WASM-related bugs
./wasmoon explore <file>.wat --stage ir vcode mc
Check IR, VCode, and machine code for issues.
d) For crashes or segfaults
lldb -- ./wasmoon test <file>.wast
(lldb) run
(lldb) bt # After crash
Before fixing, write a test that reproduces the bug:
For WASM execution bugs:
test "descriptive_bug_name" {
let source =
#|(module
#| (func (export "test") (result i32)
#| ; Bug-reproducing code here
#| )
#|)
let result = compare_jit_interp(source, "test", [])
inspect(result, content="matched")
}
For unit tests:
test "descriptive_bug_name" {
let result = buggy_function(input)
inspect(result, content="expected_value")
}
Place the test in the appropriate *_test.mbt file in the relevant package.
Verify the test fails:
moon test -p <package> -f <test_file>.mbt
Make the necessary code changes:
Run tests to verify:
moon test -p <package> # Unit tests
moon test # All tests
moon build && ./install.sh # For wasmoon binary changes
Ensure the fix doesn't break other functionality:
moon test # All unit tests
python3 scripts/run_all_wast.py --rec # All wast tests
a) Create feature branch
git checkout -b fix/<descriptive-name>
b) Commit changes
moon fmt && moon info
git add .
git commit -m "$(cat <<'EOF'
fix: <brief description>
- Root cause: <explanation>
- Solution: <what was changed>
- Test: <test that verifies the fix>
EOF
)"
c) Push and create PR
git push -u origin fix/<descriptive-name>
gh pr create --title "fix: <brief description>" --body "$(cat <<'EOF'
## Summary
- Root cause: <explanation>
- Solution: <what was changed>
- Test: <test file and description>
## Test Plan
- [ ] Regression test passes
- [ ] All existing tests pass
- [ ] Manual verification of fix
EOF
)"
commit --amend or push --force on shared branches# Build and install
moon build && ./install.sh
# Run tests
moon test -p <package> -f <file>.mbt
moon test -p <package> -f <file>.mbt -i <index>
# Analyze WASM
./wasmoon explore <file>.wat --stage ir vcode mc
./wasmoon test <file>.wast
./wasmoon test --no-jit <file>.wast
# Debug with LLDB
lldb -- ./wasmoon test <file>.wast
# Git workflow
git checkout -b fix/<name>
git add . && git commit
git push -u origin fix/<name>
gh pr create