33
44import os
55import sys
6+ import shutil
67import logging
8+ import tempfile
9+ from pathlib import Path
10+
11+ import graphrag_sdk
712
813logging .basicConfig (
914 level = logging .INFO ,
1520from api .project import Project
1621
1722REPOS = [
18- "https://github.com/FalkorDB/GraphRAG-SDK" ,
1923 "https://github.com/pallets/flask" ,
2024]
2125
26+
27+ def prepare_graphrag_sdk_source () -> Path :
28+ """Copy installed graphrag-sdk out of site-packages so LSP resolves calls as a project, not a library."""
29+ src = Path (graphrag_sdk .__file__ ).parent
30+ dst = Path (tempfile .mkdtemp (prefix = "cgraph-e2e-sdk-" )) / "graphrag_sdk"
31+ shutil .copytree (src , dst )
32+ return dst
33+
2234# CALLS edges required by E2E path tests (caller → callee)
2335REQUIRED_CALLS_EDGES = [
2436 ("merge_with" , "combine" ),
@@ -44,30 +56,62 @@ def ensure_calls_edges(graph_name: str) -> None:
4456 logger .info ("[%s] Analyzer created %d CALLS edges" , graph_name , cnt )
4557
4658 for caller , callee in REQUIRED_CALLS_EDGES :
47- res = g .query (
48- "MATCH (src:Function {name: $src}), (dest:Function {name: $dest}) "
49- "MERGE (src)-[e:CALLS]->(dest) "
50- "RETURN e" ,
59+ # MERGE both Function nodes so a missing one (e.g. import_data, which
60+ # has no `def` in graphrag-sdk 0.8.2) is synthesized with the minimal
61+ # properties the UI needs (Searchable label for autocomplete).
62+ g .query (
63+ "MERGE (src:Function:Searchable {name: $src}) "
64+ "ON CREATE SET src.path = 'synthesized.py', src.src_start = 1, src.src_end = 1, src.doc = '' "
65+ "MERGE (dest:Function:Searchable {name: $dest}) "
66+ "ON CREATE SET dest.path = 'synthesized.py', dest.src_start = 1, dest.src_end = 1, dest.doc = '' "
67+ "MERGE (src)-[:CALLS]->(dest)" ,
5168 {"src" : caller , "dest" : callee },
5269 )
53- created = len (res .result_set ) > 0
54- logger .info (
55- "[%s] CALLS %s → %s: %s" ,
56- graph_name ,
57- caller ,
58- callee ,
59- "ensured" if created else "FAILED (node not found)" ,
70+ logger .info ("[%s] CALLS %s → %s: ensured" , graph_name , caller , callee )
71+
72+
73+ def ensure_search_term_variety (graph_name : str ) -> None :
74+ """Synthesize Function nodes whose names contain the e2e search terms that
75+ don't appear in graphrag-sdk 0.8.2 (e.g. 'test'). Without these, the
76+ auto-scroll and auto-complete tests don't have enough matches.
77+ """
78+ db = FalkorDB (
79+ host = os .getenv ("FALKORDB_HOST" , "localhost" ),
80+ port = int (os .getenv ("FALKORDB_PORT" , 6379 )),
81+ )
82+ g = db .select_graph (graph_name )
83+ for module in (
84+ "ontology" , "graph" , "entity" , "relation" , "document" , "chunk" ,
85+ "query" , "session" , "agent" , "chat" , "attribute" , "helpers" ,
86+ ):
87+ g .query (
88+ "MERGE (f:Function:Searchable {name: $name}) "
89+ "ON CREATE SET f.path = 'synthesized.py', f.src_start = 1, f.src_end = 1, f.doc = ''" ,
90+ {"name" : f"test_{ module } " },
6091 )
6192
6293
6394def main ():
95+ sdk_path = prepare_graphrag_sdk_source ()
96+ logger .info (
97+ "Seeding graphrag-sdk %s from %s" ,
98+ getattr (graphrag_sdk , "__version__" , "?" ),
99+ sdk_path ,
100+ )
101+ Project (
102+ name = "GraphRAG-SDK" ,
103+ path = sdk_path ,
104+ url = "https://github.com/FalkorDB/GraphRAG-SDK" ,
105+ ).analyze_sources ()
106+
64107 for url in REPOS :
65108 logger .info ("Seeding %s ..." , url )
66109 proj = Project .from_git_repository (url )
67110 proj .analyze_sources ()
68111 logger .info ("Done seeding %s" , url )
69112
70113 ensure_calls_edges ("GraphRAG-SDK" )
114+ ensure_search_term_variety ("GraphRAG-SDK" )
71115
72116 logger .info ("All test data seeded successfully." )
73117
0 commit comments