Cut over public engine construction to ConfigKit sources
This commit is contained in:
@@ -10,13 +10,14 @@ import (
|
||||
"testing/fstest"
|
||||
|
||||
"gitea.maximumdirect.net/eric/promptkit"
|
||||
"gitea.maximumdirect.net/eric/promptkit/testfixture"
|
||||
)
|
||||
|
||||
func TestProfileInheritanceBuiltInAliasWorkflow(t *testing.T) {
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{
|
||||
engine, err := testfixture.NewEngine(testfixture.Config{
|
||||
PromptDir: frameworkPromptDir,
|
||||
SchemaDir: frameworkSchemaDir,
|
||||
}, promptkit.WithProfiles(promptkit.Profile{
|
||||
}, testfixture.WithProfiles(testfixture.Profile{
|
||||
ID: "weather-light",
|
||||
BaseProfileID: "promptkit-openrouter-standard",
|
||||
ReasoningEffort: "high",
|
||||
@@ -81,9 +82,9 @@ func TestProfileInheritanceBuiltInAliasWorkflow(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProfileInheritanceYAMLAliasOfBuiltIn(t *testing.T) {
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{},
|
||||
promptkit.WithPromptFS(fstest.MapFS{}, "."),
|
||||
promptkit.WithProfileFS(fstest.MapFS{
|
||||
engine, err := testfixture.NewEngine(testfixture.Config{},
|
||||
testfixture.WithPromptFS(fstest.MapFS{}, "."),
|
||||
testfixture.WithProfileFS(fstest.MapFS{
|
||||
"alias.yaml": &fstest.MapFile{Data: []byte("id: yaml-alias\nbase_profile: promptkit-openrouter-standard\n")},
|
||||
}, "."),
|
||||
)
|
||||
@@ -100,21 +101,21 @@ func TestProfileInheritanceYAMLAliasOfBuiltIn(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProfileInheritanceRetainsRequiredCredentialBehavior(t *testing.T) {
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{},
|
||||
promptkit.WithPromptFS(fstest.MapFS{}, "."),
|
||||
promptkit.WithBackend(promptkit.Backend{
|
||||
engine, err := testfixture.NewEngine(testfixture.Config{},
|
||||
testfixture.WithPromptFS(fstest.MapFS{}, "."),
|
||||
testfixture.WithBackend(testfixture.Backend{
|
||||
ID: "credential-backend",
|
||||
Endpoint: "https://credential.example/v1",
|
||||
APIKeyEnv: "OPTIONAL_BACKEND_KEY",
|
||||
}),
|
||||
promptkit.WithProfiles(
|
||||
promptkit.Profile{
|
||||
testfixture.WithProfiles(
|
||||
testfixture.Profile{
|
||||
ID: "credential-base",
|
||||
BackendID: "credential-backend",
|
||||
Model: "model",
|
||||
APIKeyRequired: true,
|
||||
},
|
||||
promptkit.Profile{ID: "credential-child", BaseProfileID: "credential-base"},
|
||||
testfixture.Profile{ID: "credential-child", BaseProfileID: "credential-base"},
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
@@ -130,17 +131,13 @@ func TestProfileInheritanceRetainsRequiredCredentialBehavior(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProfileInheritancePreservesPublicErrorIdentities(t *testing.T) {
|
||||
newEngine := func(t *testing.T, profiles fs.FS) *promptkit.Engine {
|
||||
newEngine := func(t *testing.T, profiles fs.FS) (*promptkit.Engine, error) {
|
||||
t.Helper()
|
||||
options := []promptkit.Option{promptkit.WithPromptFS(fstest.MapFS{}, ".")}
|
||||
options := []any{testfixture.WithPromptFS(fstest.MapFS{}, ".")}
|
||||
if profiles != nil {
|
||||
options = append(options, promptkit.WithProfileFS(profiles, "."))
|
||||
options = append(options, testfixture.WithProfileFS(profiles, "."))
|
||||
}
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{}, options...)
|
||||
if err != nil {
|
||||
t.Fatalf("construct engine: %v", err)
|
||||
}
|
||||
return engine
|
||||
return testfixture.NewEngine(testfixture.Config{}, options...)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -181,7 +178,17 @@ func TestProfileInheritancePreservesPublicErrorIdentities(t *testing.T) {
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result, err := newEngine(t, tc.profiles).InspectProfile(context.Background(), tc.profile)
|
||||
engine, err := newEngine(t, tc.profiles)
|
||||
if tc.profiles != nil {
|
||||
if engine != nil || !errors.Is(err, promptkit.ErrInvalidConfig) {
|
||||
t.Fatalf("construction = (%#v, %v), want invalid configuration", engine, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("construct engine: %v", err)
|
||||
}
|
||||
result, err := engine.InspectProfile(context.Background(), tc.profile)
|
||||
if result != nil || !errors.Is(err, tc.want) || (tc.wantNot != nil && errors.Is(err, tc.wantNot)) {
|
||||
t.Fatalf("inspection=(%+v, %v), want %v without %v", result, err, tc.want, tc.wantNot)
|
||||
}
|
||||
@@ -200,9 +207,9 @@ func TestProfileInheritanceFreezesPreparedExecution(t *testing.T) {
|
||||
"base.yaml": &fstest.MapFile{Data: []byte("id: base\nendpoint: https://base.example/v1\nmodel: first-model\n")},
|
||||
}}
|
||||
client := &fakeLLMClient{response: &promptkit.GenerateResponse{Content: "ok"}}
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{},
|
||||
promptkit.WithPromptFS(contractPromptFS("prepared", "child", "content"), "."),
|
||||
promptkit.WithProfileFS(profiles, "."),
|
||||
engine, err := testfixture.NewEngine(testfixture.Config{},
|
||||
testfixture.WithPromptFS(contractPromptFS("prepared", "child", "content"), "."),
|
||||
testfixture.WithProfileFS(profiles, "."),
|
||||
promptkit.WithLLMClient(client),
|
||||
)
|
||||
if err != nil {
|
||||
@@ -220,8 +227,8 @@ func TestProfileInheritanceFreezesPreparedExecution(t *testing.T) {
|
||||
t.Fatalf("prepared execution=(%+v, %v), requests=%+v", result, err, client.requests)
|
||||
}
|
||||
inspection, err := engine.InspectProfile(context.Background(), "child")
|
||||
if err != nil || inspection.EffectiveModelParams.Model != "second-model" {
|
||||
t.Fatalf("fresh inspection=(%+v, %v)", inspection, err)
|
||||
if err != nil || inspection.EffectiveModelParams.Model != "first-model" {
|
||||
t.Fatalf("existing engine inspection=(%+v, %v)", inspection, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user