Migrate engine tests to captured configuration
This commit is contained in:
@@ -502,6 +502,9 @@ rather than the removed private storage representation.
|
|||||||
|
|
||||||
## Stage 11 — Migrate Internal Engine And Execution Tests
|
## Stage 11 — Migrate Internal Engine And Execution Tests
|
||||||
|
|
||||||
|
Status: complete. Internal engine and use-case tests passed under the race
|
||||||
|
detector using registered loads and captured configuration.
|
||||||
|
|
||||||
Focus: existing `internal/engine` and `internal/usecase` tests and their fixtures.
|
Focus: existing `internal/engine` and `internal/usecase` tests and their fixtures.
|
||||||
|
|
||||||
1. Change internal request replacements to the new input type and pointer
|
1. Change internal request replacements to the new input type and pointer
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import (
|
|||||||
|
|
||||||
"go.maximumdirect.net/configkit"
|
"go.maximumdirect.net/configkit"
|
||||||
"go.maximumdirect.net/promptkit/internal/domain"
|
"go.maximumdirect.net/promptkit/internal/domain"
|
||||||
|
testconfiguration "go.maximumdirect.net/promptkit/internal/testsupport/configuration"
|
||||||
)
|
)
|
||||||
|
|
||||||
func engineSmokeBackendInput() configkit.Input {
|
func engineSmokeBackendInput() configkit.Input {
|
||||||
return configkit.Input{Source: configkit.Mapping("smoke-test backend", map[string]any{
|
return configkit.Input{Destination: configkit.Keys("promptkit"), Source: configkit.Mapping("smoke-test backend", map[string]any{
|
||||||
"backends": []any{map[string]any{"id": "test-backend",
|
"backends": []any{map[string]any{"id": "test-backend",
|
||||||
"endpoint": "https://test-backend.example/v1",
|
"endpoint": "https://test-backend.example/v1",
|
||||||
"smoke_tests": map[string]any{
|
"smoke_tests": map[string]any{
|
||||||
@@ -38,7 +39,11 @@ func TestEngineSmokeTestUsesInjectedGenerationWithoutHTTPSupport(t *testing.T) {
|
|||||||
return &domain.GenerateResponse{Content: "engine response"}, nil
|
return &domain.GenerateResponse{Content: "engine response"}, nil
|
||||||
}))
|
}))
|
||||||
input := engineSmokeBackendInput()
|
input := engineSmokeBackendInput()
|
||||||
assembled, err := New(Config{Sources: ConfigurationSources{Main: &input}}, options)
|
snapshot, err := testconfiguration.Capture(input, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assembled, err := New(snapshot, Config{}, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -78,7 +83,11 @@ func TestEngineSmokeTestUsesBuiltInHTTPClientForInferenceEvidence(t *testing.T)
|
|||||||
var authorization string
|
var authorization string
|
||||||
options := Options{}
|
options := Options{}
|
||||||
input := engineSmokeBackendInput()
|
input := engineSmokeBackendInput()
|
||||||
assembled, err := New(Config{Sources: ConfigurationSources{Main: &input}, HTTPClient: &http.Client{Transport: engineRoundTripperFunc(func(request *http.Request) (*http.Response, error) {
|
snapshot, err := testconfiguration.Capture(input, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assembled, err := New(snapshot, Config{HTTPClient: &http.Client{Transport: engineRoundTripperFunc(func(request *http.Request) (*http.Response, error) {
|
||||||
observedURL = request.URL.String()
|
observedURL = request.URL.String()
|
||||||
authorization = request.Header.Get("Authorization")
|
authorization = request.Header.Get("Authorization")
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
|
|||||||
40
internal/testsupport/configuration/configuration.go
Normal file
40
internal/testsupport/configuration/configuration.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// Package configuration supplies construction helpers for internal tests.
|
||||||
|
package configuration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
adapter "go.maximumdirect.net/promptkit/internal/configuration"
|
||||||
|
"go.maximumdirect.net/promptkit/internal/settings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type application struct {
|
||||||
|
PromptKit settings.Settings `yaml:"promptkit"`
|
||||||
|
Other map[string]any `yaml:",inline"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capture loads the provided native inputs with component rules and captures
|
||||||
|
// the resulting resources. Inputs specify their own destinations and context.
|
||||||
|
func Capture(main configkit.Input, underlays []configkit.Underlay) (*adapter.Snapshot, error) {
|
||||||
|
definition := configkit.Definition[application]{
|
||||||
|
SequenceIdentities: adapter.SequenceIdentities(),
|
||||||
|
Sensitive: adapter.Sensitive,
|
||||||
|
Resolve: func(value *application, resolution *configkit.Resolution) error {
|
||||||
|
adapter.Resolve(&value.PromptKit, resolution)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Validate: func(value *application, validation *configkit.Validation) {
|
||||||
|
adapter.Validate(&value.PromptKit, validation)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
result, err := configkit.LoadLayered(main, configkit.LayeredOptions[application]{Definition: definition, Underlays: underlays})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
view, ok := result.InspectSubtree(configkit.Keys("promptkit"))
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("configuration inspection unavailable")
|
||||||
|
}
|
||||||
|
return adapter.Capture(&result.Config.PromptKit, view, result.Diagnostics())
|
||||||
|
}
|
||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.maximumdirect.net/configkit"
|
"go.maximumdirect.net/configkit"
|
||||||
"go.maximumdirect.net/promptkit/internal/configuration"
|
|
||||||
"go.maximumdirect.net/promptkit/internal/domain"
|
"go.maximumdirect.net/promptkit/internal/domain"
|
||||||
"go.maximumdirect.net/promptkit/internal/profile"
|
"go.maximumdirect.net/promptkit/internal/profile"
|
||||||
|
"go.maximumdirect.net/promptkit/internal/testsupport/configuration"
|
||||||
"go.maximumdirect.net/promptkit/internal/validate"
|
"go.maximumdirect.net/promptkit/internal/validate"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ func TestResolveSmokeTestTargetSelectionAndRouting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveSmokeTestTargetBackendOnlyDoesNotLoadDefaultProfile(t *testing.T) {
|
func TestResolveSmokeTestTargetBackendOnlyDoesNotLoadDefaultProfile(t *testing.T) {
|
||||||
loaded, err := configuration.Load(configkit.Input{Source: configkit.Mapping("selection", smokeSelectionConfig())}, nil)
|
loaded, err := configuration.Capture(configkit.Input{Source: configkit.Mapping("selection", smokeSelectionConfig()), Destination: configkit.Keys("promptkit")}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -305,7 +305,7 @@ func TestResolveSmokeTestTargetSelectionAndSettingsErrors(t *testing.T) {
|
|||||||
|
|
||||||
func newSmokeSelectionRunner(t *testing.T) (*Runner, *selectionTestCollaborators) {
|
func newSmokeSelectionRunner(t *testing.T) (*Runner, *selectionTestCollaborators) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
loaded, err := configuration.Load(configkit.Input{Source: configkit.Mapping("selection", smokeSelectionConfig())}, nil)
|
loaded, err := configuration.Capture(configkit.Input{Source: configkit.Mapping("selection", smokeSelectionConfig()), Destination: configkit.Keys("promptkit")}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("load captured selection configuration: %v", err)
|
t.Fatalf("load captured selection configuration: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
"go.maximumdirect.net/promptkit/internal/configuration"
|
|
||||||
"go.maximumdirect.net/promptkit/internal/domain"
|
"go.maximumdirect.net/promptkit/internal/domain"
|
||||||
"go.maximumdirect.net/promptkit/internal/llm"
|
"go.maximumdirect.net/promptkit/internal/llm"
|
||||||
"go.maximumdirect.net/promptkit/internal/observation"
|
"go.maximumdirect.net/promptkit/internal/observation"
|
||||||
|
"go.maximumdirect.net/promptkit/internal/testsupport/configuration"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSmokeTesterAssemblesReachabilityReportWithoutGenerationAdmission(t *testing.T) {
|
func TestSmokeTesterAssemblesReachabilityReportWithoutGenerationAdmission(t *testing.T) {
|
||||||
@@ -350,7 +350,7 @@ func TestSmokeTesterKeepsCompletedAuthenticationWhenCloseCancelsCaller(t *testin
|
|||||||
|
|
||||||
func smokeTesterRunner(t *testing.T, values map[string]any) *Runner {
|
func smokeTesterRunner(t *testing.T, values map[string]any) *Runner {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
loaded, err := configuration.Load(configkit.Input{Source: configkit.Mapping("smoke-test", values)}, nil)
|
loaded, err := configuration.Capture(configkit.Input{Source: configkit.Mapping("smoke-test", values), Destination: configkit.Keys("promptkit")}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user