Skip to content

Refactor/extract engine#22

Merged
pirr merged 2 commits into
mainfrom
refactor/extract-engine
May 5, 2026
Merged

Refactor/extract engine#22
pirr merged 2 commits into
mainfrom
refactor/extract-engine

Conversation

@pirr

@pirr pirr commented May 5, 2026

Copy link
Copy Markdown
Owner

No description provided.

Aleksey Smaga 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.
@pirr pirr self-assigned this May 5, 2026
@pirr pirr added the enhancement New feature or request label May 5, 2026
@pirr pirr merged commit 10d1dc6 into main May 5, 2026
2 checks passed
@pirr pirr deleted the refactor/extract-engine branch May 5, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant