Repository navigation
fix(precommit): derive API check catalog from engine SSOT — adds 5 missing checks (#9873) - #9886
Merged
Merged
Conversation
api/analytics_precommit.py kept a hand-copied BUILTIN_CHECKS dict that had drifted out of sync with the analyzer engine (code_intelligence/precommit_ analyzer.py): the API exposed only 14 checks while the engine defines 19 — silently dropping SEC005, SEC006, DOC002, QUA004, STY003 (two of them security checks) from the API's catalog, runner, toggle and summary endpoints. Replace the duplicated dict with a derivation from the engine's BUILTIN_CHECKS (the real source of truth — it is what actually runs). The engine CheckDefinition (dataclass) is converted to the API's Pydantic CheckDefinition; the two enums share identical values so they map by .value, and the engine-only multiline flag is dropped because the API runner already compiles every pattern with re.MULTILINE. The API keeps its own mutable schema objects, so the existing per-check .enabled toggle endpoint is unaffected. Behavior change (intended): the precommit API now reports/runs all 19 engine checks. Shared checks are byte-identical to before; only the 5 previously-missing checks are added. Eliminates ~111 lines of duplication and makes future drift impossible. Verification: API catalog == engine (19 checks, 5 missing now present); every shared check field matches the engine exactly; all values are the API schema type; .enabled toggle mutates only the API copy; flake8 clean; thread-safety tests 5 passed. (Engine unit test is unusable in a deps-light env — its missing deps stub to MagicMock — so correctness was verified by direct catalog assertion.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
✅ SSOT Configuration Compliance: Passing🎉 No hardcoded values detected that have SSOT config equivalents! |
Applied Black, isort, and autoflake to match code-quality checks. Triggered by workflow auto-fix-formatting.yml. Co-Authored-By: Paperclip <noreply@paperclip.ing>
Owner
Author
CodeReviewer AssessmentCode review: ✅ Ready to merge
CI status: ⏳ Pending
Will auto-merge when CI goes green. Automated review by CodeReviewer agent |
Owner
Author
|
mrveiss
added a commit
that referenced
this pull request
Jun 10, 2026
…#9873) (#9889) Follow-up to the catalog derivation, addressing the review of #9886: syncing only the catalog was incomplete because api/analytics_precommit.py also carried a duplicate check *runner* and a fast-mode skip list that had forked from the engine. Symptoms the catalog-only change would have shipped: - _EXPENSIVE_CHECKS={'QUA002','DOC001'} was tuned to the OLD catalog; with QUA002 now meaning 'Bare Except' it skipped the wrong checks in fast mode (the default), while the engine's real expensive set is {'DOC001','DOC002','QUA003','STY003'}. - the API runner compiled re.MULTILINE line-by-line, so the engine's multiline checks (DOC002, STY003) were advertised in the catalog but never fired. Make the module a thin HTTP layer over the engine (full delegation, per maintainer decision): - Remove the duplicate run_check / matches_file_pattern / _filter_enabled_checks and the stale _EXPENSIVE_CHECKS. - Execute via PrecommitAnalyzer.analyze_content(); convert engine CheckResult → API schema CheckResult. - _active_engine_checks() applies the API's enable/disable config and (in fast mode) the engine's own expensive set, so catalog, skip list and runner can never disagree again. Behavior changes (intended, adopting the engine as SSOT): QUA002 = 'Bare Except' (API loses 'Magic Number'), SEC004 now flags loopback/0.0.0.0/localhost, and the multiline checks (DOC001/DOC002/STY003) actually run. Verification: catalog 19 checks; bare-except sample fires QUA002; multiline DOC002 now fires (previously impossible); result schema fields correct; fast_mode excludes the engine expensive set; per-check toggle still filters; flake8 clean; thread-safety tests 5 passed. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Closes #9873.
Thinking Path
Surfaced during the dedup sweep:
api/analytics_precommit.pyhad forked from the analyzer enginecode_intelligence/precommit_analyzer.py— not just a stale catalog (missing 5 checks) but a conflicting one (QUA002 = "Magic Number" in the API vs "Bare Except" in the engine), a divergent SEC004, a fast-mode skip list tuned to the old catalog, and a duplicate regex runner that couldn't execute the engine's multiline checks. A first attempt that only synced the catalog was reviewed and found to ship silent regressions. Per maintainer decision, the fix is full delegation: make the API a thin layer over the engine (single source of truth).What Changed
BUILTIN_CHECKSis derived from the engine'sBUILTIN_CHECKS(engine dataclass → API Pydantic schema via_engine_check_to_schema).PrecommitAnalyzer.analyze_content(); the duplicaterun_check/matches_file_pattern/_filter_enabled_checksand the stale_EXPENSIVE_CHECKSare removed. EngineCheckResult→ API schemaCheckResultvia_engine_result_to_schema._active_engine_checks()applies the API's enable/disable config (per-check.enabledtoggle +HookConfigallow/deny lists) and, in fast mode, the engine's ownexpensive_checks— so catalog, skip list and runner can never disagree again.Behavior changes (intended — engine is now SSOT):
QUA002is "Bare Except" (the API's old "Magic Number" check is dropped — it does not exist in the engine).SEC004now flags loopback/0.0.0.0/localhost(the engine's pattern has no exclusion).DOC001/DOC002/STY003) now actually fire via the API (the old per-line runner could not match them).Verification
QUA002; class-without-docstring fires the multilineDOC002(previously impossible via the API)._engine_result_to_schemamaps every field (file_path→file, dropscolumn); result schema validates.fast_modeexcludes the engine's expensive set{DOC001,DOC002,QUA003,STY003}; disabling a check via the toggle removes it from the active set.flake8clean;thread_safety_test.py(precommit/analytics) 5 passed. (Engine unit test can't run green in a deps-light env — missing deps stub toMagicMock— so verification is by direct functional assertion against the engine + API helpers.)Model Used
Claude Opus 4.8 (1M context)
🤖 Generated with Claude Code