Remove superseded configuration loaders and consolidate runtime tests
This commit is contained in:
@@ -12,8 +12,8 @@ import (
|
||||
"testing/fstest"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/promptkit"
|
||||
"gitea.maximumdirect.net/eric/promptkit/testfixture"
|
||||
)
|
||||
|
||||
func observedHTTPResponse(status int, body string) *http.Response {
|
||||
@@ -29,7 +29,7 @@ func TestPublicRetryRepairSequenceKeepsUsageAndEventsConsistent(t *testing.T) {
|
||||
}
|
||||
var calls int
|
||||
one := 1
|
||||
config := contractConfig(frameworkSchemaDir)
|
||||
config := simpleConfig("message")
|
||||
config.TransientRetries = &one
|
||||
config.HTTPClient = &http.Client{Transport: roundTripFunc(func(*http.Request) (*http.Response, error) {
|
||||
if calls >= len(responses) {
|
||||
@@ -40,12 +40,12 @@ func TestPublicRetryRepairSequenceKeepsUsageAndEventsConsistent(t *testing.T) {
|
||||
calls++
|
||||
return r, nil
|
||||
})}
|
||||
engine, err := testfixture.NewEngine(config)
|
||||
engine, err := promptkit.NewEngine(config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var events []promptkit.ExecutionEvent
|
||||
req := generationErrorRunRequest()
|
||||
req := simpleGenerationRequest()
|
||||
req.Validation = &promptkit.OutputContract{Format: promptkit.FormatJSON, ValidationMode: promptkit.ValidationJSON, RepairAttempts: 1}
|
||||
req.Observer = func(event promptkit.ExecutionEvent) { events = append(events, event) }
|
||||
result, err := engine.Run(context.Background(), req)
|
||||
@@ -82,6 +82,18 @@ func TestPublicRetryRepairSequenceKeepsUsageAndEventsConsistent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func reliabilityConfig(backends, profiles map[string]any) promptkit.Config {
|
||||
return promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{Source: configkit.Mapping("reliable execution", map[string]any{
|
||||
"backends": backends,
|
||||
"profiles": profiles,
|
||||
"prompts": map[string]any{"prompt": map[string]any{"1": map[string]any{
|
||||
"default_profile": "profile-a",
|
||||
"messages": []any{map[string]any{"role": "user", "content": "hello"}},
|
||||
"output": map[string]any{"format": "text", "validation_mode": "none"},
|
||||
}}},
|
||||
})}}}
|
||||
}
|
||||
|
||||
func TestProfilesSharingBackendCoordinateRetryRepairAndAdmission(t *testing.T) {
|
||||
firstA := make(chan struct{})
|
||||
enteredB := make(chan struct{})
|
||||
@@ -125,10 +137,14 @@ func TestProfilesSharingBackendCoordinateRetryRepairAndAdmission(t *testing.T) {
|
||||
}
|
||||
})
|
||||
one := 1
|
||||
engine, err := testfixture.NewEngine(testfixture.Config{HTTPClient: &http.Client{Transport: transport}, TransientRetries: &one},
|
||||
testfixture.WithPromptFS(contractPromptFS("prompt", "profile-a", "hello"), "."),
|
||||
testfixture.WithBackend(testfixture.Backend{ID: "limited", Endpoint: "https://example.invalid/v1", ConcurrencyLimit: 1, QueueCapacity: &one}),
|
||||
testfixture.WithProfiles(testfixture.Profile{ID: "profile-a", BackendID: "limited", Model: "model-a"}, testfixture.Profile{ID: "profile-b", BackendID: "limited", Model: "model-b"}))
|
||||
config := reliabilityConfig(map[string]any{"limited": map[string]any{
|
||||
"endpoint": "https://example.invalid/v1", "concurrency_limit": 1, "queue_capacity": 1,
|
||||
}}, map[string]any{
|
||||
"profile-a": map[string]any{"backend": "limited", "model": "model-a"},
|
||||
"profile-b": map[string]any{"backend": "limited", "model": "model-b"},
|
||||
})
|
||||
config.HTTPClient, config.TransientRetries = &http.Client{Transport: transport}, &one
|
||||
engine, err := promptkit.NewEngine(config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -187,11 +203,15 @@ func TestDifferentBackendPoolsCanDispatchTogether(t *testing.T) {
|
||||
return observedHTTPResponse(200, `{"choices":[{"message":{"content":"ok"}}]}`), nil
|
||||
})
|
||||
zero := 0
|
||||
engine, err := testfixture.NewEngine(testfixture.Config{HTTPClient: &http.Client{Transport: transport}, TransientRetries: &zero},
|
||||
testfixture.WithPromptFS(contractPromptFS("prompt", "profile-a", "hello"), "."),
|
||||
testfixture.WithBackend(testfixture.Backend{ID: "backend-a", Endpoint: "https://example.invalid/v1", ConcurrencyLimit: 1, QueueCapacity: &zero}),
|
||||
testfixture.WithBackend(testfixture.Backend{ID: "backend-b", Endpoint: "https://example.invalid/v1", ConcurrencyLimit: 1, QueueCapacity: &zero}),
|
||||
testfixture.WithProfiles(testfixture.Profile{ID: "profile-a", BackendID: "backend-a", Model: "model-a"}, testfixture.Profile{ID: "profile-b", BackendID: "backend-b", Model: "model-b"}))
|
||||
config := reliabilityConfig(map[string]any{
|
||||
"backend-a": map[string]any{"endpoint": "https://example.invalid/v1", "concurrency_limit": 1, "queue_capacity": 0},
|
||||
"backend-b": map[string]any{"endpoint": "https://example.invalid/v1", "concurrency_limit": 1, "queue_capacity": 0},
|
||||
}, map[string]any{
|
||||
"profile-a": map[string]any{"backend": "backend-a", "model": "model-a"},
|
||||
"profile-b": map[string]any{"backend": "backend-b", "model": "model-b"},
|
||||
})
|
||||
config.HTTPClient, config.TransientRetries = &http.Client{Transport: transport}, &zero
|
||||
engine, err := promptkit.NewEngine(config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -230,7 +250,17 @@ func TestDifferentBackendPoolsCanDispatchTogether(t *testing.T) {
|
||||
func TestPreparedRetriesFreezeSourceAndCredentialAtExecution(t *testing.T) {
|
||||
const envName = "PROMPTKIT_PREPARED_RETRY_KEY"
|
||||
t.Setenv(envName, "first-key")
|
||||
source := contractPromptFS("prompt", "profile", "original message")
|
||||
source := fstest.MapFS{"prompt.yaml": &fstest.MapFile{Data: []byte(`prompts:
|
||||
prompt:
|
||||
"1":
|
||||
default_profile: profile
|
||||
messages:
|
||||
- role: user
|
||||
content: original message
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)}}
|
||||
var calls int
|
||||
var auth, content []string
|
||||
transport := roundTripFunc(func(req *http.Request) (*http.Response, error) {
|
||||
@@ -252,8 +282,20 @@ func TestPreparedRetriesFreezeSourceAndCredentialAtExecution(t *testing.T) {
|
||||
return observedHTTPResponse(200, `{"choices":[{"message":{"content":"ok"}}]}`), nil
|
||||
})
|
||||
one := 1
|
||||
engine, err := testfixture.NewEngine(testfixture.Config{HTTPClient: &http.Client{Transport: transport}, TransientRetries: &one},
|
||||
testfixture.WithPromptFS(source, "."), testfixture.WithProfiles(testfixture.Profile{ID: "profile", Endpoint: "https://example.invalid/v1", Model: "model"}))
|
||||
inputs, err := promptkit.FilesystemInputs("prompts", source, ".")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, model := "https://example.invalid/v1", "model"
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{
|
||||
Sources: promptkit.ConfigurationSources{Underlays: []configkit.Underlay{
|
||||
{Inputs: inputs},
|
||||
{Inputs: []configkit.Input{{Source: promptkit.ProfileSource("profile", map[string]promptkit.ProfileConfig{
|
||||
"profile": {Endpoint: &endpoint, Model: &model},
|
||||
})}}},
|
||||
}},
|
||||
HTTPClient: &http.Client{Transport: transport}, TransientRetries: &one,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -262,15 +304,16 @@ func TestPreparedRetriesFreezeSourceAndCredentialAtExecution(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source["prompt.yaml"] = &fstest.MapFile{Data: []byte(`id: prompt
|
||||
version: "1"
|
||||
default_profile: profile
|
||||
messages:
|
||||
- role: user
|
||||
content: changed message
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
source["prompt.yaml"] = &fstest.MapFile{Data: []byte(`prompts:
|
||||
prompt:
|
||||
"1":
|
||||
default_profile: profile
|
||||
messages:
|
||||
- role: user
|
||||
content: changed message
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)}
|
||||
result, err := engine.RunPrepared(context.Background(), prepared)
|
||||
if err != nil || result == nil || calls != 2 {
|
||||
@@ -290,7 +333,7 @@ func TestPublicNonretryableAndInjectedAttemptsStaySingle(t *testing.T) {
|
||||
three := 3
|
||||
engine, calls := retryTestEngine(t, &three, func(int) *http.Response { return retryHTTPResponse(400, "") })
|
||||
var events []promptkit.ExecutionEvent
|
||||
req := generationErrorRunRequest()
|
||||
req := simpleGenerationRequest()
|
||||
req.Observer = func(event promptkit.ExecutionEvent) { events = append(events, event) }
|
||||
result, err := engine.Run(context.Background(), req)
|
||||
if result != nil || !errors.Is(err, promptkit.ErrLLMGenerate) || errors.Is(err, promptkit.ErrRetriesExhausted) || *calls != 1 || len(events) != 3 {
|
||||
@@ -314,7 +357,7 @@ func TestPublicExhaustionObservationRetainsProviderCause(t *testing.T) {
|
||||
one := 1
|
||||
engine, calls := retryTestEngine(t, &one, func(int) *http.Response { return retryHTTPResponse(503, "") })
|
||||
var events []promptkit.ExecutionEvent
|
||||
req := generationErrorRunRequest()
|
||||
req := simpleGenerationRequest()
|
||||
req.Observer = func(event promptkit.ExecutionEvent) { events = append(events, event) }
|
||||
result, err := engine.Run(context.Background(), req)
|
||||
var exhausted *promptkit.RetryExhaustedError
|
||||
@@ -334,7 +377,7 @@ func TestPublicObserverCancellationStopsBeforeRetry(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
var events []promptkit.ExecutionEvent
|
||||
req := generationErrorRunRequest()
|
||||
req := simpleGenerationRequest()
|
||||
req.Observer = func(event promptkit.ExecutionEvent) {
|
||||
events = append(events, event)
|
||||
if event.Kind == promptkit.ExecutionAttempt {
|
||||
|
||||
Reference in New Issue
Block a user