fix(client): watch only rule paths, forget vanished worktrees, ping http2
This commit is contained in:
1 parent
3b2dcffcf0
commit
4207f7e6f8
4 files changed
+165
-34
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
)
|
||||
|
||||
func TestDaemonWatchesOnlyRulePaths(t *testing.T) {
|
||||
m, _ := setup(t)
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { watcher.Close() })
|
||||
d := &daemon{client: m.client, watcher: watcher, owners: map[string]string{}, trees: map[string]tree{}}
|
||||
gitDir := filepath.Join(m.root, ".git")
|
||||
expectWatched := func(want ...string) {
|
||||
t.Helper()
|
||||
slices.Sort(want)
|
||||
if got := slices.Sorted(maps.Keys(d.owners)); !slices.Equal(got, want) {
|
||||
t.Fatalf("watching %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
write(t, m.root, "target/debug/deps/big.o", "build output")
|
||||
write(t, m.root, "docs/agents/sub/note.md", "note")
|
||||
d.watch(m.root)
|
||||
expectWatched(m.root, gitDir, filepath.Join(m.root, "docs"), filepath.Join(m.root, "docs/agents"), filepath.Join(m.root, "docs/agents/sub"))
|
||||
|
||||
write(t, m.root, RulesFile, "shared notes/plans\n")
|
||||
if err := os.RemoveAll(filepath.Join(m.root, "docs/agents/sub")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d.watch(m.root)
|
||||
expectWatched(m.root, gitDir)
|
||||
|
||||
for name, want := range map[string]bool{
|
||||
"notes": true,
|
||||
"notes/plans/a.md": true,
|
||||
RulesFile: true,
|
||||
".git/HEAD": true,
|
||||
".git/index": false,
|
||||
"notes/plans/a.lodge-tmp": false,
|
||||
"docs/agents/x.md": false,
|
||||
"target/debug/deps/big.o": false,
|
||||
} {
|
||||
if got := d.trees[m.root].relevant(m.root, filepath.Join(m.root, name)); got != want {
|
||||
t.Errorf("relevant(%s) = %v, want %v", name, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDaemonForgetsVanishedWorktrees(t *testing.T) {
|
||||
c := &Client{DataDir: t.TempDir()}
|
||||
if err := writeJSONFile(c.registryPath(), []string{filepath.Join(t.TempDir(), "gone")}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := &daemon{client: c, owners: map[string]string{}, trees: map[string]tree{}}
|
||||
d.syncAll()
|
||||
if roots := c.Worktrees(); len(roots) != 0 {
|
||||
t.Fatalf("registry still lists %v", roots)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user