Test native PromptKit source composition and credential policy

This commit is contained in:
2026-10-04 12:46:23 +00:00
parent ec2ac3369b
commit ef504eabb2
3 changed files with 314 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ import (
"testing/fstest"
"time"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"gitea.maximumdirect.net/eric/promptkit"
@@ -880,7 +881,12 @@ func TestPromptKitClientUsesConfiguredLocalBackend(t *testing.T) {
defer server.Close()
profilePath := filepath.Join(t.TempDir(), "profiles.yml")
if err := os.WriteFile(profilePath, []byte(`profiles:
if err := os.WriteFile(profilePath, []byte(`backends:
local:
endpoint: http://operator.example.test/v1
concurrency_limit: 9
queue_capacity: 1
profiles:
local-profile:
backend: local
model: local-model
@@ -899,6 +905,27 @@ func TestPromptKitClientUsesConfiguredLocalBackend(t *testing.T) {
if err != nil {
t.Fatalf("NewPromptKitClient() error = %v, want nil", err)
}
configuration, err := client.engine.InspectConfiguration()
if err != nil {
t.Fatalf("InspectConfiguration() error = %v", err)
}
for _, test := range []struct {
path string
want string
}{
{path: "/backends/local/endpoint", want: server.URL + "/v1"},
{path: "/backends/local/concurrency_limit", want: "2"},
{path: "/backends/local/queue_capacity", want: "1"},
} {
path, err := configkit.ParsePath(test.path)
if err != nil {
t.Fatal(err)
}
explanation, found := configuration.Explain(path)
if !found || !explanation.Effective.Present || !strings.Contains(explanation.Effective.YAML, test.want) {
t.Fatalf("effective local setting %s = %+v, want %q", test.path, explanation.Effective, test.want)
}
}
localBackend.Endpoint = "http://127.0.0.1:1/v1"
request := contracts.StructuredCompletionRequest{
@@ -929,14 +956,22 @@ func TestPromptKitClientUsesConfiguredLocalBackend(t *testing.T) {
t.Fatalf("profile manifests = %#v, want local backend", manifests)
}
missingRegistrationPath := filepath.Join(t.TempDir(), "profiles.yml")
if err := os.WriteFile(missingRegistrationPath, []byte(`profiles:
local-profile:
backend: local
model: local-model
`), 0o600); err != nil {
t.Fatal(err)
}
clientWithoutRegistration, err := NewPromptKitClient(PromptKitClientConfig{
Assets: newTestPromptKitAssets(t),
ProfileFile: profilePath,
ProfileFile: missingRegistrationPath,
})
if clientWithoutRegistration != nil || err == nil || !errors.Is(err, promptkit.ErrInvalidConfig) {
t.Fatalf("NewPromptKitClient() without local registration = (%v, %v), want invalid configuration", clientWithoutRegistration, err)
}
if strings.Contains(err.Error(), "local-profile") || strings.Contains(err.Error(), profilePath) {
if strings.Contains(err.Error(), "local-profile") || strings.Contains(err.Error(), missingRegistrationPath) {
t.Fatalf("configuration error exposes profile details: %v", err)
}
if providerCalls.Load() != 1 {