Resolve native glob prefix parents through their link targets

This commit is contained in:
2026-12-05 21:55:41 +00:00
parent 2e1a74e8c0
commit ad23955984
3 changed files with 23 additions and 6 deletions

View File

@@ -7,7 +7,12 @@ This review changes no production code or tests.
## 1. Resolve native link targets before parent steps in a literal glob prefix
Priority: P2. Status: open.
Priority: P2. Status: complete.
Completed: literal prefix parent steps now use the resolved directory identity.
The existing host/native glob regression covers both literal and wildcard link
spellings, fails before the fix, and passes afterward. Focused glob/native-link
tests and `./scripts/check.sh` pass.
Relevant code: `globStartingCandidates` in
[glob.go](../../internal/engine/glob.go), particularly lines 349–354;

View File

@@ -347,7 +347,17 @@ func globStartingCandidates(access *filesystemAccess, base, pattern string, segm
break
}
lexical, lexicalErr := resolveLiteralImportSelector(&prefixAccess, candidate.path, literal)
physical, physicalErr := resolveLiteralImportSelector(&prefixAccess, candidate.accessPath, literal)
parentAccess := candidate.accessPath
if literal == ".." {
target, err := prefixAccess.importEntryTarget(parentAccess, nil, true)
if err != nil {
return nil, 0, []Diagnostic{globCandidateDiagnostic(err, site.location, "glob parent directory could not be inspected")}
}
if target.identity != "" {
parentAccess = target.identity
}
}
physical, physicalErr := resolveLiteralImportSelector(&prefixAccess, parentAccess, literal)
if lexicalErr != nil || physicalErr != nil {
return nil, 0, []Diagnostic{*importSelectionDiagnostic(site, CodeImportOutsideRoot, "glob prefix is outside the selected namespace")}
}

View File

@@ -254,11 +254,13 @@ func TestSelectGlobParentUsesMatchedLinkTarget(t *testing.T) {
{"host", host, root, file}, {"native", native, ".", "targets/shared/one.yml"},
} {
t.Run(mode.name, func(t *testing.T) {
selection, diagnostics := selectGlobForTestWithDiagnostics(t, mode.access, mode.base, " - glob: services/*/../shared/*.yml\n required: true\n")
if len(diagnostics) != 0 || len(selection.candidates) != 1 || selection.candidates[0].accessPath != mode.want {
t.Fatalf("selection=%#v, diagnostics=%#v", selection, diagnostics)
for _, pattern := range []string{"services/*/../shared/*.yml", "services/alias/../shared/*.yml"} {
selection, diagnostics := selectGlobForTestWithDiagnostics(t, mode.access, mode.base, " - glob: "+pattern+"\n required: true\n")
if len(diagnostics) != 0 || len(selection.candidates) != 1 || selection.candidates[0].accessPath != mode.want {
t.Fatalf("pattern %q: selection=%#v, diagnostics=%#v", pattern, selection, diagnostics)
}
}
selection = selectGlobForTest(t, mode.access, mode.base, " - glob: services/*/../shared/*.yml\n follow: false\n")
selection := selectGlobForTest(t, mode.access, mode.base, " - glob: services/*/../shared/*.yml\n follow: false\n")
if len(selection.candidates) != 0 {
t.Fatalf("unfollowed link selected=%#v", selection)
}