|
| 1 | +--- |
| 2 | +description: Run pre-merge checks before submitting a PR |
| 3 | +argument-hint: "" |
| 4 | +--- |
| 5 | + |
| 6 | +# Pre-Merge Check |
| 7 | + |
| 8 | +Run automated checks and display the pre-merge checklist before submitting a PR. |
| 9 | + |
| 10 | +## Instructions |
| 11 | + |
| 12 | +### 1. Identify Changed Files |
| 13 | + |
| 14 | +Get the list of files that will be included in the PR: |
| 15 | + |
| 16 | +```bash |
| 17 | +# Get all changed files (tracked modifications + staged + untracked) |
| 18 | +git diff --name-only HEAD |
| 19 | +git diff --cached --name-only |
| 20 | +git ls-files --others --exclude-standard |
| 21 | +``` |
| 22 | + |
| 23 | +Categorize files into: |
| 24 | +- **Methodology files**: `diff_diff/*.py` (excluding `__init__.py`) |
| 25 | +- **Test files**: `tests/*.py` |
| 26 | +- **Documentation files**: `*.md`, `*.rst`, `docs/**` |
| 27 | + |
| 28 | +### 2. Run Automated Pattern Checks |
| 29 | + |
| 30 | +#### 2.1 NaN Handling Pattern Check (for methodology files) |
| 31 | + |
| 32 | +If any methodology files changed, run these pattern checks: |
| 33 | + |
| 34 | +```bash |
| 35 | +# Check for bad t-stat pattern (should use np.nan, not 0.0 or 0) |
| 36 | +grep -n "if.*se.*>.*0.*else 0" diff_diff/*.py || true |
| 37 | + |
| 38 | +# Check for potential division issues without NaN handling |
| 39 | +grep -E -n "/[[:space:]]*se\>" diff_diff/*.py | grep -v "np.nan" | grep -v "#" || true |
| 40 | +``` |
| 41 | + |
| 42 | +**Report findings**: If matches found, warn about potential NaN handling issues. |
| 43 | + |
| 44 | +#### 2.2 Test Existence Check |
| 45 | + |
| 46 | +For each changed methodology file, check if corresponding test file was also changed: |
| 47 | + |
| 48 | +| Methodology File | Expected Test File | |
| 49 | +|------------------|-------------------| |
| 50 | +| `diff_diff/staggered.py` | `tests/test_staggered.py` | |
| 51 | +| `diff_diff/estimators.py` | `tests/test_estimators.py` | |
| 52 | +| `diff_diff/twfe.py` | `tests/test_estimators.py` | |
| 53 | +| `diff_diff/synthetic_did.py` | `tests/test_estimators.py` | |
| 54 | +| `diff_diff/sun_abraham.py` | `tests/test_sun_abraham.py` | |
| 55 | +| `diff_diff/triple_diff.py` | `tests/test_triple_diff.py` | |
| 56 | +| `diff_diff/trop.py` | `tests/test_trop.py` | |
| 57 | +| `diff_diff/bacon.py` | `tests/test_bacon.py` | |
| 58 | +| `diff_diff/linalg.py` | `tests/test_linalg.py` | |
| 59 | +| `diff_diff/utils.py` | `tests/test_utils.py` | |
| 60 | +| `diff_diff/diagnostics.py` | `tests/test_diagnostics.py` | |
| 61 | +| `diff_diff/prep.py` | `tests/test_prep.py` | |
| 62 | +| `diff_diff/visualization.py` | `tests/test_visualization.py` | |
| 63 | +| `diff_diff/honest_did.py` | `tests/test_honest_did.py` | |
| 64 | +| `diff_diff/power.py` | `tests/test_power.py` | |
| 65 | +| `diff_diff/pretrends.py` | `tests/test_pretrends.py` | |
| 66 | + |
| 67 | +**Report**: List any methodology files without corresponding test changes. |
| 68 | + |
| 69 | +#### 2.3 Docstring Check (heuristic) |
| 70 | + |
| 71 | +For changed `.py` files, run a quick check for functions without docstrings: |
| 72 | +```bash |
| 73 | +# Find public function definitions (heuristic check) |
| 74 | +grep -n "^def [^_]" <changed-py-files> | head -10 |
| 75 | +grep -n "^ def [^_]" <changed-py-files> | head -10 |
| 76 | +``` |
| 77 | + |
| 78 | +Note: This is a heuristic. Verify docstrings exist for new public functions. |
| 79 | + |
| 80 | +### 3. Display Context-Specific Checklist |
| 81 | + |
| 82 | +Based on what changed, display the appropriate checklist items: |
| 83 | + |
| 84 | +#### Always Show (Core Checklist) |
| 85 | +``` |
| 86 | +## Pre-Merge Checklist |
| 87 | +
|
| 88 | +Based on your changes to: <list of changed files> |
| 89 | +
|
| 90 | +### Behavioral Completeness |
| 91 | +- [ ] Happy path tested |
| 92 | +- [ ] Edge cases tested (empty data, NaN inputs, boundary conditions) |
| 93 | +- [ ] Error/warning paths tested with behavioral assertions |
| 94 | +``` |
| 95 | + |
| 96 | +#### If Methodology Files Changed |
| 97 | +``` |
| 98 | +### Inference Field Consistency |
| 99 | +- [ ] If SE can be 0/undefined, ALL inference fields (t-stat, p-value, CI) return NaN |
| 100 | +- [ ] Aggregation methods propagate NaN correctly |
| 101 | +- [ ] Bootstrap methods handle NaN in base estimates |
| 102 | +
|
| 103 | +### Control Group Logic (if adding new modes/code paths) |
| 104 | +- [ ] Control group composition verified for new code paths |
| 105 | +- [ ] "Not-yet-treated" excludes the treatment cohort itself |
| 106 | +- [ ] Parameter interactions tested with all aggregation methods |
| 107 | +``` |
| 108 | + |
| 109 | +#### If Documentation Files Changed |
| 110 | +``` |
| 111 | +### Documentation Sync |
| 112 | +- [ ] Docstrings updated for changed function signatures |
| 113 | +- [ ] README updated if user-facing behavior changes |
| 114 | +- [ ] REGISTRY.md updated if methodology edge cases change |
| 115 | +``` |
| 116 | + |
| 117 | +#### If This Appears to Be a Bug Fix |
| 118 | +``` |
| 119 | +### Pattern Consistency (Bug Fix) |
| 120 | +- [ ] Grepped for similar patterns across codebase before fixing |
| 121 | +- [ ] Fixed ALL occurrences, not just the one that was reported |
| 122 | +- [ ] Verified fix doesn't break other code paths |
| 123 | +``` |
| 124 | + |
| 125 | +### 4. Ask About Running Tests |
| 126 | + |
| 127 | +Use AskUserQuestion to offer test options: |
| 128 | + |
| 129 | +``` |
| 130 | +Would you like to run tests now? |
| 131 | +
|
| 132 | +Options: |
| 133 | +1. Yes - run full test suite (pytest) |
| 134 | +2. Yes - run only tests for changed files |
| 135 | +3. No - skip tests for now |
| 136 | +``` |
| 137 | + |
| 138 | +If user chooses option 1: |
| 139 | +```bash |
| 140 | +pytest |
| 141 | +``` |
| 142 | + |
| 143 | +If user chooses option 2, run targeted tests based on changed files: |
| 144 | +```bash |
| 145 | +pytest tests/test_staggered.py tests/test_estimators.py # (example) |
| 146 | +``` |
| 147 | + |
| 148 | +### 5. Report Summary |
| 149 | + |
| 150 | +``` |
| 151 | +## Pre-Merge Check Complete |
| 152 | +
|
| 153 | +### Automated Checks |
| 154 | +- Pattern checks: [PASS/WARN - N potential issues found] |
| 155 | +- Test coverage: [PASS/WARN - N methodology files without test changes] |
| 156 | +
|
| 157 | +### Manual Checklist |
| 158 | +Review the checklist items above before running /submit-pr |
| 159 | +
|
| 160 | +### Findings to Address |
| 161 | +<list any warnings from pattern checks> |
| 162 | +
|
| 163 | +### Next Steps |
| 164 | +- Address any warnings above |
| 165 | +- Complete manual checklist items |
| 166 | +- When ready: /submit-pr "Your PR title" |
| 167 | +``` |
| 168 | + |
| 169 | +## Notes |
| 170 | + |
| 171 | +- This skill is read-only - it only analyzes and reports, doesn't modify files |
| 172 | +- Run this BEFORE `/submit-pr` to catch issues early |
| 173 | +- Pattern checks are heuristics - review flagged items manually to confirm |
| 174 | +- If pattern checks find issues, fix them before submitting |
0 commit comments