84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package usecase
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"math"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/promptkit/internal/domain"
|
|
)
|
|
|
|
func TestRunnerPrepareExecutionRejectsInvalidExecutionSettings(t *testing.T) {
|
|
runner := NewRunner(
|
|
&fakePromptRepo{def: promptDef(domain.FormatText, domain.ValidationNone, 0)},
|
|
&fakeExecutionProfileRepo{profiles: map[string]*domain.ExecutionProfile{"exec": defaultExecutionProfile()}},
|
|
nil,
|
|
defaultArtifactReader(),
|
|
defaultRenderer(),
|
|
&fakeLLM{forbid: true},
|
|
nil,
|
|
nil,
|
|
)
|
|
|
|
_, err := runner.PrepareExecution(context.Background(), domain.RunRequest{
|
|
PromptID: "p",
|
|
ProfileID: "exec",
|
|
Inputs: singleInputRef(),
|
|
Execution: &domain.ExecutionTargetOverride{TopP: float64Ptr(math.Inf(-1))},
|
|
})
|
|
if !errors.Is(err, ErrInvalidRequest) {
|
|
t.Fatalf("expected ErrInvalidRequest, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestRunnerPrepareExecutionValidatesAndNormalizesRequestEndpoints(t *testing.T) {
|
|
newRunner := func() *Runner {
|
|
return NewRunner(
|
|
&fakePromptRepo{def: promptDef(domain.FormatText, domain.ValidationNone, 0)},
|
|
&fakeExecutionProfileRepo{profiles: map[string]*domain.ExecutionProfile{"exec": defaultExecutionProfile()}},
|
|
nil,
|
|
defaultArtifactReader(),
|
|
defaultRenderer(),
|
|
&fakeLLM{forbid: true},
|
|
nil,
|
|
nil,
|
|
)
|
|
}
|
|
|
|
invalidEndpoints := []string{
|
|
"/v1",
|
|
"https:///v1",
|
|
"ftp://provider.example/v1",
|
|
"https://user@provider.example/v1",
|
|
"https://provider.example/v1?mode=chat",
|
|
"https://provider.example/v1#chat",
|
|
}
|
|
for _, endpoint := range invalidEndpoints {
|
|
t.Run(endpoint, func(t *testing.T) {
|
|
_, err := newRunner().PrepareExecution(context.Background(), domain.RunRequest{
|
|
PromptID: "p",
|
|
ProfileID: "exec",
|
|
Inputs: singleInputRef(),
|
|
Execution: &domain.ExecutionTargetOverride{Endpoint: endpoint},
|
|
})
|
|
if !errors.Is(err, ErrInvalidRequest) {
|
|
t.Fatalf("expected ErrInvalidRequest, got %v", err)
|
|
}
|
|
})
|
|
}
|
|
|
|
prepared, err := newRunner().PrepareExecution(context.Background(), domain.RunRequest{
|
|
PromptID: "p",
|
|
ProfileID: "exec",
|
|
Inputs: singleInputRef(),
|
|
Execution: &domain.ExecutionTargetOverride{Endpoint: " https://provider.example/nested/v1 "},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("prepare normalized endpoint: %v", err)
|
|
}
|
|
if got := prepared.Details().EffectiveModelParams.Endpoint; got != "https://provider.example/nested/v1" {
|
|
t.Fatalf("effective endpoint = %q", got)
|
|
}
|
|
}
|