MCPcopy
hub / github.com/tirth8205/code-review-graph / test_cpp_include_resolution

Function test_cpp_include_resolution

tests/test_visualization.py:145–189  ·  view source on GitHub ↗

IMPORTS_FROM edges with bare C++ include paths should resolve to File nodes stored under absolute paths — previously these were dropped, leaving the graph almost entirely disconnected for C/C++ projects.

(tmp_path)

Source from the content-addressed store, hash-verified

143
144
145def test_cpp_include_resolution(tmp_path):
146 """IMPORTS_FROM edges with bare C++ include paths should resolve to File nodes
147 stored under absolute paths — previously these were dropped, leaving the
148 graph almost entirely disconnected for C/C++ projects."""
149 from code_review_graph.visualization import export_graph_data
150
151 db_path = tmp_path / "test.db"
152 store = GraphStore(db_path)
153
154 def _file(name, path, lang="cpp"):
155 return NodeInfo(
156 kind="File", name=name, file_path=path,
157 line_start=1, line_end=10, language=lang,
158 parent_name=None, params=None, return_type=None,
159 modifiers=None, is_test=False, extra={},
160 )
161
162 store.upsert_node(_file("main.cpp", "/abs/src/main.cpp"))
163 store.upsert_node(_file("Renderer.hpp", "/abs/libs/rendering/Renderer.hpp"))
164 store.upsert_node(_file("Utils.hpp", "/abs/libs/utils/Utils.hpp"))
165
166 # Parser emits bare include paths as targets — exactly what Tree-sitter sees
167 store.upsert_edge(EdgeInfo(
168 kind="IMPORTS_FROM",
169 source="/abs/src/main.cpp",
170 target="rendering/Renderer.hpp", # relative, one directory level
171 file_path="/abs/src/main.cpp", line=1, extra={},
172 ))
173 store.upsert_edge(EdgeInfo(
174 kind="IMPORTS_FROM",
175 source="/abs/src/main.cpp",
176 target="Utils.hpp", # bare filename only
177 file_path="/abs/src/main.cpp", line=2, extra={},
178 ))
179 store.commit()
180
181 data = export_graph_data(store)
182 resolved_targets = {e["target"] for e in data["edges"] if e["kind"] == "IMPORTS_FROM"}
183
184 assert "/abs/libs/rendering/Renderer.hpp" in resolved_targets, (
185 "bare relative include 'rendering/Renderer.hpp' was not resolved to its absolute path"
186 )
187 assert "/abs/libs/utils/Utils.hpp" in resolved_targets, (
188 "bare filename include 'Utils.hpp' was not resolved to its absolute path"
189 )
190
191
192def test_generate_html_overwrites(store_with_data, tmp_path):

Callers

nothing calls this directly

Calls 7

upsert_nodeMethod · 0.95
upsert_edgeMethod · 0.95
commitMethod · 0.95
GraphStoreClass · 0.90
EdgeInfoClass · 0.90
export_graph_dataFunction · 0.90
_fileFunction · 0.85

Tested by

no test coverage detected