Backtestshugorun-20261009-153657#15174
Panic when deleting a directory in static when server is running
Worse
The merged fix was judged better than our patch.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches add a `files.ComponentFolderStatic` case to the switch in `processPartialFileEvents`, so both remove the panic itself. They differ in what else they do. **Correctness.** Patch A also goes after why static events reach the site build at all. `SourceFilesystem.Contains` only matched mounts where `dir.IsDir()` was true. That check needs the path to exist on disk, so a deleted directory or a file mount was never recognized as part of the static filesystem. The event then skipped the static syncer and fell through to the build path. Replacing that check with the stat-free `ReverseLookup` lets the static syncer claim deleted static paths, including file mounts and deleted mount roots. So A fixes both the symptom (the panic) and the routing gap behind it. Patch B only stops the panic and logs a line. Its own comment admits that a deleted static mount root can end up there, which suggests the syncer may still miss the deletion, leaving stale files in the publish dir. The `Contains` change does add some risk, because other callers depend on its semantics. However, `ReverseLookup` is the canonical way to map a filename back to a component, so the change is well grounded. **Tests.** Patch A adds server testscripts for deleting a file mount and a directory mount under static, run against a live `hugo server` and asserting no stderr. That directly matches the issue's scenario of a running server with a deleted directory. Patch B adds `TestRunning`-based Go tests, including deletion of a static subdir and of the static root. Some of these would likely panic before the fix, but they only assert home page content, not static sync behavior. Both test sets are reasonable. A's are closer to the reported scenario and cover mount edge cases that B ignores. **Scope and craft.** Both changes are small and focused. B's `logger.Println` is harmless noise. A's comment that static changes are "handled by the static file syncer" is accurate once `Contains` is fixed. Overall, A addresses the root cause more completely.
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
17m 42s
Wall-clock time in the container
Full test suite
No new failures
2,692 passed · 95 skipped · 2,794 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
47vs 78 merged
Changed lines, ours vs merged
The issue
View on GitHubunknown component: "static" in processPartialFileEvents (hugolib/hugo_sites_build.go:1084, your v0.165.0-DEV-8a5cb2344)The two patches
Our patch+47 −0
hugolib/hugo_sites_build.goindex 823f9811e..9a0dff49d 100644@@ -1080,6 +1080,10 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo changes = append(changes, identity.GenghisKhan) case files.ComponentFolderArchetypes: // Ignore for now.+ case files.ComponentFolderStatic:+ // Static files are synced to the publish dir outside of the site build,+ // but e.g. a deleted static mount root may end up here.+ logger.Println("Static changed", pathInfo.Path()) default: panic(fmt.Sprintf("unknown component: %q", pathInfo.Component())) }hugolib/rebuild_test.goindex b6d716c37..9f4f0594d 100644@@ -2211,3 +2211,46 @@ objects: ["o1"] b.AssertFileContent("public/objects/index.html", "Objects|taxonomy|<p>Objects content edited.</p>") b.AssertFileContent("public/objects/o1/index.html", "O1|term|") }++const rebuildFilesStatic = `+-- hugo.toml --+baseURL = "https://example.com"+disableKinds = ["term", "taxonomy", "sitemap", "robotstxt", "404", "rss"]+disableLiveReload = true+-- static/mydir/foo.txt --+Foo.+-- static/bar.txt --+Bar.+-- content/p1.md --+---+title: "P1"+---+-- layouts/home.html --+Home: {{ .Title }}|{{ len site.RegularPages }}|+-- layouts/single.html --+Single: {{ .Title }}|+`++func TestRebuildDeleteDirInStatic(t *testing.T) {+ b := TestRunning(t, rebuildFilesStatic)+ b.RemoveFiles("static/mydir/foo.txt", "static/mydir").Build()+ b.AssertFileContent("public/index.html", "Home: |1|")+}++func TestRebuildRenameDirInStatic(t *testing.T) {+ b := TestRunning(t, rebuildFilesStatic)+ b.RenameDir("static/mydir", "static/mydirrenamed").Build()+ b.AssertFileContent("public/index.html", "Home: |1|")+}++func TestRebuildDeleteStaticRootDir(t *testing.T) {+ b := TestRunning(t, rebuildFilesStatic)+ b.RemoveFiles("static/mydir/foo.txt", "static/mydir", "static/bar.txt", "static").Build()+ b.AssertFileContent("public/index.html", "Home: |1|")+}++func TestRebuildEditFileInStatic(t *testing.T) {+ b := TestRunning(t, rebuildFilesStatic)+ b.EditFileReplaceAll("static/bar.txt", "Bar.", "Bar edited.").Build()+ b.AssertFileContent("public/index.html", "Home: |1|")+}
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