Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@kodsurfer
Copy link
Contributor

@kodsurfer kodsurfer commented Sep 28, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved stability when processing analysis results by skipping unexpected items in pattern lists to prevent errors.
  • Tests

    • Added unit tests to confirm XML report generation for both nested and flat result structures, ensuring pattern codes appear as expected.
  • Chores

    • Added a test package initializer to organize XML-related tests.

@coderabbitai
Copy link

coderabbitai bot commented Sep 28, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Added a guard in aibolit/main.py to skip non-dict pattern items when processing results. Introduced test/xml/init.py. Added two unit tests verifying XML report generation for nested and flat result structures via create_xml_tree.

Changes

Cohort / File(s) Summary
Result processing guard
aibolit/__main__.py
Added an isinstance check and safe access (pattern.get('pattern_code')) in _process_file_result to skip non-dict items; minor whitespace change.
XML reporting tests
test/xml/test_xml.py
Added two tests validating XML report generation for nested and flat results, asserting pattern codes P1 and P2 are present.
Test package init
test/xml/__init__.py
New package initializer containing SPDX header comments; no executable logic.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CLI as CLI Runner
  participant Main as __main__._process_file_result
  participant Patterns as patterns iterable

  CLI->>Main: process file result
  loop iterate patterns
    alt item is dict
      Main->>Main: read pattern.get("pattern_code")
      Main->>CLI: record pattern_code
    else not a dict
      Note over Main: guard skips item
    end
  end
  CLI-->>CLI: continue aggregation
Loading
sequenceDiagram
  autonumber
  participant Test as unit test
  participant XML as create_xml_tree
  participant Output as XML string

  Test->>XML: create_xml_tree(results, exit_code=0, cmd)
  XML-->>Output: return XML containing patterns (e.g., "P1","P2")
  Test->>Test: assert "P1" and "P2" in XML
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my ears at XML’s gleam,
Two carrots—P1, P2—steam.
I hop past traps where dicts aren’t found,
A gentle guard keeps crashes down.
Tests sing soft—reports are sound. 🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “Fix command recommend fail” refers to an issue with command recommendation but the changes actually introduce a type guard in _process_file_result and add new XML report generation tests, so it does not accurately summarize the primary modifications. Please update the title to reflect the actual changes, for example: “Add dict guard in _process_file_result and add XML report generation tests.”
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/xml/test_xml.py (1)

1-33: Tests cannot run in current form

These new tests never execute successfully:

  • The functions are module-level but still take self, so pytest treats self as a fixture and errors out (see pipeline failure).
  • create_xml_tree is never imported, producing F821.
  • The call omits the required full_report argument, so even with an import you’d get a TypeError.
  • create_xml_tree returns an lxml Element, so self.assertIn('P1', result) will fail—you need to serialize (e.g., etree.tostring(..., encoding='unicode')) or navigate the tree.
    Please restructure the tests (e.g., move them back inside the appropriate test class or make them pure functions), import create_xml_tree, pass full_report, and assert on the rendered XML before we can merge.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d13b58 and 357d05f.

📒 Files selected for processing (3)
  • aibolit/__main__.py (1 hunks)
  • test/xml/__init__.py (1 hunks)
  • test/xml/test_xml.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/xml/test_xml.py (1)
aibolit/__main__.py (1)
  • create_xml_tree (573-601)
🪛 GitHub Actions: ty
test/xml/test_xml.py

[error] 14-14: unresolved-reference: Name create_xml_tree used when not defined.


[error] 30-30: unresolved-reference: Name create_xml_tree used when not defined.

🪛 GitHub Actions: ruff
test/xml/test_xml.py

[error] 14-14: Undefined name 'create_xml_tree'.


[error] 30-30: Undefined name 'create_xml_tree'.

aibolit/__main__.py

[warning] 449-449: Unexpected # ruff: noqa directive at aibolit/main.py:449. File-level suppression comments must appear on their own line. For line-level suppression, omit the ruff: prefix.

🪛 GitHub Actions: pylint
test/xml/test_xml.py

[warning] 12-12: Trailing whitespace detected.


[warning] 13-13: Access to a protected member '__create_mock_cmd' of a client class (protected-access).


[error] 14-14: Undefined variable 'create_xml_tree'.


[warning] 29-29: Access to a protected member '__create_mock_cmd' of a client class (protected-access).


[error] 30-30: Undefined variable 'create_xml_tree'.

test/xml/__init__.py

[error] 1-1: Trailing whitespace detected.

aibolit/__main__.py

[error] 537-537: Trailing whitespace detected.

🪛 GitHub Actions: flake8
test/xml/test_xml.py

[error] 12-12: W293 blank line contains whitespace


[error] 14-14: F821 undefined name 'create_xml_tree'


[error] 18-18: E302 expected 2 blank lines, found 1


[error] 22-22: W291 trailing whitespace


[error] 30-30: F821 undefined name 'create_xml_tree'

test/xml/__init__.py

[error] 1-1: W291 trailing whitespace

aibolit/__main__.py

[error] 537-537: W293 blank line contains whitespace

🪛 GitHub Actions: make
test/xml/test_xml.py

[error] 1-1: pytest error: fixture 'self' not found in test_xml_report_with_nested_results.


[error] 1-1: pytest error: fixture 'self' not found in test_xml_report_with_flat_results.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: latexmk

patterns_number = len(results)
importance_for_class = []

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Clean up whitespace-only line

Line 537 is a blank line filled with spaces, producing W293/W trailing-whitespace failures. Please make it an actual empty line (no spaces) or remove it.

Apply this diff:

-        
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(empty line hereensure no spaces or tabs)
🧰 Tools
🪛 GitHub Actions: pylint

[error] 537-537: Trailing whitespace detected.

🪛 GitHub Actions: flake8

[error] 537-537: W293 blank line contains whitespace

🤖 Prompt for AI Agents
In aibolit/__main__.py around line 537, the line contains trailing spaces
causing W293/W trailing-whitespace failures; fix by removing all whitespace
characters on that line so it is an actual empty line (or delete the line
entirely) and ensure the file contains no trailing spaces on that line before
committing.

@@ -0,0 +1 @@
#
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove trailing whitespace to satisfy linters

This file currently consists of a lone comment with a trailing space, which is tripping pylint/flake8 (W291). Please drop the trailing whitespace so the linters succeed.

Apply this diff:

-# 
+#
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#
#
🧰 Tools
🪛 GitHub Actions: pylint

[error] 1-1: Trailing whitespace detected.

🪛 GitHub Actions: flake8

[error] 1-1: W291 trailing whitespace

🤖 Prompt for AI Agents
In test/xml/__init__.py around line 1, the file contains a lone comment with
trailing whitespace causing linter W291; remove the trailing space at the end of
the comment line so there is no whitespace after the '#' character and save the
file.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 357d05f and 8eacbd3.

📒 Files selected for processing (2)
  • test/xml/__init__.py (1 hunks)
  • test/xml/test_xml.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/xml/init.py
🧰 Additional context used
🧬 Code graph analysis (1)
test/xml/test_xml.py (1)
aibolit/__main__.py (1)
  • create_xml_tree (573-601)
🪛 GitHub Actions: pylint
test/xml/test_xml.py

[warning] 15-15: C0303: Trailing whitespace (trailing-whitespace)


[warning] 16-16: W0212: Access to a protected member __create_mock_cmd of a client class (protected-access)


[error] 17-17: E0602: Undefined variable 'create_xml_tree' (undefined-variable)


[warning] 32-32: W0212: Access to a protected member __create_mock_cmd of a client class (protected-access)


[error] 33-33: E0602: Undefined variable 'create_xml_tree' (undefined-variable)

🪛 GitHub Actions: ty
test/xml/test_xml.py

[error] 17-17: uvx ty==0.0.1-alpha.8 check: unresolved-reference - Name 'create_xml_tree' used when not defined at test_xml.py:17.127


[error] 33-33: uvx ty==0.0.1-alpha.8 check: unresolved-reference - Name 'create_xml_tree' used when not defined at test_xml.py:33.127

🪛 GitHub Actions: ruff
test/xml/test_xml.py

[error] 17-17: F821 Undefined name create_xml_tree.


[error] 33-33: F821 Undefined name create_xml_tree.

🪛 GitHub Actions: make
test/xml/test_xml.py

[error] 4-4: fixture 'self' not found. This test defines a method with a 'self' parameter which pytest does not provide as a fixture.


[error] 21-21: fixture 'self' not found. This test defines a method with a 'self' parameter which pytest does not provide as a fixture.

🪛 GitHub Actions: flake8
test/xml/test_xml.py

[warning] 15-15: W293 blank line contains whitespace


[error] 17-17: F821 undefined name 'create_xml_tree'


[error] 21-21: E302 expected 2 blank lines, found 1


[warning] 25-25: W291 trailing whitespace


[error] 33-33: F821 undefined name 'create_xml_tree'

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: latexmk

Comment on lines +4 to +19
def test_xml_report_with_nested_results(self):
"""Test that XML report handles nested results structure correctly"""
mock_input_with_nested = [
{
'filename': 'test.java',
'results': [
[{'pattern_code': 'P1', 'importance': 5}],
[{'pattern_code': 'P2', 'importance': 3}]
]
}
]

mock_cmd = self.__create_mock_cmd()
result = create_xml_tree(mock_input_with_nested, cmd=mock_cmd, exit_code=0)
self.assertIn('P1', result)
self.assertIn('P2', result)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix unresolved names and invalid test signature before these can run

Right now the first test fails immediately: self isn’t provided for a module-level pytest test, self.__create_mock_cmd() is undefined in this scope, create_xml_tree isn’t imported, and the call omits the required full_report argument. Please either move this logic into the existing test class that defines __create_mock_cmd or turn it into a plain function without self, add the missing import (e.g., from aibolit.__main__ import create_xml_tree), and call create_xml_tree(..., full_report=<expected value>, cmd=mock_cmd, exit_code=0). Without those fixes the pipeline errors (F821, fixture “self” not found, etc.) will keep the suite red.

🧰 Tools
🪛 GitHub Actions: pylint

[warning] 15-15: C0303: Trailing whitespace (trailing-whitespace)


[warning] 16-16: W0212: Access to a protected member __create_mock_cmd of a client class (protected-access)


[error] 17-17: E0602: Undefined variable 'create_xml_tree' (undefined-variable)

🪛 GitHub Actions: ty

[error] 17-17: uvx ty==0.0.1-alpha.8 check: unresolved-reference - Name 'create_xml_tree' used when not defined at test_xml.py:17.127

🪛 GitHub Actions: ruff

[error] 17-17: F821 Undefined name create_xml_tree.

🪛 GitHub Actions: make

[error] 4-4: fixture 'self' not found. This test defines a method with a 'self' parameter which pytest does not provide as a fixture.

🪛 GitHub Actions: flake8

[warning] 15-15: W293 blank line contains whitespace


[error] 17-17: F821 undefined name 'create_xml_tree'

🤖 Prompt for AI Agents
In test/xml/test_xml.py around lines 4 to 19, the test is written as a method
using self but lives at module level and references undefined helpers and
symbols; fix by either moving this function into the existing test class that
defines __create_mock_cmd (so self and __create_mock_cmd() are valid) or convert
it to a plain pytest function: remove self, call a module-level helper to create
mock_cmd, import create_xml_tree (e.g., from aibolit.__main__ import
create_xml_tree) at top of the file, and call create_xml_tree with the required
full_report argument (e.g., create_xml_tree(mock_input_with_nested,
full_report=<expected value>, cmd=mock_cmd, exit_code=0)); ensure all names used
are defined/imported so the test no longer raises F821 or fixture “self” not
found.

Comment on lines +17 to +19
result = create_xml_tree(mock_input_with_nested, cmd=mock_cmd, exit_code=0)
self.assertIn('P1', result)
self.assertIn('P2', result)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Convert the XML element to text before asserting on pattern codes

create_xml_tree returns an lxml.etree.Element, so self.assertIn('P1', result) will never match—Python will iterate over child nodes, not the serialized XML, and 'P1' isn’t an element. After fixing the issues above, serialize the tree (e.g., xml = etree.tostring(result, encoding='unicode')) and assert on that string for both tests.

Also applies to: 33-35

🧰 Tools
🪛 GitHub Actions: pylint

[error] 17-17: E0602: Undefined variable 'create_xml_tree' (undefined-variable)

🪛 GitHub Actions: ty

[error] 17-17: uvx ty==0.0.1-alpha.8 check: unresolved-reference - Name 'create_xml_tree' used when not defined at test_xml.py:17.127

🪛 GitHub Actions: ruff

[error] 17-17: F821 Undefined name create_xml_tree.

🪛 GitHub Actions: flake8

[error] 17-17: F821 undefined name 'create_xml_tree'

🤖 Prompt for AI Agents
In test/xml/test_xml.py around lines 17 to 19 (and similarly lines 33 to 35),
the tests call create_xml_tree which returns an lxml.etree.Element and then
assertIn on raw Element objects; instead serialize the Element to a string
(e.g., xml = etree.tostring(result, encoding='unicode')) and then use
self.assertIn('P1', xml) and self.assertIn('P2', xml) (and the corresponding
assertions at 33-35) so the substring checks operate on the serialized XML text.

@kodsurfer kodsurfer marked this pull request as draft September 29, 2025 20:44
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.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.