MCPcopy Create free account
hub / github.com/diillson/chatcli / TestExtractRelevantCode

Function TestExtractRelevantCode

operator/controllers/source_controller_test.go:232–258  ·  view source on GitHub ↗

--- extractRelevantCode ---

(t *testing.T)

Source from the content-addressed store, hash-verified

230// --- extractRelevantCode ---
231
232func TestExtractRelevantCode(t *testing.T) {
233 root := t.TempDir()
234 var sb strings.Builder
235 for i := 0; i < 10; i++ {
236 sb.WriteString("package main // filler\n")
237 }
238 writeTestFile(t, filepath.Join(root, "main.go"), sb.String())
239
240 traces := []StackTrace{
241 {
242 Language: "go",
243 ExceptionType: "panic",
244 Frames: []string{"main.go:5", "not-a-frame"},
245 },
246 }
247
248 snippets := extractRelevantCode(root, nil, traces)
249 if len(snippets) != 1 {
250 t.Fatalf("expected 1 snippet, got %d", len(snippets))
251 }
252 if snippets[0].FilePath != "main.go" {
253 t.Errorf("FilePath = %q, want main.go", snippets[0].FilePath)
254 }
255 if !strings.Contains(snippets[0].Content, ">>") {
256 t.Errorf("snippet content missing target-line marker:\n%s", snippets[0].Content)
257 }
258}
259
260// --- git-backed helpers ---
261

Callers

nothing calls this directly

Calls 4

extractRelevantCodeFunction · 0.85
ErrorfMethod · 0.80
writeTestFileFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected