Strengthen composition and import selection tests
This commit is contained in:
@@ -605,6 +605,14 @@ Focused check: `go test ./internal/engine -run 'Import|Directive|Directory|Glob|
|
||||
Findings: **F10, F11**.
|
||||
Owners: `internal/engine/composition_fuzz_test.go`, `import_selection_test.go`.
|
||||
|
||||
Status: **complete** (F10, F11). Prior completed commits: `2736ddf`, `deb9aa5`,
|
||||
`ae3408a`, `ea27f17`, `08a8c25`, `877c497`, `8aba43d`, `7bf2f0c`,
|
||||
`0f9ecf1`, `119b42c`, `247a12b`, `4fcff5f`, `12d350a`, `08f2a8f`,
|
||||
`826062a`, `e4a5ecb`, `3122e2f`, `6f6130f`. Validation passed:
|
||||
`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./internal/engine -run 'FuzzCompositionAndOverlay|SelectNamedImports' -count=1`
|
||||
and `git diff --check`. The bounded composition campaign remains scheduled for
|
||||
Stage 33.
|
||||
|
||||
In `FuzzCompositionAndOverlay`, mutate an existing retained descendant or in-length
|
||||
element before comparing both original inputs with their saved values. Handle
|
||||
empty containers without assuming append affects shared storage. Keep existing
|
||||
|
||||
@@ -43,9 +43,10 @@ func FuzzCompositionAndOverlay(f *testing.F) {
|
||||
if differences := compareConfigurationValues(composed.root, reversed.root); len(differences) != 0 {
|
||||
t.Fatalf("composition order changed effective values: %#v", differences)
|
||||
}
|
||||
composed.root.Mapping = append(composed.root.Mapping, document.Entry{Key: "fuzz-detachment"})
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("composition result aliases an input document")
|
||||
if mutateExistingDocumentDescendant(composed.root) {
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("composition result aliases an input document")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +61,41 @@ func FuzzCompositionAndOverlay(f *testing.F) {
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("overlay mutated an input document")
|
||||
}
|
||||
overlaid.root.Mapping = append(overlaid.root.Mapping, document.Entry{Key: "fuzz-detachment"})
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("overlay result aliases an input document")
|
||||
if mutateExistingDocumentDescendant(overlaid.root) {
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("overlay result aliases an input document")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func mutateExistingDocumentDescendant(node *document.Node) bool {
|
||||
if node == nil {
|
||||
return false
|
||||
}
|
||||
// Empty containers have no existing element for the alias probe.
|
||||
switch node.Kind {
|
||||
case document.Mapping:
|
||||
if len(node.Mapping) == 0 {
|
||||
return false
|
||||
}
|
||||
entry := &node.Mapping[0]
|
||||
if mutateExistingDocumentDescendant(entry.Value) {
|
||||
return true
|
||||
}
|
||||
entry.Key += "-fuzz-detachment"
|
||||
return true
|
||||
case document.Sequence:
|
||||
if len(node.Sequence) == 0 {
|
||||
return false
|
||||
}
|
||||
if mutateExistingDocumentDescendant(node.Sequence[0]) {
|
||||
return true
|
||||
}
|
||||
node.Sequence[0].Text += "fuzz-detachment"
|
||||
return true
|
||||
default:
|
||||
node.Text += "fuzz-detachment"
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,8 +161,21 @@ func TestSelectNamedImportsChecksNormalizedPathsLexically(t *testing.T) {
|
||||
if len(diagnostics) != 0 || len(selection.candidates) != 2 {
|
||||
t.Fatalf("selection, diagnostics = %#v, %#v", selection, diagnostics)
|
||||
}
|
||||
if strings.Join(filesystem.statPaths, ",") != "a.yaml,a.yaml,z.yaml,z.yaml" {
|
||||
t.Fatalf("target stat order = %#v", filesystem.statPaths)
|
||||
if selection.candidates[0].path != "a.yaml" || selection.candidates[1].path != "z.yaml" {
|
||||
t.Fatalf("candidate order = %#v, want a.yaml then z.yaml", selection.candidates)
|
||||
}
|
||||
|
||||
failingFilesystem := &statOnlyImportFilesystem{statErrors: map[string]error{
|
||||
"a.yaml": fs.ErrPermission,
|
||||
"z.yaml": fs.ErrPermission,
|
||||
}}
|
||||
failingAccess := newNativeAccess(failingFilesystem, ".", &namespaceToken{})
|
||||
_, diagnostics = selectNamedImportCandidates(failingAccess, ".", specs[0], resolvedImportPolicy{})
|
||||
if len(diagnostics) != 1 || diagnostics[0].Code != CodeImportInvalid || diagnostics[0].Path.String() != "/configkit/imports/0/path/1" {
|
||||
t.Fatalf("first lexical failure = %#v, want /configkit/imports/0/path/1", diagnostics)
|
||||
}
|
||||
if diagnostics[0].Primary == nil || diagnostics[0].Primary.SourceID != "source-1" {
|
||||
t.Fatalf("first lexical failure location = %#v", diagnostics[0].Primary)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +239,6 @@ type statOnlyImportFilesystem struct {
|
||||
statErrors map[string]error
|
||||
openCalls int
|
||||
statCalls int
|
||||
statPaths []string
|
||||
}
|
||||
|
||||
func (filesystem *statOnlyImportFilesystem) Open(name string) (fs.File, error) {
|
||||
@@ -236,7 +248,6 @@ func (filesystem *statOnlyImportFilesystem) Open(name string) (fs.File, error) {
|
||||
|
||||
func (filesystem *statOnlyImportFilesystem) Stat(name string) (fs.FileInfo, error) {
|
||||
filesystem.statCalls++
|
||||
filesystem.statPaths = append(filesystem.statPaths, name)
|
||||
if err := filesystem.statErrors[name]; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user