Backtestshugorun-20260922-141813#15169

Issue #15169 Merged fix PR # Run 22 Sep 2026 · run-20260922-141813 gohugoio/hugo

resources/jsconfig: Address VS Code linting notice in jsconfig.json

Better

Our patch was judged better than the merged fix.

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

The lint fires for any source root that is at or below `dir`, because `filepath.Rel` yields a non-relative path (`*`, `sub/*`, etc.). Patch A fixes that whole class: it prepends `./` to every relative-but-non-dotted path while correctly leaving upward `..`/`../...` paths untouched, producing exactly the `./`-prefixed form VS Code asks for. Patch B only special-cases exact equality (`root == dir`) and drops that entry entirely; a descendant source root (a module/mount nested under the assets dir) would still emit a non-relative `sub/assets/*` and trigger the identical lint, so B leaves the reported problem partially unresolved. B's approach also silently deletes a mapping rather than correcting it, and for the common single-root case emits no jsconfig at all — a behavior change beyond what the issue asks. On tests, A adds a dedicated test asserting both the `./*` (root==dir) and `./sub/assets/*` (descendant) cases, which fail before and pass after and directly pin the reported symptom; B's test only asserts the nil result for the equality case and never verifies the relative-path formatting the issue is actually about. Both are small and well-commented, but A is the more complete root-cause fix with stronger, more targeted tests. A's minor cost (an extra `strings` import and a slightly fiddly prefix check) is outweighed by its correctness coverage.

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

5m 45s13 turns

Wall-clock time in the container

Full test suite

No new failures

3,692 passed · 99 skipped · 3,804 total

Contamination audit

Unknown

See the audit notes for this run

Patch size

26vs 11 merged

Changed lines, ours vs merged

When building a site that calls js.Build, the assets/jsconfig.json file looks like this:

{
 "compilerOptions": {
  "paths": {
   "*": [
    "*"
   ]
  }
 }
}

VS Code lints line 5 as follows:

Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?

The two patches

Our patch+26 −0
resources/jsconfig/jsconfig.goindex 4aabf69f7..2ba6883d8 100644@@ -16,6 +16,7 @@ package jsconfig import ( 	"path/filepath" 	"sort"+	"strings"  	"github.com/bep/helpers/maphelpers" )@@ -41,6 +42,12 @@ func (b *Builder) Build(dir string) *Config { 	for root := range b.sourceRoots.All() { 		rel, err := filepath.Rel(dir, filepath.Join(root, "*")) 		if err == nil {+			// Editors flag non-relative paths when baseUrl is unset, so make+			// sure paths at or below dir get a leading "./". Paths that go up+			// (".." or "../...") are already relative.+			if rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator)) {+				rel = "." + string(filepath.Separator) + rel+			} 			roots = append(roots, rel) 		} 	}resources/jsconfig/jsconfig_test.goindex ab9b739d1..2aefba8b2 100644@@ -38,3 +38,22 @@ func TestJsConfigBuilder(t *testing.T) {  	c.Assert(NewBuilder().Build("/a/b"), qt.IsNil) }++func TestJsConfigBuilderRelativePaths(t *testing.T) {+	c := qt.New(t)++	// A source root that is equal to the build dir should produce a relative+	// wildcard. VS Code lints non-relative paths ("./" is required) when+	// baseUrl is not set; see issue 15169.+	b := NewBuilder()+	b.AddSourceRoot("/a/b/assets")+	conf := b.Build("/a/b/assets")+	c.Assert(conf.CompilerOptions.Paths["*"], qt.DeepEquals, []string{filepath.FromSlash("./*")})++	// A source root that is a descendant of the build dir should also get the+	// leading "./".+	b = NewBuilder()+	b.AddSourceRoot("/a/b/sub/assets")+	conf = b.Build("/a/b")+	c.Assert(conf.CompilerOptions.Paths["*"], qt.DeepEquals, []string{filepath.FromSlash("./sub/assets/*")})+} 
Merged fix · PR #+11 −0
resources/jsconfig/jsconfig.goindex 4aabf69f7..d347cab19 100644@@ -39,6 +39,11 @@ func (b *Builder) Build(dir string) *Config { 	} 	var roots []string 	for root := range b.sourceRoots.All() {+		if root == dir {+			// We need mappings for other source roots (e.g. mounted modules), but not for the current one.+			// See issue 15169.+			continue+		} 		rel, err := filepath.Rel(dir, filepath.Join(root, "*")) 		if err == nil { 			roots = append(roots, rel)resources/jsconfig/jsconfig_test.goindex ab9b739d1..1fb8ef3cd 100644@@ -37,4 +37,10 @@ func TestJsConfigBuilder(t *testing.T) { 	c.Assert(string(data), qt.Not(qt.Contains), "baseUrl")  	c.Assert(NewBuilder().Build("/a/b"), qt.IsNil)++	// Issue 15169.+	b = NewBuilder()+	b.AddSourceRoot("/c/assets")+	conf = b.Build("/c/assets")+	c.Assert(conf, qt.IsNil) } 

What the agent reported

The fix is complete and the gate passes. Here's my final report.

What was wrong

Hugo's js.Build generates assets/jsconfig.json via resources/jsconfig/jsconfig.go. When a source root is at or below the build directory, filepath.Rel produces path values like "*" or "sub/assets/*" — values that don't begin with ./ or ../. VS Code's TypeScript language service flags these: "Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?"

Adding baseUrl — the other remedy the lint suggests — is explicitly forbidden here: the existing TestJsConfigBuilder asserts the marshaled JSON does not contain "baseUrl" (referencing issue 14991). So the correct fix is the lint's first suggestion: make the path values relative with a leading ./.

What I changed

resources/jsconfig/jsconfig.go — in Builder.Build, after computing each rel path, prefix it with ./ unless it is already a parent reference (.. or ../…), which is already relative. Added strings to imports. The guard uses a path-component check (rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator))) rather than a bare substring prefix, so a descendant directory whose name legitimately begins with .. (e.g. ..cache) is still correctly prefixed. OS-native separators are preserved (no ToSlash), so existing filepath.FromSlash(...) expectations hold on all platforms. No baseUrl field was added.

resources/jsconfig/jsconfig_test.go — new TestJsConfigBuilderRelativePaths covering the reported scenario (source root == build dir → ./*) plus a descendant case (./sub/assets/*). The existing TestJsConfigBuilder, including its baseUrl negative assertion, is untouched.

Test evidence

  • Before the fix, TestJsConfigBuilderRelativePaths failed: got ["*"], want ["./*"] — confirming it captures the bug.
  • After the fix, ./bt-test ./resources/jsconfig/: TestJsConfigBuilder PASS, TestJsConfigBuilderRelativePaths PASS, package ok (0.008s). Verified from test-report.json.

Requirements checklist

  1. Fix the VS Code lint on jsconfig.json line 5 ("*" non-relative path) — Implemented. Non-relative values now get a ./ prefix ("*" → "./*"); regression test asserts the outcome and passes only after the change.

Notes

  • The baseUrl route was considered and rejected — it directly contradicts the existing TestJsConfigBuilder assertion (issue 14991). I did not weaken that test.
  • The committed example docs/assets/jsconfig.json still shows the old "*" value; it's a generated artifact regenerated on the next docs build and outside the generator fix's scope, so I left it untouched to keep the change minimal.
  • The working tree's snapshot shows pre-existing staged deletions of root AGENTS.md and CLAUDE.md from the environment setup — unrelated to this ticket; I did not touch them. All my changes are left uncommitted in the working tree.