Skip to content

test(cpp): address codecov and sonar reports from #672 (macro guard coverage, complexity)#673

Merged
vitali87 merged 3 commits into
mainfrom
fix/pr672-bot-reports
Jul 9, 2026
Merged

test(cpp): address codecov and sonar reports from #672 (macro guard coverage, complexity)#673
vitali87 merged 3 commits into
mainfrom
fix/pr672-bot-reports

Conversation

@vitali87

@vitali87 vitali87 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses the two bot reports left unhandled on #672: the Codecov patch-coverage report (9 uncovered lines in cpp_frontend/frontend.py, 86.36% patch coverage) and the SonarQube new issue (S3776 cognitive complexity).

Codecov: 9 flagged lines -> 7 covered, 2 defended

New/extended tests in test_cpp_frontend_macros.py:

  • Module-caller fallback: a file-scope macro use (int global_limit = MAX_SIZE;) attributes CALLS to the Module, mirroring the module-caller rule.
  • Out-of-repo and ignored-dir use sites: a TU outside the indexed repo and a TU under build/ both use repo macros; the definition node still registers via the header, but neither use site may carry a CALLS edge. A macro DEFINED under build/ (rel resolves, no module qn) must not become a node.
  • Command-line and system macros: -DCMDLINE_LIMIT=7 and <limits.h> macros are used in source; neither is a node and their uses carry no edges.
  • Guard reordering: _process_macro_definition previously checked rel/module AFTER _macro_function_qn had already required them, making that guard unreachable; guards now run in reachability order (no file -> outside repo -> empty body), each exercised by the fixtures.

The 2 remaining lines (_queue_macro_call's location.file is None and referenced is None returns) are defensive guards against libclang returning None cursors; no source-level fixture can construct them, and removing them would trade a silent skip for a crash on unusual TUs.

SonarQube: S3776 on _register_function

The is_macro branch added in #672 pushed cognitive complexity to 16 (limit 15). The nested C++ template-location block is extracted into _record_cpp_template_child_location, dropping the function back under the threshold with behavior unchanged.

Verification

  • Full suite: 4692 passed, 0 failed
  • frontend.py macro paths: every codecov-flagged line except the two defended guards now covered
  • ruff clean; ty diagnostic count identical to main

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors macro definition processing in the C++ frontend to properly handle builtins and command-line macros that lack an associated file. Additionally, it extracts the C++ template child location recording logic in function_ingest.py into a dedicated helper method and introduces new tests covering file-scope macro usage and macro usage outside the repository. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@greptile-apps

greptile-apps Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates C++ macro handling and related tests. The main changes are:

  • Reorders macro-definition guards so no-file and out-of-repo macros are skipped before the shared eligibility check.
  • Extracts C++ template child-location bookkeeping from _register_function into a helper.
  • Adds tests for module-scope macro uses, ignored and out-of-repo translation units, command-line macros, and system macros.
  • Aligns the editable package version in uv.lock with the project metadata.

Confidence Score: 5/5

This PR is safe to merge with minimal risk.

The changes are small and localized. The code changes mainly reorganize existing guard and helper logic. The added tests cover the reported macro cases.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • I attempted to run the test suite with pytest and observed an ImportError caused by a missing loguru module during test setup.
  • I attempted the lint step with Ruff, but it could not run because the required binary or directory was missing, causing an exit code 2.
  • I saved the failing command outputs and their exit codes to artifacts for later review.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
codebase_rag/parsers/cpp_frontend/frontend.py Reorders macro-definition guards so no-file and out-of-repo macros are skipped before the shared empty-body eligibility check.
codebase_rag/parsers/function_ingest.py Extracts C++ template child-location bookkeeping from _register_function into a helper without changing behavior.
codebase_rag/tests/test_cpp_frontend_macros.py Adds macro frontend tests for module-scope uses, ignored and out-of-repo translation units, command-line macros, and system macros.
uv.lock Updates the editable package version to match the project version.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Clang as libclang cursor
participant Collector as C++ frontend collector
participant Resolver as Path/QN resolver
participant Graph as Ingestor graph

Clang->>Collector: MACRO_DEFINITION cursor
Collector->>Collector: skip no-file macros
Collector->>Resolver: resolve rel path and module QN
Resolver-->>Collector: repo/module eligibility
Collector->>Collector: skip empty-body flag macros
Collector->>Graph: add Function node and DEFINES edge

Clang->>Collector: MACRO_INSTANTIATION cursor
Collector->>Collector: queue referenced macro call
Collector->>Collector: resolve enclosing function or module caller
Collector->>Graph: add CALLS edge when caller and callee are indexed
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Clang as libclang cursor
participant Collector as C++ frontend collector
participant Resolver as Path/QN resolver
participant Graph as Ingestor graph

Clang->>Collector: MACRO_DEFINITION cursor
Collector->>Collector: skip no-file macros
Collector->>Resolver: resolve rel path and module QN
Resolver-->>Collector: repo/module eligibility
Collector->>Collector: skip empty-body flag macros
Collector->>Graph: add Function node and DEFINES edge

Clang->>Collector: MACRO_INSTANTIATION cursor
Collector->>Collector: queue referenced macro call
Collector->>Collector: resolve enclosing function or module caller
Collector->>Graph: add CALLS edge when caller and callee are indexed
Loading

Reviews (1): Last reviewed commit: "chore: regenerate uv.lock for 0.0.270" | Re-trigger Greptile

@codecov-commenter

codecov-commenter commented Jul 9, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

@vitali87
vitali87 merged commit 146c27a into main Jul 9, 2026
22 checks passed
@vitali87
vitali87 deleted the fix/pr672-bot-reports branch July 9, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants