Skip to content

Commit 13e6407

Browse files
fix(parse): emit broader tested_by candidates
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent 4db54f4 commit 13e6407

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

internal/parse/treesitter/walker.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,10 @@ func (w *Walker) resolveTestedBy(nodes []model.Node, edges *[]model.Edge, filePa
583583
}
584584

585585
testNodes := make(map[string]model.Node)
586-
nonTestNames := make(map[string]bool)
587586

588587
for _, n := range nodes {
589-
switch n.Kind {
590-
case model.NodeKindTest:
588+
if n.Kind == model.NodeKindTest {
591589
testNodes[n.QualifiedName] = n
592-
case model.NodeKindFunction:
593-
nonTestNames[n.Name] = true
594590
}
595591
}
596592

@@ -608,10 +604,6 @@ func (w *Walker) resolveTestedBy(nodes []model.Node, edges *[]model.Edge, filePa
608604
calleeParts := strings.Split(callee, ".")
609605
bareCallee := calleeParts[len(calleeParts)-1]
610606

611-
if !nonTestNames[bareCallee] {
612-
continue
613-
}
614-
615607
for testQName, testNode := range testNodes {
616608
if e.Line >= testNode.StartLine && e.Line <= testNode.EndLine {
617609
*edges = append(*edges, model.Edge{

internal/parse/treesitter/walker_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,26 @@ func TestAdd(t *testing.T) {
902902
}
903903
}
904904

905+
func TestParseGo_TestedByEmitsCandidateForCrossFileProductionCall(t *testing.T) {
906+
src := `package main
907+
908+
func TestAdd(t *testing.T) {
909+
Add(1, 2)
910+
}
911+
`
912+
w := NewWalker(GoSpec)
913+
_, edges, err := w.Parse("main_test.go", []byte(src))
914+
if err != nil {
915+
t.Fatalf("unexpected error: %v", err)
916+
}
917+
for _, e := range filterEdgesByKind(edges, model.EdgeKindTestedBy) {
918+
if containsSubstring(e.Fingerprint, "Add") && containsSubstring(e.Fingerprint, "TestAdd") {
919+
return
920+
}
921+
}
922+
t.Fatalf("expected TESTED_BY candidate for Add call in TestAdd, got %+v", edges)
923+
}
924+
905925
// --- Phase 12.1: JavaScript ---
906926

907927
func TestParseJS_Function(t *testing.T) {

0 commit comments

Comments
 (0)