Validate and compose provider endpoints
This commit is contained in:
@@ -1857,7 +1857,7 @@ func TestPrepareWorksWithInMemoryProfilesWithoutProfileFiles(t *testing.T) {
|
||||
SchemaDir: frameworkSchemaDir,
|
||||
}, promptkit.WithProfiles(promptkit.Profile{
|
||||
ID: "memory-profile",
|
||||
Endpoint: "http://memory-profile/v1",
|
||||
Endpoint: " https://memory-profile/nested/v1 ",
|
||||
Model: "memory-model",
|
||||
}))
|
||||
if err != nil {
|
||||
@@ -1878,6 +1878,9 @@ func TestPrepareWorksWithInMemoryProfilesWithoutProfileFiles(t *testing.T) {
|
||||
if prepared.EffectiveModelParams.Model != "memory-model" {
|
||||
t.Fatalf("expected in-memory profile model, got %q", prepared.EffectiveModelParams.Model)
|
||||
}
|
||||
if prepared.EffectiveModelParams.Endpoint != "https://memory-profile/nested/v1" {
|
||||
t.Fatalf("expected normalized in-memory profile endpoint, got %q", prepared.EffectiveModelParams.Endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInMemoryProfilesOverrideBuiltInsAndProfileSources(t *testing.T) {
|
||||
@@ -1961,6 +1964,79 @@ func TestWithProfilesRejectsInvalidExecutionSettings(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointValidationMapsPublicErrorCategories(t *testing.T) {
|
||||
t.Run("backend registration is invalid configuration", func(t *testing.T) {
|
||||
_, err := promptkit.NewEngine(
|
||||
promptkit.Config{PromptDir: frameworkPromptDir},
|
||||
promptkit.WithBackend(promptkit.Backend{ID: "invalid", Endpoint: "/v1"}),
|
||||
)
|
||||
if !errors.Is(err, promptkit.ErrInvalidConfig) {
|
||||
t.Fatalf("expected ErrInvalidConfig, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("in-memory profile is invalid configuration", func(t *testing.T) {
|
||||
_, err := promptkit.NewEngine(
|
||||
promptkit.Config{PromptDir: frameworkPromptDir},
|
||||
promptkit.WithProfiles(promptkit.Profile{
|
||||
ID: "invalid",
|
||||
Endpoint: "https://provider.example/v1?mode=chat",
|
||||
Model: "model",
|
||||
}),
|
||||
)
|
||||
if !errors.Is(err, promptkit.ErrInvalidConfig) {
|
||||
t.Fatalf("expected ErrInvalidConfig, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("file profile is a profile-load failure", func(t *testing.T) {
|
||||
profileFS := fstest.MapFS{
|
||||
"profiles/invalid.yaml": &fstest.MapFile{Data: []byte(`
|
||||
id: invalid
|
||||
endpoint: 'https://provider.example/v1#chat'
|
||||
model: model
|
||||
`)},
|
||||
}
|
||||
engine, err := promptkit.NewEngine(
|
||||
promptkit.Config{PromptDir: frameworkPromptDir},
|
||||
promptkit.WithProfileFS(profileFS, "profiles"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("construct engine: %v", err)
|
||||
}
|
||||
_, err = engine.InspectProfile(context.Background(), "invalid")
|
||||
if !errors.Is(err, promptkit.ErrProfileLoad) {
|
||||
t.Fatalf("expected ErrProfileLoad, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("request override is an invalid request", func(t *testing.T) {
|
||||
engine, err := promptkit.NewEngine(
|
||||
promptkit.Config{PromptDir: frameworkPromptDir},
|
||||
promptkit.WithProfiles(promptkit.Profile{
|
||||
ID: "valid",
|
||||
Endpoint: "https://provider.example/v1",
|
||||
Model: "model",
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("construct engine: %v", err)
|
||||
}
|
||||
_, err = engine.Prepare(context.Background(), promptkit.RunRequest{
|
||||
PromptID: frameworkMarkdownSummaryPromptID,
|
||||
ProfileID: "valid",
|
||||
Inputs: map[string]promptkit.ArtifactRef{
|
||||
"transcript": promptkit.Inline("Rin opens the gate."),
|
||||
"glossary": promptkit.Inline("gate: A guarded passage."),
|
||||
},
|
||||
Execution: &promptkit.ExecutionTargetOverride{Endpoint: "ftp://provider.example/v1"},
|
||||
})
|
||||
if !errors.Is(err, promptkit.ErrInvalidRequest) {
|
||||
t.Fatalf("expected ErrInvalidRequest, got %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestOpenAICompatibleProfileRunsThroughNormalProfilePath(t *testing.T) {
|
||||
fake := &fakeLLMClient{response: &promptkit.GenerateResponse{Content: "ok"}}
|
||||
prof := promptkit.OpenAICompatibleProfile(promptkit.OpenAICompatibleProfileConfig{
|
||||
|
||||
Reference in New Issue
Block a user