Refactor/extract engine#22
Merged
Merged
Conversation
added 2 commits
May 5, 2026 17:47
cli.py was a 590-line mix of Click wiring, the checker-dispatch engine, and CLI-side error-to-exit-code translation. Move dispatch to a pure pgsleuth/engine.py: open_context, run, RunResult, SkippedChecker, UnsupportedServerVersionError. The CLI is now a shell that builds Config, calls engine.run, and renders. Side effects that the engine used to perform are now structured data on the result: per-checker version gating and statement_timeout cancellations become SkippedChecker records (no stderr from inside dispatch), and an unsupported server version raises UnsupportedServerVersionError instead of sys.exit(2). The CLI translates both back to its existing stderr output and exit codes. Behavior change: baseline staleness is now keyed off RunResult.ran (the precise set of checkers that actually executed) rather than the config-only running set. Entries for version-gated or timed-out checkers are now classified as unknown_baseline_entries — their findings cannot be confirmed gone, so prune preserves them under the existing warn-before-remove policy. Closes the latent bug flagged by the comment that previously sat on _running_checkers. Tests: existing CLI tests migrate to patch pgsleuth.engine.run / pgsleuth.engine.connect via two helpers in conftest.py (make_run_result, fake_engine_run). New tests/test_engine.py covers threshold filtering, version-gating skips, statement_timeout skip via a real conn, baseline filtering with stale vs unknown classification, and open_context.
The JSON reporter now emits a "skipped" array alongside "issues" and "suppressed". Each entry carries the checker name, reason (version_gated | statement_timeout), and the human-readable detail string the engine already produces for the [skipped] stderr line. A CI consumer parsing JSON previously saw "no issues, clean run" while half the checks may have silently not run. With this field, dashboards and gating logic can decide what skips mean for them — e.g. fail the build if statement_timeout cancellations exceed N, or require explicit acknowledgement when version_gated entries appear. The text reporter is unchanged; terminal users continue to see the [skipped] lines on stderr exactly as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.