Backtestshugorun-20260917-015623#15208

Issue #15208 Merged fix PR # Run 17 Sep 2026 · run-20260917-015623 gohugoio/hugo

Add resources.Publish

Worse

The merged fix was judged better than our patch.

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

The two implementations of Publish are functionally identical — both assert r.(resource.Source), call s.Publish(), and return r with equivalent error handling — and both register the method via ns.AddMethodMapping equally cleanly, so correctness and scope are a wash. The deciding factor is test fidelity to the reported scenario. The issue's actual use case is a *transformed* resource fed into Publish (`resources.Get "main.js" | js.Build | resources.Publish`). Patch B's test exercises exactly that shape (`resources.Get "js/main.js" | minify | resources.Publish`), asserting both the returned resource's Name and that the transformed output (js/main.min.js) is actually written — so it verifies Publish works on the transformed-resource path the issue depends on. Patch A's test only publishes a raw `resources.Get` result with no transform, leaving the pipeline-with-transformation case (the real report) unverified. Patch B also matches the surrounding convention better (a `// See issue 15208.` comment mirroring the neighboring `issue 15086`/`12214` tests), whereas Patch A adds no issue reference. Patch A's doc comment is marginally more descriptive, but craft ranks below tests, and B's stronger, more representative test coverage outweighs it.

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

9m 38s1 turn

Wall-clock time in the container

Full test suite

No new failures

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

Contamination audit

Unknown

See the audit notes for this run

Patch size

37vs 37 merged

Changed lines, ours vs merged

So you can write:

{{ resources.Get "main.js" | js.Build | resources.Publish }}

Instead of:

{{ (resources.Get "main.js" | js.Build ).Publish }}

The first one reads much nicer in my eyes.

resources.Publish would return the Resource it gets as input.

The two patches

Our patch+37 −0
tpl/resources/init.goindex 9ce9bee20..65dbe33cb 100644@@ -50,6 +50,11 @@ func init() { 			[][2]string{}, 		) +		ns.AddMethodMapping(ctx.Publish,+			nil,+			[][2]string{},+		)+ 		ns.AddMethodMapping(ctx.ExecuteAsTemplate, 			nil, 			[][2]string{},tpl/resources/resources.goindex aae6ac1f3..38f125e7b 100644@@ -83,6 +83,19 @@ func (ns *Namespace) Copy(s any, r resource.Resource) (resource.Resource, error) 	return ns.createClient.Copy(r, targetPath) } +// Publish publishes r to its target path and returns r unchanged so it can be+// used in a pipeline.+func (ns *Namespace) Publish(r resource.Resource) (resource.Resource, error) {+	dst, ok := r.(resource.Source)+	if !ok {+		return nil, fmt.Errorf("resource %T does not implement resource.Source", r)+	}+	if err := dst.Publish(); err != nil {+		return nil, err+	}+	return r, nil+}+ // Get locates the filename given in Hugo's assets filesystem // and creates a Resource object that can be used for further transformations. func (ns *Namespace) Get(filename any) resource.Resource {tpl/resources/resources_integration_test.goindex b7f86111c..91d091e3c 100644@@ -169,6 +169,25 @@ Home. 	b.AssertFileExists("public/b.txt", true) // failing test } +func TestResourcesPublish(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ['page','rss','section','sitemap','taxonomy','term']+-- assets/main.js --+console.log("Hello");+-- layouts/home.html --+{{ $r := resources.Get "main.js" | resources.Publish }}+RelPermalink: {{ $r.RelPermalink }}+`++	b := hugolib.Test(t, files)++	b.AssertFileExists("public/main.js", true)+	b.AssertFileContent("public/index.html", "RelPermalink: /main.js")+}+ func TestGlobalResourcesNotPublishedRegressionIssue12214(t *testing.T) { 	t.Parallel()  
Merged fix · PR #+37 −0
tpl/resources/init.goindex 9ce9bee20..0cda68c4c 100644@@ -90,6 +90,11 @@ func init() { 			[][2]string{}, 		) +		ns.AddMethodMapping(ctx.Publish,+			nil,+			[][2]string{},+		)+ 		ns.AddMethodMapping(ctx.PostProcess, 			nil, 			[][2]string{},tpl/resources/resources.goindex aae6ac1f3..88722fb07 100644@@ -296,6 +296,18 @@ func (ns *Namespace) Minify(r resources.ResourceTransformer) (resource.Resource, 	return ns.minifyClient.Minify(r) } +// Publish publishes r to the destination and returns it.+func (ns *Namespace) Publish(r resource.Resource) (resource.Resource, error) {+	s, ok := r.(resource.Source)+	if !ok {+		return nil, fmt.Errorf("%T can not be published", r)+	}+	if err := s.Publish(); err != nil {+		return nil, err+	}+	return r, nil+}+ // PostProcess processes r after the build. // // Deprecated: Use templates.Defer instead.tpl/resources/resources_integration_test.goindex b7f86111c..b5c611d52 100644@@ -278,6 +278,26 @@ disableKinds = ['page','section','rss','sitemap','taxonomy','term'] 	b.AssertLogContains("! WARN  Dart Sass: hugo:vars") } +// See issue 15208.+func TestPublish(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ["taxonomy", "term", "section", "RSS", "sitemap", "robotsTXT", "404"]+-- assets/js/main.js --+let foo;+-- layouts/home.html --+{{ $r := resources.Get "js/main.js" | minify | resources.Publish }}+Name: {{ $r.Name }}|+`++	b := hugolib.Test(t, files)++	b.AssertFileContent("public/index.html", "Name: /js/main.js|")+	b.AssertFileExists("public/js/main.min.js", true)+}+ // See issue 15086. func TestPostProcessDeprecated(t *testing.T) { 	t.Parallel() 

What the agent reported

The reviewer confirms the change is correct, minimal, and complete. Done.

Summary

What was requested: A new template function resources.Publish so a resource can be published inline within a pipeline —

{{ resources.Get "main.js" | js.Build | resources.Publish }}

— instead of the awkward {{ (resources.Get "main.js" | js.Build ).Publish }}. It should return the Resource it receives as input so the pipeline keeps flowing.

What I changed (3 files, all uncommitted):

  1. tpl/resources/resources.go — Added a Publish method on *Namespace, placed next to the existing Copy method: go func (ns *Namespace) Publish(r resource.Resource) (resource.Resource, error) { dst, ok := r.(resource.Source) if !ok { return nil, fmt.Errorf("resource %T does not implement resource.Source", r) } if err := dst.Publish(); err != nil { return nil, err } return r, nil } The Publish() error method lives on the internal resource.Source interface (not resource.Resource), so the input is type-asserted before calling it. On success it returns the same resource r, enabling pipeline chaining.
  1. tpl/resources/init.go — Registered ctx.Publish via AddMethodMapping, following the existing pattern.
  1. tpl/resources/resources_integration_test.go — Added TestResourcesPublish, which runs {{ $r := resources.Get "main.js" | resources.Publish }} through the real template pipeline, asserts the file lands at public/main.js, and asserts $r.RelPermalink renders — proving the return value is the usable resource.

Test evidence (./bt-test, results from test-report.json):

  • TestResourcesPublish — PASS
  • TestGet, TestCopy, TestCopyPageShouldFail, TestGlobalResourcesNotPublishedRegressionIssue12190, TestGlobalResourcesNotPublishedRegressionIssue12214 — all PASS
  • 0 failures across the entire suite.

Note: The regression test could not be observed failing before the implementation, because the implementer and test-writer ran concurrently and the method was already present when the test first ran. However, the test invokes resources.Publish purely through the template pipeline with no stub or workaround, so it genuinely depends on the new function — removing the method would break the test. One pre-existing, unrelated quirk was left untouched as instructed: a duplicate ctx.Match registration already in init.go.