package configuration import ( "context" "testing" "go.maximumdirect.net/configkit" ) func TestTargetInterpretationPreservesComposedNestedValues(t *testing.T) { state, err := load(mapping("padded target", map[string]any{ "backends": []any{map[string]any{ "id": "local", "endpoint": " HTTPS://example.invalid/v1 ", "concurrency_limit": 1, "smoke_tests": map[string]any{ "reachability": map[string]any{"endpoint": " https://example.invalid/health "}, "authentication": map[string]any{"kind": " NONE ", "endpoint": " https://example.invalid/key "}, }, }}, "profiles": []any{map[string]any{"id": "partial", "backend": "local", "service_tier": " standard ", "api_key_env": " TOKEN "}}, }), nil) if err != nil { t.Fatal(err) } backend, err := state.GetBackend("local") if err != nil || backend.Endpoint != "https://example.invalid/v1" || backend.QueueCapacity != 1024 || backend.SmokeTests == nil || *backend.SmokeTests.Reachability.Endpoint != "https://example.invalid/health" || *backend.SmokeTests.Authentication.Kind != "none" || *backend.SmokeTests.Authentication.Endpoint != "https://example.invalid/key" { t.Fatalf("interpreted backend = %+v, %v", backend, err) } profile, err := state.GetProfile(context.Background(), "partial") if err != nil || profile.ResolvedTarget.ServiceTier != "standard" || profile.ResolvedTarget.APIKeyEnv != "TOKEN" { t.Fatalf("interpreted profile = %+v, %v", profile, err) } composed := state.result.Config.Backends[0] if *composed.Endpoint != " HTTPS://example.invalid/v1 " || composed.QueueCapacity != nil || *composed.SmokeTests.Reachability.Endpoint != " https://example.invalid/health " || *composed.SmokeTests.Authentication.Kind != " NONE " || *composed.SmokeTests.Authentication.Endpoint != " https://example.invalid/key " || *state.result.Config.Profiles[0].ServiceTier != " standard " || *state.result.Config.Profiles[0].APIKeyEnv != " TOKEN " { t.Fatalf("composed values were mutated: %+v", state.result.Config) } path := configkit.Keys("backends").Index(0).Key("smoke_tests").Key("authentication").Key("endpoint") field, found := state.result.Metadata().Lookup(path) if !found || len(field.Origin.Locations) == 0 || field.Origin.Operation == configkit.ChangeNormalization { t.Fatalf("nested field origin changed: %+v", field) } }