Validate external imports and retain distinct glob traversal targets
This commit is contained in:
@@ -15,6 +15,9 @@ selection in `import_selection.go` preserves a normalized
|
||||
namespace path separately from canonical access identity: overlapping roots
|
||||
coalesce the same candidate spelling in that namespace, while aliases reached
|
||||
through distinct spellings retain separate inclusion routes for admission.
|
||||
Glob parent traversal also retains distinct physical targets when link routes
|
||||
normalize to the same lexical spelling, so neither branch disappears before
|
||||
discovery and admission finish.
|
||||
Directory searches walk each distinct normalized root once, apply all filename
|
||||
patterns to discovered names, and form a set union of matching candidates across
|
||||
overlapping roots. Exclusions are applied as set difference after discovery and
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
# Absolute and parent-relative imports
|
||||
|
||||
Status: agreed target behavior; implementation pending.
|
||||
Status: complete; see the [completed implementation record](implementation.md).
|
||||
Baseline: `9037fdb74e1cd4f35ac78032f1bf70854b0e8754`.
|
||||
|
||||
The current [import contract](../config.md#explicit-imports),
|
||||
[resource-context contract](../config.md#source-resource-contexts), and
|
||||
[import internals](../internal/imports.md) own implemented behavior.
|
||||
[ADR 0026](../adr/0026-optional-host-import-containment.md) records the decision;
|
||||
the [consumer example](../../examples/consumers/external_imports_test.go) shows use.
|
||||
|
||||
## Purpose and agreed direction
|
||||
|
||||
Applications should be able to import shared configuration from locations such
|
||||
@@ -26,15 +32,15 @@ This feature changes filesystem selection and access. Existing composition,
|
||||
precedence, configuration destinations, schema/version handling and inspection
|
||||
semantics continue to apply.
|
||||
|
||||
## Current baseline
|
||||
## Planning baseline (historical)
|
||||
|
||||
The [configuration contract](../config.md#explicit-imports) currently accepts
|
||||
At the planning baseline, the configuration contract accepted
|
||||
slash-separated relative selectors and rejects absolute paths. Host access uses
|
||||
a canonical root which defaults to the selected main file's directory. Relative
|
||||
targets and symlink targets must remain within that root. A caller can supply a
|
||||
wider root, but absolute selector syntax remains invalid.
|
||||
|
||||
Host byte, reader and mapping sources currently require explicit absolute
|
||||
At that baseline, host byte, reader and mapping sources required explicit absolute
|
||||
`BaseDir` and `Root` directories for filesystem imports. A `Filesystem.File`
|
||||
source uses its selected namespace, with `.` as its default root. Synthetic
|
||||
sources with native context provide namespace-relative base and root directories.
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
# Implementation plan: absolute and parent-relative imports
|
||||
|
||||
Status: implementation in progress.
|
||||
Status: complete.
|
||||
Planning baseline: `8c04dfd`; runtime baseline: `a441347`.
|
||||
|
||||
Implemented behavior is owned by the [import contract](../config.md#explicit-imports),
|
||||
[resource-context contract](../config.md#source-resource-contexts), and
|
||||
[import internals](../internal/imports.md). The decision is recorded in
|
||||
[ADR 0026](../adr/0026-optional-host-import-containment.md); the maintained
|
||||
[consumer example](../../examples/consumers/external_imports_test.go) demonstrates
|
||||
the public workflow.
|
||||
|
||||
## Scope and execution
|
||||
|
||||
Implement the agreed end state in [absolute-imports.md](absolute-imports.md).
|
||||
@@ -216,8 +223,8 @@ weakening explicit-root access or retaining handles in published metadata.
|
||||
|
||||
Completed: the shared iterative link resolver supports absolute host coordinates
|
||||
and ordinary unbounded Lstat/Readlink operations. Focused link/access/regular-file
|
||||
checks pass. Overlay integration remains pending in stage 10; the broader FIFO
|
||||
test currently reports a missing overlay because access still uses import mode.
|
||||
checks pass. Overlay integration was deferred to stage 10, which resolved the
|
||||
intermediate FIFO overlay failure caused by using import mode for overlay access.
|
||||
|
||||
Read `filesystem_links.go`, `filesystem_links_test.go`, `directory_walk.go` and
|
||||
the regular-file tests. Update host import-entry inspection and link operations
|
||||
@@ -506,6 +513,14 @@ roadmap points to canonical owners after completion.
|
||||
|
||||
## Stage 15 — Validate and finish the sprint
|
||||
|
||||
Completed: the context/capture tables and feature diff were reviewed against
|
||||
behavioral evidence. Final audit found and corrected glob union of distinct
|
||||
physical parent directories after wildcard links; host/native regression tests
|
||||
pass. Go 1.27.4 focused engine/public/consumer checks, ./scripts/check.sh and
|
||||
go test -race ./... pass. Changed local Markdown links resolve. Public/dependency
|
||||
boundaries, terminal failures, cleanup and retained resource coordinates pass
|
||||
their existing suites. No release publication or downstream changes were made.
|
||||
|
||||
Use installed compatible Go and explicitly acquired dependencies as described
|
||||
in development guidance. Run focused commands as relevant after dependent
|
||||
stages compile:
|
||||
|
||||
@@ -5,13 +5,19 @@ import (
|
||||
"io/fs"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const globReadBatch = 128
|
||||
|
||||
// A parent step can give distinct link targets the same lexical spelling.
|
||||
// Keep both coordinates until traversal and source admission have completed.
|
||||
type globCandidateKey struct {
|
||||
lexical string
|
||||
physical string
|
||||
}
|
||||
|
||||
// selectGlobImportCandidates expands path components while retaining the
|
||||
// lexical spelling used for filtering and later source admission.
|
||||
func selectGlobImportCandidates(access *filesystemAccess, basePath string, spec importDeclarationSpec, policy resolvedImportPolicy, limits importLimits, accounting *importAccounting) (importSelection, []Diagnostic) {
|
||||
@@ -37,7 +43,7 @@ func selectGlobImportCandidates(access *filesystemAccess, basePath string, spec
|
||||
literal, patterned := globLiteralSegment(segment)
|
||||
// nextByPath is the set union of candidates reached from each matching
|
||||
// parent at this segment; final exclusions below are set difference.
|
||||
nextByPath := make(map[string]selectedImportCandidate)
|
||||
nextByPath := make(map[globCandidateKey]selectedImportCandidate)
|
||||
for _, parent := range candidates {
|
||||
if !patterned {
|
||||
childPath := access.join(parent.path, literal)
|
||||
@@ -60,7 +66,7 @@ func selectGlobImportCandidates(access *filesystemAccess, basePath string, spec
|
||||
return importSelection{}, diagnostics
|
||||
}
|
||||
if !missing {
|
||||
nextByPath[candidate.path] = candidate
|
||||
nextByPath[globCandidateKey{candidate.path, candidate.accessPath}] = candidate
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -78,7 +84,7 @@ func selectGlobImportCandidates(access *filesystemAccess, basePath string, spec
|
||||
return importSelection{}, []Diagnostic{*diagnostic}
|
||||
}
|
||||
if selected {
|
||||
nextByPath[candidate.path] = candidate
|
||||
nextByPath[globCandidateKey{candidate.path, candidate.accessPath}] = candidate
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,16 +243,17 @@ func globCandidateDiagnostic(err error, location Location, message string) Diagn
|
||||
return globFilesystemDiagnostic(err, message, location)
|
||||
}
|
||||
|
||||
func candidatesFromMap(candidates map[string]selectedImportCandidate) []selectedImportCandidate {
|
||||
paths := make([]string, 0, len(candidates))
|
||||
for candidatePath := range candidates {
|
||||
paths = append(paths, candidatePath)
|
||||
}
|
||||
slices.Sort(paths)
|
||||
result := make([]selectedImportCandidate, 0, len(paths))
|
||||
for _, candidatePath := range paths {
|
||||
result = append(result, candidates[candidatePath])
|
||||
func candidatesFromMap(candidates map[globCandidateKey]selectedImportCandidate) []selectedImportCandidate {
|
||||
result := make([]selectedImportCandidate, 0, len(candidates))
|
||||
for _, candidate := range candidates {
|
||||
result = append(result, candidate)
|
||||
}
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
if result[i].path != result[j].path {
|
||||
return result[i].path < result[j].path
|
||||
}
|
||||
return result[i].accessPath < result[j].accessPath
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -265,3 +265,38 @@ func TestSelectGlobParentUsesMatchedLinkTarget(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectGlobRetainsDistinctPhysicalParents(t *testing.T) {
|
||||
root := canonicalTestPath(t, t.TempDir())
|
||||
for _, branch := range []string{"one", "two"} {
|
||||
writeImportFile(t, root, branch+"/unit/marker", "marker")
|
||||
writeImportFile(t, root, branch+"/shared/"+branch+".yml", "value: "+branch+"\n")
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(root, "services"), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for alias, target := range map[string]string{"a": "../one/unit", "b": "../two/unit"} {
|
||||
if err := os.Symlink(target, filepath.Join(root, "services", alias)); err != nil {
|
||||
t.Skipf("symlinks unavailable: %v", err)
|
||||
}
|
||||
}
|
||||
access, err := openHostAccess(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer access.close()
|
||||
for _, mode := range []struct {
|
||||
name string
|
||||
access *filesystemAccess
|
||||
base string
|
||||
}{
|
||||
{"host", access, root}, {"native", newNativeAccess(os.DirFS(root), ".", &namespaceToken{}), "."},
|
||||
} {
|
||||
t.Run(mode.name, func(t *testing.T) {
|
||||
selection := selectGlobForTest(t, mode.access, mode.base, " - glob: services/*/../shared/*.yml\n required: true\n")
|
||||
if len(selection.candidates) != 2 {
|
||||
t.Fatalf("distinct physical parents coalesced: %#v", selection)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user