Skip to content

#829: Fix metric AST contract test#1244

Merged
yegor256 merged 1 commit into
cqfn:masterfrom
Beeeeeeee-c:fix-issue-829-metric-ast-contract
Jul 14, 2026
Merged

#829: Fix metric AST contract test#1244
yegor256 merged 1 commit into
cqfn:masterfrom
Beeeeeeee-c:fix-issue-829-metric-ast-contract

Conversation

@Beeeeeeee-c

@Beeeeeeee-c Beeeeeeee-c commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Tests
    • Updated metric configuration coverage to validate AST support only for metrics that are compatible.
    • Removed an outdated expected-failure status, so the test now runs as a normal check.
    • Cleaned up redundant test imports.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The test test_each_metric_in_config_accepts_ast is no longer marked xfail; it now filters out metrics whose codes are listed in metrics_exclude before asserting on ast parameter presence and type hints, with the unused pytest import removed.

Changes

Test config update

Layer / File(s) Summary
Un-xfail and filter AST test
test/config/test_config.py
Removes xfail marker and pytest import; test now excludes metrics listed in metrics_exclude before validating ast parameter presence and type hints.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related PRs

  • cqfn/aibolit#814: Adds the original xfail interface contract test for metrics' ast parameter that this PR un-xfails and modifies.

Suggested reviewers: ivanovmg

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: fixing the metric AST contract test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
test/config/test_config.py (2)

21-27: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Filtering by metrics_exclude weakens contract enforcement without guardrails.

Any metric code added to patterns_config['metrics_exclude'] (aibolit/config.py) now silently escapes this AST-contract check, with no assertion that the exclusion list itself stays bounded or that excluded metrics are tracked/justified. A future contributor could bypass this test entirely for a non-compliant metric by adding its code to metrics_exclude, without any reviewer being alerted by the test itself.

Consider asserting that the exclusion list doesn't grow unexpectedly (e.g., pin the exact expected excluded set, or require each excluded code to reference a tracking issue) so regressions in coverage are caught.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/config/test_config.py` around lines 21 - 27, The AST contract test now
skips any metric listed in metrics_exclude, which weakens coverage without any
safeguard. Tighten test_config.py by asserting the exact expected excluded set
(or otherwise validating each excluded code is explicitly justified/tracked)
before building ast_compatible_metrics, so metric exclusions in patterns_config
cannot silently bypass the check.

10-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Update stale docstring.

The docstring still says "Once all metrics meet requirements, remove the decorator," but the @pytest.mark.xfail decorator has already been removed in this change. The TODO reference and instructions no longer match the current test behavior (filtering by metrics_exclude rather than requiring all metrics to comply).

📝 Suggested docstring update
     '''
-    TODO `#813`:30min/DEV Ensure All Metrics Accept `ast: AST` Parameter with Type Hints
-    Verify that all metrics in the config accept an AST parameter with proper type hints.
-    Probable solutions:
-    1. Every metric factory in patterns_config["metrics"] produces a metric with:
-       - A parameter named "ast" in its call signature
-       - The "ast" parameter properly annotated as `aibolit.ast_framework.ast.AST` or a subclass
-    2. Remove any metrics that cannot comply with this interface.
-    Once all metrics meet requirements, remove the decorator.
+    Verify that metrics not listed in `metrics_exclude` accept an AST
+    parameter with proper type hints (named "ast", annotated as
+    `aibolit.ast_framework.ast.AST`).
     '''
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/config/test_config.py` around lines 10 - 19, Update the stale docstring
in the test helper around the metrics validation logic so it matches the current
behavior. Remove the outdated xfail/decorator language and rewrite the TODO to
describe the actual check performed by the test, which now filters metrics via
metrics_exclude and verifies the remaining metric factories’ ast parameter
signature and type hints. Keep the references to the
metrics_config/patterns_config validation flow and the test function context
clear so the docstring aligns with the current implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/config/test_config.py`:
- Around line 21-27: The AST contract test now skips any metric listed in
metrics_exclude, which weakens coverage without any safeguard. Tighten
test_config.py by asserting the exact expected excluded set (or otherwise
validating each excluded code is explicitly justified/tracked) before building
ast_compatible_metrics, so metric exclusions in patterns_config cannot silently
bypass the check.
- Around line 10-19: Update the stale docstring in the test helper around the
metrics validation logic so it matches the current behavior. Remove the outdated
xfail/decorator language and rewrite the TODO to describe the actual check
performed by the test, which now filters metrics via metrics_exclude and
verifies the remaining metric factories’ ast parameter signature and type hints.
Keep the references to the metrics_config/patterns_config validation flow and
the test function context clear so the docstring aligns with the current
implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 639aa193-2dab-4e5c-89cb-071f7640f6a7

📥 Commits

Reviewing files that changed from the base of the PR and between 0b0555f and 81234aa.

📒 Files selected for processing (1)
  • test/config/test_config.py

@yegor256 yegor256 merged commit fc75460 into cqfn:master Jul 14, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants