-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathe2e_lang_test.go
More file actions
254 lines (229 loc) · 6.42 KB
/
Copy pathe2e_lang_test.go
File metadata and controls
254 lines (229 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// Copyright 2026 Aeneas Rekkas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build e2e
package main
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"testing"
"github.com/bradleyjkemp/cupaloy/v2"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
var snapshotter = cupaloy.New(
cupaloy.EnvVariableName("UPDATE_SNAPSHOTS"),
cupaloy.SnapshotSubdirectory("testdata/snapshots"),
)
func fixturesPath(lang string) string {
p, _ := filepath.Abs(filepath.Join("testdata", "fixtures", lang))
return p
}
// startLangServer starts the MCP server with a reduced max chunk token size
// suitable for all-minilm's 512-token context window.
func startLangServer(t *testing.T) *mcp.ClientSession {
t.Helper()
dataHome := t.TempDir()
ollamaHost := "http://localhost:11434"
if h := os.Getenv("OLLAMA_HOST"); h != "" {
ollamaHost = h
}
cmd := exec.Command(serverBinary, "stdio")
cmd.Env = []string{
"OLLAMA_HOST=" + ollamaHost,
"LUMEN_EMBED_MODEL=all-minilm",
// all-minilm uses BERT WordPiece tokenisation which is ~4x denser than
// our 4-chars-per-token estimate, so cap chunks at 100 "tokens" (400
// chars) to stay within the model's 512-token context window.
"LUMEN_MAX_CHUNK_TOKENS=100",
// Lang tests need indexing to complete before the first search returns.
// On CI, 12 parallel test suites share a single Ollama instance, so
// embedding can take well over the default 15s timeout. Allow up to 10m
// to avoid returning incomplete results from a partially-built index.
"LUMEN_REINDEX_TIMEOUT=10m",
"XDG_DATA_HOME=" + dataHome,
"HOME=" + os.Getenv("HOME"),
"PATH=" + os.Getenv("PATH"),
}
transport := &mcp.CommandTransport{Command: cmd}
client := mcp.NewClient(&mcp.Implementation{
Name: "e2e-lang-test-client",
Version: "0.1.0",
}, nil)
ctx := context.Background()
session, err := client.Connect(ctx, transport, nil)
if err != nil {
t.Fatalf("failed to connect to server: %v", err)
}
t.Cleanup(func() { session.Close() })
return session
}
func langSearch(t *testing.T, session *mcp.ClientSession, lang, query string) string {
t.Helper()
dir := fixturesPath(lang)
out := callSearch(t, session, map[string]any{
"query": query,
"path": dir,
"limit": 10,
"min_score": -1.0,
})
// Sort by (filePath, startLine) for deterministic snapshots across environments.
slices.SortFunc(out.Results, func(a, b searchResultItem) int {
if a.FilePath != b.FilePath {
if a.FilePath < b.FilePath {
return -1
}
return 1
}
return a.StartLine - b.StartLine
})
var b strings.Builder
fmt.Fprintf(&b, "results: %d\n", len(out.Results))
for _, r := range out.Results {
fmt.Fprintf(&b, "%s:%d-%d %s (%s)\n", r.FilePath, r.StartLine, r.EndLine, r.Symbol, r.Kind)
}
return b.String()
}
func runLangTest(t *testing.T, lang string, queries []string) {
t.Helper()
session := startLangServer(t)
for _, q := range queries {
q := q
t.Run(strings.ReplaceAll(q, " ", "_"), func(t *testing.T) {
result := langSearch(t, session, lang, q)
snapshotter.SnapshotT(t, result)
})
}
}
func TestLang_Go(t *testing.T) {
t.Parallel()
runLangTest(t, "go", []string{
"HTTP request handler",
"authentication token validation",
"database connection pool",
"time series storage and retrieval",
"error handling and logging",
"configuration loading from file",
})
}
func TestLang_Java(t *testing.T) {
t.Parallel()
runLangTest(t, "java", []string{
"pet owner repository database",
"REST controller request mapping",
"JPA entity model fields",
"Spring service dependency injection",
"form input validation",
})
}
func TestLang_Dart(t *testing.T) {
t.Parallel()
runLangTest(t, "dart", []string{
"HTTP request handler middleware",
"server pipeline shelf handler",
"response body status code",
"cascade route matching",
"logging middleware interceptor",
})
}
func TestLang_PHP(t *testing.T) {
t.Parallel()
runLangTest(t, "php", []string{
"HTTP request handling middleware",
"database query builder",
"authentication guard session",
"collection helper methods",
"model relationships",
})
}
func TestLang_JavaScript(t *testing.T) {
t.Parallel()
runLangTest(t, "js", []string{
"HTTP router middleware",
"request response object",
"event emitter listener",
"error handling exception",
"module exports function",
})
}
func TestLang_TypeScript(t *testing.T) {
t.Parallel()
runLangTest(t, "ts", []string{
"event listener registration",
"async operation with cancellation",
"URI path manipulation",
"lifecycle disposable resource",
"platform detection operating system",
})
}
func TestLang_Ruby(t *testing.T) {
t.Parallel()
runLangTest(t, "ruby", []string{
"route matching URL",
"controller action rendering",
"database record query scope",
"authentication callback filter",
"module include concern",
})
}
func TestLang_Python(t *testing.T) {
t.Parallel()
runLangTest(t, "python", []string{
"HTTP route handler decorator",
"database model query filter",
"authentication login view",
"request context middleware",
"exception error handling",
})
}
func TestLang_Rust(t *testing.T) {
t.Parallel()
runLangTest(t, "rust", []string{
"async runtime executor spawn",
"file search pattern match",
"TCP network listener accept",
"mutex lock concurrent access",
"error result propagation",
})
}
func TestLang_YAML(t *testing.T) {
t.Parallel()
runLangTest(t, "yaml", []string{
"Kubernetes deployment replicas",
"CI pipeline build steps",
"service port configuration",
"environment variables secrets",
})
}
func TestLang_Markdown(t *testing.T) {
t.Parallel()
runLangTest(t, "md", []string{
"installation setup guide",
"ownership borrowing memory",
"error handling panic recover",
"async concurrent threads",
})
}
func TestLang_JSON(t *testing.T) {
t.Parallel()
runLangTest(t, "json", []string{
"build scripts commands",
"TypeScript compiler options",
"package dependencies versions",
"API paths endpoints",
})
}