Backtestshugorun-20260917-015623#15174
Panic when deleting a directory in static when server is running
The merged fix was judged better than our patch.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches share the minimal root fix: adding a `case files.ComponentFolderStatic` to the switch in processPartialFileEvents so the default panic ('unknown component: "static"') no longer fires. That alone resolves the reported crash, so on the narrow panic both are correct. B wins on the remaining criteria. Correctness/depth: B also makes SourceFilesystem.Contains stat-free by delegating to ReverseLookup, with the comment 'it also works for deleted files.' The reported bug is specifically about *deleting* a static directory, and the old Contains relied on d.mounts() + dir.IsDir() + a filename prefix check, which fails for a path that no longer exists on disk — so B fixes a second, deletion-specific weakness that A leaves in place. This is closely tied to the issue rather than drive-by refactoring. Tests: B reproduces the issue at the level it was reported — an actual `hugo server` run — and covers both the file-mount and directory-mount deletion cases, asserting `! stderr .` which directly catches the panic/error. A's test is an in-process rebuild that *renames* a static directory rather than deleting it; it exercises the delete event indirectly and covers only one case, and does not exercise the Contains-on-deleted-path path at all. B's tests are a stronger fail-before/pass-after match to the issue. Scope: A is smaller, but B's Contains change is justified by the deletion scenario rather than incidental churn, so the extra scope is warranted. Craft: A's handler calls logger.Println('Static changed', ...) on every static change, adding recurring log noise during normal server operation; B's case is a clean documented no-op and the Contains rewrite reduces code while improving correctness. Net: B fixes the same panic plus a related deletion edge case, with tests that mirror the exact reported conditions.
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
14m 6s1 turn
Wall-clock time in the container
Full test suite
No new failures
3,689 passed · 99 skipped · 3,801 total
Contamination audit
Unknown
See the audit notes for this run
Patch size
26vs 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
hugolib/hugo_sites_build.goindex 823f9811e..993559c00 100644@@ -1078,6 +1078,13 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo // It's hard to determine the exact change set of this, // so be very coarse grained for now. changes = append(changes, identity.GenghisKhan)+ case files.ComponentFolderStatic:+ // Static files are synced to the destination directory separately+ // (by the static syncer when running the server). They are not part+ // of the page/resource dependency graph, so there is nothing to+ // resolve here; we just need to handle the component to avoid the+ // panic in the default case below.+ logger.Println("Static changed", pathInfo.Path()) case files.ComponentFolderArchetypes: // Ignore for now. default:hugolib/rebuild_test.goindex b6d716c37..7bf926924 100644@@ -309,6 +309,25 @@ Pages: {{ range .Site.RegularPages }}{{ .RelPermalink }}|{{ end }}$ b.AssertFileContent("public/index.html", "Pages: /bar/p1/|$") } +func TestRebuildRenameDirectoryStatic(t *testing.T) {+ files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+-- static/mydir/file.txt --+Static file content.+-- layouts/index.html --+Home.+`+ b := TestRunning(t, files)++ b.AssertFileContent("public/index.html", "Home.")++ b.RenameDir("static/mydir", "static/mydirrenamed").Build()++ b.AssertFileContent("public/index.html", "Home.")+}+ func TestRebuildAddRegularFileRegularPageUsedInHomeMultilingual(t *testing.T) { files := ` -- hugo.toml --
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
What the agent reported
The reviewer confirms the fix is correct, minimal, and well-scoped, and the regression test genuinely reproduces the panic. The task is complete.
Summary
What was wrong
Deleting or renaming a directory inside static/ while hugo server was running caused a panic:
panic: unknown component: "static" in processPartialFileEvents (hugolib/hugo_sites_build.go:1084)
In hugolib/hugo_sites_build.go, the processPartialFileEvents function processes filesystem events for partial rebuilds. When a static/ directory is removed, the event resolves to a *paths.Path whose Component() is "static" (the extensionless-directory removal path appends /_index.md to the path string but keeps the static component). That path is fed into the handleChange closure's switch pathInfo.Component(), which only had cases for content/layouts/assets/data/i18n/archetypes — so "static" fell through to default: panic(...).
What I changed
hugolib/hugo_sites_build.go(production fix): Added acase files.ComponentFolderStatic:before thedefaultpanic. Static files are synced to the output separately (by the static syncer in server mode) and aren't part of the page/resource dependency graph, so the case only logs — it adds no identity changes, doesn't setneedsPagesAssemble, and doesn't trigger a coarse rebuild. Minimal, 7-line change.hugolib/rebuild_test.go(regression test): AddedTestRebuildRenameDirectoryStatic, which seedsstatic/mydir/file.txt, runs in watch/running mode, then renames the static directory and rebuilds — exactly the reported scenario.
Test evidence
- The test-writer confirmed fail-before/pass-after: with the fix temporarily reverted, the test fails with
panic: unknown component: "static"athugo_sites_build.go:1084; with the fix restored it passes. - My authoritative gate —
./bt-test -run TestRebuild ./hugolib/— passed: 59 rebuild tests passed, 0 failed, including the newTestRebuildRenameDirectoryStatic.
All changes are left uncommitted in the working tree. (Note: the pre-existing AGENTS.md/CLAUDE.md deletions shown in git status predate this task and are unrelated to the fix.)