Centralize execution setting and session validation

This commit is contained in:
2026-08-11 21:12:56 +00:00
parent 5ccfa4a345
commit 8cfc71c351
18 changed files with 345 additions and 104 deletions

View File

@@ -12,6 +12,7 @@ import (
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
"testing"
"testing/fstest"
@@ -1792,6 +1793,35 @@ func TestWithProfilesRejectsDuplicateIDs(t *testing.T) {
}
}
func TestWithProfilesRejectsInvalidExecutionSettings(t *testing.T) {
type testCase struct {
name string
profile promptkit.Profile
}
tests := []testCase{
{name: "non-finite temperature", profile: promptkit.Profile{Temperature: math.NaN()}},
{name: "non-finite top p", profile: promptkit.Profile{TopP: math.Inf(-1)}},
}
if strconv.IntSize == 64 {
durationLimit := int64(math.MaxInt64 / int64(time.Second))
tests = append(tests, testCase{name: "unrepresentable timeout", profile: promptkit.Profile{TimeoutSeconds: int(durationLimit) + 1}})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.profile.ID = "invalid-settings"
tt.profile.Endpoint = "http://example.test/v1"
tt.profile.Model = "model"
_, err := promptkit.NewEngine(promptkit.Config{PromptDir: frameworkPromptDir},
promptkit.WithProfiles(tt.profile),
)
if !errors.Is(err, promptkit.ErrInvalidConfig) {
t.Fatalf("expected ErrInvalidConfig, got %v", err)
}
})
}
}
func TestOpenAICompatibleProfileRunsThroughNormalProfilePath(t *testing.T) {
fake := &fakeLLMClient{response: &promptkit.GenerateResponse{Content: "ok"}}
prof := promptkit.OpenAICompatibleProfile(promptkit.OpenAICompatibleProfileConfig{