73 lines
3.7 KiB
Go
73 lines
3.7 KiB
Go
package configuration
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"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)
|
|
}
|
|
}
|
|
|
|
func TestPromptInterpretationPreservesComposedOutputAndRejectsDuplicateNames(t *testing.T) {
|
|
definition := map[string]any{
|
|
"id": "example", "inputs": []any{map[string]any{"name": " document "}},
|
|
"messages": []any{map[string]any{"role": "user", "content": "hello"}},
|
|
"output": map[string]any{"format": "json", "validation_mode": "json_schema", "schema_path": " schema.json "},
|
|
}
|
|
state, err := load(mapping("prompt metadata", map[string]any{"prompts": []any{definition}}), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
selected, inspection, err := state.prompt("example")
|
|
if err != nil || selected.Validation.SchemaPath != "schema.json" || inspection.OutputContract.SchemaPath != "schema.json" || selected.Inputs[0].Name != "document" {
|
|
t.Fatalf("interpreted prompt = %+v, %+v, %v", selected, inspection, err)
|
|
}
|
|
composed := state.result.Config.Prompts[0]
|
|
if *composed.Output.SchemaPath != " schema.json " || composed.Inputs[0].Name != " document " {
|
|
t.Fatalf("composed prompt changed: %+v", composed)
|
|
}
|
|
definition["inputs"] = []any{map[string]any{"name": " document "}, map[string]any{"name": "document"}}
|
|
_, err = load(mapping("duplicate inputs", map[string]any{"prompts": []any{definition}}), nil)
|
|
if err == nil || !strings.Contains(err.Error(), "/prompts/0/inputs/1") || !strings.Contains(err.Error(), "duplicated") {
|
|
t.Fatalf("duplicate normalized names were not rejected: %v", err)
|
|
}
|
|
}
|