Backtestshugorun-20261007-020926#15174

Issue #15174 Merged fix PR # Run 7 Oct 2026 · run-20261007-020926 gohugoio/hugo

Panic when deleting a directory in static when server is running

Better

Our patch was judged better than the merged fix.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Both patches stop the panic in processPartialFileEvents, but B is the more contained and better-tested fix.

Patch B filters static-component paths out of the resolved component paths before any per-path processing. Static files then never reach the switch or any later logic in the build-graph code. The comment states the right reason: static files are handled by the static syncer, not the site build. Because the filter works per component path, a file mounted into both static and assets still triggers an asset rebuild. B tests exactly that dual-mount case.

B's tests use the in-process TestRunning harness. They cover removing a directory (the issue's scenario), renaming a directory, removing a file, adding and editing a file, and the dual static/assets mount. Each would hit the panic before the fix and pass after. They also assert that nothing is rendered and that later edits still rebuild correctly.

Patch A adds a `case files.ComponentFolderStatic` no-op to the switch, which fixes the panic. It also rewrites `SourceFilesystem.Contains` to use `ReverseLookup`. That change goes beyond the issue: it alters how the static syncer decides whether a path belongs to a filesystem, now including file mounts that were previously skipped. It may be a legitimate improvement, but it adds behavioral risk in code shared by other callers and is not needed for the reported panic.

A's tests are server testscripts with sleeps and a check for empty stderr. They exercise the real server path but are timing-dependent. Both use custom mounts rather than the plain static-directory deletion described in the issue.

Overall, B fixes the root symptom precisely, guards the edge cases, and has stronger, deterministic tests with no unrelated churn.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

58m 45s

Wall-clock time in the container

Full test suite

No new failures

3,698 passed · 99 skipped · 3,806 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

90vs 78 merged

Changed lines, ours vs merged

unknown  component: "static" in processPartialFileEvents (hugolib/hugo_sites_build.go:1084, your v0.165.0-DEV-8a5cb2344)

The two patches

Our patch+90 −0
hugolib/hugo_sites_build.goindex 823f9811e..225ed3bf2 100644@@ -22,6 +22,7 @@ import ( 	"os" 	"path" 	"path/filepath"+	"slices" 	"strings" 	"time" @@ -919,6 +920,14 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo  	for _, ev := range eventInfos { 		cpss := h.BaseFs.ResolvePaths(ev.Name)+		// Static files are not part of the build graph; they are synced+		// to the publish dir by the static syncer in the commands package.+		cpss = slices.DeleteFunc(cpss, func(cps hugofs.ComponentPath) bool {+			return cps.Component == files.ComponentFolderStatic+		})+		if len(cpss) == 0 {+			continue+		} 		pss := make([]*paths.Path, len(cpss)) 		for i, cps := range cpss { 			p := cps.Pathhugolib/rebuild_test.goindex b6d716c37..7a6a22a1e 100644@@ -2211,3 +2211,84 @@ objects: ["o1"] 	b.AssertFileContent("public/objects/index.html", "Objects|taxonomy|<p>Objects content edited.</p>") 	b.AssertFileContent("public/objects/o1/index.html", "O1|term|") }++// Static files are synced by the static syncer, not by the site build,+// so change events for them must be ignored and not panic.+func TestRebuildStaticChanges(t *testing.T) {+	t.Parallel()+	files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+disableKinds = ["taxonomy", "term", "rss", "sitemap"]+-- static/foo/bar.txt --+bar+-- static/baz.txt --+baz+-- content/p1.md --+---+title: "P1"+---+-- layouts/all.html --+{{ .Title }}|{{ .Kind }}|+`++	t.Run("Remove directory", func(t *testing.T) {+		t.Parallel()+		b := TestRunning(t, files)+		b.AssertFileContent("public/p1/index.html", "P1|page|")+		b.RemoveFiles("static/foo/bar.txt", "static/foo").Build()+		b.AssertRenderCountPage(0)+		b.EditFileReplaceAll("content/p1.md", "P1", "P1 edited").Build()+		b.AssertFileContent("public/p1/index.html", "P1 edited|page|")+	})++	t.Run("Rename directory", func(t *testing.T) {+		t.Parallel()+		b := TestRunning(t, files)+		b.RenameDir("static/foo", "static/foo2").Build()+		b.AssertRenderCountPage(0)+	})++	t.Run("Remove file", func(t *testing.T) {+		t.Parallel()+		b := TestRunning(t, files)+		b.RemoveFiles("static/baz.txt").Build()+		b.AssertRenderCountPage(0)+	})++	t.Run("Add and edit file", func(t *testing.T) {+		t.Parallel()+		b := TestRunning(t, files)+		b.AddFiles("static/new.txt", "new").EditFileReplaceAll("static/baz.txt", "baz", "baz edited").Build()+		b.AssertRenderCountPage(0)+	})+}++// A file mounted into both static and assets must still trigger+// a rebuild of what depends on the asset.+func TestRebuildStaticAlsoMountedAsAsset(t *testing.T) {+	t.Parallel()+	files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+disableKinds = ["taxonomy", "term", "rss", "sitemap"]+[[module.mounts]]+source = "static"+target = "static"+[[module.mounts]]+source = "static"+target = "assets"+-- static/foo/bar.txt --+bar+-- layouts/home.html --+{{ with resources.Get "foo/bar.txt" }}Bar: {{ .Content }}|{{ end }}+`+	b := TestRunning(t, files)+	b.AssertFileContent("public/index.html", "Bar: bar|")+	b.EditFileReplaceAll("static/foo/bar.txt", "bar", "bar edited").Build()+	b.AssertFileContent("public/index.html", "Bar: bar edited|")+	// Removing a directory with a file mounted in both static and assets must not panic.+	b.RemoveFiles("static/foo/bar.txt", "static/foo").Build()+} 
Merged fix · PR #+69 −9
hugolib/filesystems/basefs.goindex 13cc942fc..74f59b03c 100644@@ -426,16 +426,10 @@ func (d *SourceFilesystem) RealFilename(rel string) string { }  // Contains returns whether the given filename is a member of the current filesystem.+// It's stat-free, so it also works for deleted files. func (d *SourceFilesystem) Contains(filename string) bool {-	for _, dir := range d.mounts() {-		if !dir.IsDir() {-			continue-		}-		if strings.HasPrefix(filename, dir.Meta().Filename) {-			return true-		}-	}-	return false+	cps, _ := d.ReverseLookup(filename, false)+	return len(cps) > 0 }  // RealDirs gets a list of absolute paths to directories starting from the givenhugolib/hugo_sites_build.goindex 823f9811e..0feaada59 100644@@ -1080,6 +1080,8 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo 			changes = append(changes, identity.GenghisKhan) 		case files.ComponentFolderArchetypes: 			// Ignore for now.+		case files.ComponentFolderStatic:+			// Handled by the static file syncer. 		default: 			panic(fmt.Sprintf("unknown component: %q", pathInfo.Component())) 		}testscripts/server/server__delete_static_file_mount.txtnew file mode 100644index 000000000..df77b2a04@@ -0,0 +1,32 @@+# Test the hugo server command when removing a file mounted into static.+# See issue 15174.++hugo server &++waitServer++rm myfiles/robots.txt++sleep 2++stopServer+! stderr .++-- hugo.toml --+title = "Hugo Server Test"+baseURL = "https://example.org/"+disableKinds = ["taxonomy", "term", "sitemap"]+[[module.mounts]]+source = "content"+target = "content"+[[module.mounts]]+source = "layouts"+target = "layouts"+[[module.mounts]]+source = "myfiles/robots.txt"+target = "static/robots.txt"+-- layouts/all.html --+All.+-- content/p1.md --+-- myfiles/robots.txt --+robotstestscripts/server/server__delete_static_mount_dir.txtnew file mode 100644index 000000000..8c338812e@@ -0,0 +1,32 @@+# Test the hugo server command when removing a directory mounted into static.+# See issue 15174.++hugo server &++waitServer++rm mystatic/foo++sleep 2++stopServer+! stderr .++-- hugo.toml --+title = "Hugo Server Test"+baseURL = "https://example.org/"+disableKinds = ["taxonomy", "term", "sitemap"]+[[module.mounts]]+source = "content"+target = "content"+[[module.mounts]]+source = "layouts"+target = "layouts"+[[module.mounts]]+source = "mystatic/foo"+target = "static/foo"+-- layouts/all.html --+All.+-- content/p1.md --+-- mystatic/foo/static.txt --+static