Skip to content

Fix Issue 104: Tests are failing upon migration to codeanalyzer v2.1.0+ #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 21, 2025

Conversation

rahlk
Copy link
Collaborator

@rahlk rahlk commented Feb 21, 2025

Motivation and Context

The failing test cases were caused by incorrect handling of analysis.json (which had changed since version 2.0.0 of codeanalyzer). Further, there were some nagging bugs on cyclic NotImplementedError, issues with super classes in TreeSitter etc.

How Has This Been Tested?

The changes were tested by:

  • Running the updated test suite locally (Fedora 41 with Java 11+).
  • Validating that all previously failing test cases now pass.
❯ poetry run pytest --pspec --cov=cldk --disable-warnings
=================================================================================================================================================================== test session starts ====================================================================================================================================================================
platform linux -- Python 3.11.9, pytest-8.3.4, pluggy-1.5.0
rootdir: /home/rkrsn/workspace/codellm-devkit/python-sdk
configfile: pyproject.toml
testpaths: tests
plugins: anyio-4.8.0, cov-6.0.0, pspec-0.0.4
collected 120 items

tests/analysis/java/test_java_analysis.py                                                                                                                                                                                                                                                                                                                   
java analysis
 ✓ return a symbol table that is not null
 ✓ return NotImplemented for get imports()
 ✓ return NotImplemented for get variables()
 ✓ return NotImplemented for get service entry point classes()
 ✓ return NotImplemented for get service entry point methods()
 ✓ return the application view
 ✓ return the symbol table
 ✓ return the compilation units
 ✓ return the class hierarchy
 ✓ be parsable
 ✓ return the raw AST
 ✓ return the Call Graph
 ✓ return the Call Graph as JSON
 ✓ return the callers
 ✓ return the callees
 ✓ return the methods
 ✓ return the classes
 ✓ return the classes by criteria
 ✓ return a single class
 ✓ return a single method
 ✓ return the java file and compilation unit
 ✓ return the methods in a class
 ✓ return the fields for a class
 ✓ return the nested classes for a class
 ✓ return the subclasses for a class
 ✓ return the extended classes for a class
 ✓ return the implemented interfaces classes for a class
 ✓ return the class call graph
 ✓ return the entry point classes
 ✓ return the entry point methods
 ✓ remove all comments
 ✓ return methods with annotations
 ✓ return test methods
 ✓ return calling lines
 ✓ return calling targets
                                                                                                                                                                                                                                                                                                                                                     [  0%]
tests/analysis/java/test_java_sitter.py                                                                                                                                                                                                                                                                                                                     
java sitter
 ✓ not find the method in the class
 ✓ be able to parse the file
 ✓ return the raw AST
 ✓ return all of the imports
 ✓ return the package name
 ✓ return the class name
 ✓ return the superclass name
 ✓ return all interfaces
 ✓ return the method name from a declarations
 ✓ return the method name from an invocation
 ✓ return the method name from an arbitrary statement
 ✓ safely ascend the node tree
 ✓ get the call targets
 ✓ get the calling lines
 ✓ return the test methods
 ✓ return methods with annotations
 ✓ return all of the type invocations
 ✓ get the methods return type
 ✓ return the lexical tokens
 ✓ remove all comments
 ✓ make pruned code prettier
                                                                                                                                                                                                                                                                                                                                                     [  0%]
tests/analysis/java/test_jcodeanalyzer.py                                                                                                                                                                                                                                                                                                                   
jcodeanalyzer
 ✓ return the initialized JApplication
 ✓ initialize the codeanalyzer without a json path
 ✓ initialize the codeanalyzer with a json path
 ✓ return the correct codeanalyzer location
 ✓ generate a graph
 ✓ process a single file
 ✓ return the application
 ✓ return the symbol table
 ✓ return an application view
 ✓ return an system dependency graph
 ✓ return a call graph
 ✓ return the call graph as json
 ✓ return all of the callers
 ✓ return all of the callees
 ✓ return all of the classes in an application
 ✓ return a class given the qualified name
 ✓ return the method
 ✓ return the java file for a class
 ✓ return all of the methods for a class
 ✓ return all of the constructors for a class
 ✓ return all of the subclasses for a class
 ✓ return all of the fields for a class
 ✓ return all the nested classes for a class
 ✓ return all of the extended classes for a class
 ✓ return all of the implemented interfaces for a class
 ✓ return the call graph using the symbol table
 ✓ return the call graph
 ✓ return all of the methods in an application
 ✓ return all of the entrypoint methods in an application
 ✓ return all of the entrypoint classes in an application
 ✓ return all of the CRUD operations in an application
 ✓ return all of the CRUD read operations in an application
 ✓ return all of the CRUD create operations in an application
 ✓ return all of the CRUD update operations in an application
 ✓ return all of the CRUD delete operations in an application
 ✓ return all of the CRUD operations in an application
                                                                                                                                                                                                                                                                                                                                                     [  0%]
tests/analysis/python/test_python_analysis.py                                                                                                                                                                                                                                                                                                               
python analysis
 ✓ return raise a not implemented exception
 ✓ return all of the methods
 ✓ return all of the functions
 ✓ return all of the modules
 ✓ return the method details
 ✓ be able to parse the code
 ✓ return the raw AST
 ✓ return all of the imports
 ✓ return all of the variables
 ✓ return all of the classes
 ✓ return all of the classes that match the criteria
 ✓ return all of the subclasses
 ✓ return all of the nested classes
 ✓ return all of the constructors
 ✓ return all of the methods in the class
 ✓ return all of the fields in the class
                                                                                                                                                                                                                                                                                                                                                     [  0%]
tests/analysis/python/test_python_sitter.py                                                                                                                                                                                                                                                                                                                 
python sitter
 ✓ be able to parse the code
 ✓ return the raw AST
 ✓ return all of the methods
 ✓ return all of the functions
 ✓ return the method details
 ✓ return all of the imports
 ✓ return the module details
 ✓ return all of the import details
 ✓ return all of the classes
 ✓ return all of the modules
                                                                                                                                                                                                                                                                                                                                                     [  0%]
tests/models/java/test_java_models.py                                                                                                                                                                                                                                                                                                                       
java models
 ✓ get class call graph
                                                                                                                                                                                                                                                                                                                                                     [  0%]
tests/test_core.py                                                                                                                                                                                                                                                                                                                                          
core
 ✓ codeanalyzer jar in wheel


---------- coverage: platform linux, python 3.11.9-final-0 -----------
Name                                                   Stmts   Miss  Cover   Missing
------------------------------------------------------------------------------------
cldk/__init__.py                                           2      0   100%
cldk/analysis/__init__.py                                  6      0   100%
cldk/analysis/analysis_level.py                            6      0   100%
cldk/analysis/c/__init__.py                                1      0   100%
cldk/analysis/c/c_analysis.py                            103     66    36%   34-36, 47-56, 64, 67, 70, 73, 76, 79, 90, 98, 110, 125, 139, 150-151, 163, 177, 191, 205, 216, 230, 239-242, 254-256, 265-268, 280-282, 291-294, 306-308, 317-320, 332-334, 343-346, 358-360, 372-374
cldk/analysis/c/clang/__init__.py                          2      0   100%
cldk/analysis/c/clang/clang_analyzer.py                  138    100    28%   27-32, 46, 55, 67-69, 77-82, 88-105, 110-121, 141-159, 169-177, 181, 201-231, 237-260, 279-286, 299-306
cldk/analysis/call_graph.py                               22      1    95%   26
cldk/analysis/common/__init__.py                           0      0   100%
cldk/analysis/common/lsp/__init__.py                       0      0   100%
cldk/analysis/common/lsp/lsp.py                            0      0   100%
cldk/analysis/java/__init__.py                             2      0   100%
cldk/analysis/java/codeanalyzer/__init__.py                3      0   100%
cldk/analysis/java/codeanalyzer/bin/__init__.py            0      0   100%
cldk/analysis/java/codeanalyzer/codeanalyzer.py          398     19    95%   145, 198-199, 230-233, 251, 253-254, 350, 394, 429, 525, 539, 554, 617-618, 632-633
cldk/analysis/java/codeanalyzer/jar/__init__.py            0      0   100%
cldk/analysis/java/codeql/__init__.py                      2      0   100%
cldk/analysis/java/codeql/backend.py                      50     37    26%   70-71, 88-107, 123-147, 161-168
cldk/analysis/java/codeql/codeql.py                       55     33    40%   73, 98-122, 133-156, 175, 185-254
cldk/analysis/java/java_analysis.py                      176     16    91%   82, 95, 183, 226, 391, 422-424, 455, 514, 604, 637, 645, 653, 661, 669
cldk/analysis/java/treesitter/__init__.py                  2      0   100%
cldk/analysis/java/treesitter/java_sitter.py             164     16    90%   76-77, 84, 122, 250-264, 298-300, 332-334, 434-435
cldk/analysis/program_dependence_graph.py                  4      1    75%   26
cldk/analysis/python/__init__.py                           2      0   100%
cldk/analysis/python/python_analysis.py                   50      0   100%
cldk/analysis/python/treesitter/__init__.py                2      0   100%
cldk/analysis/python/treesitter/python_sitter.py         215     34    84%   59-61, 133, 199, 238, 283, 297-312, 336, 343-347, 355, 359, 370, 393-394
cldk/analysis/symbol_table.py                             28      1    96%   26
cldk/analysis/system_dependence_graph.py                   4      1    75%   26
cldk/core.py                                              31     11    65%   115, 118, 132-135, 147-150, 168-171
cldk/models/__init__.py                                    0      0   100%
cldk/models/c/__init__.py                                  1      0   100%
cldk/models/c/models.py                                  122      1    99%   283
cldk/models/java/__init__.py                               3      0   100%
cldk/models/java/enums.py                                 10      0   100%
cldk/models/java/models.py                               148      4    97%   223, 304, 307, 372
cldk/models/python/__init__.py                             0      0   100%
cldk/models/python/models.py                              44      0   100%
cldk/models/treesitter/__init__.py                         2      0   100%
cldk/models/treesitter/models.py                          21      1    95%   87
cldk/utils/__init__.py                                     0      0   100%
cldk/utils/analysis_engine.py                              4      0   100%
cldk/utils/exceptions/__init__.py                          2      0   100%
cldk/utils/exceptions/exceptions.py                       20     10    50%   26-27, 34-35, 42-43, 50-51, 60-61
cldk/utils/logging.py                                      0      0   100%
cldk/utils/sanitization/__init__.py                        0      0   100%
cldk/utils/sanitization/java/__init__.py                   2      0   100%
cldk/utils/sanitization/java/treesitter_sanitizer.py     109     95    13%   34-36, 53-58, 88-121, 139-176, 202-246, 280-306, 326-343
cldk/utils/sanitization/java/treesitter_utils.py         147    147     0%   21-375
cldk/utils/treesitter/__init__.py                          0      0   100%
cldk/utils/treesitter/tree_sitter_utils.py                15      7    53%   61-68
------------------------------------------------------------------------------------
TOTAL                                                   2118    601    72%

Required test coverage of 50% reached. Total coverage: 71.62%

============================================================================================================================================================= 120 passed in 181.71s (0:03:01) ==============================================================================================================================================================

Breaking Changes

No breaking changes. The fixes ensure correctness without modifying existing API contracts or requiring configuration changes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the Codellm-Devkit Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Fixed some bugs where treesitter fails to identify a superclass if public class A extends B<C> { ... }

rahlk and others added 7 commits February 19, 2025 19:37
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
…a superclass if

Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk rahlk added the bug Something isn't working label Feb 21, 2025
@rahlk rahlk requested a review from rofrano February 21, 2025 03:24
@rahlk rahlk self-assigned this Feb 21, 2025
@rahlk rahlk linked an issue Feb 21, 2025 that may be closed by this pull request
@rahlk rahlk changed the title Fix Issue 104: Tests are failing upon migration to codeanalyzer v2.1 Fix Issue 104: Tests are failing upon migration to codeanalyzer v2.1.0+ Feb 21, 2025
Copy link
Collaborator Author

@rahlk rahlk left a comment

Choose a reason for hiding this comment

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

Note: There were a number of folders and files related to mkdocs that were removed as part of this PR (therefore the 146 files changed)

Signed-off-by: John Rofrano <johnnyroy@johnrofrano.com>
Copy link
Collaborator

@rofrano rofrano left a comment

Choose a reason for hiding this comment

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

Looks good. I increased the code coverage minimum in our Makefile to 70% since we ave now surpassed that. Great work!

@rofrano rofrano merged commit 4ff354f into main Feb 21, 2025
@rofrano rofrano deleted the 104-tests-are-failing-upon-migration-to-codeanalyzer-21 branch February 21, 2025 15:36
@rahlk rahlk added fix Bug fixes and removed bug Something isn't working labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests are failing upon migration to codeanalyzer 2.1+
2 participants