1+ name : Graph Engine Integration Tests
2+
3+ on :
4+ push :
5+ branches : [ main, master, feat/round7-phase2-graph-storage ]
6+ pull_request :
7+ branches : [ main, master ]
8+
9+ jobs :
10+ test-graph-engine :
11+ runs-on : ubuntu-latest
12+
13+ services :
14+ redis :
15+ image : redis:7-alpine
16+ ports :
17+ - 6379:6379
18+ options : >-
19+ --health-cmd "redis-cli ping"
20+ --health-interval 10s
21+ --health-timeout 5s
22+ --health-retries 5
23+
24+ postgres :
25+ image : postgres:15-alpine
26+ env :
27+ POSTGRES_DB : codesage_test
28+ POSTGRES_USER : codesage_test
29+ POSTGRES_PASSWORD : codesage_test
30+ ports :
31+ - 5432:5432
32+ options : >-
33+ --health-cmd "pg_isready -U codesage_test -d codesage_test"
34+ --health-interval 10s
35+ --health-timeout 5s
36+ --health-retries 5
37+
38+ strategy :
39+ matrix :
40+ python-version : [3.10, 3.11, 3.12]
41+
42+ steps :
43+ - uses : actions/checkout@v4
44+
45+ - name : Set up Python ${{ matrix.python-version }}
46+ uses : actions/setup-python@v4
47+ with :
48+ python-version : ${{ matrix.python-version }}
49+
50+ - name : Install Poetry
51+ uses : snok/install-poetry@v1
52+ with :
53+ version : latest
54+ virtualenvs-create : true
55+ virtualenvs-in-project : true
56+
57+ - name : Load cached venv
58+ id : cached-poetry-dependencies
59+ uses : actions/cache@v3
60+ with :
61+ path : .venv
62+ key : venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
63+
64+ - name : Install dependencies
65+ if : steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
66+ run : poetry install --no-interaction --no-root
67+
68+ - name : Install project
69+ run : poetry install --no-interaction
70+
71+ - name : Wait for services
72+ run : |
73+ # Wait for Redis
74+ timeout 30 bash -c 'until redis-cli -h localhost -p 6379 ping; do sleep 1; done'
75+
76+ # Wait for PostgreSQL
77+ timeout 30 bash -c 'until pg_isready -h localhost -p 5432 -U codesage_test; do sleep 1; done'
78+
79+ - name : Run unit tests
80+ run : |
81+ poetry run pytest tests/unit/graph/ -v --cov=codesage.graph --cov-report=xml --cov-report=term-missing
82+ env :
83+ PYTHONPATH : .
84+
85+ - name : Run integration tests
86+ run : |
87+ poetry run pytest tests/integration/storage/ -v --tb=short
88+ env :
89+ PYTHONPATH : .
90+ # Redis configuration
91+ REDIS_HOST : localhost
92+ REDIS_PORT : 6379
93+ REDIS_DB : 15
94+ # PostgreSQL configuration
95+ POSTGRES_HOST : localhost
96+ POSTGRES_PORT : 5432
97+ POSTGRES_DB : codesage_test
98+ POSTGRES_USER : codesage_test
99+ POSTGRES_PASSWORD : codesage_test
100+
101+ - name : Run performance tests
102+ run : |
103+ poetry run pytest tests/performance/test_graph_query_perf.py -v --tb=short -s
104+ env :
105+ PYTHONPATH : .
106+
107+ - name : Upload coverage reports
108+ if : matrix.python-version == '3.11'
109+ uses : codecov/codecov-action@v3
110+ with :
111+ file : ./coverage.xml
112+ flags : graph-engine
113+ name : graph-engine-coverage
114+ fail_ci_if_error : false
115+
116+ test-graph-scenarios :
117+ runs-on : ubuntu-latest
118+ needs : test-graph-engine
119+
120+ services :
121+ redis :
122+ image : redis:7-alpine
123+ ports :
124+ - 6379:6379
125+ options : >-
126+ --health-cmd "redis-cli ping"
127+ --health-interval 10s
128+ --health-timeout 5s
129+ --health-retries 5
130+
131+ postgres :
132+ image : postgres:15-alpine
133+ env :
134+ POSTGRES_DB : codesage_test
135+ POSTGRES_USER : codesage_test
136+ POSTGRES_PASSWORD : codesage_test
137+ ports :
138+ - 5432:5432
139+ options : >-
140+ --health-cmd "pg_isready -U codesage_test -d codesage_test"
141+ --health-interval 10s
142+ --health-timeout 5s
143+ --health-retries 5
144+
145+ steps :
146+ - uses : actions/checkout@v4
147+
148+ - name : Set up Python 3.11
149+ uses : actions/setup-python@v4
150+ with :
151+ python-version : 3.11
152+
153+ - name : Install Poetry
154+ uses : snok/install-poetry@v1
155+ with :
156+ version : latest
157+ virtualenvs-create : true
158+ virtualenvs-in-project : true
159+
160+ - name : Install dependencies
161+ run : poetry install --no-interaction
162+
163+ - name : Test end-to-end graph pipeline
164+ run : |
165+ poetry run python -c "
166+ import tempfile
167+ import os
168+ from pathlib import Path
169+
170+ from codesage.analyzers.parser_factory import create_parser, detect_language
171+ from codesage.graph.graph_builder import GraphBuilder
172+ from codesage.graph.storage.redis_impl import RedisStorageAdapter, RedisConfig
173+ from codesage.graph.storage.postgres_impl import PostgreSQLStorageAdapter, PostgresConfig
174+ from codesage.graph.query.dsl import parse_query
175+ from codesage.graph.query.processor import QueryProcessor
176+
177+ # Create test Python file
178+ test_code = '''
179+ def fibonacci(n) :
180+ if n <= 1 :
181+ return n
182+ return fibonacci(n-1) + fibonacci(n-2)
183+
184+ def factorial(n) :
185+ if n <= 1 :
186+ return 1
187+ return n * factorial(n-1)
188+
189+ def main() :
190+ print(fibonacci(10))
191+ print(factorial(5))
192+
193+ if __name__ == '__main__' :
194+ main()
195+ ' ''
196+
197+ with tempfile.NamedTemporaryFile(mode=' w', suffix='.py', delete=False) as f:
198+ f.write(test_code)
199+ test_file = f.name
200+
201+ try :
202+ # Parse file
203+ language = detect_language(test_file)
204+ parser = create_parser(language)
205+ parser.parse(test_code)
206+ parser_output = parser.to_graph_format(test_file)
207+
208+ # Build graph
209+ builder = GraphBuilder()
210+ graph = builder.from_parser_output(parser_output)
211+
212+ print(f'Built graph with {len(graph.nodes)} nodes and {len(graph.edges)} edges')
213+
214+ # Test Redis storage
215+ redis_config = RedisConfig(host='localhost', port=6379, db=15)
216+ redis_adapter = RedisStorageAdapter(redis_config)
217+ redis_adapter.save_graph(graph)
218+ loaded_graph = redis_adapter.load_graph(list(graph.nodes.keys())[0])
219+ print(f'Redis : Saved and loaded graph with {len(loaded_graph.nodes)} nodes')
220+
221+ # Test PostgreSQL storage
222+ postgres_config = PostgresConfig(
223+ host='localhost', port=5432, database='codesage_test',
224+ username='codesage_test', password='codesage_test'
225+ )
226+ postgres_adapter = PostgreSQLStorageAdapter(postgres_config)
227+ postgres_adapter.save_graph(graph)
228+ loaded_graph = postgres_adapter.load_graph(list(graph.nodes.keys())[0])
229+ print(f'PostgreSQL : Saved and loaded graph with {len(loaded_graph.nodes)} nodes')
230+
231+ # Test queries
232+ processor = QueryProcessor(postgres_adapter)
233+
234+ # Query all functions
235+ query_ast = parse_query('FIND function')
236+ result = processor.execute(query_ast)
237+ print(f'Query result : Found {len(result.nodes)} functions')
238+
239+ # Query high complexity functions
240+ high_complexity = processor.find_high_complexity_functions(threshold=2)
241+ print(f'High complexity functions : {len(high_complexity)}')
242+
243+ print('✅ End-to-end pipeline test passed!')
244+
245+ finally :
246+ os.unlink(test_file)
247+ "
248+ env:
249+ PYTHONPATH: .
250+
251+ - name: Test incremental updates
252+ run: |
253+ poetry run python -c "
254+ import tempfile
255+ import os
256+ import time
257+ from pathlib import Path
258+
259+ from codesage.graph.storage.redis_impl import RedisStorageAdapter, RedisConfig
260+ from codesage.graph.graph_builder import GraphBuilder
261+ from codesage.graph.incremental.updater import IncrementalUpdater, ChangeType
262+
263+ # Setup
264+ redis_config = RedisConfig(host='localhost', port=6379, db=15)
265+ redis_adapter = RedisStorageAdapter(redis_config)
266+ builder = GraphBuilder()
267+ updater = IncrementalUpdater(redis_adapter, builder, debounce_interval=0.1)
268+
269+ # Create test file
270+ with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f :
271+ f.write('def test_func() : pass')
272+ test_file = f.name
273+
274+ try :
275+ # Test file change processing
276+ updater.on_file_changed(test_file, ChangeType.CREATE)
277+ time.sleep(0.2) # Wait for debounce
278+
279+ # Check statistics
280+ stats = updater.get_statistics()
281+ print(f'Updater stats : {stats}')
282+
283+ print('✅ Incremental update test passed!')
284+
285+ finally :
286+ os.unlink(test_file)
287+ "
288+ env:
289+ PYTHONPATH: .
0 commit comments