Backtestshugorun-20260917-015623#15169
resources/jsconfig: Address VS Code linting notice in jsconfig.json
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches eliminate the flagged `"*"` entry for the exact case where a source root equals the build dir, so both fix the literal issue reported. But correctness (criterion 1) favors B. The lint fires on any non-relative path — not only `"*"`. A source root nested *below* `dir` (e.g. root=/a/b/assets/sub, dir=/a/b/assets) yields `filepath.Rel` = `"sub/*"`, which is equally non-relative and would trigger the identical VS Code notice. Patch A's `root == dir` guard skips only the exact-match case and leaves such nested roots emitting `"sub/*"`, so it under-fixes. Patch B's `!strings.HasPrefix(rel, "..")` rule prepends `"./"` to every non-`..` result, correctly producing `"./*"` and `"./sub/*"`, covering both cases. B also implements exactly the remedy VS Code recommends (a leading `./`) while preserving the current-root mapping's intent, whereas A silently drops it. Tests (criterion 2): both discriminate (fail-before/pass-after), but A only asserts the config is nil — a proxy that never inspects the emitted path strings — while B asserts every path is relative and checks both `./*` and the nested `./sub/*`, directly verifying the property the issue is about. Scope and craft are comparable (B adds a `strings` import and uses `filepath.Separator`, consistent with the existing OS-separator handling and the `filepath.FromSlash` test). B is the more complete, better-tested fix.
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
23m 25s4 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
35vs 11 merged
Changed lines, ours vs merged
The issue
View on GitHubWhen 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
resources/jsconfig/jsconfig.goindex 4aabf69f7..7968768c5 100644@@ -16,6 +16,7 @@ package jsconfig import ( "path/filepath" "sort"+ "strings" "github.com/bep/helpers/maphelpers" )@@ -41,6 +42,13 @@ func (b *Builder) Build(dir string) *Config { for root := range b.sourceRoots.All() { rel, err := filepath.Rel(dir, filepath.Join(root, "*")) if err == nil {+ // filepath.Rel only emits relative results prefixed with "..";+ // any other result (e.g. "*", "sub/*" or ".config/*") is not a+ // relative path in TypeScript terms and needs a leading "./" so+ // editors don't flag it as a non-relative path without a baseUrl.+ if !strings.HasPrefix(rel, "..") {+ rel = "." + string(filepath.Separator) + rel+ } roots = append(roots, rel) } }resources/jsconfig/jsconfig_test.goindex ab9b739d1..2dabcb34c 100644@@ -38,3 +38,30 @@ func TestJsConfigBuilder(t *testing.T) { c.Assert(NewBuilder().Build("/a/b"), qt.IsNil) }++func TestJsConfigBuilderRelativePaths(t *testing.T) {+ c := qt.New(t)++ b := NewBuilder()+ // A source root that is the same directory as the build dir.+ b.AddSourceRoot("/a/b/assets")+ // A nested source root below the build dir.+ b.AddSourceRoot("/a/b/assets/sub")++ conf := b.Build("/a/b/assets")++ paths := conf.CompilerOptions.Paths["*"]++ // Every path must be relative, i.e. begin with a leading ".".+ // Non-relative paths (e.g. "*") are flagged by editors with:+ // "Non-relative paths are not allowed when 'baseUrl' is not set."+ for _, p := range paths {+ c.Assert(p, qt.Not(qt.Equals), "")+ c.Assert(string(p[0]), qt.Equals, ".", qt.Commentf("path %q must be relative (begin with a leading '.')", p))+ }++ // The same-dir case must be "./*" rather than "*".+ c.Assert(paths, qt.Contains, filepath.FromSlash("./*"))+ // The nested case must be "./sub/*".+ c.Assert(paths, qt.Contains, filepath.FromSlash("./sub/*"))+}
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
Both tests pass. The work is complete.
Summary
What was wrong
When a site calls js.Build, Hugo generates assets/jsconfig.json from resources/jsconfig/jsconfig.go. In Builder.Build, each source root's path is computed with filepath.Rel(dir, filepath.Join(root, "*")). When a source root is the same directory as the build dir, filepath.Rel returns just "*" — a non-relative path. The result is "paths": {"*": ["*"]}, which VS Code flags:
Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?
Adding a baseUrl was not an option: the existing TestJsConfigBuilder asserts the JSON must not contain baseUrl (issue 14991). So the correct fix is to make the paths relative with a leading ./.
What I changed (resources/jsconfig/jsconfig.go, production code only)
- Added the
stringsimport. - In
Builder.Build, anyfilepath.Relresult that is not already relative (i.e. does not start with..) is prefixed with./(using the OS separator). So"*"→"./*","sub/*"→"./sub/*", while already-relative"../../c/assets/*"paths are left unchanged. NobaseUrlis introduced.
I used the .. prefix as the "already relative" check (rather than a bare .) because filepath.Rel only ever emits relative results starting with ..; this also correctly handles hidden-directory roots like .config/*, which a bare-. check would have wrongly left non-relative (a point raised by the review).
Regression test (resources/jsconfig/jsconfig_test.go, tests only)
- Added
TestJsConfigBuilderRelativePaths, which builds with a same-dir root and a nested root and asserts every emitted path begins with.and that the same-dir case is./*and the nested case./sub/*. The existingTestJsConfigBuilderwas left untouched.
Test evidence (via ./bt-test, output in test-report.json)
- Before the fix:
TestJsConfigBuilderRelativePathsfailed (got "*", want leading "."), confirming the reported behavior. - After the fix: both
TestJsConfigBuilderandTestJsConfigBuilderRelativePathspass.
All changes are left uncommitted in the working tree.