Exercise document-root controls through the public API

This commit is contained in:
2026-11-02 00:44:04 +00:00
parent eb87a10e1c
commit cf9e2fd677
24 changed files with 196 additions and 91 deletions

View File

@@ -19,7 +19,7 @@ func TestImportDepthChecksSuffixAfterSaturation(t *testing.T) {
{"-0", true},
} {
t.Run(test.depth, func(t *testing.T) {
main := writeFacadeImportFile(t, t.TempDir(), "main.yml", "value: true\nconfigkit:\n imports:\n - dir: absent\n recursive: true\n depth: "+test.depth+"\n")
main := writeFacadeImportFile(t, t.TempDir(), "main.yml", "value: true\nconfig:\n imports:\n - dir: absent\n recursive: true\n depth: "+test.depth+"\n")
result, err := Load[map[string]any](File(main), Options[map[string]any]{Imports: true})
if test.valid {
if err != nil || result.Config["value"] != true {
@@ -31,7 +31,7 @@ func TestImportDepthChecksSuffixAfterSaturation(t *testing.T) {
if !errors.As(err, &loadError) || len(loadError.Diagnostics()) != 1 {
t.Fatalf("invalid depth accepted: %v", err)
}
if diagnostic := loadError.Diagnostics()[0]; diagnostic.Code != CodeImportInvalid || diagnostic.Path.String() != "/configkit/imports/0/depth" {
if diagnostic := loadError.Diagnostics()[0]; diagnostic.Code != CodeImportInvalid || diagnostic.Path.String() != "/config/imports/0/depth" {
t.Fatalf("invalid depth diagnostic = %#v", diagnostic)
}
})
@@ -47,12 +47,12 @@ func TestImportDefaultsApplyToTransitiveAndUnderlayImports(t *testing.T) {
IgnoredDeep string `yaml:"ignored_deep"`
}
directory := t.TempDir()
mainPath := writeFacadeImportFile(t, directory, "main.yml", `configkit:
mainPath := writeFacadeImportFile(t, directory, "main.yml", `config:
imports:
- path: parent/parent.yml
main: main
`)
writeFacadeImportFile(t, directory, "parent/parent.yml", `configkit:
writeFacadeImportFile(t, directory, "parent/parent.yml", `config:
imports:
- dir: generated
- dir: explicit
@@ -64,7 +64,7 @@ main: main
explicitPath := writeFacadeImportFile(t, directory, "parent/explicit/exception.yaml", "exception: declaration\n")
writeFacadeImportFile(t, directory, "parent/explicit/deep/ignored.yaml", "ignored_deep: wrong-depth\n")
writeFacadeImportFile(t, directory, "parent/explicit/ignored.cfg", "ignored_deep: wrong-explicit-pattern\n")
underlayPath := writeFacadeImportFile(t, directory, "underlay.yml", `configkit:
underlayPath := writeFacadeImportFile(t, directory, "underlay.yml", `config:
imports:
- dir: underlay-files
`)
@@ -97,7 +97,7 @@ func TestImportDefaultsPreserveEmptyPatternAndRequiredness(t *testing.T) {
Hidden string `yaml:"hidden"`
}
directory := t.TempDir()
mainPath := writeFacadeImportFile(t, directory, "main.yml", `configkit:
mainPath := writeFacadeImportFile(t, directory, "main.yml", `config:
imports:
- dir: snippets
`)
@@ -118,7 +118,7 @@ func TestImportDefaultsPreserveEmptyPatternAndRequiredness(t *testing.T) {
t.Fatalf("empty pattern = %#v, %v", empty, err)
}
emptySources := empty.Sources()
if len(emptySources) != 1 || len(emptySources[0].EmptyImportSelections) != 1 || emptySources[0].EmptyImportSelections[0].Path.String() != "/configkit/imports/0" || emptySources[0].EmptyImportSelections[0].Selector != ImportSelectorDirectory {
if len(emptySources) != 1 || len(emptySources[0].EmptyImportSelections) != 1 || emptySources[0].EmptyImportSelections[0].Path.String() != "/config/imports/0" || emptySources[0].EmptyImportSelections[0].Selector != ImportSelectorDirectory {
t.Fatalf("empty-pattern evidence = %#v", emptySources)
}
required := true
@@ -141,7 +141,7 @@ func TestImportDefaultsAreSnapshottedBeforeOrdinaryAndLayeredCallbacks(t *testin
t.Run(map[bool]string{false: "ordinary", true: "layered"}[layered], func(t *testing.T) {
directory := t.TempDir()
mainPath := writeFacadeImportFile(t, directory, "main.yml", `version: v1
configkit:
config:
imports:
- dir: parts
`)
@@ -229,7 +229,7 @@ func TestPublicImportSelectionSnapshotsAreDetachedAcrossResultErrorAndResolution
Value string `yaml:"value"`
}
directory := t.TempDir()
mainPath := writeFacadeImportFile(t, directory, "main.yml", `configkit:
mainPath := writeFacadeImportFile(t, directory, "main.yml", `config:
imports:
- dir: absent
value: loaded
@@ -242,7 +242,7 @@ value: loaded
}
first.EmptyImportSelections[0].Path = Keys("callback mutation")
second, ok := resolution.Source("source-1")
if !ok || second.EmptyImportSelections[0].Path.String() != "/configkit/imports/0" {
if !ok || second.EmptyImportSelections[0].Path.String() != "/config/imports/0" {
t.Fatalf("resolution snapshot changed after mutation: %#v", second)
}
callbackPath = second.EmptyImportSelections[0].Path.String()
@@ -251,7 +251,7 @@ value: loaded
if err != nil {
t.Fatal(err)
}
if callbackPath != "/configkit/imports/0" {
if callbackPath != "/config/imports/0" {
t.Fatalf("callback path = %q", callbackPath)
}
sources := loaded.Sources()
@@ -259,11 +259,11 @@ value: loaded
t.Fatalf("result source evidence = %#v", sources)
}
sources[0].EmptyImportSelections[0].Path = Keys("result mutation")
if got := loaded.Sources()[0].EmptyImportSelections[0].Path.String(); got != "/configkit/imports/0" {
if got := loaded.Sources()[0].EmptyImportSelections[0].Path.String(); got != "/config/imports/0" {
t.Fatalf("result snapshot changed after mutation: %q", got)
}
failurePath := writeFacadeImportFile(t, directory, "failure.yml", `configkit:
failurePath := writeFacadeImportFile(t, directory, "failure.yml", `config:
imports:
- dir: absent
- path: required-missing.yml
@@ -275,11 +275,11 @@ value: loaded
t.Fatalf("failed load error = %T %v", err, err)
}
errorSources := loadError.Sources()
if len(errorSources) != 1 || len(errorSources[0].EmptyImportSelections) != 1 || errorSources[0].EmptyImportSelections[0].Path.String() != "/configkit/imports/0" {
if len(errorSources) != 1 || len(errorSources[0].EmptyImportSelections) != 1 || errorSources[0].EmptyImportSelections[0].Path.String() != "/config/imports/0" {
t.Fatalf("error source evidence = %#v", errorSources)
}
errorSources[0].EmptyImportSelections[0].Path = Keys("error mutation")
if got := loadError.Sources()[0].EmptyImportSelections[0].Path.String(); got != "/configkit/imports/0" {
if got := loadError.Sources()[0].EmptyImportSelections[0].Path.String(); got != "/config/imports/0" {
t.Fatalf("error snapshot changed after mutation: %q", got)
}
}