Refactor rules to remove some false positives#48
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR focuses on reducing audit-identified false positives across multiple SQL validation rules by making table/alias resolution more scope-aware (especially around CTE shadowing), adds a new anti-pattern rule for CTE names that collide with OMOP tables, and includes a small UI enhancement showing MCP mount status.
Changes:
- Add
anti_patterns.cte_shadows_omop_tableand supporting helpercollect_cte_names, plus tests and changelog updates. - Refine multiple rules to avoid false positives: CTE-shadow-aware
has_table_reference, scope-aware alias resolution (schema validation / OMOP_149),LIMITscalar-aggregate carve-out, visit-occurrence join-key gating, and IN-subquery CTE bridging for join-path validation. - UI: add an MCP on/off “pill” backed by the app’s live
mcp_mountedstate.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_rules.py | Adds regression tests for CTE shadowing, alias scoping, scalar-aggregate LIMIT carve-out, visit join-key gating, and new rule coverage. |
| tests/test_patch.py | Extends canonical suggested-fix verbs to include RENAME:. |
| tests/test_helpers_cte.py | Adds focused tests for new CTE-aware helper behavior. |
| src/fastssv/rules/joins/visit_occurrence_inner_join_validation.py | Gates OMOP_043 warnings on whether visit_occurrence_id is actually used in the join criteria. |
| src/fastssv/rules/joins/left_join_then_where_on_right_table.py | Refactors OMOP_149 to evaluate LEFT-join/right-table filters per-SELECT scope to avoid cross-CTE leakage. |
| src/fastssv/rules/joins/join_path_validation.py | Suppresses join-path warnings for canonical IN (SELECT ... FROM <vocab_cte>) cohort-builder bridging. |
| src/fastssv/rules/data_quality/comprehensive_schema_validation.py | Makes column resolution scope-aware and skips sqlglot time-unit keywords parsed as Column nodes. |
| src/fastssv/rules/concept_standardization/standard_concept_enforcement.py | Makes suggested-fix messaging CTE-shadow-aware (schema-qualified fix under shadow). |
| src/fastssv/rules/anti_patterns/limit_without_order_by.py | Adds scalar-aggregate detection to suppress LIMIT-without-ORDER-BY warnings for single-row aggregates. |
| src/fastssv/rules/anti_patterns/cte_shadows_omop_table.py | New anti-pattern rule warning on CTE names that shadow OMOP CDM tables. |
| src/fastssv/rules/anti_patterns/init.py | Exposes the new anti-pattern rule via package imports/__all__. |
| src/fastssv/core/helpers.py | Adds collect_cte_names and makes has_table_reference CTE-shadow-aware. |
| src/fastssv/api/ui.py | Adds MCP mount-status fields to the UI template context. |
| src/fastssv/api/templates/index.html | Renders an MCP on/off status pill. |
| src/fastssv/api/static/style.css | Styles the MCP status pill. |
| CHANGELOG.md | Documents the new rule and multiple false-positive reductions/fixes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vvcb
reviewed
May 12, 2026
vvcb
left a comment
Contributor
There was a problem hiding this comment.
Should this apply to sub queries as well as CTEs?
Collaborator
Author
yes, good catch. I have extended it |
vvcb
approved these changes
Jun 5, 2026
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.
joins/,data_quality/,anti_patterns/, andconcept_standardization/, plus one new rule and a small UI MCP improvement (a pill that shows if the MCP is on/off).