Skip to content

Commit 544fafb

Browse files
committed
Auto-start watcher when workspace is accessed and add tests
1 parent 7a0bf85 commit 544fafb

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

internal/workspace/manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ func (m *Manager) GetMemoryForWorkspaceLanguage(ctx context.Context, info *Info,
287287
)
288288
}
289289

290+
// Ensure filesystem watcher is running so future changes trigger reindex automatically
291+
m.StartWatcher(info.Root)
292+
290293
collectionName := info.CollectionNameForLanguage(language)
291294

292295
// Check memory cache

internal/workspace/watcher_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package workspace
2+
3+
import "testing"
4+
5+
func TestManagerStartWatcherRegistersWatcher(t *testing.T) {
6+
root := t.TempDir()
7+
8+
mgr := &Manager{
9+
watchers: make(map[string]*FileWatcher),
10+
}
11+
12+
mgr.StartWatcher(root)
13+
14+
mgr.watchersMu.Lock()
15+
watcher, ok := mgr.watchers[root]
16+
mgr.watchersMu.Unlock()
17+
if !ok {
18+
t.Fatalf("expected watcher for %s", root)
19+
}
20+
if watcher == nil {
21+
t.Fatalf("watcher for %s is nil", root)
22+
}
23+
t.Cleanup(watcher.Stop)
24+
25+
// Starting the watcher again for the same root should reuse the same instance
26+
mgr.StartWatcher(root)
27+
28+
mgr.watchersMu.Lock()
29+
defer mgr.watchersMu.Unlock()
30+
if len(mgr.watchers) != 1 {
31+
t.Fatalf("expected exactly one watcher, got %d", len(mgr.watchers))
32+
}
33+
if mgr.watchers[root] != watcher {
34+
t.Fatalf("expected watcher instance to be reused for %s", root)
35+
}
36+
}

0 commit comments

Comments
 (0)