CLI-279 Fail soft on hook crash outside CI#273
Conversation
SummaryThis PR changes git hooks (pre-commit and pre-push) to gracefully handle scan failures differently depending on the environment. In CI ( The implementation adds a Test coverage includes new cases for fail-soft behavior alongside updated assertions that the fail-hard behavior still works in CI. What reviewers should knowStart with the core logic: Check Non-obvious changes:
What to watch:
|
cc6964e to
7a6519d
Compare
d30bf0f to
08c5ae6
Compare
08c5ae6 to
3aefd0c
Compare
3aefd0c to
b1d9705
Compare
b1d9705 to
300f9cf
Compare
|
| binaryPath: string; | ||
| } | ||
|
|
||
| export function handleScanError(context: 'Commit' | 'Push'): void { |
There was a problem hiding this comment.
Bug: process.env.CI === 'true' is still an exact-string match. The previous review comment on this line flagged that several common CI platforms (Azure DevOps, custom runners with CI=1 or CI=yes) will not match this check and will silently skip enforcement. A truthy check is safer and matches the convention used by Jest, create-react-app, and most JS tooling.
| export function handleScanError(context: 'Commit' | 'Push'): void { | |
| if (process.env.CI) { |
- Mark as noise
|
|
||
| export function handleScanError(context: 'Commit' | 'Push'): void { | ||
| if (process.env.CI === 'true') { | ||
| throw new CommandFailedError('Secrets scan failed'); |
There was a problem hiding this comment.
Bug: The original error is still not surfaced in the fail-soft path. handleScanError() accepts no error parameter, so the debug log at the call site already printed the message, but the warn() shown to the user is always the same generic string regardless of what actually went wrong (binary not found, SIGSEGV, network timeout, etc.). Accepting the error here and including at least its message in the warning would make local debugging meaningful without changing the fail-soft contract.
- Mark as noise
| throw new CommandFailedError('Secrets detected in pushed commits'); | ||
| } |
There was a problem hiding this comment.
Bug: return false is still reached after handleScanError('Push') returns normally (outside CI). This breaks the loop and silently skips all remaining refs — the opposite of the fail-soft contract, which should warn but keep scanning. The return false / break pattern is only correct for the CI throw path; it should not apply when the soft path falls through.
Fix: return true after handleScanError so remaining refs are still scanned:
| throw new CommandFailedError('Secrets detected in pushed commits'); | |
| } | |
| handleScanError('Push'); // throws in CI, warns outside CI | |
| return true; |
- Mark as noise



No description provided.