Skip to content

Commit 6af7bff

Browse files
author
razvan
committed
test: add coverage for ExactSearchPolyglot refactors in find_usages + list_package_exports
- find_usages: verify filter key is relations[].target_name; polyglot merge (go+python) - list_package_exports: verify is_public not in Qdrant filter; isExported fallback (uppercase kept, lowercase excluded); RelationsCount shown in markdown output
1 parent fa6df9d commit 6af7bff

File tree

2 files changed

+143
-4
lines changed

2 files changed

+143
-4
lines changed

internal/service/tools/tests/find_usages_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,58 @@ var _ = Describe("FindUsagesTool", func() {
101101
usage := data[0].(map[string]interface{})
102102
Expect(usage["name"]).To(Equal("CallerFunc"))
103103
})
104+
105+
It("should send relations[].target_name as filter key to ExactSearch", func() {
106+
var capturedFilter map[string]interface{}
107+
mockStore.ExactSearchFunc = func(ctx context.Context, col string, filters map[string]interface{}, limit int) ([]storage.SearchResult, error) {
108+
capturedFilter = filters
109+
return []storage.SearchResult{}, nil
110+
}
111+
112+
tool.Execute(ctx, map[string]interface{}{"symbol_name": "TargetSym", "file_path": "main.go"})
113+
114+
Expect(capturedFilter).NotTo(BeNil(), "ExactSearch should have been called")
115+
Expect(capturedFilter["relations[].target_name"]).To(Equal("TargetSym"))
116+
})
117+
118+
It("should merge usages from multiple language collections (polyglot)", func() {
119+
mockStore.ExactSearchFunc = func(ctx context.Context, col string, filters map[string]interface{}, limit int) ([]storage.SearchResult, error) {
120+
if strings.HasSuffix(col, "-go") {
121+
return []storage.SearchResult{
122+
{Score: 1.0, Point: storage.Point{ID: "go-caller", Payload: map[string]interface{}{
123+
"name": "GoCallerFunc", "type": "function", "file_path": "a.go",
124+
"relations": []interface{}{map[string]interface{}{"target_name": "SharedSym", "type": "calls"}},
125+
}}},
126+
}, nil
127+
}
128+
if strings.HasSuffix(col, "-python") {
129+
return []storage.SearchResult{
130+
{Score: 1.0, Point: storage.Point{ID: "py-caller", Payload: map[string]interface{}{
131+
"name": "py_caller_func", "type": "function", "file_path": "b.py",
132+
"relations": []interface{}{map[string]interface{}{"target_name": "SharedSym", "type": "calls"}},
133+
}}},
134+
}, nil
135+
}
136+
return []storage.SearchResult{}, nil
137+
}
138+
139+
resJSON, err := tool.Execute(ctx, map[string]interface{}{"symbol_name": "SharedSym", "file_path": "main.go"})
140+
Expect(err).NotTo(HaveOccurred())
141+
142+
var resp tools.ToolResponse
143+
json.Unmarshal([]byte(resJSON), &resp)
144+
Expect(resp.Status).To(Equal("success"))
145+
146+
data := resp.Data.([]interface{})
147+
Expect(data).To(HaveLen(2), "Expected usages from both go and python collections")
148+
149+
names := map[string]bool{}
150+
for _, d := range data {
151+
m := d.(map[string]interface{})
152+
names[m["name"].(string)] = true
153+
}
154+
Expect(names["GoCallerFunc"]).To(BeTrue())
155+
Expect(names["py_caller_func"]).To(BeTrue())
156+
})
104157
})
105158
})

internal/service/tools/tests/list_package_exports_test.go

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ var _ = Describe("ListPackageExportsTool", func() {
5353
Point: storage.Point{
5454
ID: "sym-1",
5555
Payload: map[string]interface{}{
56-
"name": "ExportedFunc",
57-
"type": "function",
58-
"package": "mypkg",
59-
"code": "func ExportedFunc() {}",
56+
"name": "ExportedFunc",
57+
"type": "function",
58+
"package": "mypkg",
59+
"code": "func ExportedFunc() {}",
60+
"is_public": true,
6061
},
6162
},
6263
},
@@ -86,5 +87,90 @@ var _ = Describe("ListPackageExportsTool", func() {
8687

8788
Expect(resp.Message).To(ContainSubstring("Found package exports"))
8889
})
90+
91+
It("should NOT include is_public in the Qdrant filter", func() {
92+
var capturedFilter map[string]interface{}
93+
mockStore.ExactSearchFunc = func(ctx context.Context, col string, filters map[string]interface{}, limit int) ([]storage.SearchResult, error) {
94+
capturedFilter = filters
95+
return []storage.SearchResult{}, nil
96+
}
97+
98+
tool.Execute(ctx, map[string]interface{}{"package": "mypkg", "file_path": "main.go"})
99+
100+
Expect(capturedFilter).NotTo(BeNil())
101+
Expect(capturedFilter["package"]).To(Equal("mypkg"))
102+
_, hasIsPublic := capturedFilter["is_public"]
103+
Expect(hasIsPublic).To(BeFalse(), "is_public should NOT be in the Qdrant filter — filtering is done in Go code")
104+
})
105+
106+
It("should include symbol when is_public is absent but name is exported (isExported fallback)", func() {
107+
mockStore.ExactSearchFunc = func(ctx context.Context, col string, filters map[string]interface{}, limit int) ([]storage.SearchResult, error) {
108+
if !strings.HasSuffix(col, "-go") {
109+
return []storage.SearchResult{}, nil
110+
}
111+
return []storage.SearchResult{
112+
// is_public absent (old indexed entry), but name is uppercase-exported
113+
{Score: 1.0, Point: storage.Point{ID: "old-sym", Payload: map[string]interface{}{
114+
"name": "ExportedOldFunc", "type": "function", "package": "mypkg",
115+
}}},
116+
}, nil
117+
}
118+
119+
resJSON, err := tool.Execute(ctx, map[string]interface{}{"package": "mypkg", "file_path": "main.go"})
120+
Expect(err).NotTo(HaveOccurred())
121+
var resp tools.ToolResponse
122+
json.Unmarshal([]byte(resJSON), &resp)
123+
Expect(resp.Status).To(Equal("success"))
124+
data := resp.Data.(map[string]interface{})
125+
funcs := data["function"].([]interface{})
126+
Expect(funcs).To(HaveLen(1), "ExportedOldFunc should be included via isExported fallback")
127+
})
128+
129+
It("should exclude symbol when is_public is absent and name is NOT exported", func() {
130+
mockStore.ExactSearchFunc = func(ctx context.Context, col string, filters map[string]interface{}, limit int) ([]storage.SearchResult, error) {
131+
if !strings.HasSuffix(col, "-go") {
132+
return []storage.SearchResult{}, nil
133+
}
134+
return []storage.SearchResult{
135+
// is_public absent and name starts lowercase → unexported
136+
{Score: 1.0, Point: storage.Point{ID: "priv-sym", Payload: map[string]interface{}{
137+
"name": "internalHelper", "type": "function", "package": "mypkg",
138+
}}},
139+
}, nil
140+
}
141+
142+
resJSON, err := tool.Execute(ctx, map[string]interface{}{"package": "mypkg", "file_path": "main.go"})
143+
Expect(err).NotTo(HaveOccurred())
144+
var resp tools.ToolResponse
145+
json.Unmarshal([]byte(resJSON), &resp)
146+
Expect(resp.Status).To(Equal("success"))
147+
Expect(resp.Data).To(BeNil(), "internalHelper should be excluded by isExported check")
148+
})
149+
150+
It("should populate RelationsCount and show it in output", func() {
151+
mockStore.ExactSearchFunc = func(ctx context.Context, col string, filters map[string]interface{}, limit int) ([]storage.SearchResult, error) {
152+
if !strings.HasSuffix(col, "-go") {
153+
return []storage.SearchResult{}, nil
154+
}
155+
return []storage.SearchResult{
156+
{Score: 1.0, Point: storage.Point{ID: "sym-rel", Payload: map[string]interface{}{
157+
"name": "MyExportedFn", "type": "function", "package": "mypkg",
158+
"is_public": true,
159+
"relations": []interface{}{
160+
map[string]interface{}{"target_name": "A", "type": "calls"},
161+
map[string]interface{}{"target_name": "B", "type": "calls"},
162+
map[string]interface{}{"target_name": "C", "type": "calls"},
163+
},
164+
}}},
165+
}, nil
166+
}
167+
168+
resJSON, err := tool.Execute(ctx, map[string]interface{}{"package": "mypkg", "file_path": "main.go"})
169+
Expect(err).NotTo(HaveOccurred())
170+
var resp tools.ToolResponse
171+
json.Unmarshal([]byte(resJSON), &resp)
172+
Expect(resp.Status).To(Equal("success"))
173+
Expect(resp.Message).To(ContainSubstring("**Relations:** 3"), "Output should display RelationsCount when > 0")
174+
})
89175
})
90176
})

0 commit comments

Comments
 (0)