Backtestshugorun-20260930-140149#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 add the same core fix: a `files.ComponentFolderStatic` case in `processPartialFileEvents`, so the reported panic goes away with either one. Patch B goes further in a way that matters for the delete scenario. The old `SourceFilesystem.Contains` only checked directory mounts, via `dir.IsDir()`, with a prefix match. Deleted paths, especially file mounts such as `myfiles/robots.txt -> static/robots.txt`, may therefore not be recognised as belonging to the static filesystem, and the static syncer in the commands package would never see them. Patch B makes `Contains` stat-free by using `ReverseLookup`, so the static syncer can correctly identify deleted static files and directories, including file mounts. That addresses the underlying handling of deletions, not just the panic. On tests, Patch B adds two server testscripts that run the real `hugo server`, delete a mounted static file and a mounted static directory, and assert no stderr output, so a panic would fail them. These exercise the actual reported scenario end to end. Patch A's integration test removes a static directory in a `TestRunning` builder and only checks that the home page still renders. It likely does trigger the panic path, but it does not cover mounts or syncing. The `Contains` change carries some risk because it alters semantics for other callers, but the new behaviour is the more correct membership check. Overall, B is more complete and better tested.
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
22m 42s23 turns
Wall-clock time in the container
Full test suite
No new failures
3,693 passed · 99 skipped · 3,801 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
29vs 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..0009c5b03 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:+ // Static files are synced by the static syncer in the commands package. default: panic(fmt.Sprintf("unknown component: %q", pathInfo.Component())) }hugolib/rebuild_test.goindex b6d716c37..2b7ef9f8c 100644@@ -2211,3 +2211,30 @@ objects: ["o1"] b.AssertFileContent("public/objects/index.html", "Objects|taxonomy|<p>Objects content edited.</p>") b.AssertFileContent("public/objects/o1/index.html", "O1|term|") }++// Deleting a directory in static while the server is running used to panic+// with "unknown component: \"static\"".+func TestRebuildDeleteDirInStatic(t *testing.T) {+ t.Parallel()+ files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+disableKinds = ["term", "taxonomy", "sitemap", "robotstxt", "404", "rss"]+-- static/mydir/foo.txt --+Foo.+-- static/bar.txt --+Bar.+-- content/_index.md --+---+title: "Home"+---+-- layouts/home.html --+Home: {{ .Title }}|+`+ b := TestRunning(t, files)+ b.AssertFileContent("public/index.html", "Home: Home|")++ b.RemoveFiles("static/mydir/foo.txt", "static/mydir").Build()+ b.AssertFileContent("public/index.html", "Home: Home|")+}
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
I fixed the panic when a directory in static is deleted while hugo server is running. The new regression test fails on the old code with the reported panic and passes with the fix. ./bt-test couldn't build anything in this sandbox, so every test result below comes from running go test directly.
What was wrong: the switch pathInfo.Component() in processPartialFileEvents (hugolib/hugo_sites_build.go) has no case for static, and its default: panics with unknown component. Static files are normally filtered out earlier: commands/hugobuilder.go sends an event to the static syncer only if SourceFilesystems.IsStatic says the path is static. That check depends on RootMappingFs.Mounts (hugofs/rootmapping_fs.go:257), which quietly drops any mounted directory that no longer exists. So after a mounted static directory is deleted, its event can be misrouted to HugoSites.Build and hit the panic.
Change: one line in hugolib/hugo_sites_build.go. I added a no-op case files.ComponentFolderStatic: with a comment, next to the existing no-op for archetypes. Nothing in that code builds anything from static files, so skipping them loses nothing there.
Test: TestRebuildDeleteDirInStatic, added at the end of hugolib/rebuild_test.go. It builds a site with static/mydir/foo.txt, deletes the file and then the directory, rebuilds, and checks the home page still renders.
- Without the fix:
--- FAIL ... panic: unknown component: "static"athugo_sites_build.go:1084, matching the report. - With the fix:
--- PASS.
Test runs:
./bt-testcouldn't build any package: its module cache is empty and the network is blocked, so the report showsFAIL github.com/gohugoio/hugo/hugolib [setup failed]. I rango testagainst the existing module cache instead (GOMODCACHE=/bt/cache/go-mod GOPROXY=off).- On the full
./hugolibpackage, the only failures areTestModulePrivateRepoand the threeTestGitInfoFromGitModule*tests. They fail the same way on the unmodified code and depend on network or git module access. ./commandshas no tests.
Requirements:
- No panic when deleting a directory in static while the server runs: done. The regression test fails before the fix and passes after.
Not fixed: the fix stops the crash, but a misrouted event still never reaches the static syncer. So when a whole mounted static directory is deleted, its copied files can stay in the publish directory until the next full static sync. Fixing that means changing how IsStatic checks mounts, which affects code outside this bug, so I left it out.
The test harness sends events straight to HugoSites.Build, so it skips the command-layer routing. That means the test covers the panic, not the routing. I couldn't pin down exactly which paths get misrouted in the reporter's setup.
Everything is left as uncommitted edits in hugolib/hugo_sites_build.go and hugolib/rebuild_test.go. The AGENTS.md and CLAUDE.md deletions in the working tree were there before I started.