Commit 0e246ee
authored
## Summary
Implements standardized exit codes and the `--fail-on` flag for both `scan` and `ci` commands, enabling selective CI/CD pipeline failures based on security finding severities.
## Changes
### Core Exit Code Logic (`output/exit_code.go`)
- **Exit Code Constants**:
- `ExitCodeSuccess (0)`: No findings or no --fail-on match
- `ExitCodeFindings (1)`: Findings match --fail-on severities
- `ExitCodeError (2)`: Configuration or execution errors
- **DetermineExitCode()**: Calculates appropriate exit code with error precedence
- **ParseFailOn()**: Parses comma-separated severity values
- **ValidateSeverities()**: Validates severity names (case-insensitive)
- **InvalidSeverityError**: Custom error type for validation failures
### Command Integration
- **scan command**: Add --fail-on flag and integrate exit code logic
- **ci command**: Add --fail-on flag and integrate exit code logic
- Both commands now:
- Exit 0 by default (regardless of findings)
- Exit 1 only when findings match --fail-on severities
- Exit 2 on configuration/execution errors
- Support case-insensitive severity validation
### Bug Fixes
- Fixed SARIF output always exiting 0 (now respects --fail-on)
## Testing
### Unit Tests (`output/exit_code_test.go`)
- 16 tests for `DetermineExitCode()` covering all exit scenarios
- 12 tests for `ParseFailOn()` covering edge cases
- 13 tests for `ValidateSeverities()` covering validation
- All tests verify case-insensitive behavior
### Integration Tests (`cmd/exit_code_integration_test.go`)
- Tests actual binary exit codes for both scan and ci commands
- Tests all output formats (SARIF, JSON, CSV)
- Tests invalid severity handling
- Tests case-insensitive severity matching
- Requires `INTEGRATION=1` and pre-built binary
**Test Results**: All tests passing ✅
```bash
$ gradle testGo
ok .../output 0.223s
ok .../cmd 0.317s
```
## Examples
```bash
# Default: no exit on findings
pathfinder scan --rules rules/ --project .
# Exit: 0 (even if vulnerabilities found)
# Fail on critical findings
pathfinder scan --rules rules/ --project . --fail-on critical
# Exit: 1 if critical findings, 0 otherwise
# Fail on critical or high findings
pathfinder ci --rules rules/ --project . --output sarif --fail-on critical,high
# Exit: 1 if critical/high findings, 0 otherwise
# Case insensitive
pathfinder scan --rules rules/ --project . --fail-on CRITICAL,High,MeDiUm
# Exit: 1 if any match
# Invalid severity
pathfinder scan --rules rules/ --project . --fail-on invalid
# Error: invalid severity 'invalid', must be one of: critical, high, medium, low, info
```
## Migration Notes
### Breaking Changes
- **Default behavior changed**: Previously, any findings caused exit 1. Now requires explicit `--fail-on` flag.
- **CI/CD pipelines**: Add `--fail-on critical,high` to maintain previous fail-on-findings behavior.
### Non-Breaking
- Existing commands without `--fail-on` continue to work (exit 0)
- All output formats work identically with exit codes
## Checklist
- [x] Core exit code logic implemented
- [x] Integrated with scan command
- [x] Integrated with ci command
- [x] Unit tests (95%+ coverage)
- [x] Integration tests
- [x] All tests passing
- [x] Linter passing
- [x] Binary builds successfully
- [x] Documentation in commit messages
## Stacked PRs
This PR stacks on top of:
- PR #5: SARIF Formatter (#395)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 40c3ebe commit 0e246ee
File tree
5 files changed
+752
-14
lines changed- sourcecode-parser
- cmd
- output
5 files changed
+752
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
51 | 60 | | |
52 | 61 | | |
53 | 62 | | |
| |||
107 | 116 | | |
108 | 117 | | |
109 | 118 | | |
| 119 | + | |
110 | 120 | | |
111 | 121 | | |
112 | 122 | | |
113 | 123 | | |
114 | 124 | | |
115 | 125 | | |
116 | 126 | | |
| 127 | + | |
117 | 128 | | |
118 | 129 | | |
119 | 130 | | |
| |||
139 | 150 | | |
140 | 151 | | |
141 | 152 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | 153 | | |
147 | 154 | | |
148 | 155 | | |
| |||
154 | 161 | | |
155 | 162 | | |
156 | 163 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | 164 | | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
165 | 168 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | 169 | | |
171 | 170 | | |
172 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
173 | 180 | | |
174 | 181 | | |
175 | 182 | | |
| |||
185 | 192 | | |
186 | 193 | | |
187 | 194 | | |
| 195 | + | |
188 | 196 | | |
189 | 197 | | |
190 | 198 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
46 | 55 | | |
47 | 56 | | |
48 | 57 | | |
| |||
105 | 114 | | |
106 | 115 | | |
107 | 116 | | |
| 117 | + | |
108 | 118 | | |
109 | 119 | | |
110 | 120 | | |
111 | 121 | | |
| 122 | + | |
112 | 123 | | |
113 | 124 | | |
114 | 125 | | |
| |||
128 | 139 | | |
129 | 140 | | |
130 | 141 | | |
131 | | - | |
132 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
133 | 146 | | |
134 | 147 | | |
135 | 148 | | |
| |||
172 | 185 | | |
173 | 186 | | |
174 | 187 | | |
| 188 | + | |
175 | 189 | | |
176 | 190 | | |
177 | 191 | | |
0 commit comments