Capture resolved backend and profile resources
This commit is contained in:
53
internal/configuration/resources_test.go
Normal file
53
internal/configuration/resources_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/promptkit/internal/backend"
|
||||
"go.maximumdirect.net/promptkit/internal/profile"
|
||||
)
|
||||
|
||||
func TestResolvedBackendAndProfileResources(t *testing.T) {
|
||||
state, err := load(mapping("resources", map[string]any{
|
||||
"backends": []any{map[string]any{"id": "local", "endpoint": "https://example.test/v1", "concurrency_limit": 2,
|
||||
"extra_params": map[string]any{"backend": true}, "smoke_tests": map[string]any{"default_profile": "missing", "reachability": map[string]any{}}}},
|
||||
"profiles": []any{
|
||||
map[string]any{"id": "parent", "backend": "local", "temperature": 0.4},
|
||||
map[string]any{"id": "child", "extends": map[string]any{"id": "parent"}, "temperature": 0, "endpoint": "", "extra_params": map[string]any{}},
|
||||
},
|
||||
}), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resource, err := state.InspectProfile(context.Background(), "child")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if resource.ID != "child" || resource.Backend == nil || *resource.Backend != "local" || resource.Endpoint == nil || *resource.Endpoint != "" || resource.Temperature == nil || *resource.Temperature != 0 || resource.Model != nil || resource.ExtraParams == nil || len(resource.ExtraParams) != 0 {
|
||||
t.Fatalf("profile resource = %+v", resource)
|
||||
}
|
||||
target, err := state.GetProfile(context.Background(), "child")
|
||||
if err != nil || target.ResolvedTarget.ExtraParams["backend"] != true {
|
||||
t.Fatalf("execution target = %+v, %v", target, err)
|
||||
}
|
||||
resourceBackend, err := state.InspectBackend(context.Background(), "local")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if resourceBackend.Endpoint != "https://example.test/v1" || resourceBackend.QueueCapacity == nil || *resourceBackend.QueueCapacity != 1024 || resourceBackend.SmokeTests == nil || resourceBackend.SmokeTests.DefaultProfile == nil || *resourceBackend.SmokeTests.DefaultProfile != "missing" || resourceBackend.SmokeTests.Reachability == nil || resourceBackend.SmokeTests.Reachability.Endpoint != nil {
|
||||
t.Fatalf("backend resource = %+v", resourceBackend)
|
||||
}
|
||||
if _, err := state.InspectBackend(context.Background(), "missing"); !errors.Is(err, backend.ErrBackendNotFound) {
|
||||
t.Fatalf("backend error = %v", err)
|
||||
}
|
||||
if _, err := state.InspectProfile(context.Background(), "missing"); !errors.Is(err, profile.ErrProfileNotFound) {
|
||||
t.Fatalf("profile error = %v", err)
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
if _, err := state.InspectBackend(ctx, "local"); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("cancellation = %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user