helpers: Limit verbose watch output for better readability

Limits the number of root groups shown in 'Watching for changes' output
to 10 maximum, with a summary message for remaining paths. This prevents
the message from becoming excessively long when watching sites with many
mount points.

Fixes #14277

Signed-off-by: majiayu000 <1835304752@qq.com>
This commit is contained in:
majiayu000
2025-12-30 14:44:27 +08:00
committed by Bjørn Erik Pedersen
parent 86cd1838ff
commit d3b5d47a43
2 changed files with 35 additions and 12 deletions
+27 -12
View File
@@ -345,19 +345,34 @@ func TestAbsPathify(t *testing.T) {
}
func TestExtractAndGroupRootPaths(t *testing.T) {
in := []string{
filepath.FromSlash("/a/b/c/d"),
filepath.FromSlash("/a/b/c/e"),
filepath.FromSlash("/a/b/e/f"),
filepath.FromSlash("/a/b"),
filepath.FromSlash("/a/b/c/b/g"),
filepath.FromSlash("/c/d/e"),
}
result := helpers.ExtractAndGroupRootPaths(in)
c := qt.New(t)
c.Assert(result, qt.DeepEquals, []string{"/a/b/{c,e}", "/c/d/e"})
t.Run("Basic grouping", func(t *testing.T) {
in := []string{
filepath.FromSlash("/a/b/c/d"),
filepath.FromSlash("/a/b/c/e"),
filepath.FromSlash("/a/b/e/f"),
filepath.FromSlash("/a/b"),
filepath.FromSlash("/a/b/c/b/g"),
filepath.FromSlash("/c/d/e"),
}
result := helpers.ExtractAndGroupRootPaths(in)
c.Assert(result, qt.DeepEquals, []string{"/a/b/{c,e}", "/c/d/e"})
})
t.Run("Limits number of root groups", func(t *testing.T) {
in := []string{}
// Create 15 different root paths to exceed maxRootGroups (10)
for i := 0; i < 15; i++ {
in = append(in, filepath.FromSlash(fmt.Sprintf("/path%d/subdir", i)))
}
result := helpers.ExtractAndGroupRootPaths(in)
// Should have 10 paths + 1 "... and X more" message
c.Assert(len(result), qt.Equals, 11)
c.Assert(result[10], qt.Matches, `\.\.\. and \d+ more`)
})
}
func BenchmarkExtractAndGroupRootPaths(b *testing.B) {