(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestHandleFindFileAndStatus(t *testing.T) { |
| 76 | root := t.TempDir() |
| 77 | if err := os.WriteFile(filepath.Join(root, "main.go"), []byte("package main\n"), 0o644); err != nil { |
| 78 | t.Fatal(err) |
| 79 | } |
| 80 | if err := os.MkdirAll(filepath.Join(root, "nested"), 0o755); err != nil { |
| 81 | t.Fatal(err) |
| 82 | } |
| 83 | if err := os.WriteFile(filepath.Join(root, "nested", "helper.go"), []byte("package nested\n"), 0o644); err != nil { |
| 84 | t.Fatal(err) |
| 85 | } |
| 86 | |
| 87 | findRes, _, err := handleFindFile(context.Background(), nil, FindInput{Path: root, Pattern: "main"}) |
| 88 | if err != nil { |
| 89 | t.Fatalf("handleFindFile error: %v", err) |
| 90 | } |
| 91 | findOut := resultText(t, findRes) |
| 92 | if !strings.Contains(findOut, "Found 1 files") || !strings.Contains(findOut, "main.go") { |
| 93 | t.Fatalf("unexpected find output:\n%s", findOut) |
| 94 | } |
| 95 | |
| 96 | missingRes, _, err := handleFindFile(context.Background(), nil, FindInput{Path: root, Pattern: "absent"}) |
| 97 | if err != nil { |
| 98 | t.Fatalf("handleFindFile missing error: %v", err) |
| 99 | } |
| 100 | if !strings.Contains(resultText(t, missingRes), "No files found matching 'absent'") { |
| 101 | t.Fatalf("unexpected missing-file output:\n%s", resultText(t, missingRes)) |
| 102 | } |
| 103 | |
| 104 | watchersMu.Lock() |
| 105 | watchers = map[string]*watch.Daemon{"/tmp/demo": nil} |
| 106 | watchersMu.Unlock() |
| 107 | t.Cleanup(func() { |
| 108 | watchersMu.Lock() |
| 109 | watchers = make(map[string]*watch.Daemon) |
| 110 | watchersMu.Unlock() |
| 111 | }) |
| 112 | |
| 113 | statusRes, _, err := handleStatus(context.Background(), nil, EmptyInput{}) |
| 114 | if err != nil { |
| 115 | t.Fatalf("handleStatus error: %v", err) |
| 116 | } |
| 117 | statusOut := resultText(t, statusRes) |
| 118 | if !strings.Contains(statusOut, "codemap MCP server") || !strings.Contains(statusOut, "Active watchers: 1 active: /tmp/demo") { |
| 119 | t.Fatalf("unexpected status output:\n%s", statusOut) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | func TestHandleGetStructureUsesStateHubs(t *testing.T) { |
| 124 | root := t.TempDir() |
nothing calls this directly
no test coverage detected