test(11.1-06): branch-level tests for every docsite stage (94.8% coverage)

- load, render, emit, snippet, highlight, serve and checker branch tests;
  docs:build --check, docs:sync and docs:serve output tests in cmd/summer
- fix: a CRLF or BOM page is reported as such, not as a page without a
  frontmatter block (TestFrontmatterEncodingProblems)
- fix: src=#Type.Method finds a method with a parenthesised receiver
  (TestSnippetGenericsAndGroups, Box.Paren)
- fix: docs:serve adds its watches before announcing the server, so an
  edit made right after the serving line rebuilds (TestServeWatchRebuilds)
This commit is contained in:
Jakub Zych
2026-10-01 00:05:12 +02:00
parent 1d38e73f03
commit 28afd4d197
13 changed files with 2276 additions and 11 deletions

View File

@@ -49,6 +49,15 @@ func Serve(ctx context.Context, opts Options, addr string, allowRemote bool, out
return errors.New("docs:serve: build failed")
}
// The watches are in place before the serving line is printed, so an
// edit made as soon as the server is announced triggers a rebuild.
w, err := fsnotify.NewWatcher()
if err != nil {
return fmt.Errorf("docs:serve: watcher: %w", err)
}
defer w.Close()
s.addWatches(w)
ln, err := net.Listen("tcp", addr)
if err != nil {
return fmt.Errorf("docs:serve: %w", err)
@@ -61,7 +70,7 @@ func Serve(ctx context.Context, opts Options, addr string, allowRemote bool, out
watchErr := make(chan error, 1)
watchCtx, stopWatch := context.WithCancel(ctx)
defer stopWatch()
go func() { watchErr <- s.watch(watchCtx) }()
go func() { watchErr <- s.watch(watchCtx, w) }()
select {
case <-ctx.Done():
@@ -149,15 +158,8 @@ func (s *server) rebuild() bool {
}
// watch rebuilds on changes under Src, modules/ and every src= source
// directory, debounced.
func (s *server) watch(ctx context.Context) error {
w, err := fsnotify.NewWatcher()
if err != nil {
return fmt.Errorf("docs:serve: watcher: %w", err)
}
defer w.Close()
s.addWatches(w)
// directory, debounced. The caller owns w and has added the first watches.
func (s *server) watch(ctx context.Context, w *fsnotify.Watcher) error {
var timer *time.Timer
fire := make(chan struct{}, 1)
for {