Skip to content

Commit 5b1a1f6

Browse files
Merge pull request CodeGraphContext#1132 from CodeGraphContext/fix/e2e-security-followup
fix: preserve multiple IMPORTS edges per file and in bundle export
2 parents d6ba08b + 93e7fe2 commit 5b1a1f6

64 files changed

Lines changed: 11342 additions & 11303 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CGC_E2E_BUG_REPORT.md

Lines changed: 80 additions & 187 deletions
Large diffs are not rendered by default.

src/codegraphcontext/core/cgc_bundle.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,6 @@ def _extract_edges(self, output_file: Path, repo_path: Optional[Path]) -> int:
635635
else:
636636
to_id = str(id(target))
637637

638-
edge_key = (str(from_id), str(rel_type), str(to_id))
639-
if edge_key in seen_edges:
640-
continue
641-
seen_edges.add(edge_key)
642-
643638
# Clean up absolute path prefix inside edge properties
644639
if repo_path:
645640
repo_str = str(repo_path.resolve())
@@ -652,6 +647,17 @@ def _extract_edges(self, output_file: Path, repo_path: Optional[Path]) -> int:
652647
elif val.startswith(repo_prefix):
653648
rel = val[len(repo_prefix):].lstrip('/\\')
654649
rel_props[key] = "./" + rel if rel else "."
650+
651+
props_key = tuple(
652+
sorted(
653+
(k, json.dumps(v, sort_keys=True, default=str))
654+
for k, v in rel_props.items()
655+
)
656+
)
657+
edge_key = (str(from_id), str(rel_type), str(to_id), props_key)
658+
if edge_key in seen_edges:
659+
continue
660+
seen_edges.add(edge_key)
655661

656662
# Create edge representation
657663
edge_dict = {

src/codegraphcontext/tools/graph_builder.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,9 @@ def add_file_to_graph(self, file_data: Dict, repo_name: str, imports_map: dict,
499499
UNWIND $batch AS row
500500
MATCH (f:File {path: $file_path})
501501
MERGE (m:Module {name: row.module_name})
502-
MERGE (f)-[r:IMPORTS]->(m)
502+
MERGE (f)-[r:IMPORTS {line_number: row.line_number}]->(m)
503503
SET r.imported_name = row.imported_name,
504-
r.alias = row.alias,
505-
r.line_number = row.line_number
504+
r.alias = row.alias
506505
""", batch=js_imports, file_path=file_path_str)
507506

508507
if other_imports:
@@ -513,9 +512,8 @@ def add_file_to_graph(self, file_data: Dict, repo_name: str, imports_map: dict,
513512
MERGE (m:Module {name: row.name})
514513
SET m.alias = row.alias,
515514
m.full_import_name = coalesce(row.full_import_name, m.full_import_name)
516-
MERGE (f)-[r:IMPORTS]->(m)
517-
SET r.line_number = row.line_number,
518-
r.alias = row.alias
515+
MERGE (f)-[r:IMPORTS {line_number: row.line_number}]->(m)
516+
SET r.alias = row.alias
519517
""", batch=other_imports, file_path=file_path_str)
520518

521519
# ── Batch: Ruby Class INCLUDES Module ─────────────────────────────

src/codegraphcontext/tools/indexing/persistence/writer.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,9 @@ def add_file_to_graph(
446446
UNWIND $batch AS row
447447
MATCH (f:File {path: $file_path})
448448
MERGE (m:Module {name: row.module_name})
449-
MERGE (f)-[r:IMPORTS]->(m)
449+
MERGE (f)-[r:IMPORTS {line_number: row.line_number}]->(m)
450450
SET r.imported_name = row.imported_name,
451-
r.alias = row.alias,
452-
r.line_number = row.line_number
451+
r.alias = row.alias
453452
""",
454453
batch=js_imports,
455454
file_path=file_path_str,
@@ -463,9 +462,8 @@ def add_file_to_graph(
463462
MERGE (m:Module {name: row.name})
464463
SET m.lang = coalesce(row.lang, m.lang),
465464
m.full_import_name = coalesce(row.full_import_name, m.full_import_name)
466-
MERGE (f)-[r:IMPORTS]->(m)
467-
SET r.line_number = row.line_number,
468-
r.alias = coalesce(row.alias, ""),
465+
MERGE (f)-[r:IMPORTS {line_number: row.line_number}]->(m)
466+
SET r.alias = coalesce(row.alias, ""),
469467
r.imported_name = row.imported_name,
470468
r.full_import_name = row.full_import_name
471469
""",

tests/fixtures/goldens/sample_project/edges_have.jsonl

Lines changed: 560 additions & 558 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"cgc_version": "0.1.0",
3-
"exported_at": "2026-06-07T16:25:53Z",
3+
"exported_at": "2026-06-07T18:00:01Z",
44
"format_version": "1.0.0",
55
"repo": "sample_project",
66
"repo_path": ".",
77
"is_dependency": false,
8-
"commit": "c6d693bc",
9-
"branch": "main",
8+
"commit": "f3f62d33",
9+
"branch": "fix/e2e-security-followup",
1010
"generator": "PYv0.4.16",
1111
"name": "sample_project.cgc",
1212
"graph_metrics": {
1313
"total_nodes": 482,
14-
"total_edges": 619
14+
"total_edges": 621
1515
}
1616
}

0 commit comments

Comments
 (0)