@@ -193,3 +193,121 @@ def broken(
193193 generateTaintSummaries (callGraph , codeGraph , registry )
194194 })
195195}
196+
197+ func TestGenerateTaintSummaries_StatementExtractionError (t * testing.T ) {
198+ // Create a temporary test file with code that parses but has extraction issues
199+ tmpDir := t .TempDir ()
200+ testFile := filepath .Join (tmpDir , "test.py" )
201+
202+ sourceCode := `
203+ def valid_function():
204+ pass
205+ `
206+
207+ err := os .WriteFile (testFile , []byte (sourceCode ), 0644 )
208+ assert .NoError (t , err )
209+
210+ funcNode := & graph.Node {
211+ ID : "test.valid_function" ,
212+ Type : "function_definition" ,
213+ Name : "valid_function" ,
214+ File : testFile ,
215+ LineNumber : 2 ,
216+ }
217+
218+ callGraph := NewCallGraph ()
219+ callGraph .Functions ["test.valid_function" ] = funcNode
220+
221+ codeGraph := & graph.CodeGraph {
222+ Nodes : map [string ]* graph.Node {
223+ funcNode .ID : funcNode ,
224+ },
225+ Edges : make ([]* graph.Edge , 0 ),
226+ }
227+
228+ registry := & ModuleRegistry {
229+ Modules : make (map [string ]string ),
230+ FileToModule : make (map [string ]string ),
231+ }
232+
233+ // Should handle extraction gracefully
234+ generateTaintSummaries (callGraph , codeGraph , registry )
235+
236+ // Should have created a summary for the valid function
237+ assert .GreaterOrEqual (t , len (callGraph .Summaries ), 1 )
238+ }
239+
240+ func TestGenerateTaintSummaries_MultipleFunctions (t * testing.T ) {
241+ // Create a temporary test file with multiple functions
242+ tmpDir := t .TempDir ()
243+ testFile := filepath .Join (tmpDir , "test.py" )
244+
245+ sourceCode := `
246+ def func1():
247+ x = 1
248+ return x
249+
250+ def func2():
251+ y = 2
252+ return y
253+
254+ def func3():
255+ z = 3
256+ return z
257+ `
258+
259+ err := os .WriteFile (testFile , []byte (sourceCode ), 0644 )
260+ assert .NoError (t , err )
261+
262+ funcNode1 := & graph.Node {
263+ ID : "test.func1" ,
264+ Type : "function_definition" ,
265+ Name : "func1" ,
266+ File : testFile ,
267+ LineNumber : 2 ,
268+ }
269+
270+ funcNode2 := & graph.Node {
271+ ID : "test.func2" ,
272+ Type : "function_definition" ,
273+ Name : "func2" ,
274+ File : testFile ,
275+ LineNumber : 6 ,
276+ }
277+
278+ funcNode3 := & graph.Node {
279+ ID : "test.func3" ,
280+ Type : "function_definition" ,
281+ Name : "func3" ,
282+ File : testFile ,
283+ LineNumber : 10 ,
284+ }
285+
286+ callGraph := NewCallGraph ()
287+ callGraph .Functions ["test.func1" ] = funcNode1
288+ callGraph .Functions ["test.func2" ] = funcNode2
289+ callGraph .Functions ["test.func3" ] = funcNode3
290+
291+ codeGraph := & graph.CodeGraph {
292+ Nodes : map [string ]* graph.Node {
293+ funcNode1 .ID : funcNode1 ,
294+ funcNode2 .ID : funcNode2 ,
295+ funcNode3 .ID : funcNode3 ,
296+ },
297+ Edges : make ([]* graph.Edge , 0 ),
298+ }
299+
300+ registry := & ModuleRegistry {
301+ Modules : make (map [string ]string ),
302+ FileToModule : make (map [string ]string ),
303+ }
304+
305+ // Generate summaries for all functions
306+ generateTaintSummaries (callGraph , codeGraph , registry )
307+
308+ // Should have created summaries for all three functions
309+ assert .Equal (t , 3 , len (callGraph .Summaries ))
310+ assert .NotNil (t , callGraph .Summaries ["test.func1" ])
311+ assert .NotNil (t , callGraph .Summaries ["test.func2" ])
312+ assert .NotNil (t , callGraph .Summaries ["test.func3" ])
313+ }
0 commit comments