Test inherited configuration resolution

This commit is contained in:
2026-10-03 17:35:55 +00:00
parent bbb473a3d9
commit ea964707f7
3 changed files with 174 additions and 1 deletions

View File

@@ -75,6 +75,90 @@ backends:
}
}
func TestDocumentResolvesBackendInheritance(t *testing.T) {
result, err := loadDocumentBytes(`backends:
base:
endpoint: http://base.invalid/v1
api_key_env: BASE_API_KEY
concurrency_limit: 2
queue_capacity: 4
extra_params:
enabled: true
shared: visible
count: 7
child:
extends: base
queue_capacity: 0
extra_params:
enabled: false
nullable-child:
extends: base
queue_capacity: null
`)
if err != nil {
t.Fatalf("load inherited document: %v", err)
}
child := result.Config.Backends["child"]
if child.Endpoint != "http://base.invalid/v1" || child.APIKeyEnv != "BASE_API_KEY" || child.ConcurrencyLimit != 2 {
t.Fatalf("child did not inherit backend settings: %+v", child)
}
if child.QueueCapacity == nil || *child.QueueCapacity != 0 {
t.Fatalf("explicit zero queue capacity was not retained: %+v", child.QueueCapacity)
}
if child.ExtraParams["enabled"] != false || child.ExtraParams["shared"] != "visible" || child.ExtraParams["count"] != int64(7) {
t.Fatalf("child parameters were not combined with explicit presence: %#v", child.ExtraParams)
}
nullableChild := result.Config.Backends["nullable-child"]
if nullableChild.QueueCapacity != nil {
t.Fatalf("explicit null inherited the parent's queue capacity: %+v", nullableChild.QueueCapacity)
}
metadata := result.Metadata()
endpointPath := configkit.Keys("backends", "child", "endpoint")
field, known := metadata.Lookup(endpointPath)
if !known || !field.Explicit || !metadata.IsExplicit(endpointPath) {
t.Fatalf("inherited endpoint presence was lost: field=%+v known=%t", field, known)
}
wantFrom := configkit.Keys("backends", "base", "endpoint").String()
wantTo := endpointPath.String()
wantReference := configkit.Keys("backends", "child", "extends").String()
foundInheritance := false
for _, step := range field.Origin.Inheritance {
if step.From.String() == wantFrom && step.To.String() == wantTo && step.Reference.String() == wantReference {
foundInheritance = true
break
}
}
if !foundInheritance {
t.Fatalf("inherited endpoint provenance missing: %+v", field.Origin.Inheritance)
}
settings := Settings(result.Config)
wantIDs := []string{"base", "child", "nullable-child"}
if len(settings.Backends) != len(wantIDs) {
t.Fatalf("backend definitions were dropped: %+v", settings.Backends)
}
for i, want := range wantIDs {
if settings.Backends[i].ID != want {
t.Fatalf("backend IDs are not sorted: %+v", settings.Backends)
}
}
convertedChild := settings.Backends[1]
if convertedChild.Endpoint != child.Endpoint || convertedChild.APIKeyEnv != child.APIKeyEnv || convertedChild.ConcurrencyLimit != 2 {
t.Fatalf("inherited settings changed during conversion: %+v", convertedChild)
}
if convertedChild.QueueCapacity == nil || *convertedChild.QueueCapacity != 0 {
t.Fatalf("zero queue capacity presence changed during conversion: %+v", convertedChild.QueueCapacity)
}
if value := convertedChild.ExtraParams["count"]; value != int64(7) {
t.Fatalf("dynamic integer changed during conversion: %T %v", value, value)
}
if settings.Backends[2].QueueCapacity != nil {
t.Fatalf("nullable queue capacity changed during conversion: %+v", settings.Backends[2].QueueCapacity)
}
}
func TestDocumentRecordsEffectiveNormalization(t *testing.T) {
result, err := loadDocumentBytes(`prompt_dir: " ./one/../two "
profile_dir: " "