Skip to content

fix(test): update tests for entity class refactoring#623

Merged
gkorland merged 1 commit intostagingfrom
fix/broken-test-imports
Mar 20, 2026
Merged

fix(test): update tests for entity class refactoring#623
gkorland merged 1 commit intostagingfrom
fix/broken-test-imports

Conversation

@gkorland
Copy link
Contributor

@gkorland gkorland commented Mar 20, 2026

Summary

Fix 3 test collection errors caused by importing deleted entity classes (Struct, Class, Function) and using GitPython instead of pygit2.

Changes

  • test_c_analyzer.py: Replace Struct/Function imports with FalkorDB Node property comparisons
  • test_py_analyzer.py: Replace Class/Function imports with FalkorDB Node property comparisons
  • test_git_history.py: Replace from git import Repo (GitPython) with pygit2.Repository
  • test_graph_ops.py: Use add_entity() and Node properties instead of deleted classes
  • api/graph.py: Fix get_file() to return Node (was calling deleted File(path, name, ext) constructor)

Testing

  • pytest --collect-only now collects all 28 tests (was 3 errors blocking all tests)
  • Unit tests pass, lint passes on changed files
  • Integration tests (analyzer, git history, graph ops) require FalkorDB — verified collection only

Memory / Performance Impact

N/A

Related Issues

Entity classes were removed in commit 19231c7 but tests were not updated.

Summary by CodeRabbit

  • Refactor
    • Streamlined graph data retrieval to return core entity objects directly
    • Updated test infrastructure with enhanced property-based validation patterns
    • Modernized git integration dependencies for improved compatibility

The entity classes (Struct, Class, Function) were removed in commit
19231c7 but the tests were not updated. Also replaced GitPython
with pygit2 in test_git_history.py to match the project dependency.

Changes:
- test_c_analyzer.py: use FalkorDB Node property comparisons
- test_py_analyzer.py: use FalkorDB Node property comparisons
- test_git_history.py: replace GitPython with pygit2 API
- test_graph_ops.py: use add_entity() and Node properties
- api/graph.py: fix get_file() to return Node (consistent with
  other getters; old code called deleted File constructor)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: edae6b03-b240-4db4-9a55-38056261ec53

📥 Commits

Reviewing files that changed from the base of the PR and between 887b82f and d5c8469.

📒 Files selected for processing (5)
  • api/graph.py
  • tests/test_c_analyzer.py
  • tests/test_git_history.py
  • tests/test_graph_ops.py
  • tests/test_py_analyzer.py

📝 Walkthrough

Walkthrough

This PR refactors the graph API to return raw FalkorDB Node objects directly from Graph.get_file() instead of custom File entity objects, and updates all test files to validate graph entity properties through .properties dictionaries rather than object equality. Additionally, git history tests migrate from GitPython to pygit2.

Changes

Cohort / File(s) Summary
API Signature Change
api/graph.py
Modified Graph.get_file() return type from Optional[File] to Optional[Node], removing entity object construction; returns raw FalkorDB nodes. Minor formatting adjustment in zero-result check.
Test Assertion Refactoring
tests/test_c_analyzer.py, tests/test_py_analyzer.py, tests/test_graph_ops.py
Updated test assertions to validate entity properties via .properties dictionaries instead of object equality comparisons; removed imports of custom entity types (File, Class, Function, Struct).
Git History Test Migration
tests/test_git_history.py
Replaced GitPython (git module) with pygit2 for repository access; updated commit traversal logic (c.parentsc.parent_ids), date field access (c.committed_datec.commit_time), and file metadata retrieval to use .properties pattern.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Raw nodes hop freely now, no wrapping in disguise,
Properties we read direct—no need for compromise!
GitPython steps aside, pygit2 takes the throne,
Tests assert the truth within, straight from the graph's own stone. 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating tests to accommodate the entity class refactoring that removed File, Class, Function, and Struct entity classes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/broken-test-imports

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.

@gkorland gkorland requested a review from Copilot March 20, 2026 19:08
@gkorland gkorland merged commit c372a5e into staging Mar 20, 2026
14 checks passed
@gkorland gkorland deleted the fix/broken-test-imports branch March 20, 2026 19:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the test suite and a Graph helper to align with the recent removal/refactor of entity classes, moving tests toward validating FalkorDB Node properties and swapping Git history tests from GitPython to pygit2.

Changes:

  • Update analyzer and graph ops tests to stop importing deleted entity classes and assert against Node.properties.
  • Replace GitPython Repo usage with pygit2.Repository in git history tests.
  • Change Graph.get_file() to return the underlying FalkorDB Node instead of constructing a deleted File entity.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_py_analyzer.py Replaces Class/Function entity comparisons with Node.properties assertions.
tests/test_c_analyzer.py Replaces Struct/Function entity comparisons with Node.properties assertions.
tests/test_git_history.py Migrates repository checkout/commit traversal from GitPython to pygit2.
tests/test_graph_ops.py Uses Graph.add_entity() and Node.properties assertions; updates file creation path handling.
api/graph.py Updates get_file() to return a FalkorDB Node and adjusts its docstring/type.
Comments suppressed due to low confidence (1)

api/graph.py:444

  • The docstring/arg naming here is ambiguous about what path should contain. add_file() stores path=str(file.path) (full file path), but other call sites (e.g. coverage processing) often treat path as the directory. Please clarify in the docstring (and example) whether path is expected to be the full file path or the directory, and align get_file()/add_file() semantics accordingly to avoid hard-to-debug mismatches.
    def get_file(self, path: str, name: str, ext: str) -> Optional[Node]:
        """
        Retrieves a File node from the graph database based on its path, name,
        and extension.

        Args:
            path (str): The file path.
            name (str): The file name.
            ext (str): The file extension.

        Returns:
            Optional[Node]: The File node if found, otherwise None.

        Example:
            file = self.get_file('/path/to/file', 'filename', '.py')
        """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -24,37 +25,50 @@ def test_analyzer(self):
analyzer.analyze_local_folder(path, g)

f = g.get_file('', 'src.py', '.py')
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

Graph.add_file() stores the File node with path=str(file.path) (full file path, including filename), so calling g.get_file('', 'src.py', '.py') will return None on a clean graph. Update this test to pass the same path value that gets persisted (e.g., the full path to src.py, or adjust Graph to store directory paths consistently).

Suggested change
f = g.get_file('', 'src.py', '.py')
src_file_path = os.path.join(path, 'src.py')
f = g.get_file(src_file_path, 'src.py', '.py')

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +39
self.assertEqual(log.properties['name'], 'log')
self.assertEqual(log.properties['path'], 'src.py')
self.assertEqual(log.properties['ret_type'], 'None')
self.assertEqual(log.properties['src_start'], 0)
self.assertEqual(log.properties['src_end'], 1)
self.assertEqual(log.properties['args'], [['msg', 'str']])
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

These assertions assume metadata like ret_type and args are present on Function nodes and that path == 'src.py'. In the current analysis pipeline, entities are created via graph.add_entity(..., props={}) (no ret_type/args), and path is set from str(file.path) (typically an absolute path). This will raise KeyError/fail in a fresh DB. Consider asserting only on guaranteed properties (name, path, src_start, src_end, doc) or updating the analyzer to populate these properties before asserting on them.

Copilot uses AI. Check for mistakes.
Comment on lines 27 to +30
f = g.get_file('', 'src.c', '.c')
self.assertEqual(File('', 'src.c', '.c'), f)
self.assertIsNotNone(f)
self.assertEqual(f.properties['name'], 'src.c')
self.assertEqual(f.properties['ext'], '.c')
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

Graph.add_file() persists file nodes with path=str(file.path) (full file path). Using g.get_file('', 'src.c', '.c') will not match that representation on a clean graph. Update the test to query using the same stored path value (or change the storage/query convention so path is directory-only and name is basename).

Copilot uses AI. Check for mistakes.
Comment on lines 32 to +35
s = g.get_struct_by_name('exp')
expected_s = Struct('src.c', 'exp', '', 9, 13)
expected_s.add_field('i', 'int')
expected_s.add_field('f', 'float')
expected_s.add_field('data', 'char[]')
self.assertEqual(expected_s, s)
self.assertIsNotNone(s)
self.assertEqual(s.properties['name'], 'exp')
self.assertEqual(s.properties['path'], 'src.c')
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

This test expects Struct/C Function nodes to exist after SourceAnalyzer.analyze_local_folder(path_to_c_sources, g), but the current SourceAnalyzer only enumerates *.java, *.py, and *.cs files (so no C files are analyzed and get_struct_by_name('exp') will be None on a clean graph). Either re-enable C support in the analyzer pipeline or skip/adjust this test to use a supported language.

Copilot uses AI. Check for mistakes.
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.

2 participants